|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsk.baka.tools.jpa.DaoTools
public class DaoTools
Contains useful utility methods for JPA entity retrieving.
Note for integrators: all methods in the class are meant to be run in a transaction. You'll have to configure your dependency injection tool to:setEntityManager(EntityManager) setter.
| Constructor Summary | |
|---|---|
DaoTools()
|
|
| Method Summary | ||
|---|---|---|
void |
delete(Object bean)
Removes given bean. |
|
int |
deleteAll(Class<?> aClass)
Deletes all instances of given JPA bean. |
|
void |
deleteById(Class<?> clazz,
Object id)
Deletes bean with given ID. |
|
|
find(Class<T> clazz,
CriteriaList criteria,
Paging paging,
Sorting sorting)
The ultimate find command :) Retrieves all instances of given JPA bean, sorted by a particular column, matching given criteria. |
|
|
findAll(Class<T> clazz)
Retrieves all instances of given JPA bean. |
|
|
findAll(Class<T> clazz,
int firstResult,
int maxResults)
Retrieves all instances of given JPA bean. |
|
|
findAll(Class<T> clazz,
int firstResult,
int maxResults,
String column,
boolean asc)
Retrieves all instances of given JPA bean, sorted by a particular column. |
|
|
findById(Class<T> clazz,
Object id)
Returns an entity with given ID. |
|
|
findSingle(Class<T> clazz)
Retrieves a single instances of JPA bean. |
|
long |
getCount(Class<?> clazz)
Returns a count of all instances of given JPA bean. |
|
long |
getCount(Class<?> clazz,
CriteriaList criteria)
Returns a count of instances of given JPA bean which passes given filtering criteria. |
|
void |
persist(Object bean)
Simply invokes the EntityManager.persist(java.lang.Object) method. |
|
void |
setEntityManager(javax.persistence.EntityManager em)
Sets the entity manager. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DaoTools()
| Method Detail |
|---|
public void setEntityManager(javax.persistence.EntityManager em)
em - the entity manager, must not be null.public <T> List<T> findAll(Class<T> clazz)
T - the JPA bean typeclazz - the bean class
public <T> List<T> findAll(Class<T> clazz,
int firstResult,
int maxResults)
T - the JPA bean typeclazz - the bean classfirstResult - the start position of the first result, numbered from 0maxResults - the maximum number of results to retrieve.
public <T> List<T> findAll(Class<T> clazz,
int firstResult,
int maxResults,
String column,
boolean asc)
T - the JPA bean typeclazz - the bean classfirstResult - the start position of the first result, numbered from 0maxResults - the maximum number of results to retrieve.column - sort using this column. A java bean field name, not a physical table column name.asc - use ascending order if true, descending order if false.
public <T> List<T> find(Class<T> clazz,
CriteriaList criteria,
Paging paging,
Sorting sorting)
T - the JPA bean typeclazz - the bean classpaging - defines the result paging. If null then all results are returned.criteria - declares conditions on the result list. If null then all results are returned.sorting - sort using given expression. If null then the sorting is undefined.
public <T> T findById(Class<T> clazz,
Object id)
T - the entity typeclazz - the entity classid - the ID
public long getCount(Class<?> clazz)
clazz - the bean class
public long getCount(Class<?> clazz,
CriteriaList criteria)
clazz - the bean classcriteria - the criteria. If null then no beans are filtered out.
public <T> T findSingle(Class<T> clazz)
T - the JPA bean typeclazz - the bean class
public int deleteAll(Class<?> aClass)
aClass - the JPA bean class.
public void delete(Object bean)
EntityManager.remove(java.lang.Object).
bean - the JPA beanpublic void persist(Object bean)
EntityManager.persist(java.lang.Object) method. Handles possibly detached entities
by invoking EntityManager.merge(java.lang.Object) if required. Expects that the entity ID is accessible by
invoking zero-arg getId() method.
bean - the bean to persist.
public void deleteById(Class<?> clazz,
Object id)
clazz - the bean classid - the ID.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||