Salome HOME
Refactoring of Database, replacing SQL by DAOs calls. Methods for search by criteria...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / dao / kernel / GenericDAO.java
1 /*****************************************************************************
2  * Company         EURIWARE
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 objects which were previously persisted to the database using the given criteria.
75          * 
76          * @param aCondition
77          *            a search condition
78          * @return a list of objects filtered according to the given criteria
79          */
80         public List<T> getFilteredList(Criterion aCondition);
81         /**
82          * Retrieve a list of objects which were previously persisted to the database using the given criteria.
83          * 
84          * @param aCondition
85          *            a search condition
86          * @param anOrder
87          *            a result list order. Null is ignored and in such case the result list is unordered.
88          * @return a list of objects filtered according to the given criteria
89          */
90         @SuppressWarnings("unchecked")
91         public List<T> getFilteredList(Criterion aCondition, Order anOrder);
92 }