Package org.europa.together.application
Class GenericHbmDAO<T,PK extends Serializable>
java.lang.Object
org.europa.together.application.GenericHbmDAO<T,PK>
- Type Parameters:
T
- as template.PK
- as PrimaryKey
- All Implemented Interfaces:
Serializable
,GenericDAO<T,
PK>
- Direct Known Subclasses:
ConfigurationHbmDAO
@Repository
@Transactional
public abstract class GenericHbmDAO<T,PK extends Serializable>
extends Object
implements GenericDAO<T,PK>
Abstract implementation of Domain Access Object (DAO) Pattern.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionjakarta.persistence.EntityManager
JPA Entity Manager for Transactions.Fields inherited from interface org.europa.together.business.GenericDAO
FEATURE_ID
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
Count the entries of corresponding table to the domain object is specialized in the DAO.boolean
Persist a new entity and return TRUE if it was successful.In the case that the entity is already existing or the persist project is not a valid entity the method return FALSE.void
Search for an persistent entity.If it's already existent then it will be delete, otherwise a EntityNotFoundException will thrown.deserializeJsonAsList
(String json) Tries to create from a collection of JSON objects a list of enties.deserializeJsonAsObject
(String json, Class<T> object) Tried to create a entity object from a given JSON String.Try to find a persited domain object.getPrimaryKeyOfObject
(T object) Get the primary key of the DAO entity.listAllElements
(JpaPagination pivotElement) Get all persited entries of an entity as list.serializeAsJson
(T object) Check if the entity is not NULL and try to create a JSON object as String, otherwise the String will be empty.void
Search an entity in the persistence context and update it.If it's not exist a EntityNotFoundException will thrown.
-
Field Details
-
mainEntityManagerFactory
public transient jakarta.persistence.EntityManager mainEntityManagerFactoryJPA Entity Manager for Transactions.
-
-
Constructor Details
-
GenericHbmDAO
public GenericHbmDAO()Constructor.
-
-
Method Details
-
create
Description copied from interface:GenericDAO
Persist a new entity and return TRUE if it was successful.In the case that the entity is already existing or the persist project is not a valid entity the method return FALSE.- Specified by:
create
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
object
- as Generic- Returns:
- true on success
-
delete
Description copied from interface:GenericDAO
Search for an persistent entity.If it's already existent then it will be delete, otherwise a EntityNotFoundException will thrown.- Specified by:
delete
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
id
- as Generic- Throws:
DAOException
-
update
Description copied from interface:GenericDAO
Search an entity in the persistence context and update it.If it's not exist a EntityNotFoundException will thrown.- Specified by:
update
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
id
- as Genericobject
- as Generic- Throws:
DAOException
-
countAllElements
@Transactional(readOnly=true) public long countAllElements()Description copied from interface:GenericDAO
Count the entries of corresponding table to the domain object is specialized in the DAO.- Specified by:
countAllElements
in interfaceGenericDAO<T,
PK extends Serializable> - Returns:
- count as long
-
listAllElements
Description copied from interface:GenericDAO
Get all persited entries of an entity as list.- Specified by:
listAllElements
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
pivotElement
- as JpaPagination- Returns:
- List of Entity Objects
-
getPrimaryKeyOfObject
Description copied from interface:GenericDAO
Get the primary key of the DAO entity.- Specified by:
getPrimaryKeyOfObject
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
object
- as Genric- Returns:
- id as Genric
-
serializeAsJson
Description copied from interface:GenericDAO
Check if the entity is not NULL and try to create a JSON object as String, otherwise the String will be empty.- Specified by:
serializeAsJson
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
object
- as Generic- Returns:
- JSON object as String
- Throws:
JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
-
deserializeJsonAsObject
public T deserializeJsonAsObject(String json, Class<T> object) throws JsonProcessingException, ClassNotFoundException Description copied from interface:GenericDAO
Tried to create a entity object from a given JSON String.- Specified by:
deserializeJsonAsObject
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
json
- as Stringobject
- as T- Returns:
- Entity as Generic
- Throws:
JsonProcessingException
ClassNotFoundException
-
deserializeJsonAsList
public List<T> deserializeJsonAsList(String json) throws JsonProcessingException, ClassNotFoundException Description copied from interface:GenericDAO
Tries to create from a collection of JSON objects a list of enties.- Specified by:
deserializeJsonAsList
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
json
- as String- Returns:
- List of Entities
- Throws:
JsonProcessingException
ClassNotFoundException
-
find
Description copied from interface:GenericDAO
Try to find a persited domain object.- Specified by:
find
in interfaceGenericDAO<T,
PK extends Serializable> - Parameters:
id
- as Generic- Returns:
- object as Generic
-