|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.muni.fi.pclis.commons.dao.GenericHibernateDao<T>
@Repository public class GenericHibernateDao<T extends DomainObject>
Generic hibernate implementation of GenericDao
Field Summary | |
---|---|
private javax.persistence.EntityManager |
entityManager
Used Entity Manager |
private boolean |
FIND_LOCK_DEFAULT
|
private Class<? extends T> |
persistentClass
Persistent class of this DAO |
Constructor Summary | |
---|---|
|
GenericHibernateDao()
Creates new GenericHibernateDao with the \ persistentClass being the class of generalized type ( |
protected |
GenericHibernateDao(Class<? extends T> persistentClass)
Creates new GenericHibernateDao |
Method Summary | ||
---|---|---|
boolean |
contains(T entity)
Returns true if the entity is persisted |
|
boolean |
containsById(Long id)
Returns true if entity with given id is persisted |
|
void |
create(T entity)
Persists the entity |
|
protected org.hibernate.Query |
createHibernateQuery(String query)
creates hibernate query |
|
protected javax.persistence.Query |
createJPAQuery(String query)
creates JPA query |
|
protected javax.persistence.Query |
createNamedQuery(String name)
Creates named query |
|
protected javax.persistence.Query |
createQuery(String query)
creates query |
|
protected List<T> |
createResultList()
Creates the new result list used to store dao method results. |
|
protected Set<T> |
createResultSet()
Creates the new result set used to store dao method results. |
|
void |
delete(T entity)
Deletes the entity from the database |
|
javax.persistence.EntityManager |
em()
Uses the entity manager for internal purposes. |
|
List<T> |
findAll()
Returns list of all entities in natural sort order. |
|
protected List<T> |
findByCriteria(org.hibernate.criterion.Criterion... criterion)
Searches through database by given criteria |
|
T |
findById(long id)
Finds the object by its id |
|
T |
findById(long id,
boolean lock)
Finds the object by its id |
|
List<T> |
findByIDs(long[] IDs,
boolean lck)
Searches for the objects by their respective id's. |
|
void |
flush()
flushes the cachce to the database |
|
protected String |
getEntityClassSimpleName()
Gets the simple name of entity class |
|
javax.persistence.EntityManager |
getEntityManager()
Gets the entityManager. |
|
protected org.hibernate.ejb.HibernateEntityManager |
getHibernateEntityManager()
|
|
protected org.hibernate.Session |
getHibernateSession()
|
|
Class<? extends T> |
getPersistentClass()
Returns the type of the implemented dato |
|
protected T |
getQuerySingleOrNullResult(javax.persistence.Query query)
Returns single result of the query or null value if the result is empty |
|
protected T |
getSingleResult(javax.persistence.Query query)
Returns the single result of the query |
|
|
refresh(T entity)
Refreshes the entity from the database |
|
List |
runNamedQuery(String name,
Map<String,Object> params)
Runs named query |
|
Object |
runNamedQueryForSingleResult(String name,
Map<String,Object> params)
Runs named query which should return single result |
|
T |
save(T entity)
Merge the state of the given entity into the current dao context. |
|
void |
setEntityManager(javax.persistence.EntityManager entityManager)
|
|
Set<T> |
toSet(Collection col)
Utility. |
|
static
|
toSet(Collection col,
Class<? extends T> cls)
Utility. |
|
T |
update(T entity)
Update the persistent instance with the identifier of the given detached instance. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final boolean FIND_LOCK_DEFAULT
private Class<? extends T extends DomainObject> persistentClass
private javax.persistence.EntityManager entityManager
Constructor Detail |
---|
public GenericHibernateDao()
persistentClass
being the class of generalized type (
protected GenericHibernateDao(Class<? extends T> persistentClass)
persistentClass
- Method Detail |
---|
public void setEntityManager(javax.persistence.EntityManager entityManager)
entityManager
- Sets entityManager.public javax.persistence.EntityManager getEntityManager()
public javax.persistence.EntityManager em()
entityManager
is not set \
( by none possible way ( ioc / manual setting)) \
it throws the detailed IllegalStateException
.
IllegalStateException
- if the entityManager
is not set.protected org.hibernate.ejb.HibernateEntityManager getHibernateEntityManager()
protected org.hibernate.Session getHibernateSession()
public Class<? extends T> getPersistentClass()
GenericDao
getPersistentClass
in interface GenericDao<T extends DomainObject>
protected final String getEntityClassSimpleName()
public T findById(long id)
findById
in interface GenericDao<T extends DomainObject>
id
- of the object
public T findById(long id, boolean lock)
GenericDao
findById
in interface GenericDao<T extends DomainObject>
id
- of the objectlock
- if the object should be locked in the database
public List<T> findByIDs(long[] IDs, boolean lck)
findByIDs
in interface GenericDao<T extends DomainObject>
@Transactional public List<T> findAll()
GenericDao
findAll
in interface GenericDao<T extends DomainObject>
public T save(T entity)
GenericDao
save
in interface GenericDao<T extends DomainObject>
public T update(T entity)
update
in interface GenericDao<T extends DomainObject>
entity
- a detached instance containing updated stateSession.update(Object)
public void create(T entity)
create
in interface GenericDao<T extends DomainObject>
public boolean contains(T entity)
contains
in interface GenericDao<T extends DomainObject>
public boolean containsById(Long id)
containsById
in interface GenericDao<T extends DomainObject>
public void delete(T entity)
delete
in interface GenericDao<T extends DomainObject>
public <T> T refresh(T entity)
refresh
in interface GenericDao<T extends DomainObject>
public void flush()
flush
in interface GenericDao<T extends DomainObject>
protected List<T> findByCriteria(org.hibernate.criterion.Criterion... criterion)
criterion
-
protected final javax.persistence.Query createNamedQuery(String name)
name
-
protected final javax.persistence.Query createQuery(String query)
query
-
protected final javax.persistence.Query createJPAQuery(String query)
query
-
protected final org.hibernate.Query createHibernateQuery(String query)
query
-
protected final T getQuerySingleOrNullResult(javax.persistence.Query query)
query
-
javax.persistence.NonUniqueResultException
- if the query returns more than one resultpublic List runNamedQuery(String name, Map<String,Object> params)
runNamedQuery
in interface GenericDao<T extends DomainObject>
name
- of the query
public Object runNamedQueryForSingleResult(String name, Map<String,Object> params)
runNamedQueryForSingleResult
in interface GenericDao<T extends DomainObject>
name
- of the query
public Set<T> toSet(Collection col)
col
-
public static <T> Set<T> toSet(Collection col, Class<? extends T> cls)
col
-
protected List<T> createResultList()
protected Set<T> createResultSet()
protected T getSingleResult(javax.persistence.Query query)
query
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |