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 * Update the persistent instance with the identifier of the given detached <BR>
65 * instance. If there is a persistent instance with the same identifier, an <BR>
66 * exception is thrown. This operation cascades to associated instances if <BR>
67 * the association is mapped with cascade="save-update".
69 * @param detachedObject
70 * transient instance of the object to update
71 * @see Session#update(Object)
73 public void update(final T detachedObject);
76 * Refresh a persistent object.
78 * @param transientObject
79 * transient instance of the object to refresh
80 * @see Session#refresh(Object)
82 void refresh(T transientObject);
85 * Load a persistent object.
87 * @param transientObject
88 * transient instance of the object to load
91 * @see Session#load(Object, Serializable)
93 public void load(final T transientObject, final PK id);
96 * Lock a persistent object.
98 * @param transientObject
99 * transient instance of the object to lock
102 * @see Session#refresh(Object, LockOptions)
104 public void refresh(final T transientObject, final LockOptions lockOptions);
107 * Remove an object from persistent storage in the database.
109 * @param persistentObject
110 * a persistent object to delete from the database
111 * @see Session#delete(Object)
113 void delete(T persistentObject);
116 * Retrieve an object that was previously persisted to the database using the given criteria.
120 * @return an object found according to the given criteria
122 public T findByCriteria(Criterion aCondition);
125 * Retrieve an object that was previously persisted to the database using the given criteria.
128 * a properties values to filter with AND condition
129 * @return an object found according to the given criteria
131 public T findByCriteria(Properties andParams);
134 * Retrieve a list of all objects of the considered type T which were previously persisted to the database.
136 * @return a list of all objects of the considered type T
138 public List<T> getAll();
141 * Retrieve an ordered list of all objects of the considered type T which were previously persisted to the database.
144 * a result list order. Null is ignored and in such case the result list is unordered.
145 * @return an ordered list of all objects of the considered type T
147 public List<T> getAll(Order... anOrder);
150 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
152 * @param aDetachedCriteria
154 * @return a list of objects filtered according to the given criteria
156 public List<T> getFilteredList(final DetachedCriteria aDetachedCriteria);
159 * Retrieve a first found object in the database using the given criteria.
161 * @param aDetachedCriteria
163 * @return a first found object filtered according to the given criteria
165 public T getFirstResult(final DetachedCriteria aDetachedCriteria);
168 * Retrieve a list of DTO objects using the given criteria.
171 * the class of returned DTOs
172 * @param aDetachedCriteria
174 * @return a list of DTO objects filtered according to the given criteria
176 public <DTO> List<DTO> getFilteredDTOList(
177 final DetachedCriteria aDetachedCriteria);
180 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
184 * @return a list of objects filtered according to the given criteria
186 public List<T> getFilteredList(Criterion aCondition);
189 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
194 * a result list order. Null is ignored and in such case the result list is unordered.
195 * @return a list of objects filtered according to the given criteria
197 public List<T> getFilteredList(Criterion aCondition, Order... anOrder);
200 * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
201 * Joined field allows applying a filter condition to the child object.<BR>
202 * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
203 * <code>knowledgeElementDAO.getFilteredList(
204 "type", Restrictions.eq("name", "bestpractice"));</code>
207 * a field containing object to apply the condition
211 * @return a list of objects filtered according to the given criteria
213 public List<T> getFilteredList(final String joinField,
214 final Criterion aCondition);
217 * Retrieve a list of objects which were previously persisted to the database using the given criteria.<BR>
218 * Joined field allows applying a filter condition to the child object.<BR>
219 * In the following example we get all knowledge elements of the "bestpractice" knowledge type:<BR>
220 * <code>knowledgeElementDAO.getFilteredList(
221 "type", Restrictions.eq("name", "bestpractice"), Order.asc("title"));</code>
224 * a field containing object to apply the condition
229 * a result list order. Null is ignored and in such case the result list is unordered.
230 * @return a list of objects filtered according to the given criteria
232 public List<T> getFilteredList(final String joinField,
233 final Criterion aCondition, final Order... anOrder);
236 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
239 * a properties values to filter with AND condition
240 * @return a list of objects filtered according to the given criteria
242 public List<T> getFilteredList(Properties andParams);
245 * Retrieve a list of objects which were previously persisted to the database using the given criteria.
248 * a properties values to filter with AND condition
250 * a result list order. Null is ignored and in such case the result list is unordered.
251 * @return a list of objects filtered according to the given criteria
253 public List<T> getFilteredList(Properties andParams, Order... anOrder);
256 * Make a transient instance persistent. This operation cascades to <BR>
257 * associated instances if the association is mapped with cascade="persist".
259 * @param transientObject
260 * transient instance of the object to be made persistent
261 * @see Session#persist(Object)
263 public void persist(T transientObject);
266 * Copy the state of the given object onto the persistent object with the <BR>
267 * same identifier. If there is no persistent instance currently associated<BR>
268 * with the session, it will be loaded. Return the persistent instance. If <BR>
269 * the given instance is unsaved, save a copy of and return it as a newly <BR>
270 * persistent instance. The given instance does not become associated with <BR>
271 * the session. This operation cascades to associated instances if the <BR>
272 * association is mapped with cascade="merge".
274 * @param transientObject
275 * transient instance of the object to be merged with persistent data
276 * @return merged persistent object
277 * @see Session#merge(Object)
279 public T merge(T transientObject);
282 * Remove this instance from the session cache. Changes to the instance will<BR>
283 * not be synchronized with the database. This operation cascades to <BR>
284 * associated instances if the association is mapped with cascade="evict".
286 * @param persistentObject
287 * the object to be removed from session cache
288 * @see Session#evict(Object)
290 public void evict(final T persistentObject);
293 * Synchronize the session data with the database.
295 * @see Session#flush()