org.synyx.hades.dao
Interface GenericDao<T,PK extends java.io.Serializable>

All Known Implementing Classes:
GenericJpaDao

public interface GenericDao<T,PK extends java.io.Serializable>

Interface for generic CRUD operations on a DAO for a specific type.

Author:
Eberhard Wolff, Oliver Gierke

Method Summary
 java.lang.Long count()
          Returns the number of entities available.
 void delete(java.util.Collection<? extends T> entities)
          Deletes the given entities.
 void delete(T entity)
          Deletes a given entity.
 void deleteAll()
          Deletes all entities managed by the DAO.
 boolean exists(PK primaryKey)
          Returns whether an entity with the given id exists.
 void flush()
          Flushes all pending changes to the database.
 java.util.List<T> readAll()
          Returns all instances of the type.
 Page<T> readAll(Pageable pageable)
          Returns a paged list of entities meeting the paging restriction provided in the Pageable object.
 java.util.List<T> readAll(Sort sort)
          Returns all entities sorted by the given options.
 java.util.List<T> readAll(Specification<T> spec)
          Returns all entities matching the given Specification.
 Page<T> readAll(Specification<T> spec, Pageable pageable)
          Returns a Page of entities matching the given Specification.
 T readByPrimaryKey(PK primaryKey)
          Retrives an entity by it's primary key.
 java.util.List<T> save(java.util.Collection<? extends T> entities)
           
 T save(T entity)
          Saves a given entity.
 T saveAndFlush(T entity)
          Saves an entity and flushes changes instantly to the database.
 

Method Detail

save

T save(T entity)
Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.

Parameters:
entity -
Returns:
the saved entity

save

java.util.List<T> save(java.util.Collection<? extends T> entities)
Parameters:
entities -
Returns:

saveAndFlush

T saveAndFlush(T entity)
Saves an entity and flushes changes instantly to the database.

Parameters:
entity -
Returns:
the saved entity

readByPrimaryKey

T readByPrimaryKey(PK primaryKey)
Retrives an entity by it's primary key.

Parameters:
primaryKey -
Returns:
the entity with the given primary key or null if none found
Throws:
java.lang.IllegalArgumentException - if primaryKey is null

exists

boolean exists(PK primaryKey)
Returns whether an entity with the given id exists.

Parameters:
primaryKey -
Returns:
true if an entity with the given id exists, alse otherwise
Throws:
java.lang.IllegalArgumentException - if primaryKey is null

readAll

java.util.List<T> readAll()
Returns all instances of the type.

Returns:
all entities

readAll

java.util.List<T> readAll(Sort sort)
Returns all entities sorted by the given options.

Parameters:
sort -
Returns:
all entities sorted by the given options

readAll

Page<T> readAll(Pageable pageable)
Returns a paged list of entities meeting the paging restriction provided in the Pageable object.

Parameters:
pageable -
Returns:
a page of entities

readAll

java.util.List<T> readAll(Specification<T> spec)
Returns all entities matching the given Specification.

Parameters:
spec -
Returns:

readAll

Page<T> readAll(Specification<T> spec,
                Pageable pageable)
Returns a Page of entities matching the given Specification.

Parameters:
spec -
pageable -
Returns:

count

java.lang.Long count()
Returns the number of entities available.

Returns:
the number of entities

delete

void delete(T entity)
Deletes a given entity.

Parameters:
entity -

delete

void delete(java.util.Collection<? extends T> entities)
Deletes the given entities.

Parameters:
entities -

deleteAll

void deleteAll()
Deletes all entities managed by the DAO.


flush

void flush()
Flushes all pending changes to the database.



Copyright © 2009-2010 Synyx GmbH & Co. KG. All Rights Reserved.