T - a type variablePK - the primary key for that typepublic class GenericHibernate4DAO<T,PK extends Serializable> extends Object implements GenericDAO<T,PK>
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
log
Log variable for all child classes.
|
| Modifier | Constructor and Description |
|---|---|
protected |
GenericHibernate4DAO(Class<? extends T> persistentClass)
Constructor that takes in a class to see which type of entity to persist
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears session.
|
protected org.hibernate.Criteria |
createCriteria() |
protected static <T,PK extends Serializable> |
createDaoInstance(Class<T> clazz)
For Spring configuration purpose only.
|
void |
evict(T object)
Evicts given object from session.
|
boolean |
exists(PK id)
Checks for existence of an object with given key.
|
void |
flush()
Flushes session.
|
Collection<T> |
get(Collection<PK> ids)
Generic method to get objects based on class and identifiers.
|
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> |
getByExample(T object)
Gets objects from the database that match given example.
|
T |
getByUniqueExample(T object)
Gets object from the database that match given example.
|
protected String |
getIdPropertyName() |
PK |
getKey(T object)
Generic method to get the identifier of a given object.
|
T |
getLast()
Generic method to get the last object.
|
PK |
getNextPK(PK id)
Get primary key larger than given one
|
PK |
getPreviousPK(PK id)
Get primary key smaller than given one
|
org.hibernate.SessionFactory |
getSessionFactory() |
void |
remove(Collection<T> objects)
Generic method to delete a given object
|
void |
remove(PK id)
Generic method to delete an object with given id
|
void |
remove(T object)
Generic method to delete a given object
|
<C extends Collection<T>> |
save(C objects)
Generic method to save collection of objects - handles insert, update and
remove.
|
T |
save(T object)
Generic method to save an object - handles insert, update and remove.
|
void |
setKey(T object,
PK key)
Generic method to set the identifier for a given object.
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory) |
protected final org.apache.commons.logging.Log log
public List<T> getAll()
getAll in interface GenericDAO<T,PK extends Serializable>public T get(PK id)
GenericDAOget in interface GenericDAO<T,PK extends Serializable>id - The identifier (primary key) of the object to getGenericDAO.get(java.io.Serializable)public Collection<T> get(Collection<PK> ids)
GenericDAOget in interface GenericDAO<T,PK extends Serializable>ids - The identifiers (primary keys) of the objects to getGenericDAO.get(Collection)public List<T> getByExample(T object)
GenericDAOgetByExample in interface GenericDAO<T,PK extends Serializable>object - The template object to match (not null columns)GenericDAO.getByExample(java.lang.Object)public T getByUniqueExample(T object)
GenericDAOgetByUniqueExample in interface GenericDAO<T,PK extends Serializable>object - The template object to match (not null columns)GenericDAO.getByExample(java.lang.Object)public boolean exists(PK id)
GenericDAOexists in interface GenericDAO<T,PK extends Serializable>id - The id of the entityGenericDAO.exists(java.io.Serializable)public T save(T object)
GenericDAOsave in interface GenericDAO<T,PK extends Serializable>object - The object to saveGenericDAO.save(java.lang.Object)public void remove(T object)
GenericDAOremove in interface GenericDAO<T,PK extends Serializable>object - The object to removeGenericDAO.remove(java.lang.Object)public void remove(Collection<T> objects)
GenericDAOremove in interface GenericDAO<T,PK extends Serializable>GenericDAO.remove(java.util.Collection)public void remove(PK id)
GenericDAOremove in interface GenericDAO<T,PK extends Serializable>id - The identifier (primary key) of the object to removeGenericDAO.remove(java.io.Serializable)public <C extends Collection<T>> C save(C objects)
GenericDAOsave in interface GenericDAO<T,PK extends Serializable>C - Type of collectionobjects - The objects to saveGenericDAO.save(java.util.Collection)public void clear()
GenericDAOclear in interface GenericDAO<T,PK extends Serializable>GenericDAO.clear()public void flush()
GenericDAOflush in interface GenericDAO<T,PK extends Serializable>GenericDAO.flush()public void evict(T object)
GenericDAOevict in interface GenericDAO<T,PK extends Serializable>GenericDAO.evict(java.lang.Object)public PK getKey(T object)
GenericDAOgetKey in interface GenericDAO<T,PK extends Serializable>object - The object to get PK forGenericDAO.getKey(java.lang.Object)public void setKey(T object, PK key)
GenericDAOsetKey in interface GenericDAO<T,PK extends Serializable>object - The object to get PK forkey - The identifier (primary key) of a given objectGenericDAO.setKey(java.lang.Object, java.io.Serializable)public T getLast()
GenericDAOgetLast in interface GenericDAO<T,PK extends Serializable>public PK getNextPK(PK id)
GenericDAOgetNextPK in interface GenericDAO<T,PK extends Serializable>public PK getPreviousPK(PK id)
GenericDAOgetPreviousPK in interface GenericDAO<T,PK extends Serializable>protected org.hibernate.Criteria createCriteria()
protected String getIdPropertyName()
public org.hibernate.SessionFactory getSessionFactory()
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
protected static <T,PK extends Serializable> GenericHibernate4DAO<T,PK> createDaoInstance(Class<T> clazz)
clazz - Copyright © 2019. All Rights Reserved.