|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openwms.core.integration.jpa.AbstractGenericJpaDao<T,ID>
T
- Any serializable type, mostly an Entity class type.ID
- The type of the Entity class' unique id@Transactional(propagation=MANDATORY) public abstract class AbstractGenericJpaDao<T extends AbstractEntity,ID extends Serializable>
An AbstractGenericJpaDao - Extend this DAO implementation to inherit simple JPA CRUD operations.
This GenericDao
implementation acts as a transactional superclass to
have a benefit from Springs exception translation and transaction management.
Furthermore an AbstractGenericJpaDao
has transactional behavior
expressed with Springs Transactional
annotation.
Repository
,
Transactional
Field Summary | |
---|---|
protected org.slf4j.Logger |
logger
Logger instance can be used by subclasses. |
Fields inherited from interface org.openwms.core.integration.GenericDao |
---|
FIND_ALL, FIND_BY_ID |
Constructor Summary | |
---|---|
protected |
AbstractGenericJpaDao()
Create a new AbstractGenericJpaDao. |
Method Summary | |
---|---|
protected void |
beforeUpdate(T entity)
This method is considered as a hook to do something before an update is performed. |
List<T> |
findAll()
Find all entities and return them as a List . |
T |
findById(ID id)
Find and return the entity identified by the technical key. |
List<T> |
findByNamedParameters(String queryName,
Map<String,?> params)
Use a named query to find all entities. |
List<T> |
findByPositionalParameters(String queryName,
Object... values)
Use an own JPA query to fetch entities. |
T |
findByUniqueId(Serializable id)
Find and return the entity identified by the natural unique id. |
protected javax.persistence.EntityManager |
getEm()
Subclasses can call this method to retrieve an shared EntityManager instance. |
protected abstract String |
getFindAllQuery()
Returns the name of the NamedQuery to find all Entity
classes. |
protected abstract String |
getFindByUniqueIdQuery()
Returns the name of the NamedQuery to find an Entity by the
business key. |
protected Class<T> |
getPersistentClass()
Returns the entity class to deals with. The Java Reflection API is used to find the type. |
void |
persist(T entity)
Persist a transient entity. |
void |
remove(T entity)
Removes an already persistent entity. |
T |
save(T entity)
Synchronize an entity with the persistence layer and return it. |
void |
setPersistentClass(Class<T> persistentClass)
Set the type of entity to deal with. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.slf4j.Logger logger
Constructor Detail |
---|
protected AbstractGenericJpaDao()
Method Detail |
---|
protected Class<T> getPersistentClass()
public void setPersistentClass(Class<T> persistentClass)
setPersistentClass
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
persistentClass
- Class type of the entity instancepublic T findById(ID id)
findById
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
id
- Unique technical key to find the entity
public List<T> findAll()
List
.
findAll
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
public List<T> findByNamedParameters(String queryName, Map<String,?> params)
NamedQuery
and a parameter map.
findByNamedParameters
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
queryName
- Defined name of the NamedQueryparams
- Map of parameters to pass to the query
public List<T> findByPositionalParameters(String queryName, Object... values)
findByPositionalParameters
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
queryName
- Defined name of the NamedQueryvalues
- A list of values to use as parameters
public T findByUniqueId(Serializable id)
NoUniqueResultException
is thrown when more than one entity was
found. In case of no result, null
is returned.
findByUniqueId
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
id
- Natural key to find the entity (also known as business key)
null
NoUniqueResultException
- when more than one entity was foundpublic T save(T entity)
save
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
entity
- Entity instance to be synchronized with the persistence layer
public void remove(T entity)
remove
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
entity
- Entity instance to be removedpublic void persist(T entity)
persist
in interface GenericDao<T extends AbstractEntity,ID extends Serializable>
entity
- Entity instance to be persistedprotected abstract String getFindAllQuery()
NamedQuery
to find all Entity
classes.
protected abstract String getFindByUniqueIdQuery()
NamedQuery
to find an Entity by the
business key.
protected void beforeUpdate(T entity)
entity
- The Entity that is updatedprotected final javax.persistence.EntityManager getEm()
EntityManager
instance.
EntityManager
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |