javardfsesame

Building AliBaba java example


Good evening,

I am new to Java Persistence API and I would like to test AliBaba to see what it could do. AliBaba website. I read part of the exemple given here. I have the whole AliBaba project and two files for the exemple, I modified a little the exemple.

//Document.java
package org.openrdf.example;

import org.openrdf.annotations.Iri;

@Iri(Document.NS + "Document")
public class Document {
public static final String NS = "http://meta.leighnet.ca/rdf/2009/gs#";

@Iri(NS + "title") String title;

public String getTitle() {
    return title;
}
public void setTitle(String title) {
    this.title = title;
}
}

And my other file:

//my Main with many imports
public class Main {
public static void main(String[] args) throws java.lang.IllegalAccessException {
    // create a Document
    Document doc = new Document();
    // give it a title
    doc.setTitle("Getting Started");
    System.out.println("Title of the new document: "+doc.getTitle());
    
    // add a Document to the repository
    ObjectConnection con = repository.getConnection();
    // the problem is here

My problem is located in the line:

ObjectConnection con = repository.getConnection();

I have nowhere a declaration of 'repository'. But I get an error for the object type.

Thank you for you help, i hope my writting is understandable as it is my first post here.


Solution

  • You can create an in-memory Sesame repository like this:

    // create a repository
    Repository store = new SailRepository(new MemoryStore());
    store.initialize();
    
    // wrap in an object repository
    ObjectRepositoryFactory factory = new ObjectRepositoryFactory();
    ObjectRepository repository = factory.createRepository(store);