Interface Dao<T,ID extends Serializable>

Type Parameters:
T - the entity type
ID - 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 Details

    • getEntityType

      Class<T> getEntityType()
      Get the type of Entity this DAO processes
      Returns:
      the entity type
    • findIdsByUriQuery

      ConstrainedResultSet<ID> findIdsByUriQuery(WebQuery query)
      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

      ConstrainedResultSet<T> findByUriQuery(WebQuery constraints)
      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

      ConstrainedResultSet<T> find(WebQuery constraints)
      Execute a query, returning entities
      Parameters:
      constraints -
      Returns:
    • find

      ConstrainedResultSet<T> find(WebQuery constraints, JPASearchStrategy strategy)
      Execute a query, using the named strategy (defaults to AUTO if null)
      Parameters:
      constraints -
      strategy - strategy, or null to default to AUTO
      Returns:
    • findIds

      ConstrainedResultSet<ID> findIds(WebQuery constraints)
      Execute a query, using the ID strategy
      Parameters:
      constraints -
      Returns:
    • count

      long count(WebQuery query)
      Return the total number of results for a given query (ignoring offset/limit values)
      The value returned is the same as the total field returned by setting query.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 AUTO
      serialiser - the serialiser function to use to convert each row returned to the resulting resultset
      Returns:
    • getAll

      List<T> getAll()
      Retrieve every object accessible through this DAO
      Returns:
      all entities of this type in the database
    • getReference

      T getReference(ID id)
    • getById

      T getById(ID id)
      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

      List<T> getByIds(Collection<ID> ids)
      Deprecated.
      See Also:
    • getListById

      List<T> getListById(Collection<ID> ids)
      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 than ids. May be ordered differently from ids
    • deleteById

      void deleteById(ID id)
      Delete an item by its primary key
      Parameters:
      id - the id of an entity
    • delete

      void delete(T obj)
      Delete an item from the database
      Parameters:
      obj - the entity
      See Also:
      • Session.delete(Object)
    • saveOrUpdate

      void saveOrUpdate(T obj)
      Create or Update an item in the database
      Parameters:
      obj - the entity
      See Also:
      • Session.saveOrUpdate(Object)
    • save

      ID save(T obj)
      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

      void update(T obj)
      Update an existing item in the database
      Parameters:
      obj - the entity
      See Also:
      • Session.update(Object)
    • merge

      T merge(T obj)
      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

      T 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)
      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