Package org.trellisldp.triplestore
Class TriplestoreResourceService
- java.lang.Object
-
- org.trellisldp.triplestore.TriplestoreResourceService
-
- All Implemented Interfaces:
ResourceService,RetrievalService<Resource>
@ApplicationScoped public class TriplestoreResourceService extends Object implements ResourceService
A triplestore-based implementation of the Trellis ResourceService API.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIG_TRIPLESTORE_LDP_TYPEThe configuration key used to set whether the LDP type should be included in the body of the RDF.static StringCONFIG_TRIPLESTORE_RDF_LOCATIONThe configuration key used to set where the RDF is stored.
-
Constructor Summary
Constructors Constructor Description TriplestoreResourceService()Create a triplestore-backed resource service.TriplestoreResourceService(RDFConnection rdfConnection)Create a triplestore-backed resource service.TriplestoreResourceService(RDFConnection rdfConnection, IdentifierService identifierService)Create a triplestore-backed resource service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>add(IRI id, Dataset dataset)static RDFConnectionbuildRDFConnection(String location)Build an RDF connection from a location value.CompletionStage<Void>create(Metadata metadata, Dataset dataset)Create a resource in the server.CompletionStage<Void>delete(Metadata metadata)Delete a resource from the server.StringgenerateIdentifier()An identifier generator.CompletionStage<Resource>get(IRI identifier)Get a resource by the given identifier.voidinitialize()This code is equivalent to the SPARQL queries below.CompletionStage<Void>replace(Metadata metadata, Dataset dataset)Replace a resource in the server.Set<IRI>supportedInteractionModels()Return a collection of interaction models supported by this Resource Service.CompletionStage<Void>touch(IRI identifier)Update the modification date of the provided resource.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.trellisldp.api.ResourceService
getResourceIdentifier, skolemize, toExternal, toInternal, unskolemize
-
-
-
-
Field Detail
-
CONFIG_TRIPLESTORE_RDF_LOCATION
public static final String CONFIG_TRIPLESTORE_RDF_LOCATION
The configuration key used to set where the RDF is stored.- See Also:
- Constant Field Values
-
CONFIG_TRIPLESTORE_LDP_TYPE
public static final String CONFIG_TRIPLESTORE_LDP_TYPE
The configuration key used to set whether the LDP type should be included in the body of the RDF.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TriplestoreResourceService
public TriplestoreResourceService()
Create a triplestore-backed resource service.
-
TriplestoreResourceService
public TriplestoreResourceService(RDFConnection rdfConnection)
Create a triplestore-backed resource service.- Parameters:
rdfConnection- the connection to an RDF datastore
-
TriplestoreResourceService
@Inject public TriplestoreResourceService(RDFConnection rdfConnection, IdentifierService identifierService)
Create a triplestore-backed resource service.- Parameters:
rdfConnection- the connection to an RDF datastoreidentifierService- an ID supplier service
-
-
Method Detail
-
delete
public CompletionStage<Void> delete(Metadata metadata)
Description copied from interface:ResourceServiceDelete a resource from the server.- Specified by:
deletein interfaceResourceService- Parameters:
metadata- metadata for the resource- Returns:
- a new completion stage that, when the stage completes normally, indicates that the resource
was successfully deleted from the corresponding persistence layer. In the case of an unsuccessful delete
operation, the
CompletionStagewill complete exceptionally and can be handled withCompletionStage.handle(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>),CompletionStage.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>)or similar methods.
-
create
public CompletionStage<Void> create(Metadata metadata, Dataset dataset)
Description copied from interface:ResourceServiceCreate a resource in the server.- Specified by:
createin interfaceResourceService- Parameters:
metadata- metadata for the new resourcedataset- the dataset to be persisted- Returns:
- a new completion stage that, when the stage completes normally, indicates that the supplied data were
successfully created in the corresponding persistence layer. In the case of an unsuccessful write operation,
the
CompletionStagewill complete exceptionally and can be handled withCompletionStage.handle(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>),CompletionStage.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>)or similar methods.
-
replace
public CompletionStage<Void> replace(Metadata metadata, Dataset dataset)
Description copied from interface:ResourceServiceReplace a resource in the server.- Specified by:
replacein interfaceResourceService- Parameters:
metadata- metadata for the resourcedataset- the dataset to be persisted- Returns:
- a new completion stage that, when the stage completes normally, indicates that the supplied data
were successfully stored in the corresponding persistence layer. In the case of an unsuccessful write operation,
the
CompletionStagewill complete exceptionally and can be handled withCompletionStage.handle(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>),CompletionStage.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>)or similar methods.
-
initialize
@PostConstruct public void initialize()
This code is equivalent to the SPARQL queries below.SELECT ?object WHERE { GRAPH trellis:PreferServerManaged { IDENTIFIER rdf:type ?object } }INSERT DATA { GRAPH trellis:PreferServerManaged { IDENTIFIER rdf:type ldp:Container ; dc:modified "NOW"^^xsd:dateTime } GRAPH IDENTIFIER?ext=audit { IDENTIFIER prov:wasGeneratedBy [ rdf:type prov:Activity , as:Create ; prov:wasAssociatedWith trellis:AdministorAgent ; prov:atTime "TIME"^^xsd:dateTime ] } GRAPH IDENTIFIER?ext=acl { IDENTIFIER acl:mode acl.Read , acl:Write , acl:Control ; acl:agentClass foaf:Agent ; acl:accessTo IDENTIFIER } }
-
get
public CompletionStage<Resource> get(IRI identifier)
Description copied from interface:RetrievalServiceGet a resource by the given identifier.- Specified by:
getin interfaceRetrievalService<Resource>- Parameters:
identifier- the resource identifier- Returns:
- the resource
-
generateIdentifier
public String generateIdentifier()
Description copied from interface:ResourceServiceAn identifier generator.- Specified by:
generateIdentifierin interfaceResourceService- Returns:
- a new identifier
-
add
public CompletionStage<Void> add(IRI id, Dataset dataset)
- Specified by:
addin interfaceResourceService- Parameters:
id- the identifier under which to persist a datasetdataset- a dataset to persist- Returns:
- a new completion stage that, when the stage completes normally, indicates that the supplied data
were successfully stored in the corresponding persistence layer. In the case of an unsuccessful write operation,
the
CompletionStagewill complete exceptionally and can be handled withCompletionStage.handle(java.util.function.BiFunction<? super T, java.lang.Throwable, ? extends U>),CompletionStage.exceptionally(java.util.function.Function<java.lang.Throwable, ? extends T>)or similar methods.
-
touch
public CompletionStage<Void> touch(IRI identifier)
Description copied from interface:ResourceServiceUpdate the modification date of the provided resource.- Specified by:
touchin interfaceResourceService- Parameters:
identifier- the identifier of the resource- Returns:
- a new completion stage that, when the stage completes normally, indicates that the identified resource has been updated with a new modification date.
-
supportedInteractionModels
public Set<IRI> supportedInteractionModels()
Description copied from interface:ResourceServiceReturn a collection of interaction models supported by this Resource Service.- Specified by:
supportedInteractionModelsin interfaceResourceService- Returns:
- a set of supported interaction models
-
buildRDFConnection
public static RDFConnection buildRDFConnection(String location)
Build an RDF connection from a location value.- Parameters:
location- the location of the RDF- Returns:
- a connection to the RDF store
- Implementation Note:
- A null value will create an in-memory RDF store, a file path will create a TDB2 RDF store, and a URL will use a remote triplestore.
-
-