Package net.hironico.common.entities
Class EntitiesUtils
java.lang.Object
net.hironico.common.entities.EntitiesUtils
Utility class for entity management operations with JPA EntityManager.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidremoveEntities(javax.persistence.EntityManager entityManager, Object... entities) REmoves all provided entities into a SINGLE transaction.static voidremoveEntity(javax.persistence.EntityManager entityManager, Object entity) Removes the entity from the database.static <T> List<T>saveEntities(javax.persistence.EntityManager entityManager, T... entities) Saves the entity into the database using commit transaction if possible.static <T> TsaveEntity(javax.persistence.EntityManager entityManager, T entity) Saves the entity into the database using commit transaction if possible.
-
Constructor Details
-
EntitiesUtils
public EntitiesUtils()
-
-
Method Details
-
saveEntities
@SafeVarargs public static <T> List<T> saveEntities(javax.persistence.EntityManager entityManager, T... entities) throws Exception Saves the entity into the database using commit transaction if possible. the transaction scope is the whole set of given entities. If one fails then the whole batch will be rollback.- Parameters:
entityManager- properly initialized entity managerentities- one or more entity to persist in the DB.- Returns:
- merged entities in a list.
- Throws:
Exception- in case of any problem
-
saveEntity
public static <T> T saveEntity(javax.persistence.EntityManager entityManager, T entity) throws Exception Saves the entity into the database using commit transaction if possible.- Parameters:
entityManager- properly initialized entity managerentity- entity object to save into database.- Returns:
- merged entity
- Throws:
Exception- in case of any problem
-
removeEntity
public static void removeEntity(javax.persistence.EntityManager entityManager, Object entity) throws Exception Removes the entity from the database.- Parameters:
entityManager- properly initialized entity managerentity- entity object to remove from database- Throws:
Exception- in case of any problem
-
removeEntities
public static void removeEntities(javax.persistence.EntityManager entityManager, Object... entities) throws Exception REmoves all provided entities into a SINGLE transaction.- Parameters:
entityManager- the entitiy manager to useentities- list of entities to delete in the database.- Throws:
Exception- in case of problem
-