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 String
CONFIG_TRIPLESTORE_LDP_TYPE
The configuration key used to set whether the LDP type should be included in the body of the RDF.static String
CONFIG_TRIPLESTORE_RDF_LOCATION
The 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 RDFConnection
buildRDFConnection(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.String
generateIdentifier()
An identifier generator.CompletionStage<Resource>
get(IRI identifier)
Get a resource by the given identifier.void
initialize()
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:ResourceService
Delete a resource from the server.- Specified by:
delete
in 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
CompletionStage
will 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:ResourceService
Create a resource in the server.- Specified by:
create
in 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
CompletionStage
will 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:ResourceService
Replace a resource in the server.- Specified by:
replace
in 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
CompletionStage
will 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:RetrievalService
Get a resource by the given identifier.- Specified by:
get
in interfaceRetrievalService<Resource>
- Parameters:
identifier
- the resource identifier- Returns:
- the resource
-
generateIdentifier
public String generateIdentifier()
Description copied from interface:ResourceService
An identifier generator.- Specified by:
generateIdentifier
in interfaceResourceService
- Returns:
- a new identifier
-
add
public CompletionStage<Void> add(IRI id, Dataset dataset)
- Specified by:
add
in 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
CompletionStage
will 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:ResourceService
Update the modification date of the provided resource.- Specified by:
touch
in 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:ResourceService
Return a collection of interaction models supported by this Resource Service.- Specified by:
supportedInteractionModels
in 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.
-
-