|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.sidaof.dao.AbstractDao<K,E>
net.sf.sidaof.dao.jpa.AbstractJpaDao<K,E>
K - The primary key class of the entity, e.g. Long.E - The entity class the DAO persists, e.g. Person.public abstract class AbstractJpaDao<K,E>
Base class for JPA DAOs. To use, extend it in DAO classes and implement
JpaDao.getEntityManager().
JpaDao.getEntityManager() is externalized to allow subclasses to obtain the
correct entity manager, particularly when using multiple persistence units,
and in the necessary manner, e.g. specifying the unitName:
@PersistenceContext(unitName = "persistenceUnitName") private EntityManager entityManager;
JpaDaoImpl| Field Summary | |
|---|---|
private static org.slf4j.Logger |
LOG
|
| Fields inherited from class net.sf.sidaof.dao.AbstractDao |
|---|
entityClass, QUERY_SINGLERESULT_MULTFOUND_LOGMSG, QUERY_SINGLERESULT_NOTFOUND_LOGMSG |
| Constructor Summary | |
|---|---|
AbstractJpaDao()
Make a new instance, automatically determining the entity class. |
|
AbstractJpaDao(Class<E> entityClass)
Make a new instance, specifying the entity class. |
|
| Method Summary | |
|---|---|
void |
clear()
Clear the in-memory persistable state, including unflushed changes. |
boolean |
contains(E entity)
Check if the entity belongs to the current persistence context. |
Long |
countAll(String where,
String pathExpression)
Count all values represented by the specified where clause and pathExpression for the entity class this DAO persists. |
List<E> |
findAll()
Find all entities. |
List<E> |
findAll(int startPosition,
int maxResult)
Find all entities starting in the resultset specified by startPosition and obtaining up to the number specified by maxResult. |
E |
findById(K id)
Find an entity by its id, and return null if not found. |
E |
findById(K id,
javax.persistence.LockModeType lockMode,
boolean exceptionIfNotFound)
Find an entity by its id, optionally throwing an exception if not found (this prevents NullPointerExceptions from occurring later),
and optionally locking the found entity. |
void |
flush()
Synchronize the underlying persistent store with persistable state held in memory. |
protected void |
handleQueryException(String msg,
javax.persistence.PersistenceException e,
javax.persistence.Query q,
boolean throwException)
|
E |
merge(E entity)
Merge the entity. |
void |
persist(E entity)
Save the entity. |
void |
refresh(E entity)
Reload the entity. |
void |
remove(E entity)
Delete the entity. |
E |
runQueryWithSingleResult(javax.persistence.Query q)
Run the specified query, using getSingleResult(), expecting a single entity result and returning null if not found. |
E |
runQueryWithSingleResult(javax.persistence.Query q,
javax.persistence.LockModeType lockMode,
boolean exceptionIfNotFound)
Run the specified query, using getSingleResult(), expecting a single entity result and returning null if not found. |
| Methods inherited from class net.sf.sidaof.dao.AbstractDao |
|---|
countAll, countAll, getEntityClass, persist |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface net.sf.sidaof.dao.jpa.JpaDao |
|---|
getEntityManager, setEntityManager |
| Methods inherited from interface net.sf.sidaof.dao.Dao |
|---|
countAll, countAll, persist |
| Field Detail |
|---|
private static final org.slf4j.Logger LOG
| Constructor Detail |
|---|
public AbstractJpaDao()
public AbstractJpaDao(Class<E> entityClass)
entityClass - The entity class to manage.| Method Detail |
|---|
public E findById(K id)
Dao
findById in interface Dao<K,E>id - The id (primary key) of the entity to find.
public E findById(K id,
javax.persistence.LockModeType lockMode,
boolean exceptionIfNotFound)
JpaDaoNullPointerExceptions from occurring later),
and optionally locking the found entity.
findById in interface JpaDao<K,E>id - The id (primary key) of the entity to find.lockMode - Lock the entity in the persistence context for the specified
lockMode, or null for no locking.exceptionIfNotFound - true to throw an exception if entity not found.
public List<E> findAll()
Dao
findAll in interface Dao<K,E>
public List<E> findAll(int startPosition,
int maxResult)
Dao
findAll in interface Dao<K,E>startPosition - The starting position in the result set to retrieve.maxResult - The maximum number of rows to retrieve.
public void persist(E entity)
Dao
persist in interface Dao<K,E>entity - The persistence entity to save.public E merge(E entity)
Dao
merge in interface Dao<K,E>entity - The persistence entity to merge.
public void remove(E entity)
Dao
remove in interface Dao<K,E>entity - The persistence entity to delete.public void clear()
Dao
clear in interface Dao<K,E>public void flush()
Dao
flush in interface Dao<K,E>public boolean contains(E entity)
Dao
contains in interface Dao<K,E>entity - The persistence entity to see if exists.
public void refresh(E entity)
Dao
refresh in interface Dao<K,E>entity - The persistence entity to reload from the persistence context.
public Long countAll(String where,
String pathExpression)
DaoThis convenience method is meant for simple count queries. For complex ones, create custom ones in the product DAOs.
countAll in interface Dao<K,E>where - The where clause to append to the count query to narrow the
counted values. Do not prefix with "where" as it is
automatically added. The underlying query uses "e" as the
identification variable, so the where will use "e", e.g.
"e.name = 'Fred'". Specifying null disregards a where clause.pathExpression - A String representing the object graph navigation to the
element to count. The underlying query uses "e" as the
identification variable, so the pathExpression will u "e",
e.g. "e.address.zip", "e.name", "e.id". Specify either an
identification variable (e.g. "e") or a path expression (e.g.
"e.address.zip"). Specifying null disregards a pathExpression
(defaults to "*").
public E runQueryWithSingleResult(javax.persistence.Query q)
JpaDao
runQueryWithSingleResult in interface JpaDao<K,E>q - The query to run getSingleResult() on.
public E runQueryWithSingleResult(javax.persistence.Query q,
javax.persistence.LockModeType lockMode,
boolean exceptionIfNotFound)
JpaDao
runQueryWithSingleResult in interface JpaDao<K,E>q - The query to run getSingleResult() on.lockMode - Lock the entity in the persistence context for the specified
lockMode, or null for no locking.exceptionIfNotFound - true to throw an exception if entity not found.
protected void handleQueryException(String msg,
javax.persistence.PersistenceException e,
javax.persistence.Query q,
boolean throwException)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||