org.synyx.hades.dao.orm
Class GenericDaoSupport<T>

java.lang.Object
  extended by org.synyx.hades.dao.orm.GenericDaoSupport<T>
Type Parameters:
T - the type of entity to be handled
Direct Known Subclasses:
GenericJpaDao

public abstract class GenericDaoSupport<T>
extends java.lang.Object

Abstract base class for generic DAOs.

Author:
Oliver Gierke - gierke@synyx.de

Nested Class Summary
static interface GenericDaoSupport.IsNewStrategy
          Interface to abstract the ways to determine if a
static class GenericDaoSupport.PersistableIsNewStrategy
          Implementation of GenericDaoSupport.IsNewStrategy that assumes the entity handled implements Persistable and uses Persistable.isNew() for the GenericDaoSupport.PersistableIsNewStrategy.isNew(Object) check.
static class GenericDaoSupport.ReflectiveIsNewStrategy
          GenericDaoSupport.IsNewStrategy implementation that reflectively checks a Field or Method annotated with Id.
 
Constructor Summary
GenericDaoSupport()
           
 
Method Summary
protected  void assertEntityManagerClass(java.lang.Class<? extends javax.persistence.EntityManager> clazz)
          Asserts that the EntityManager implementation being used by the dao is an instance of the given type.
protected  void createIsNewStrategy(java.lang.Class<?> domainClass)
          Return whether the given entity is to be regarded as new.
protected  java.lang.String getCountQueryString()
          Returns the query string to count entities.
protected  java.lang.String getDeleteAllQueryString()
          Returns the query string to delete all entities.
protected  java.lang.Class<T> getDomainClass()
          Returns the domain class to handle.
protected  javax.persistence.EntityManager getEntityManager()
          Returns the EntityManager.
protected  GenericDaoSupport.IsNewStrategy getIsNewStrategy()
          Returns the strategy how to determine whether an entity is to be regarded as new.
protected  javax.persistence.Query getReadAllQuery()
          Returns the query to retrieve all entities.
protected  java.lang.String getReadAllQueryString()
          Returns the query string to retrieve all entities.
 void setDomainClass(java.lang.Class<T> domainClass)
          Sets the domain class to handle.
 void setEntityManager(javax.persistence.EntityManager entityManager)
          Setter to inject EntityManager.
 void validate()
          Callback method to validate the class setup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDaoSupport

public GenericDaoSupport()
Method Detail

getEntityManager

protected javax.persistence.EntityManager getEntityManager()
Returns the EntityManager.

Returns:

setEntityManager

public void setEntityManager(javax.persistence.EntityManager entityManager)
Setter to inject EntityManager.

Parameters:
entityManager -

getDomainClass

protected java.lang.Class<T> getDomainClass()
Returns the domain class to handle.

Returns:
the domain class

setDomainClass

public void setDomainClass(java.lang.Class<T> domainClass)
Sets the domain class to handle.

Parameters:
domainClass - the domain class to set

getReadAllQueryString

protected java.lang.String getReadAllQueryString()
Returns the query string to retrieve all entities.

Returns:
string to retrieve all entities

getDeleteAllQueryString

protected java.lang.String getDeleteAllQueryString()
Returns the query string to delete all entities.

Returns:
string to delete all entities

getCountQueryString

protected java.lang.String getCountQueryString()
Returns the query string to count entities.

Returns:
string to count entities

getReadAllQuery

protected javax.persistence.Query getReadAllQuery()
Returns the query to retrieve all entities.

Returns:
the query to retrieve all entities.

assertEntityManagerClass

protected void assertEntityManagerClass(java.lang.Class<? extends javax.persistence.EntityManager> clazz)
Asserts that the EntityManager implementation being used by the dao is an instance of the given type.

Parameters:
clazz -
Throws:
java.lang.IllegalArgumentException - if the entity manager is not of the given type

validate

public void validate()
Callback method to validate the class setup.


createIsNewStrategy

protected void createIsNewStrategy(java.lang.Class<?> domainClass)
Return whether the given entity is to be regarded as new. Default implementation will inspect the given domain class and use either GenericDaoSupport.PersistableIsNewStrategy if the class implements Persistable or GenericDaoSupport.ReflectiveIsNewStrategy otherwise.

Parameters:
entity -

getIsNewStrategy

protected GenericDaoSupport.IsNewStrategy getIsNewStrategy()
Returns the strategy how to determine whether an entity is to be regarded as new.

Returns:
the isNewStrategy


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