Interface Dao<T,ID extends Serializable>
- Type Parameters:
T
- the entity typeID
- the primary key type for the entity
- All Known Implementing Classes:
HibernateDao
,OAuthDelegatedTokenDaoImpl
,OAuthServiceDaoImpl
,OAuthSessionContextDaoImpl
,OAuthSessionDaoImpl
,RoleDaoImpl
,UserDaoImpl
public interface Dao<T,ID extends Serializable>
An abstraction over the store/retrieve semantics of hibernate to allow a higher-level pattern of access
-
Method Summary
Modifier and TypeMethodDescriptionlong
Return the total number of results for a given query (ignoring offset/limit values)
The value returned is the same as thetotal
field returned by settingquery.computeSize(true)
void
Delete an item from the databasevoid
deleteById
(ID id) Delete an item by its primary keyExecute a query, returning entitiesfind
(WebQuery constraints, JPASearchStrategy strategy) Execute a query, using the named strategy (defaults to AUTO if null)<RT> ConstrainedResultSet<RT>
find
(WebQuery constraints, JPASearchStrategy strategy, Function<?, RT> serialiser) Execute a query, using the named strategy (defaults to AUTO if null) and optionally serialising the resulting rows using the provided serialiserfindByUriQuery
(WebQuery constraints) Execute a Dynamic query using the specified constraints, returning the result as a ConstrainedResultSet of this entity typeExecute a query, using the ID strategyfindIdsByUriQuery
(WebQuery query) Given a query, return the IDs of the matching entities, returning the result as a ConstrainedResultSet of this entity's id typegetAll()
Retrieve every object accessible through this DAORetrieve an item by its primary keygetByIds
(Collection<ID> ids) Deprecated.getByUniqueProperty
(String propertyName, Object value) Convenience method which retrieves an entity by the equality of a single property (may return null if no entities match)Get the type of Entity this DAO processesgetListById
(Collection<ID> ids) Query the database for all items with the given primary keys (convenience method for an ORred id query)getReference
(ID id) Merge an unmanaged entity into a (new or existing) managed entitySave a new item in the database, returning its primary keyvoid
saveOrUpdate
(T obj) Create or Update an item in the databasevoid
Update an existing item in the database
-
Method Details
-
getEntityType
Get the type of Entity this DAO processes- Returns:
- the entity type
-
findIdsByUriQuery
Given a query, return the IDs of the matching entities, returning the result as a ConstrainedResultSet of this entity's id type- Parameters:
query
-- Returns:
-
findByUriQuery
Execute a Dynamic query using the specified constraints, returning the result as a ConstrainedResultSet of this entity type- Parameters:
constraints
- the constraints to apply- Returns:
- a resultset containing the requested number of results
-
find
Execute a query, returning entities- Parameters:
constraints
-- Returns:
-
find
Execute a query, using the named strategy (defaults to AUTO if null)- Parameters:
constraints
-strategy
- strategy, or null to default to AUTO- Returns:
-
findIds
Execute a query, using the ID strategy- Parameters:
constraints
-- Returns:
-
count
Return the total number of results for a given query (ignoring offset/limit values)
The value returned is the same as thetotal
field returned by settingquery.computeSize(true)
- Parameters:
query
-- Returns:
- the total number of results
-
find
<RT> ConstrainedResultSet<RT> find(WebQuery constraints, JPASearchStrategy strategy, Function<?, RT> serialiser) Execute a query, using the named strategy (defaults to AUTO if null) and optionally serialising the resulting rows using the provided serialiser- Parameters:
constraints
-strategy
- strategy, or null to default to AUTOserialiser
- the serialiser function to use to convert each row returned to the resulting resultset- Returns:
-
getAll
Retrieve every object accessible through this DAO- Returns:
- all entities of this type in the database
-
getReference
-
getById
Retrieve an item by its primary key- Parameters:
id
- the id of an entity- Returns:
- the item (or null if it is not present)
- See Also:
-
Session.get(Class, java.io.Serializable)
-
getByIds
Deprecated.usegetListById(Collection)
instead- See Also:
-
getListById
Query the database for all items with the given primary keys (convenience method for an ORred id query)- Parameters:
ids
- a collection of primary keys (may be empty)- Returns:
- any items whose id are contained within
ids
. May be empty if no matches were found. May be smaller thanids
. May be ordered differently fromids
-
deleteById
Delete an item by its primary key- Parameters:
id
- the id of an entity
-
delete
Delete an item from the database- Parameters:
obj
- the entity- See Also:
-
Session.delete(Object)
-
saveOrUpdate
Create or Update an item in the database- Parameters:
obj
- the entity- See Also:
-
Session.saveOrUpdate(Object)
-
save
Save a new item in the database, returning its primary key- Parameters:
obj
- the entity- Returns:
- the primary key of the newly saved object
- See Also:
-
Session.save(Object)
-
update
Update an existing item in the database- Parameters:
obj
- the entity- See Also:
-
Session.update(Object)
-
merge
Merge an unmanaged entity into a (new or existing) managed entity- Parameters:
obj
- the entity- Returns:
- a Hibernate entity version of obj
- See Also:
-
Session.merge(Object)
-
getByUniqueProperty
Convenience method which retrieves an entity by the equality of a single property (may return null if no entities match)- Parameters:
propertyName
- the property name (MUST be a simple property)value
- the property value- Returns:
- the entity, or null if no results were found
- Throws:
org.hibernate.HibernateException
- if more than one property is returned
-
getListById(Collection)
instead