Salome HOME
bfed9c5ecc74fb9a13e2bf4e60924b5c17d82303
[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          * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
42          * 
43          * @param id
44          *            primary key of an object to read
45          * @return an object found by the given key
46          */
47         T get(PK id);
48
49         /**
50          * Save changes made to a persistent object.
51          * 
52          * @param transientObject
53          *            transient instance of the object to update
54          */
55         void update(T transientObject);
56
57         /**
58          * Remove an object from persistent storage in the database.
59          * 
60          * @param persistentObject
61          *            a persistent object to delete from the database
62          */
63         void delete(T persistentObject);
64
65         /**
66          * Retrieve an object that was previously persisted to the database using the given criteria.
67          * 
68          * @param aCondition
69          *            a search condition
70          * @return an object found according to the given criteria
71          */
72         public T findByCriteria(Criterion aCondition);
73
74         /**
75          * Retrieve an object that was previously persisted to the database using the given criteria.
76          * 
77          * @param andParams
78          *            a properties values to filter with AND condition
79          * @return an object found according to the given criteria
80          */
81         public T findByCriteria(Properties andParams);
82
83         /**
84          * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
85          * 
86          * @return a list of all objects of the considered type T
87          */
88         public List<T> getAll();
89
90         /**
91          * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
92          * 
93          * @param anOrder
94          *            a result list order. Null is ignored and in such case the result list is unordered.
95          * @return an ordered list of all objects of the considered type T
96          */
97         public List<T> getAll(Order... anOrder);
98
99         /**
100          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
101          * 
102          * @param aCondition
103          *            a search condition
104          * @return a list of objects filtered according to the given criteria
105          */
106         public List<T> getFilteredList(Criterion aCondition);
107
108         /**
109          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
110          * 
111          * @param aCondition
112          *            a search condition
113          * @param anOrder
114          *            a result list order. Null is ignored and in such case the result list is unordered.
115          * @return a list of objects filtered according to the given criteria
116          */
117         public List<T> getFilteredList(Criterion aCondition, Order... anOrder);
118
119         /**
120          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
121          * 
122          * @param andParams
123          *            a properties values to filter with AND condition
124          * @return a list of objects filtered according to the given criteria
125          */
126         public List<T> getFilteredList(Properties andParams);
127
128         /**
129          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
130          * 
131          * @param andParams
132          *            a properties values to filter with AND condition
133          * @param anOrder
134          *            a result list order. Null is ignored and in such case the result list is unordered.
135          * @return a list of objects filtered according to the given criteria
136          */
137         public List<T> getFilteredList(Properties andParams, Order... anOrder);
138
139         /**
140          * Makes detached object persistent.
141          * 
142          * @param transientObject
143          *            transient instance of the object to be made persistent
144          */
145         public void persist(T transientObject);
146
147         /**
148          * Merge detached object with persistent data.
149          * 
150          * @param transientObject
151          *            transient instance of the object to be merged with persistent data
152          * @return merged persistent object
153          */
154         public T merge(T transientObject);
155 }