T - a type variablePK - the primary key for that typepublic class GenericDaoHibernate<T,PK extends Serializable> extends Object implements GenericDao<T,PK>
To register this class in your Spring context file, use the following XML.
<bean id="fooDao" class="org.appfuse.dao.hibernate.GenericDaoHibernate">
<constructor-arg value="org.appfuse.model.Foo"/>
</bean>
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
log
Log variable for all child classes.
|
| Constructor and Description |
|---|
GenericDaoHibernate(Class<T> persistentClass)
Constructor that takes in a class to see which type of entity to persist.
|
GenericDaoHibernate(Class<T> persistentClass,
org.hibernate.SessionFactory sessionFactory)
Constructor that takes in a class and sessionFactory for easy creation of DAO.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
exists(PK id)
Checks for existence of an object of type T using the id arg.
|
List<T> |
findByNamedQuery(String queryName,
Map<String,Object> queryParams)
Find a list of records by using a named query
|
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.
|
org.hibernate.Session |
getSession() |
org.hibernate.SessionFactory |
getSessionFactory() |
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.
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory) |
protected final org.apache.commons.logging.Log log
public GenericDaoHibernate(Class<T> persistentClass)
persistentClass - the class type you'd like to persistpublic GenericDaoHibernate(Class<T> persistentClass, org.hibernate.SessionFactory sessionFactory)
persistentClass - the class type you'd like to persistsessionFactory - the pre-configured Hibernate SessionFactorypublic org.hibernate.SessionFactory getSessionFactory()
public org.hibernate.Session getSession()
throws org.hibernate.HibernateException
org.hibernate.HibernateException@Autowired public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
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 List<T> search(String searchTerm) throws SearchException
search in interface GenericDao<T,PK extends Serializable>searchTerm - the term to search forSearchExceptionpublic T get(PK id)
get in interface GenericDao<T,PK extends Serializable>id - the identifier (primary key) of the object to getObjectRetrievalFailureExceptionpublic boolean exists(PK id)
exists in interface GenericDao<T,PK extends Serializable>id - the id of the entitypublic T save(T object)
save in interface GenericDao<T,PK extends Serializable>object - the object to savepublic 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 removepublic List<T> findByNamedQuery(String queryName, Map<String,Object> queryParams)
findByNamedQuery in interface GenericDao<T,PK extends Serializable>queryName - query name of the named queryqueryParams - a map of the query names and the valuespublic 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 asynchronouslyCopyright © 2003–2013. All rights reserved.