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.LockOptions;
17 import org.hibernate.Session;
18 import org.hibernate.criterion.Criterion;
19 import org.hibernate.criterion.DetachedCriteria;
20 import org.hibernate.criterion.Order;
23 * Generic DAO interface.
25 * @author <a href="mailto:roman.kozlov@opencascade.com">Roman Kozlov (RKV)</a>
28 * Persistent object class
32 public interface GenericDAO<T, PK extends Serializable> {
35 * Persist the newInstance object into database.
38 * new object as a transient instance
39 * @return new primary key for the created persistent object
40 * @see Session#save(Object)
42 PK create(T newInstance);
45 * Persist the newInstance object into database.
48 * new object as a transient instance
49 * @see Session#saveOrUpdate(Object)
51 public void saveOrUpdate(final T newInstance);
54 * Retrieve an object that was previously persisted to the database using the indicated id as primary key.
57 * primary key of an object to read
58 * @return an object found by the given key
59 * @see Session#get(Class, Serializable)
64 * Save changes made to a persistent object.
66 * @param transientObject
67 * transient instance of the object to update
69 void update(T transientObject);
72 * Refresh a persistent object.
74 * @param transientObject
75 * transient instance of the object to refresh
76 * @see Session#refresh(Object)
78 void refresh(T transientObject);
81 * Load a persistent object.
83 * @param transientObject
84 * transient instance of the object to load
87 * @see Session#load(Object, Serializable)
89 public void load(final T transientObject, final PK id);
92 * Lock a persistent object.
94 * @param transientObject
95 * transient instance of the object to lock
98 * @see Session#refresh(Object, LockOptions)
100 public void refresh(final T transientObject, final LockOptions lockOptions);
103 * Remove an object from persistent storage in the database.
105 * @param persistentObject
106 * a persistent object to delete from the database
107 * @see Session#delete(Object)
109 void delete(T persistentObject);
112 * Retrieve an object that was previously persisted to the database using the given criteria.
116 * @return an object found according to the given criteria
118 public T findByCriteria(Criterion aCondition);
121 * Retrieve an object that was previously persisted to the database using the given criteria.
124 * a properties values to filter with AND condition
125 * @return an object found according to the given criteria
127 public T findByCriteria(Properties andParams);
130 * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
132 * @return a list of all objects of the considered type T
134 public List<T> getAll();
137 * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
140 * a result list order. Null is ignored and in such case the result list is unordered.
141 * @return an ordered list of all objects of the considered type T
143 public List<T> getAll(Order... anOrder);
146 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
148 * @param aDetachedCriteria
150 * @return a list of objects filtered according to the given criteria
152 public List<T> getFilteredList(final DetachedCriteria aDetachedCriteria);
155 * Retrieve a list of DTO objects using the given criteria.
158 * the class of returned DTOs
159 * @param aDetachedCriteria
161 * @return a list of DTO objects filtered according to the given criteria
163 public <DTO> List<DTO> getFilteredDTOList(
164 final DetachedCriteria aDetachedCriteria);
167 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
171 * @return a list of objects filtered according to the given criteria
173 public List<T> getFilteredList(Criterion aCondition);
176 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
181 * a result list order. Null is ignored and in such case the result list is unordered.
182 * @return a list of objects filtered according to the given criteria
184 public List<T> getFilteredList(Criterion aCondition, Order... anOrder);
187 * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
188 * Joined field allows applying a filter condition to the child object.<BR>
189 * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
190 * <code>knowledgeElementDAO.getFilteredList(
191 "type", Restrictions.eq("name", "bestpractice"));</code>
194 * a field containing object to apply the condition
198 * @return a list of objects filtered according to the given criteria
200 public List<T> getFilteredList(final String joinField,
201 final Criterion aCondition);
204 * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
205 * Joined field allows applying a filter condition to the child object.<BR>
206 * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
207 * <code>knowledgeElementDAO.getFilteredList(
208 "type", Restrictions.eq("name", "bestpractice"), Order.asc("title"));</code>
211 * a field containing object to apply the condition
216 * a result list order. Null is ignored and in such case the result list is unordered.
217 * @return a list of objects filtered according to the given criteria
219 public List<T> getFilteredList(final String joinField,
220 final Criterion aCondition, final Order... anOrder);
223 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
226 * a properties values to filter with AND condition
227 * @return a list of objects filtered according to the given criteria
229 public List<T> getFilteredList(Properties andParams);
232 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
235 * a properties values to filter with AND condition
237 * a result list order. Null is ignored and in such case the result list is unordered.
238 * @return a list of objects filtered according to the given criteria
240 public List<T> getFilteredList(Properties andParams, Order... anOrder);
243 * Make a transient instance persistent. This operation cascades to <BR>
244 * associated instances if the association is mapped with cascade="persist".
246 * @param transientObject
247 * transient instance of the object to be made persistent
248 * @see Session#persist(Object)
250 public void persist(T transientObject);
253 * Copy the state of the given object onto the persistent object with the <BR>
254 * same identifier. If there is no persistent instance currently associated<BR>
255 * with the session, it will be loaded. Return the persistent instance. If <BR>
256 * the given instance is unsaved, save a copy of and return it as a newly <BR>
257 * persistent instance. The given instance does not become associated with <BR>
258 * the session. This operation cascades to associated instances if the <BR>
259 * association is mapped with cascade="merge".
261 * @param transientObject
262 * transient instance of the object to be merged with persistent data
263 * @return merged persistent object
264 * @see Session#merge(Object)
266 public T merge(T transientObject);
269 * Remove this instance from the session cache. Changes to the instance will<BR>
270 * not be synchronized with the database. This operation cascades to <BR>
271 * associated instances if the association is mapped with cascade="evict".
273 * @param persistentObject
274 * the object to be removed from session cache
275 * @see Session#evict(Object)
277 public void evict(final T persistentObject);
280 * Synchronize the session data with the database.
282 * @see Session#flush()