RDF2Go/Binding
From semanticweb.org
RDF2Go has several ways to configure, which triple store driver (aka adapter) to use.
Contents |
[edit] Register a ModelFactory
RDF2Go.getModelFactory() does two things:
- First, it looks if anybody had explicitly registered a ModelFactory to be used via RDF2Go.
// register adapter of implementation XYZ, could be Jena or Sesame or anything. RDF2Go.register( new org.ontoware.rdf2go.impl.XYZ.ModelFactoryImpl() );
// start using RDF2Go Model m = RDF2Go.getModelFactory().createModel();
See also API docs of RDF2Go.class.
[edit] Static Binding
As a fallback, if no RDF2Go.register(..) was ever called, RDF2Go looks for a static binding, that is, it loads the class org.ontoware.rdf2go.impl.StaticBinding - wherever that is found on the classpath. The Sesame adapters e.g. contain such a class.
THis idea is dea stolen from slf4j, look in their [http://www.slf4j.org/faq.html FAQ). This is the most elegant way, with no triple store specific code at all.
Any explicitly registered ModelFactory will be used before RDF2Go looks in the classpath.
[edit] OSGi
Third, one can use OSGI to do that.
[edit] Use a ModelFactory directly
Fourth, one can completely ignore the RDF2Go.class and direclty use a certain ModelFactory, e.g.
MyStoreFactory.createModel().
[edit] Create Model directly, wrap later
Fifth, one can ignore the idea of Factories alltogether, and configure a certain
x = MyStoreSpecificModel( .. );
by hand and only wrap it later, by calling
new MyStoreRDF2GoModel( x );
An example for Sesame
// create native store
NativeStore ns = new NativeStore(storageDir);
// add many indexec = vendor-specific configuration
ns.setParameter("triple-indexes", "spoc, posc, sopc, psoc, ospc, opsc");
Repository myRepository = new SailRepository(ns);
myRepository.initialize();
// wrap Sesame in an RDF2Go adapter ModelSet rdf2goModelSet = new RepositoryModelSet(myRepository);
// open rdf2goModelSet.open();
