org.appfuse.dao.jpa
Class UniversalDaoJpa

java.lang.Object
  extended by org.appfuse.dao.jpa.UniversalDaoJpa
All Implemented Interfaces:
UniversalDao
Direct Known Subclasses:
LookupDaoJpa

public class UniversalDaoJpa
extends java.lang.Object
implements UniversalDao

This class serves as the a class that can CRUD any object witout any Spring configuration. The only downside is it does require casting from Object to the object class.

Author:
Bryan Noll

Field Summary
protected  javax.persistence.EntityManager entityManager
          Entity manager, injected by Spring using @PersistenceContext annotation on setEntityManager()
protected  org.apache.commons.logging.Log log
          Log variable for all child classes.
 
Constructor Summary
UniversalDaoJpa()
           
 
Method Summary
 java.lang.Object get(java.lang.Class clazz, java.io.Serializable id)
          Generic method to get an object based on class and identifier.
 java.util.List getAll(java.lang.Class clazz)
          Generic method used to get all objects of a particular type.
 void remove(java.lang.Class clazz, java.io.Serializable id)
          Generic method to delete an object based on class and id
 java.lang.Object save(java.lang.Object o)
          Generic method to save an object - handles both update and insert.
 void setEntityManager(javax.persistence.EntityManager entityManager)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Log variable for all child classes. Uses LogFactory.getLog(getClass()) from Commons Logging


entityManager

protected javax.persistence.EntityManager entityManager
Entity manager, injected by Spring using @PersistenceContext annotation on setEntityManager()

Constructor Detail

UniversalDaoJpa

public UniversalDaoJpa()
Method Detail

setEntityManager

public void setEntityManager(javax.persistence.EntityManager entityManager)

save

public java.lang.Object save(java.lang.Object o)
Generic method to save an object - handles both update and insert.

Specified by:
save in interface UniversalDao
Parameters:
o - the object to save
Returns:
a populated object

get

public java.lang.Object get(java.lang.Class clazz,
                            java.io.Serializable id)
Generic method to get an object based on class and identifier. An ObjectRetrievalFailureException Runtime Exception is thrown if nothing is found.

Specified by:
get in interface UniversalDao
Parameters:
clazz - model class to lookup
id - the identifier (primary key) of the class
Returns:
a populated object
See Also:
org.springframework.orm.ObjectRetrievalFailureException

getAll

public java.util.List getAll(java.lang.Class clazz)
Generic method used to get all objects of a particular type. This is the same as lookup up all rows in a table.

Specified by:
getAll in interface UniversalDao
Parameters:
clazz - the type of objects (a.k.a. while table) to get data from
Returns:
List of populated objects

remove

public void remove(java.lang.Class clazz,
                   java.io.Serializable id)
Generic method to delete an object based on class and id

Specified by:
remove in interface UniversalDao
Parameters:
clazz - model class to lookup
id - the identifier (primary key) of the class


Copyright © 2003-2007. All Rights Reserved.