1. Project Clover database Mon Dec 22 2025 14:59:38 CST
  2. Package org.europa.together.business

File GenericDAO.java

 

Code metrics

0
0
0
1
159
42
0
-
-
0
-

Classes

Class Line # Actions
GenericDAO 28 0 - 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package org.europa.together.business;
2   
3    import java.io.Serializable;
4    import java.util.List;
5    import org.apiguardian.api.API;
6    import static org.apiguardian.api.API.Status.STABLE;
7    import org.europa.together.domain.JpaPagination;
8    import org.europa.together.exceptions.DAOException;
9    import org.europa.together.exceptions.JsonProcessingException;
10    import org.springframework.stereotype.Component;
11   
12    /**
13    * GenericDAO primary for CRUD database operations. To use the DAO by your own
14    * configuration, you need to load the spring-dao.xml into your Spring
15    * context.<br>
16    * A detailed documentation can found at:
17    * https://github.com/ElmarDott/TP-CORE/wiki/%5BCORE-02%5D-generic-Data-Access-Object---DAO
18    *
19    * @param <T> the entity to save
20    * @param <PK> the primary key
21    *
22    * @author elmar.dott@gmail.com
23    * @version 1.4
24    * @since 1.0
25    */
26    @API(status = STABLE, since = "1.0", consumers = "GenrericHbmDAO")
27    @Component
 
28    public interface GenericDAO<T, PK extends Serializable> extends Serializable {
29   
30    /**
31    * Identifier for the given feature.
32    */
33    @API(status = STABLE, since = "1.2")
34    String FEATURE_ID = "CM-02";
35   
36    /**
37    * Persist a new entity and return TRUE if it was successful.In the case
38    * that the entity is already existing or the persist project is not a valid
39    * entity the method return FALSE.
40    *
41    * @param object as Generic
42    * @return true on success
43    * @throws org.europa.together.exceptions.DAOException in case of error
44    */
45    @API(status = STABLE, since = "1.0")
46    boolean create(T object) throws DAOException;
47   
48    /**
49    * Search for an persistent entity.If it's already existent then it will be
50    * delete, otherwise a EntityNotFoundException will thrown.
51    *
52    * @param id as Generic
53    * @throws org.europa.together.exceptions.DAOException in case of error
54    */
55    @API(status = STABLE, since = "1.0")
56    void delete(PK id) throws DAOException;
57   
58    /**
59    * Search an entity in the persistence context and update it.If it's not
60    * exist a EntityNotFoundException will thrown.
61    *
62    * @param id as Generic
63    * @param object as Generic
64    * @throws org.europa.together.exceptions.DAOException in case of error
65    */
66    @API(status = STABLE, since = "1.0")
67    void update(PK id, T object) throws DAOException;
68   
69    /**
70    * Count the entries of corresponding table to the domain object is
71    * specialized in the DAO.
72    *
73    * @return count as long
74    */
75    @API(status = STABLE, since = "3.0")
76    long countAllElements();
77   
78    /**
79    * Get all persited entries of an entity as list.
80    *
81    * @param seekElement as JpaPagination
82    * @return List of Entity Objects
83    */
84    @API(status = STABLE, since = "1.0")
85    List<T> listAllElements(JpaPagination seekElement);
86   
87    /**
88    * Get the primary key of the DAO entity.
89    *
90    * @param object as Genric
91    * @return id as Genric
92    */
93    @API(status = STABLE, since = "1.0")
94    PK getPrimaryKeyOfObject(T object);
95   
96    /**
97    * Check if the entity is not NULL and try to create a JSON object as
98    * String, otherwise the String will be empty.
99    *
100    * @param object as Generic
101    * @return JSON object as String
102    * @throws org.europa.together.exceptions.JsonProcessingException in case of
103    * error
104    */
105    @API(status = STABLE, since = "1.0")
106    String serializeAsJson(T object)
107    throws JsonProcessingException;
108   
109    /**
110    * Tried to create a entity object from a given JSON String.
111    *
112    * @param json as String
113    * @param object as T
114    * @return Entity as Generic
115    * @throws org.europa.together.exceptions.JsonProcessingException in case of
116    * error
117    * @throws java.lang.ClassNotFoundException in case of error
118    */
119    @API(status = API.Status.DEPRECATED, since = "2.1")
120    @Deprecated
121    //TOTO: Remove in Release TP-CORE 4.0.0 (API Change)
122    T deserializeJsonAsObject(String json, Class<T> object)
123    throws JsonProcessingException, ClassNotFoundException;
124   
125    /**
126    * Tried to create a entity object from a given JSON String.
127    *
128    * @param json as String
129    * @return Entity as Generic
130    * @throws org.europa.together.exceptions.JsonProcessingException in case of
131    * error
132    * @throws java.lang.ClassNotFoundException in case of error
133    */
134    @API(status = STABLE, since = "3.2")
135    T deserializeJsonAsObject(String json)
136    throws JsonProcessingException, ClassNotFoundException;
137   
138    /**
139    * Tries to create from a collection of JSON objects a list of enties.
140    *
141    * @param json as String
142    * @return List of Entities
143    * @throws org.europa.together.exceptions.JsonProcessingException in case of
144    * error
145    * @throws java.lang.ClassNotFoundException in case of error
146    */
147    @API(status = STABLE, since = "3.0")
148    List<T> deserializeJsonAsList(String json)
149    throws JsonProcessingException, ClassNotFoundException;
150   
151    /**
152    * Try to find a persited domain object.
153    *
154    * @param id as Generic
155    * @return object as Generic
156    */
157    @API(status = STABLE, since = "1.0")
158    T find(PK id);
159    }