]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java
Salome HOME
DAO's method getFilteredList is improved so that it is possible to do subqueries...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / kernel / GenericDAO.java
1 /*****************************************************************************
2  * Company         OPEN CASCADE
3  * Application     SIMAN
4  * File            $Id$ 
5  * Creation date   08.10.2012
6  * @author         $Author$
7  * @version        $Revision$
8  *****************************************************************************/
9
10 package org.splat.dal.dao.kernel;
11
12 import java.io.Serializable;
13 import java.util.List;
14 import java.util.Properties;
15
16 import org.hibernate.criterion.Criterion;
17 import org.hibernate.criterion.Order;
18
19 /**
20  * Generic DAO interface.
21  * 
22  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
23  * 
24  * @param <T>
25  *            Persistent object class
26  * @param <PK>
27  *            Primary key class
28  */
29 public interface GenericDAO<T, PK extends Serializable> {
30
31         /**
32          * Persist the newInstance object into database.
33          * 
34          * @param newInstance
35          *            new object as a transient instance
36          * @return new primary key for the created persistent object
37          */
38         PK create(T newInstance);
39
40         /**
41          * Persist the newInstance object into database.
42          * 
43          * @param newInstance
44          *            new object as a transient instance
45          */
46         public void saveOrUpdate(final T newInstance);
47
48         /**
49          * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
50          * 
51          * @param id
52          *            primary key of an object to read
53          * @return an object found by the given key
54          */
55         T get(PK id);
56
57         /**
58          * Save changes made to a persistent object.
59          * 
60          * @param transientObject
61          *            transient instance of the object to update
62          */
63         void update(T transientObject);
64
65         /**
66          * Remove an object from persistent storage in the database.
67          * 
68          * @param persistentObject
69          *            a persistent object to delete from the database
70          */
71         void delete(T persistentObject);
72
73         /**
74          * Retrieve an object that was previously persisted to the database using the given criteria.
75          * 
76          * @param aCondition
77          *            a search condition
78          * @return an object found according to the given criteria
79          */
80         public T findByCriteria(Criterion aCondition);
81
82         /**
83          * Retrieve an object that was previously persisted to the database using the given criteria.
84          * 
85          * @param andParams
86          *            a properties values to filter with AND condition
87          * @return an object found according to the given criteria
88          */
89         public T findByCriteria(Properties andParams);
90
91         /**
92          * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
93          * 
94          * @return a list of all objects of the considered type T
95          */
96         public List<T> getAll();
97
98         /**
99          * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
100          * 
101          * @param anOrder
102          *            a result list order. Null is ignored and in such case the result list is unordered.
103          * @return an ordered list of all objects of the considered type T
104          */
105         public List<T> getAll(Order... anOrder);
106
107         /**
108          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
109          * 
110          * @param aCondition
111          *            a search condition
112          * @return a list of objects filtered according to the given criteria
113          */
114         public List<T> getFilteredList(Criterion aCondition);
115
116         /**
117          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
118          * 
119          * @param aCondition
120          *            a search condition
121          * @param anOrder
122          *            a result list order. Null is ignored and in such case the result list is unordered.
123          * @return a list of objects filtered according to the given criteria
124          */
125         public List<T> getFilteredList(Criterion aCondition, Order... anOrder);
126
127         /**
128          * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
129          * Joined field allows applying a filter condition to the child object.<BR>
130          * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
131          * <code>knowledgeElementDAO.getFilteredList(
132                                 "type", Restrictions.eq("name", "bestpractice"));</code>
133          * 
134          * @param joinField
135          *            a field containing object to apply the condition
136          * 
137          * @param aCondition
138          *            a search condition
139          * @return a list of objects filtered according to the given criteria
140          */
141         public List<T> getFilteredList(final String joinField,
142                         final Criterion aCondition);
143
144         /**
145          * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
146          * Joined field allows applying a filter condition to the child object.<BR>
147          * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
148          * <code>knowledgeElementDAO.getFilteredList(
149                                 "type", Restrictions.eq("name", "bestpractice"), Order.asc("title"));</code>
150          * 
151          * @param joinField
152          *            a field containing object to apply the condition
153          * 
154          * @param aCondition
155          *            a search condition
156          * @param anOrder
157          *            a result list order. Null is ignored and in such case the result list is unordered.
158          * @return a list of objects filtered according to the given criteria
159          */
160         public List<T> getFilteredList(final String joinField,
161                         final Criterion aCondition, final Order... anOrder);
162
163         /**
164          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
165          * 
166          * @param andParams
167          *            a properties values to filter with AND condition
168          * @return a list of objects filtered according to the given criteria
169          */
170         public List<T> getFilteredList(Properties andParams);
171
172         /**
173          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
174          * 
175          * @param andParams
176          *            a properties values to filter with AND condition
177          * @param anOrder
178          *            a result list order. Null is ignored and in such case the result list is unordered.
179          * @return a list of objects filtered according to the given criteria
180          */
181         public List<T> getFilteredList(Properties andParams, Order... anOrder);
182
183         /**
184          * Makes detached object persistent.
185          * 
186          * @param transientObject
187          *            transient instance of the object to be made persistent
188          */
189         public void persist(T transientObject);
190
191         /**
192          * Merge detached object with persistent data.
193          * 
194          * @param transientObject
195          *            transient instance of the object to be merged with persistent data
196          * @return merged persistent object
197          */
198         public T merge(T transientObject);
199
200         /**
201          * Synchronize the session data with the database.
202          */
203         public void flush();
204 }