|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.appfuse.dao.jpa.GenericDaoJpa<T,PK>
T - a type variablePK - the primary key for that typepublic class GenericDaoJpa<T,PK extends Serializable>
This class serves as the Base class for all other DAOs - namely to hold common CRUD methods that they might all use. You should only need to extend this class when your require custom CRUD logic.
To register this class in your Spring context file, use the following XML.
<bean id="fooDao" class="org.appfuse.dao.hibernate.GenericDaoJpaHibernate">
<constructor-arg value="org.appfuse.model.Foo"/>
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
| Field Summary | |
|---|---|
protected org.apache.commons.logging.Log |
log
Log variable for all child classes. |
static String |
PERSISTENCE_UNIT_NAME
|
| Constructor Summary | |
|---|---|
GenericDaoJpa(Class<T> persistentClass)
Constructor that takes in a class to see which type of entity to persist. |
|
GenericDaoJpa(Class<T> persistentClass,
javax.persistence.EntityManager entityManager)
Constructor that takes in a class to see which type of entity to persist. |
|
| Method Summary | |
|---|---|
boolean |
exists(PK id)
Checks for existence of an object of type T using the id arg. |
T |
get(PK id)
Generic method to get an object based on class and identifier. |
List<T> |
getAll()
Generic method used to get all objects of a particular type. |
List<T> |
getAllDistinct()
Gets all records without duplicates. |
javax.persistence.EntityManager |
getEntityManager()
|
void |
reindex()
Generic method to regenerate full text index of the persistent class T |
void |
reindexAll(boolean async)
Generic method to regenerate full text index of all indexed classes |
void |
remove(PK id)
Generic method to delete an object |
void |
remove(T object)
Generic method to delete an object |
T |
save(T object)
Generic method to save an object - handles both update and insert. |
List<T> |
search(String searchTerm)
Gets all records that match a search term. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final org.apache.commons.logging.Log log
public static final String PERSISTENCE_UNIT_NAME
| Constructor Detail |
|---|
public GenericDaoJpa(Class<T> persistentClass)
persistentClass - the class type you'd like to persist
public GenericDaoJpa(Class<T> persistentClass,
javax.persistence.EntityManager entityManager)
persistentClass - the class type you'd like to persistentityManager - the configured EntityManager for JPA implementation.| Method Detail |
|---|
public javax.persistence.EntityManager getEntityManager()
public List<T> getAll()
getAll in interface GenericDao<T,PK extends Serializable>public List<T> getAllDistinct()
Note that if you use this method, it is imperative that your model classes correctly implement the hashcode/equals methods
getAllDistinct in interface GenericDao<T,PK extends Serializable>public T get(PK id)
get in interface GenericDao<T,PK extends Serializable>id - the identifier (primary key) of the object to get
org.springframework.orm.ObjectRetrievalFailureExceptionpublic boolean exists(PK id)
exists in interface GenericDao<T,PK extends Serializable>id - the id of the entity
public T save(T object)
save in interface GenericDao<T,PK extends Serializable>object - the object to save
public void remove(T object)
remove in interface GenericDao<T,PK extends Serializable>object - the object to removepublic void remove(PK id)
remove in interface GenericDao<T,PK extends Serializable>id - the identifier (primary key) of the object to remove
public List<T> search(String searchTerm)
throws SearchException
GenericDao
search in interface GenericDao<T,PK extends Serializable>searchTerm - the term to search for
SearchExceptionpublic void reindex()
reindex in interface GenericDao<T,PK extends Serializable>public void reindexAll(boolean async)
reindexAll in interface GenericDao<T,PK extends Serializable>async - true to perform the reindexing asynchronously
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||