Lyo Store is a library that provides a simple interface for working with a triplestore via Java objects representing OSLC Resources. Lyo Store and Jena Models in the triple stores.
- For an in-memory option: JVM heap should be set to 1G or above (see Jena documentation for more information on this).
- For an on-disk option: an empty writable folder on disk, around 200MB of space is pre-allocated.
- For a SPARQL option: a pair of SPARQL Query and SPARQL Update URLs, optionally with basic authentication.
<dependency>
<groupId>org.eclipse.lyo.store</groupId>
<artifactId>store-core</artifactId>
<version>2.2.0</version>
</dependency>
String sparqlQueryEndpoint = properties.getProperty("sparqlQueryEndpoint");
String sparqlUpdateEndpoint = properties.getProperty("sparqlUpdateEndpoint");
Store store = StoreFactory.sparql(sparqlQueryEndpoint, sparqlUpdateEndpoint);
String storeDirProp = properties.getProperty("storeDir");
Path storeDir = Paths.get(storeDirProp);
Store store = StoreFactory.onDisk(storeDir);
Store store = StoreFactory.inMemory();
try {
store.updateResources(GRAPH_NAME, // URI of the named graph
resourceArray); // an array of OSLC Resources
} catch (StoreAccessException e) {
logger.error("Error executing a query on a triplestore");
}
if (store.namedGraphExists(GRAPH_NAME)) {
try {
final int limit = 10; // fetch 10 resources
final int offset = 0; // start with the first page
// 'limit+1' is a technique that allows you to determine if there are
// more results on the next page
List<Requirement> requirements = store.getResources(GRAPH_NAME,
Requirement.class, // resources of this class will be fetched and unmarshalled
limit + 1, // resource limit
offset)); // how many resources to skip, use for paging
} catch (StoreAccessException e) {
logger.error("Error executing a query on a triplestore");
} catch ( ModelUnmarshallingException e) {
logger.error("Error unmarshalling the RDF from triplestore into Requirement class instances");
}
}