Package org.eclipse.rdf4j.spring.dao
Class RDF4JCRUDDao<ENTITY,INPUT,ID>
java.lang.Object
org.eclipse.rdf4j.spring.dao.RDF4JDao
org.eclipse.rdf4j.spring.dao.RDF4JCRUDDao<ENTITY,INPUT,ID>
- Type Parameters:
ENTITY
-INPUT
-ID
-
- Direct Known Subclasses:
SimpleRDF4JCRUDDao
Base class for DAOs providing CRUD functionality. The class allows for entities to be represented with different
classes for read (ENTITY type) vs write (INPUT type) operations. DAOs that do not require this distinction must use
the same class for both parameters.
- Since:
- 4.0.0
- Author:
- Florian Kleedorfer
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.rdf4j.spring.dao.RDF4JDao
RDF4JDao.NamedSparqlSupplierFinishBuilder, RDF4JDao.NamedSparqlSupplierPreparer
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRDF4JCRUDDao
(RDF4JTemplate rdf4JTemplate) Constructor to be used by implementations that use IRI for the ID type.RDF4JCRUDDao
(RDF4JTemplate rdf4JTemplate, Class<ID> idClass) Constructor that provides the type of the ID to the base implementation. -
Method Summary
Modifier and TypeMethodDescriptionprotected IRI
convertIdToIri
(ID id) Converts the provided id to an IRI.void
Naive implementation usingRDF4JTemplate.delete(IRI)
.protected void
deleteForUpdate
(ID id) When updating an entity viasave(Object)
, its triples are removed first using this method.protected ID
generateNewId
(ID providedId) Generates a new id for an entity.final ENTITY
Obtains the entity with the specified id, throwing an exception if none is found.getByIdOptional
(ID id) Obtains an optional entity with the specified id.protected ID
getInputId
(INPUT input) Obtains the id of the input instance or null if it is new (or a partially populated composite key).protected NamedSparqlSupplier
getInsertSparql
(INPUT input) Returns the SPARQL string used to write an instance of T to the database.protected String
Returns the SPARQL string used to read an instance of T from the database.protected NamedSparqlSupplier
getUpdateSparql
(INPUT input) Returns the SPARQL string used to update an instance of T in the database.list()
protected ENTITY
mapSolution
(BindingSet querySolution) Map one solution of the readQuery to the type of this DAO.protected static BindingsBuilder
Returns a new BindingsBuilder for your convenience.protected void
populateBindingsForUpdate
(MutableBindings bindingsBuilder, INPUT input) Sets the non-id bindings on for the write query such that the instance of type I is written to the database.protected abstract void
populateIdBindings
(MutableBindings bindingsBuilder, ID id) Binds the instance id to query variable(s).protected ENTITY
postProcessMappedSolution
(ENTITY entity) Callback invoked after mapping a solution to an entity, allowing subclasses to modify the entity before returning it to the client.protected void
postProcessUpdate
(INPUT input, Map<String, Value> bindings) Callback invoked after a successful insert/update.final ENTITY
Saves the entity, loads it again and returns it.saveAndReturnId
(INPUT input) saveAndReturnId
(INPUT input, ID id) Saves the entity and returns its (possibly newly generated) ID.Methods inherited from class org.eclipse.rdf4j.spring.dao.RDF4JDao
getNamedGraphQuery, getNamedSparqlString, getNamedSparqlSupplier, getNamedTupleQuery, getNamedUpdate, getRdf4JTemplate, prepareNamedSparqlSuppliers
-
Field Details
-
KEY_PREFIX_INSERT
- See Also:
-
KEY_PREFIX_UPDATE
- See Also:
-
-
Constructor Details
-
RDF4JCRUDDao
Constructor that provides the type of the ID to the base implementation. This constructor has to be used if the ID is anything but IRI. -
RDF4JCRUDDao
Constructor to be used by implementations that use IRI for the ID type.
-
-
Method Details
-
save
Saves the entity, loads it again and returns it. If the modified entity is not required, clients should prefersaveAndReturnId(Object, Object)
orsaveAndReturnId(Object)
-
saveAndReturnId
-
saveAndReturnId
Saves the entity and returns its (possibly newly generated) ID.- Parameters:
input
- the entityid
- the id or null for a new entity.- Returns:
- the id (a newly generated one if the specified
id
is null, otherwise justid
.
-
deleteForUpdate
When updating an entity viasave(Object)
, its triples are removed first using this method. The default implementation usedRDF4JTemplate.deleteTriplesWithSubject(IRI)
. If more complex deletion behaviour (e.g. cascading) is needed, this method should be overriden. -
convertIdToIri
Converts the provided id to an IRI. The default implementation only works for DAOs that use IRI ids.- Parameters:
id
-- Returns:
-
generateNewId
Generates a new id for an entity. The default implementation only works for IRI ids.- Parameters:
providedId
-- Returns:
- a new id.
-
list
-
getById
Obtains the entity with the specified id, throwing an exception if none is found.- Parameters:
id
- the id- Returns:
- the entity
- Throws:
IncorrectResultSetSizeException
- if no entity is found with the specified id
-
getByIdOptional
Obtains an optional entity with the specified id.- Parameters:
id
- the id- Returns:
- an Optional maybe containing the entity
-
delete
Naive implementation usingRDF4JTemplate.delete(IRI)
. DAOs that need more complex deletion behaviour (e.g. cascading) should override this method. -
getReadQuery
Returns the SPARQL string used to read an instance of T from the database. The base implementation will cache the query string, so implementations should not try to cache the query. -
mapSolution
Map one solution of the readQuery to the type of this DAO. -
postProcessMappedSolution
Callback invoked after mapping a solution to an entity, allowing subclasses to modify the entity before returning it to the client. -
postProcessUpdate
Callback invoked after a successful insert/update. -
getInsertSparql
Returns the SPARQL string used to write an instance of T to the database. The instance to be inserted is passed to the function so implementations can decide which query to use based on the instance. -
getUpdateSparql
Returns the SPARQL string used to update an instance of T in the database. The instance to be updated is passed to the function so implementations can decide which query to use based on the instance. -
populateIdBindings
Binds the instance id to query variable(s). -
populateBindingsForUpdate
Sets the non-id bindings on for the write query such that the instance of type I is written to the database. ID bindings are set through populateIdBindings() -
getInputId
Obtains the id of the input instance or null if it is new (or a partially populated composite key). -
newBindingsBuilder
Returns a new BindingsBuilder for your convenience.
-