1 /*****************************************************************************
5 * Creation date 08.10.2012
8 *****************************************************************************/
10 package org.splat.dal.dao.kernel;
12 import java.io.Serializable;
13 import java.util.List;
14 import java.util.Properties;
16 import org.hibernate.criterion.Criterion;
17 import org.hibernate.criterion.Order;
20 * Generic DAO interface.
22 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
25 * Persistent object class
29 public interface GenericDAO<T, PK extends Serializable> {
32 * Persist the newInstance object into database.
35 * new object as a transient instance
36 * @return new primary key for the created persistent object
38 PK create(T newInstance);
41 * Persist the newInstance object into database.
44 * new object as a transient instance
46 public void saveOrUpdate(final T newInstance);
49 * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
52 * primary key of an object to read
53 * @return an object found by the given key
58 * Save changes made to a persistent object.
60 * @param transientObject
61 * transient instance of the object to update
63 void update(T transientObject);
66 * Remove an object from persistent storage in the database.
68 * @param persistentObject
69 * a persistent object to delete from the database
71 void delete(T persistentObject);
74 * Retrieve an object that was previously persisted to the database using the given criteria.
78 * @return an object found according to the given criteria
80 public T findByCriteria(Criterion aCondition);
83 * Retrieve an object that was previously persisted to the database using the given criteria.
86 * a properties values to filter with AND condition
87 * @return an object found according to the given criteria
89 public T findByCriteria(Properties andParams);
92 * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
94 * @return a list of all objects of the considered type T
96 public List<T> getAll();
99 * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
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
105 public List<T> getAll(Order... anOrder);
108 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
112 * @return a list of objects filtered according to the given criteria
114 public List<T> getFilteredList(Criterion aCondition);
117 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
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
125 public List<T> getFilteredList(Criterion aCondition, Order... anOrder);
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>
135 * a field containing object to apply the condition
139 * @return a list of objects filtered according to the given criteria
141 public List<T> getFilteredList(final String joinField,
142 final Criterion aCondition);
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>
152 * a field containing object to apply the condition
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
160 public List<T> getFilteredList(final String joinField,
161 final Criterion aCondition, final Order... anOrder);
164 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
167 * a properties values to filter with AND condition
168 * @return a list of objects filtered according to the given criteria
170 public List<T> getFilteredList(Properties andParams);
173 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
176 * a properties values to filter with AND condition
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
181 public List<T> getFilteredList(Properties andParams, Order... anOrder);
184 * Makes detached object persistent.
186 * @param transientObject
187 * transient instance of the object to be made persistent
189 public void persist(T transientObject);
192 * Merge detached object with persistent data.
194 * @param transientObject
195 * transient instance of the object to be merged with persistent data
196 * @return merged persistent object
198 public T merge(T transientObject);
201 * Synchronize the session data with the database.