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
FieldsModifier and TypeFieldDescriptionjakarta.persistence.EntityManagerJPA Entity Manager for Transactions.Fields inherited from interface org.europa.together.business.GenericDAO
FEATURE_ID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongCount the entries of corresponding table to the domain object is specialized in the DAO.booleanPersist 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.voidSearch 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.Tried to create a entity object from a given JSON String.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.voidSearch 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:GenericDAOPersist 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:
createin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
object- as Generic- Returns:
- true on success
-
delete
Description copied from interface:GenericDAOSearch for an persistent entity.If it's already existent then it will be delete, otherwise a EntityNotFoundException will thrown.- Specified by:
deletein interfaceGenericDAO<T,PK extends Serializable> - Parameters:
id- as Generic- Throws:
DAOException- in case of error
-
update
Description copied from interface:GenericDAOSearch an entity in the persistence context and update it.If it's not exist a EntityNotFoundException will thrown.- Specified by:
updatein interfaceGenericDAO<T,PK extends Serializable> - Parameters:
id- as Genericobject- as Generic- Throws:
DAOException- in case of error
-
countAllElements
@Transactional(readOnly=true) public long countAllElements()Description copied from interface:GenericDAOCount the entries of corresponding table to the domain object is specialized in the DAO.- Specified by:
countAllElementsin interfaceGenericDAO<T,PK extends Serializable> - Returns:
- count as long
-
listAllElements
Description copied from interface:GenericDAOGet all persited entries of an entity as list.- Specified by:
listAllElementsin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
pivotElement- as JpaPagination- Returns:
- List of Entity Objects
-
getPrimaryKeyOfObject
Description copied from interface:GenericDAOGet the primary key of the DAO entity.- Specified by:
getPrimaryKeyOfObjectin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
object- as Genric- Returns:
- id as Genric
-
serializeAsJson
Description copied from interface:GenericDAOCheck if the entity is not NULL and try to create a JSON object as String, otherwise the String will be empty.- Specified by:
serializeAsJsonin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
object- as Generic- Returns:
- JSON object as String
- Throws:
JsonProcessingException- in case of error
-
deserializeJsonAsObject
public T deserializeJsonAsObject(String json, Class<T> object) throws JsonProcessingException, ClassNotFoundException Description copied from interface:GenericDAOTried to create a entity object from a given JSON String.- Specified by:
deserializeJsonAsObjectin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
json- as Stringobject- as T- Returns:
- Entity as Generic
- Throws:
JsonProcessingException- in case of errorClassNotFoundException- in case of error
-
deserializeJsonAsObject
public T deserializeJsonAsObject(String json) throws JsonProcessingException, ClassNotFoundException Description copied from interface:GenericDAOTried to create a entity object from a given JSON String.- Specified by:
deserializeJsonAsObjectin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
json- as String- Returns:
- Entity as Generic
- Throws:
JsonProcessingException- in case of errorClassNotFoundException- in case of error
-
deserializeJsonAsList
public List<T> deserializeJsonAsList(String json) throws JsonProcessingException, ClassNotFoundException Description copied from interface:GenericDAOTries to create from a collection of JSON objects a list of enties.- Specified by:
deserializeJsonAsListin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
json- as String- Returns:
- List of Entities
- Throws:
JsonProcessingException- in case of errorClassNotFoundException- in case of error
-
find
Description copied from interface:GenericDAOTry to find a persited domain object.- Specified by:
findin interfaceGenericDAO<T,PK extends Serializable> - Parameters:
id- as Generic- Returns:
- object as Generic
-