Salome HOME
More business logic has been moved from BO to services. ServiceLocator is created...
[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
15 import org.hibernate.criterion.Criterion;
16 import org.hibernate.criterion.Order;
17
18 /**
19  * Generic DAO interface.
20  * 
21  * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
22  * 
23  * @param <T>
24  *            Persistent object class
25  * @param <PK>
26  *            Primary key class
27  */
28 public interface GenericDAO<T, PK extends Serializable> {
29
30         /**
31          * Persist the newInstance object into database.
32          * 
33          * @param newInstance
34          *            new object as a transient instance
35          * @return new primary key for the created persistent object
36          */
37         PK create(T newInstance);
38
39         /**
40          * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
41          * 
42          * @param id
43          *            primary key of an object to read
44          * @return an object found by the given key
45          */
46         T get(PK id);
47
48         /**
49          * Save changes made to a persistent object.
50          * 
51          * @param transientObject
52          *            transient instance of the object to update
53          */
54         void update(T transientObject);
55
56         /**
57          * Remove an object from persistent storage in the database.
58          * 
59          * @param persistentObject
60          *            a persistent object to delete from the database
61          */
62         void delete(T persistentObject);
63
64         /**
65          * Retrieve an object that was previously persisted to the database using the given criteria.
66          * 
67          * @param aCondition
68          *            a search condition
69          * @return an object found according to the given criteria
70          */
71         public T findByCriteria(Criterion aCondition);
72
73         /**
74          * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
75          * 
76          * @return a list of all objects of the considered type T
77          */
78         @SuppressWarnings("unchecked")
79         public List<T> getAll();
80
81         /**
82          * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
83          * 
84          * @param anOrder
85          *            a result list order. Null is ignored and in such case the result list is unordered.
86          * @return an ordered list of all objects of the considered type T
87          */
88         @SuppressWarnings("unchecked")
89         public List<T> getAll(Order anOrder);
90         
91         /**
92          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
93          * 
94          * @param aCondition
95          *            a search condition
96          * @return a list of objects filtered according to the given criteria
97          */
98         public List<T> getFilteredList(Criterion aCondition);
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          * @param anOrder
105          *            a result list order. Null is ignored and in such case the result list is unordered.
106          * @return a list of objects filtered according to the given criteria
107          */
108         @SuppressWarnings("unchecked")
109         public List<T> getFilteredList(Criterion aCondition, Order anOrder);
110
111         /**
112          * Makes detached object persistent.
113          * @param transientObject
114          *            transient instance of the object to be made persistent
115          */
116         public void persist(T transientObject);
117
118         /**
119          * Merge detached object with persistent data.
120          * 
121          * @param transientObject
122          *            transient instance of the object to be merged with persistent data
123          * @return merged persistent object
124          */
125         public T merge(T transientObject);
126 }