public class TransactionHelper extends Object
Constructor and Description |
---|
TransactionHelper(javax.persistence.EntityManager manager) |
Modifier and Type | Method and Description |
---|---|
<T> T |
executeInTransaction(Runnable<T> runnable)
see executeInTransaction(runnable, clearAfterCommit) .
|
<T> T |
executeInTransaction(Runnable<T> runnable,
boolean clearAfterCommit)
Encapsulates execution of runnable.run() in transactions.
|
javax.persistence.EntityManager |
getEntityManager() |
<T> List<T> |
loadAllObjects(Class<T> clazz)
Returns all objects of the given class in persistence context.
|
<T> T |
loadObject(Class<T> clazz,
Object id)
Finds and returns the object of the given id in the persistence context.
|
<T> T |
loadObject(javax.persistence.EntityManager entityManager,
Class<T> clazz,
Object id) |
<T> T |
persist(T obj) |
<T> T |
persist(T obj,
javax.persistence.EntityManager entityManager) |
<T> T |
saveObject(T obj)
Saves the given object in the database.
|
public TransactionHelper(javax.persistence.EntityManager manager)
public final <T> T saveObject(T obj) throws Exception
T
- type of given object objobj
- object to saveException
- save objects failedpublic final <T> T loadObject(Class<T> clazz, Object id) throws Exception
T
- type of searched objectclazz
- type of searched objectid
- technical id of searched objectException
- finding object failedpublic final <T> List<T> loadAllObjects(Class<T> clazz) throws Exception
T
- type of searched objectsclazz
- type of searched objectsIllegalArgumentException
- if the instance is not an entityException
- selecting objects failedpublic final <T> T executeInTransaction(Runnable<T> runnable, boolean clearAfterCommit) throws Exception
T
- result type of runnable.run()runnable
- algorithm to executeclearAfterCommit
- true triggers entityManager.clear() after transaction
commitException
- execution failedpublic final <T> T executeInTransaction(Runnable<T> runnable) throws Exception
T
- result type of runnable.run()runnable
- algorithm to executeException
- execution failedpublic final javax.persistence.EntityManager getEntityManager()
public <T> T persist(T obj, javax.persistence.EntityManager entityManager)
public <T> T persist(T obj)
Copyright © 2014. All rights reserved.