1. Project Clover database Wed Jan 17 2024 23:40:18 CST
  2. Package org.europa.together.business

File GenericDAO.java

 

Code metrics

0
0
0
1
142
38
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
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
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
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
103    * @throws com.fasterxml.jackson.core.JsonProcessingException
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
116    * @throws java.lang.ClassNotFoundException
117    */
118    @API(status = STABLE, since = "2.1")
119    T deserializeJsonAsObject(String json, Class<T> object)
120    throws JsonProcessingException, ClassNotFoundException;
121   
122    /**
123    * Tries to create from a collection of JSON objects a list of enties.
124    *
125    * @param json as String
126    * @return List of Entities
127    * @throws JsonProcessingException
128    * @throws ClassNotFoundException
129    */
130    @API(status = STABLE, since = "3.0")
131    List<T> deserializeJsonAsList(String json)
132    throws JsonProcessingException, ClassNotFoundException;
133   
134    /**
135    * Try to find a persited domain object.
136    *
137    * @param id as Generic
138    * @return object as Generic
139    */
140    @API(status = STABLE, since = "1.0")
141    T find(PK id);
142    }