net.sf.sidaof.dao
Interface Dao<K,E>

Type Parameters:
K - The primary key class of the entity, e.g. Long.
E - The entity class the DAO persists, e.g. Person.
All Known Subinterfaces:
HibernateDao<K,E>, JpaDao<K,E>
All Known Implementing Classes:
AbstractDao, AbstractHibernateDao, AbstractJpaDao, HibernateDaoAdapter, HibernateDaoImpl, JpaDaoAdapter, JpaDaoImpl

public interface Dao<K,E>

Base interface for all DAOs. To use, extend it in DAO interfaces.


Method Summary
 void clear()
          Clear the in-memory persistable state, including unflushed changes.
 boolean contains(E entity)
          Check if the entity belongs to the current persistence context.
 Long countAll()
          Count all values represented by the entity class this DAO persists (no where clause, no path expression).
 Long countAll(String where)
          Count all values represented by the specified where clause for the entity class this DAO persists.
 Long countAll(String where, String pathExpression)
          Count all values represented by the specified where clause and pathExpression for the entity class this DAO persists.
 List<E> findAll()
          Find all entities.
 List<E> findAll(int startPosition, int maxResult)
          Find all entities starting in the resultset specified by startPosition and obtaining up to the number specified by maxResult.
 E findById(K id)
          Find an entity by its id, and return null if not found.
 void flush()
          Synchronize the underlying persistent store with persistable state held in memory.
 E merge(E entity)
          Merge the entity.
 void persist(Collection<E> entities)
          Save the Collection of entities.
 void persist(E entity)
          Save the entity.
 void refresh(E entity)
          Reload the entity.
 void remove(E entity)
          Delete the entity.
 

Method Detail

persist

void persist(E entity)
Save the entity.

Parameters:
entity - The persistence entity to save.

persist

void persist(Collection<E> entities)
Save the Collection of entities.

Parameters:
entities - The Collection of persistence entities to save.

merge

E merge(E entity)
Merge the entity.

Parameters:
entity - The persistence entity to merge.
Returns:
The merged entity.

remove

void remove(E entity)
Delete the entity.

Parameters:
entity - The persistence entity to delete.

findById

E findById(K id)
Find an entity by its id, and return null if not found.

Parameters:
id - The id (primary key) of the entity to find.
Returns:
The entity for the specified id, null when entity not found.

findAll

List<E> findAll()
Find all entities.

Returns:
List of all entities.

findAll

List<E> findAll(int startPosition,
                int maxResult)
Find all entities starting in the resultset specified by startPosition and obtaining up to the number specified by maxResult. This method is useful for pagination of results.

Parameters:
startPosition - The starting position in the result set to retrieve.
maxResult - The maximum number of rows to retrieve.
Returns:
List of a subset of all entities, starting with startPosition and containing up to maxResult entries.

flush

void flush()
Synchronize the underlying persistent store with persistable state held in memory.


clear

void clear()
Clear the in-memory persistable state, including unflushed changes.


contains

boolean contains(E entity)
Check if the entity belongs to the current persistence context.

Parameters:
entity - The persistence entity to see if exists.
Returns:
true if the entity belongs to the current persistence context.

refresh

void refresh(E entity)
Reload the entity.

Parameters:
entity - The persistence entity to reload from the persistence context.

countAll

Long countAll()
Count all values represented by the entity class this DAO persists (no where clause, no path expression).

Returns:
Long representing number of values in the group.

countAll

Long countAll(String where)
Count all values represented by the specified where clause for the entity class this DAO persists.

This convenience method is meant for simple count queries. For complex ones, create custom ones in the product DAOs.

Parameters:
where - See where param for #countAll(String, String)
Returns:
Long representing number of values in the group.

countAll

Long countAll(String where,
              String pathExpression)
Count all values represented by the specified where clause and pathExpression for the entity class this DAO persists.

This convenience method is meant for simple count queries. For complex ones, create custom ones in the product DAOs.

Parameters:
where - The where clause to append to the count query to narrow the counted values. Do not prefix with "where" as it is automatically added. The underlying query uses "e" as the identification variable, so the where will use "e", e.g. "e.name = 'Fred'". Specifying null disregards a where clause.
pathExpression - A String representing the object graph navigation to the element to count. The underlying query uses "e" as the identification variable, so the pathExpression will u "e", e.g. "e.address.zip", "e.name", "e.id". Specify either an identification variable (e.g. "e") or a path expression (e.g. "e.address.zip"). Specifying null disregards a pathExpression (defaults to "*").
Returns:
Long representing number of values in the group.


Copyright © 2009-2011. All Rights Reserved.