Package org.eclipse.lyo.store.internals
Class SparqlStoreImpl
java.lang.Object
org.eclipse.lyo.store.internals.SparqlStoreImpl
- All Implemented Interfaces:
Store
Store interface implementation that interacts with any SPARQL-based triplestore
through a Query and Update endpoints.- Since:
- 0.14.0
- Version:
- $version-stub$
- Author:
- Andrew Berezovskyi (andriib@kth.se)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intCould be used to prevent extremely large results -
Constructor Summary
ConstructorsConstructorDescriptionSparqlStoreImpl(String queryEndpoint, String updateEndpoint) Initialises the Store with the endpoints for query and update.SparqlStoreImpl(String queryEndpoint, String updateEndpoint, String username, String password) Initialises the Store with the endpoints for query and update.SparqlStoreImpl(JenaQueryExecutor queryExecutor) Initialises the Store with the customJenaQueryExecutor. -
Method Summary
Modifier and TypeMethodDescription<T extends IResource>
booleanappendResources(URI namedGraph, Collection<T> resources) Adds OSLCIResourceinstances in addition to other instances already present on this named graph into the triplestore.voidDeletes the resources and statements stored under the given named graph from the triplestore.voidclose()Close connectionvoiddeleteResources(URI namedGraphUri, URI... subjectUris) Delete all statements whose subject is one of nodeUrisvoiddeleteResources(URI namedGraphUri, IResource... resources) Delete all statements whose subject is one of the resources's URis.getJenaModelForSubject(URI namedGraphUri, URI subject) Retrieve a JenaModelfor triples under the given subject from the corresponding named graph.<T extends IResource>
TgetResource(URI namedGraphUri, URI resourceUri, Class<T> clazz) Retrieve a singleIResourceinstance specified by the concrete type, unmarshaled from the RDF graph persisted in the triplestore under the given named graph.getResources(URI namedGraph, Class<T> clazz) Retrieve the collection ofIResourceinstances specified by the concrete type, unmarshaled from the RDF graph persisted in the triplestore under the given named graph.getResources(URI namedGraph, Class<T> clazz, int limit, int offset) Alternative toStore.getResources(URI, Class)with paging on the OSLC resource level.getResources(URI namedGraph, Class<T> clazz, String prefixes, String where, String searchTerms, int limit, int offset) Alternative toStore.getResources(URI, Class)with paging on the OSLC resource level.getResources(URI namedGraph, Class<T> clazz, String prefixes, String where, String searchTerms, int limit, int offset, List<String> additionalDistinctVars, org.apache.jena.arq.querybuilder.SelectBuilder additionalQueryFilter) Alternative toStore.getResources(URI, Class, String, String, String, int, int)with additional parameters for inlined resources.getResources(URI namedGraph, String prefixes, String where, int limit, int offset) Retrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html) If thenamedGraphis null, the query is applied on allnamedGraphin the triplestore.getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset) Retrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html) If thenamedGraphis null, the query is applied on allnamedGraphin the triplestore.getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset, List<String> additionalDistinctVars, org.apache.jena.arq.querybuilder.SelectBuilder additionalQueryFilter) Alternative toStore.getResources(URI, String, String, String, int, int)with additional parameters for inlined resources.voidinsertJenaModel(URI namedGraph, Model model) Insert a jena model into the named graph with corresponding URI.booleaninsertResources(URI namedGraph, Object... resources) Insert Jena models representations of OSLCIResourceinstances into the named graph.keySet()Deprecated.booleannamedGraphExists(URI namedGraphUri) Checks if the triplestore has the named graph under the corresponding URI.<T extends IResource>
booleanputResources(URI uri, Collection<T> resources) Inserts OSLCIResourceinstances into the triplestore in the designed namedGraph.voidRemove EVERYTHING from the triplestore.booleanresourceExists(URI namedGraphUri, URI resourceUri) Checks if a resource with resourceUri exists under the corresponding named graph.<T extends IResource>
booleanupdateResources(URI namedGraphUri, T... resources) Insert Jena models representations of OSLCIResourceinstances into the named graph.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.lyo.store.Store
appendResource
-
Field Details
-
TRIPLE_LIMIT
public static final int TRIPLE_LIMITCould be used to prevent extremely large results- See Also:
-
-
Constructor Details
-
SparqlStoreImpl
Initialises the Store with the endpoints for query and update. Must be available over HTTP or HTTPS (TLS & cipher support depends on the JDK version) without authentication.- Parameters:
queryEndpoint- SPARQL QUERY endpointupdateEndpoint- SPARQL UPDATE endpoint
-
SparqlStoreImpl
public SparqlStoreImpl(String queryEndpoint, String updateEndpoint, String username, String password) Initialises the Store with the endpoints for query and update. Must be available over HTTP or HTTPS (TLS & cipher support depends on the JDK version) with authentication via username and password combinations. Authentication works with the basic and digest HTTP authentication schemes.- Parameters:
queryEndpoint- SPARQL QUERY endpointupdateEndpoint- SPARQL UPDATE endpointusername- Usernamepassword- Password
-
SparqlStoreImpl
Initialises the Store with the customJenaQueryExecutor.- Parameters:
queryExecutor- Instance of theJenaQueryExecutorthat can run queries and updates.
-
-
Method Details
-
insertJenaModel
Description copied from interface:StoreInsert a jena model into the named graph with corresponding URI.- Specified by:
insertJenaModelin interfaceStore
-
insertResources
Description copied from interface:StoreInsert Jena models representations of OSLCIResourceinstances into the named graph. existing statements already present in the named graph are not overridden, nor removed.- Specified by:
insertResourcesin interfaceStore- Throws:
StoreAccessException
-
deleteResources
Description copied from interface:StoreDelete all statements whose subject is one of nodeUris- Specified by:
deleteResourcesin interfaceStore
-
deleteResources
Description copied from interface:StoreDelete all statements whose subject is one of the resources's URis.- Specified by:
deleteResourcesin interfaceStore
-
namedGraphExists
Description copied from interface:StoreChecks if the triplestore has the named graph under the corresponding URI.- Specified by:
namedGraphExistsin interfaceStore- Parameters:
namedGraphUri- URI of a named graph that shall be a valid URI and was used before with theput*methods.- Returns:
- does the triplestore contain any resources for a given named graph
-
resourceExists
Description copied from interface:StoreChecks if a resource with resourceUri exists under the corresponding named graph.- Specified by:
resourceExistsin interfaceStore
-
getJenaModelForSubject
Description copied from interface:StoreRetrieve a JenaModelfor triples under the given subject from the corresponding named graph.- Specified by:
getJenaModelForSubjectin interfaceStore- Throws:
NoSuchElementException
-
getResources
public <T extends IResource> List<T> getResources(URI namedGraph, Class<T> clazz) throws StoreAccessException, ModelUnmarshallingException Description copied from interface:StoreRetrieve the collection ofIResourceinstances specified by the concrete type, unmarshaled from the RDF graph persisted in the triplestore under the given named graph. The named graph must represent a URI that was previously given to another method call or a Resource about URI if the resource was saved alone.- Specified by:
getResourcesin interfaceStore- Parameters:
clazz- Concrete type of the stored resources. Must be correct (correspond to the marshaled type and be a subclass ofIResource), otherwise the instantiation from model will not succeed.- Returns:
- A collection of
IResourceinstances, unmarshaled from the RDF graph persisted in the triplestore. - Throws:
StoreAccessException- if there was a problem with the triplestore (or the dataset, more broadly).ModelUnmarshallingException- if the classes cannot be instantiated or another error occurred when working with Jena model.
-
getResources
public <T extends IResource> List<T> getResources(URI namedGraph, Class<T> clazz, int limit, int offset) throws StoreAccessException, ModelUnmarshallingException Description copied from interface:StoreAlternative toStore.getResources(URI, Class)with paging on the OSLC resource level.- Specified by:
getResourcesin interfaceStore- Parameters:
namedGraph- URI of a named graph under which resources were storedclazz- class of the resources being retrievedlimit- paging limitoffset- paging offset- Returns:
- list of OSLC resources, size is less or equal to 'limit'
- Throws:
StoreAccessException- if there was a problem with the triplestore (or the dataset, more broadly).ModelUnmarshallingException- if the classes cannot be instantiated or another error occurred when working with Jena model.
-
getResources
public <T extends IResource> List<T> getResources(URI namedGraph, Class<T> clazz, String prefixes, String where, String searchTerms, int limit, int offset) throws StoreAccessException, ModelUnmarshallingException Description copied from interface:StoreAlternative toStore.getResources(URI, Class)with paging on the OSLC resource level.- Specified by:
getResourcesin interfaceStore- Parameters:
namedGraph- URI of a named graph under which resources were storedclazz- class of the resources being retrievedprefixes- defines the prefixes for prefixed names that appear in the oslc.where query parameter.where- filters the member list, keeping only those member resources that satisfy the boolean test on the member resource properties. (See oslc.where at https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/oslc-query.html)searchTerms- score each member resource using a full text search on it text-valued properties. (See oslc.searchTerms at https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/oslc-query.html)limit- paging limitoffset- paging offset- Returns:
- list of OSLC resources, size is less or equal to 'limit'
- Throws:
StoreAccessException- if there was a problem with the triplestore (or the dataset, more broadly).ModelUnmarshallingException- if the classes cannot be instantiated or another error occurred when working with Jena model.
-
getResources
public <T extends IResource> List<T> getResources(URI namedGraph, Class<T> clazz, String prefixes, String where, String searchTerms, int limit, int offset, List<String> additionalDistinctVars, org.apache.jena.arq.querybuilder.SelectBuilder additionalQueryFilter) throws StoreAccessException, ModelUnmarshallingException Description copied from interface:StoreAlternative toStore.getResources(URI, Class, String, String, String, int, int)with additional parameters for inlined resources. These parameters extend the default query from:DESCRIBE ?s WHERE { ... SELECT distinct ?s WHERE { ?s ?p ?o . ?s rdf:type <http://...> . ... } }to:DESCRIBE ?s ?a ?b WHERE { ... SELECT distinct ?s ?a ?b WHERE { ?s ?p ?o . ?s rdf:type <http://...> . ?s <http://...#prp1> ?a . ?a <http://prp2> ?b } }hence allowing?aand?bto be described, as well as?s. Corresponding parameters to achieve this:List
additionalDistinctVars = new ArrayList (); additionalDistinctVars.add("a"); additionalDistinctVars.add("b"); SelectBuilder additionalQueryFilter = new SelectBuilder(); additionalQueryFilter .addWhere( "?s", new ResourceImpl("http://...#" + "prp1"), "?a") .addWhere( "?a", new ResourceImpl(http://...# + "prp2"), "?b"); - Specified by:
getResourcesin interfaceStore- Parameters:
additionalDistinctVars-additionalQueryFilter-- Throws:
StoreAccessExceptionModelUnmarshallingException
-
getResources
Description copied from interface:StoreRetrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html) If thenamedGraphis null, the query is applied on allnamedGraphin the triplestore. The method currently only provides support for terms of type Comparisons, where the operator is'EQUALS', and the operand is either aStringor aURI.- Specified by:
getResourcesin interfaceStore- Parameters:
namedGraph- namedGraphUri URI of a named graph under which resources were storedprefixes- defines the prefixes for prefixed names that appear in the oslc.where query parameter.where- filters the member list, keeping only those member resources that satisfy the boolean test on the member resource properties. (Seeoslc.whereat https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/oslc-query.html)limit- paging limitoffset- paging offset- Returns:
- list of resources, size is less or equal to 'limit'
-
getResources
public Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset) Description copied from interface:StoreRetrieve a Jena model that satisfies the given where parameter as defined in the OSLC Query language (https://tools.oasis-open.org/version-control/svn/oslc-core/trunk/specs/oslc-query.html) If thenamedGraphis null, the query is applied on allnamedGraphin the triplestore. The method currently only provides support for terms of type Comparisons, where the operator is'EQUALS', and the operand is either aStringor aURI.- Specified by:
getResourcesin interfaceStore- Parameters:
namedGraph- namedGraphUri URI of a named graph under which resources were storedprefixes- defines the prefixes for prefixed names that appear in theoslc.wherequery parameter.where- filters the member list, keeping only those member resources that satisfy the boolean test on the member resource properties. (Seeoslc.whereat https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/oslc-query.html)searchTerms- score each member resource using a full text search on it text-valued properties. (Seeoslc.searchTermsat https://tools.oasis-open.org/version-control/browse/wsvn/oslc-core/trunk/specs/oslc-query.html)limit- paging limitoffset- paging offset- Returns:
- a Jena
Modelwith the less than or equal tolimitresources.
-
getResources
public Model getResources(URI namedGraph, String prefixes, String where, String searchTerms, int limit, int offset, List<String> additionalDistinctVars, org.apache.jena.arq.querybuilder.SelectBuilder additionalQueryFilter) Description copied from interface:StoreAlternative toStore.getResources(URI, String, String, String, int, int)with additional parameters for inlined resources. SeeStore.getResources(URI, Class, String, String, String, int, int, List, SelectBuilder)for an explanation of these additional parameters.- Specified by:
getResourcesin interfaceStore
-
getResource
public <T extends IResource> T getResource(URI namedGraphUri, URI resourceUri, Class<T> clazz) throws NoSuchElementException, StoreAccessException, ModelUnmarshallingException Description copied from interface:StoreRetrieve a singleIResourceinstance specified by the concrete type, unmarshaled from the RDF graph persisted in the triplestore under the given named graph. namedGraph must represent a URI that was previously given to another call.- Specified by:
getResourcein interfaceStore- Parameters:
namedGraphUri- URI of a named graph under which resources were storedclazz- Java class of the stored resources.- Returns:
- An
IResourceinstance, unmarshaled from the RDF graph persisted in the triplestore. - Throws:
NoSuchElementException- if the resource is not present under a given named graph URI or if the named graph itself contains no resources (effectively missing).StoreAccessException- if there was a problem with the triplestore (or the dataset, more broadly).ModelUnmarshallingException- if the classes cannot be instantiated or another error occurred when working with Jena model.
-
updateResources
public <T extends IResource> boolean updateResources(URI namedGraphUri, T... resources) throws StoreAccessException Description copied from interface:StoreInsert Jena models representations of OSLCIResourceinstances into the named graph. Any existing model representations of these instances are overridden. other existing statements in the named graph are not overridden, nor removed.- Specified by:
updateResourcesin interfaceStore- Throws:
StoreAccessException
-
putResources
public <T extends IResource> boolean putResources(URI uri, Collection<T> resources) throws StoreAccessException Description copied from interface:StoreInserts OSLCIResourceinstances into the triplestore in the designed namedGraph.Any previously stored resource(s) and/or statements will be overwritten.
- Specified by:
putResourcesin interfaceStore- Parameters:
uri- A unique URI that is used as a named graph to which resources are appendedresources- A collection ofIResourceinstances- Returns:
- Operation success
- Throws:
StoreAccessException- if the operation can't be performed
-
appendResources
public <T extends IResource> boolean appendResources(URI namedGraph, Collection<T> resources) throws StoreAccessException Description copied from interface:StoreAdds OSLCIResourceinstances in addition to other instances already present on this named graph into the triplestore. Jena models representing existing and added resource arrays will be combined.- Specified by:
appendResourcesin interfaceStore- Parameters:
namedGraph- A unique URI that is used as a named graph to which resources are appendedresources- A collection ofIResourceinstances- Returns:
- Operation success
- Throws:
StoreAccessException- if the operation can't be performed
-
clear
Description copied from interface:StoreDeletes the resources and statements stored under the given named graph from the triplestore.May delete the containing named graph, many triplestores will delete the named graph automatically as well as soon as it doesn't contain any triples.
-
keySet
Deprecated.Description copied from interface:StoreEnumerates all named graph URIs within the dataset.If the dataset was not manipulated by other means than via this interface, it can be assumed that all URIs in the set are valid keys.
-
removeAll
public void removeAll()Description copied from interface:StoreRemove EVERYTHING from the triplestore. -
close
public void close()Description copied from interface:StoreClose connection
-