org.synyx.hades.dao.orm
Class GenericJpaDao<T,PK extends java.io.Serializable>

java.lang.Object
  extended by org.synyx.hades.dao.orm.GenericDaoSupport<T>
      extended by org.synyx.hades.dao.orm.GenericJpaDao<T,PK>
Type Parameters:
T - the type of the entity to handle
PK - the type of the entity's identifier
All Implemented Interfaces:
GenericDao<T,PK>
Direct Known Subclasses:
AbstractExtendedGenericJpaDao

@Repository
public class GenericJpaDao<T,PK extends java.io.Serializable>
extends GenericDaoSupport<T>
implements GenericDao<T,PK>

Default implementation of the GenericDao interface. This will offer you a more sophisticated interface than the plain EntityManager.

Author:
Oliver Gierke - gierke@synyx.de, Eberhard Wolff

Nested Class Summary
 
Nested classes/interfaces inherited from class org.synyx.hades.dao.orm.GenericDaoSupport
GenericDaoSupport.IsNewStrategy, GenericDaoSupport.PersistableIsNewStrategy, GenericDaoSupport.ReflectiveIsNewStrategy
 
Constructor Summary
GenericJpaDao()
           
 
Method Summary
 java.lang.Long count()
          Returns the number of entities available.
static
<T,PK extends java.io.Serializable>
GenericDao<T,PK>
create(javax.persistence.EntityManager entityManager, java.lang.Class<T> domainClass)
          Factory method to create GenericJpaDao instances.
 void delete(java.util.List<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.
 T readByPrimaryKey(PK primaryKey)
          Retrives an entity by it's primary key.
protected  Page<T> readPage(Pageable pageable, java.lang.String query)
          Reads a page of entities for the given JPQL query.
 java.util.List<T> save(java.util.List<T> entities)
           
 T save(T entity)
          Saves a given entity.
 T saveAndFlush(T entity)
          Saves an entity and flushes changes instantly to the database.
 
Methods inherited from class org.synyx.hades.dao.orm.GenericDaoSupport
assertEntityManagerClass, createIsNewStrategy, getCountQueryString, getDeleteAllQueryString, getDomainClass, getEntityManager, getIsNewStrategy, getReadAllQuery, getReadAllQueryString, setDomainClass, setEntityManager, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericJpaDao

public GenericJpaDao()
Method Detail

create

public static <T,PK extends java.io.Serializable> GenericDao<T,PK> create(javax.persistence.EntityManager entityManager,
                                                                          java.lang.Class<T> domainClass)
Factory method to create GenericJpaDao instances.

Type Parameters:
T - the type of the entity to handle
PK - the type of the entity's identifier
Parameters:
entityManager - the EntityManager backing the DAO
domainClass - the domain class to handle
Returns:

delete

public void delete(T entity)
Description copied from interface: GenericDao
Deletes a given entity.

Specified by:
delete in interface GenericDao<T,PK extends java.io.Serializable>

delete

public void delete(java.util.List<T> entities)
Description copied from interface: GenericDao
Deletes the given entities.

Specified by:
delete in interface GenericDao<T,PK extends java.io.Serializable>

deleteAll

public void deleteAll()
Description copied from interface: GenericDao
Deletes all entities managed by the DAO.

Specified by:
deleteAll in interface GenericDao<T,PK extends java.io.Serializable>

readByPrimaryKey

public T readByPrimaryKey(PK primaryKey)
Description copied from interface: GenericDao
Retrives an entity by it's primary key.

Specified by:
readByPrimaryKey in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
the entity with the given primary key or null if none found

exists

public boolean exists(PK primaryKey)
Description copied from interface: GenericDao
Returns whether an entity with the given id exists.

Specified by:
exists in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
true if an entity with the given id exists, alse otherwise

readAll

public java.util.List<T> readAll()
Description copied from interface: GenericDao
Returns all instances of the type.

Specified by:
readAll in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
all entities

readAll

public java.util.List<T> readAll(Sort sort)
Description copied from interface: GenericDao
Returns all entities sorted by the given options.

Specified by:
readAll in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
all entities sorted by the given options

readAll

public Page<T> readAll(Pageable pageable)
Description copied from interface: GenericDao
Returns a paged list of entities meeting the paging restriction provided in the Pageable object.

Specified by:
readAll in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
a page of entities

count

public java.lang.Long count()
Description copied from interface: GenericDao
Returns the number of entities available.

Specified by:
count in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
the number of entities

save

public T save(T entity)
Description copied from interface: GenericDao
Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely.

Specified by:
save in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
the saved entity

saveAndFlush

public T saveAndFlush(T entity)
Description copied from interface: GenericDao
Saves an entity and flushes changes instantly to the database.

Specified by:
saveAndFlush in interface GenericDao<T,PK extends java.io.Serializable>
Returns:
the saved entity

save

public java.util.List<T> save(java.util.List<T> entities)
Specified by:
save in interface GenericDao<T,PK extends java.io.Serializable>
Returns:

flush

public void flush()
Description copied from interface: GenericDao
Flushes all pending changes to the database.

Specified by:
flush in interface GenericDao<T,PK extends java.io.Serializable>

readPage

protected Page<T> readPage(Pageable pageable,
                           java.lang.String query)
Reads a page of entities for the given JPQL query.

Parameters:
pageable -
query -
Returns:
a page of entities for the given JPQL query


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