Package org.trellisldp.jdbc
Class DBResourceService
- java.lang.Object
-
- org.trellisldp.jdbc.DBResourceService
-
- All Implemented Interfaces:
ResourceService
,RetrievalService<Resource>
@ApplicationScoped public class DBResourceService extends Object implements ResourceService
A Database-backed implementation of the Trellis ResourceService API.Note: one can manipulate the size of a batched query by setting a property for
trellis.db.batch-size
. By default, this value is 1,000. One can also configure the persistence layer to add the LDP type to the body of an RDF response by setting the environment variabletrellis.db.ldp.type
to "true". By default, this value is false.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIG_JDBC_BATCH_SIZE
Configuration key used to define the size of database write batches.static String
CONFIG_JDBC_DIRECT_CONTAINMENT
The configuration key used to define whether indirect containers are supported.static String
CONFIG_JDBC_INDIRECT_CONTAINMENT
The configuration key used to define whether direct containers are supported.static String
CONFIG_JDBC_LDP_TYPE
The configuration key used to define whether to include the LDP type in an RDF body.static String
CONFIG_JDBC_URL
Configuration key used to define a database connection url.static int
DEFAULT_BATCH_SIZE
The default size of a database batch write operation.
-
Constructor Summary
Constructors Constructor Description DBResourceService()
Create a Database-backed resource service.DBResourceService(DataSource ds)
Create a Database-backed resource service.DBResourceService(org.jdbi.v3.core.Jdbi jdbi)
Create a Database-backed resource service.DBResourceService(org.jdbi.v3.core.Jdbi jdbi, int batchSize, boolean includeLdpType, boolean supportDirectContainment, boolean supportIndirectContainment, IdentifierService identifierService)
Create a Database-backed resource service.DBResourceService(org.jdbi.v3.core.Jdbi jdbi, int batchSize, boolean includeLdpType, IdentifierService identifierService)
Create a Database-backed resource service.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>
add(IRI id, Dataset dataset)
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.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 id)
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_JDBC_URL
public static final String CONFIG_JDBC_URL
Configuration key used to define a database connection url.- See Also:
- Constant Field Values
-
CONFIG_JDBC_BATCH_SIZE
public static final String CONFIG_JDBC_BATCH_SIZE
Configuration key used to define the size of database write batches.- See Also:
- Constant Field Values
-
CONFIG_JDBC_LDP_TYPE
public static final String CONFIG_JDBC_LDP_TYPE
The configuration key used to define whether to include the LDP type in an RDF body.- See Also:
- Constant Field Values
-
CONFIG_JDBC_DIRECT_CONTAINMENT
public static final String CONFIG_JDBC_DIRECT_CONTAINMENT
The configuration key used to define whether indirect containers are supported.- See Also:
- Constant Field Values
-
CONFIG_JDBC_INDIRECT_CONTAINMENT
public static final String CONFIG_JDBC_INDIRECT_CONTAINMENT
The configuration key used to define whether direct containers are supported.- See Also:
- Constant Field Values
-
DEFAULT_BATCH_SIZE
public static final int DEFAULT_BATCH_SIZE
The default size of a database batch write operation.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DBResourceService
public DBResourceService()
Create a Database-backed resource service.This constructor is generally used by CDI proxies and should not be invoked directly.
-
DBResourceService
@Inject public DBResourceService(DataSource ds)
Create a Database-backed resource service.- Parameters:
ds
- the data source
-
DBResourceService
public DBResourceService(org.jdbi.v3.core.Jdbi jdbi)
Create a Database-backed resource service.- Parameters:
jdbi
- the jdbi object
-
DBResourceService
public DBResourceService(org.jdbi.v3.core.Jdbi jdbi, int batchSize, boolean includeLdpType, IdentifierService identifierService)
Create a Database-backed resource service.- Parameters:
jdbi
- the jdbi objectbatchSize
- the batch sizeincludeLdpType
- whether to include the LDP type in the RDF bodyidentifierService
- an ID supplier service
-
DBResourceService
public DBResourceService(org.jdbi.v3.core.Jdbi jdbi, int batchSize, boolean includeLdpType, boolean supportDirectContainment, boolean supportIndirectContainment, IdentifierService identifierService)
Create a Database-backed resource service.- Parameters:
jdbi
- the jdbi objectbatchSize
- the batch sizeincludeLdpType
- whether to include the LDP type in the RDF bodysupportDirectContainment
- whether to support direct containmentsupportIndirectContainment
- whether to support indirect containmentidentifierService
- an ID supplier service
-
-
Method Detail
-
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.
-
touch
public CompletionStage<Void> touch(IRI id)
Description copied from interface:ResourceService
Update the modification date of the provided resource.- Specified by:
touch
in interfaceResourceService
- Parameters:
id
- 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.
-
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.
-
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
-
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.
-
-