2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.dao
.common
;
12 import java
.util
.Collection
;
13 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.hibernate
.LockOptions
;
19 import org
.hibernate
.Session
;
20 import org
.springframework
.dao
.DataAccessException
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.IBeanInitializer
;
24 import eu
.etaxonomy
.cdm
.persistence
.dto
.MergeResult
;
25 import eu
.etaxonomy
.cdm
.persistence
.query
.Grouping
;
26 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
27 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
30 * An data access interface that all data access classes implement
32 * @since 02-Nov-2007 19:36:10
34 public interface ICdmEntityDao
<T
extends CdmBase
> {
37 * @param transientObject
39 * @throws DataAccessException
41 public UUID
saveOrUpdate(T transientObject
) throws DataAccessException
;
44 * @param newOrManagedObject
46 * @throws DataAccessException
48 public T
save(T newOrManagedObject
) throws DataAccessException
;
50 public T
merge(T transientObject
) throws DataAccessException
;
53 * This method allows for the possibility of returning the input transient
54 * entity instead of the merged persistent entity
56 * WARNING : This method should never be used when the objective of the merge
57 * is to attach to an existing session which is the standard use case.
58 * This method should only be used in the case of an external call which does
59 * not use hibernate sessions and is only interested in the entity as a POJO.
60 * This method returns the root merged transient entity as well as all newly merged
61 * persistent entities within the return object.
63 * @param transientObject
64 * @param returnTransientEntity
65 * @return transient or persistent object depending on the value of returnTransientEntity
66 * @throws DataAccessException
68 public MergeResult
<T
> merge(T transientObject
, boolean returnTransientEntity
) throws DataAccessException
;
71 * Obtains the specified LockMode on the supplied object
75 * @throws DataAccessException
77 public void lock(T t
, LockOptions lockOptions
) throws DataAccessException
;
80 * Globally replace all references to instance t1 with t2 (including
82 * NOTE: This replaces all non-bidirectional relationships where type T is on the
83 * "owning" side of the relationship (since the "owned" objects are, in theory,
84 * sub-components of the entity and this kind of global replace doesn't really make sense
86 * Consequently it is a good idea to either map such owned relationships with cascading
87 * semantics (i.e. CascadeType.DELETE, @OneToMany(orphanRemoval=true)) allowing them to be saved,
88 * updated, and deleted along with the owning entity automatically.
90 * @param x the object to replace, must not be null
91 * @param y the object that will replace. If y is null, then x will be removed from all collections
92 * and all properties that refer to x will be replaced with null
93 * @return T the replaced object
95 public T
replace(T x
, T y
);
98 * Refreshes the state of the supplied object using the given LockMode (e.g. use LockMode.READ
99 * to bypass the second-level cache and session cache and query the database directly)
101 * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
103 * For detailed description and examples <b>please refer to:</b>
104 * {@link IBeanInitializer#initialize(Object, List)}
108 * @param propertyPaths
109 * @throws DataAccessException
111 public void refresh(T t
, LockOptions lockOptions
, List
<String
> propertyPaths
) throws DataAccessException
;
113 public void clear() throws DataAccessException
;
115 public Session
getSession() throws DataAccessException
;
117 public Map
<UUID
, T
> saveAll(Collection
<T
> cdmObjCollection
) throws DataAccessException
;
119 public Map
<UUID
, T
> saveOrUpdateAll(Collection
<T
> cdmObjCollection
);
122 * @param transientObject
124 * @throws DataAccessException
126 public UUID
update(T transientObject
) throws DataAccessException
;
129 * @param persistentObject
131 * @throws DataAccessException
133 public UUID
refresh(T persistentObject
) throws DataAccessException
;
136 * @param persistentObject
138 * @throws DataAccessException
140 public UUID
delete(T persistentObject
) throws DataAccessException
;
143 * Returns a sublist of CdmBase instances stored in the database.
144 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
145 * @param limit the maximum number of entities returned (can be null to return all entities)
148 * @throws DataAccessException
150 public List
<T
> list(Integer limit
, Integer start
) throws DataAccessException
;
153 * Returns a sublist of CdmBase instances stored in the database. A maximum
154 * of 'limit' objects are returned, starting at object with index 'start'.
157 * the maximum number of entities returned (can be null to return
161 * Supports path like <code>orderHints.propertyNames</code> which
162 * include *-to-one properties like createdBy.username or
163 * authorTeam.persistentTitleCache
165 * @throws DataAccessException
167 public List
<T
> list(Integer limit
, Integer start
, List
<OrderHint
> orderHints
);
171 * Returns a sublist of CdmBase instances stored in the database. A maximum
172 * of 'limit' objects are returned, starting at object with index 'start'.
176 * the maximum number of entities returned (can be null to return
180 * Supports path like <code>orderHints.propertyNames</code> which
181 * include *-to-one properties like createdBy.username or
182 * authorTeam.persistentTitleCache
184 * @throws DataAccessException
186 public <S
extends T
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
189 * Returns a sublist of CdmBase instances stored in the database. A maximum
190 * of 'limit' objects are returned, starting at object with index 'start'.
191 * The bean properties specified by the parameter <code>propertyPaths</code>
192 * and recursively initialized for each of the entities in the resultset
194 * For detailed description and examples regarding
195 * <code>propertyPaths</code> <b>please refer to:</b>
196 * {@link IBeanInitializer#initialize(Object, List)}
199 * the maximum number of entities returned (can be null to return
203 * Supports path like <code>orderHints.propertyNames</code> which
204 * include *-to-one properties like createdBy.username or
205 * authorTeam.persistentTitleCache
206 * @param propertyPaths
208 * @throws DataAccessException
210 public List
<T
> list(Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
213 * Returns a list of Cdm entities stored in the database filtered by the restrictions defined by
214 * the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>
216 * of 'limit' objects are returned, starting at object with index 'start'.
217 * The bean properties specified by the parameter <code>propertyPaths</code>
218 * and recursively initialized for each of the entities in the resultset
220 * For detailed description and examples regarding
221 * <code>propertyPaths</code> <b>please refer to:</b>
222 * {@link IBeanInitializer#initialize(Object, List)}
225 * Restrict the query to objects of a certain class, or null for
226 * all objects of type T or subclasses
227 * @param restrictions
228 * This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
229 * {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
230 * can be supplied per property, that is the values per property are combined with OR. The per property
231 * restrictions are combined with AND. </br>
232 * <b>NOTE:</b> For non string type properties you must use
233 * {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
236 * the maximum number of entities returned (can be null to return
239 * The list of criterion objects representing the restriction to be applied.
241 * Supports path like <code>orderHints.propertyNames</code> which
242 * include *-to-one properties like createdBy.username or
243 * authorTeam.persistentTitleCache
244 * @param propertyPaths
246 * @throws DataAccessException
248 public List
<T
> list(Class
<?
extends T
> type
, List
<Restriction
<?
>> restrictions
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
251 * Counts the Cdm entities matching the restrictions defined by
252 * the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>.
255 * Restrict the query to objects of a certain class, or null for
256 * all objects of type T or subclasses
257 * @param restrictions
258 * This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
259 * {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
260 * can be supplied per property, that is the values per property are combined with OR. The per property
261 * restrictions are combined with AND. </br>
262 * <b>NOTE:</b> For non string type properties you must use
263 * {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
266 * The list of criterion objects representing the restriction to be applied.
270 public int count(Class
<?
extends T
> type
, List
<Restriction
<?
>> restrictions
);
273 * Returns a sublist of CdmBase instances of type <TYPE> stored in the database.
274 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
275 * @param limit the maximum number of entities returned (can be null to return all entities)
278 * @throws DataAccessException
280 public <S
extends T
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
) throws DataAccessException
;
283 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
285 * It would be nice to have an equivalent countGroups method, but for the moment hibernate doesn't
286 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
288 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
289 * @param limit the maximum number of entities returned (can be null to return
291 * @param start The (0-based) offset from the start of the recordset
292 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
293 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
294 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
296 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
298 public List
<T
> rows(String tableName
, int limit
, int start
) throws DataAccessException
;
303 * @throws DataAccessException
305 public T
findById(int id
) throws DataAccessException
;
308 * Finds the cdm entity specified by the id parameter and
309 * recursively initializes all bean properties given in the
310 * <code>propertyPaths</code> parameter.
312 * For detailed description and examples <b>please refer to:</b>
313 * {@link IBeanInitializer#initialize(Object, List)}
316 * @param propertyPaths properties to be initialized
319 public T
load(int id
, List
<String
> propertyPaths
);
323 * @param propertyPaths
325 * @throws DataAccessException
327 public List
<T
> loadList(Collection
<Integer
> ids
, List
<String
> propertyPaths
) throws DataAccessException
;
332 * @throws DataAccessException
334 public T
findByUuid(UUID Uuid
) throws DataAccessException
;
337 * Method to find CDM Entity by Uuid, by making sure that the underlying
338 * hibernate session is not flushed (Session.FLUSH_MODE set to MANUAL temporarily)
339 * when performing the read query.
343 * @throws DataAccessException
345 public T
findByUuidWithoutFlush(UUID uuid
) throws DataAccessException
;
353 * @param propertyPaths
355 * @throws DataAccessException
357 public List
<T
> list(Collection
<UUID
> uuids
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) throws DataAccessException
;
360 * Finds the cdm entity specified by the <code>uuid</code> parameter and
361 * initializes all its *ToOne relations.
366 public T
load(UUID uuid
);
369 * Finds the cdm entity specified by the <code>uuid</code> parameter and
370 * recursively initializes all bean properties given in the
371 * <code>propertyPaths</code> parameter.
373 * For detailed description and examples <b>please refer to:</b>
374 * {@link IBeanInitializer#initialize(Object, List)}
377 * @param propertyPaths properties to be initialized
380 public T
load(UUID uuid
, List
<String
> propertyPaths
);
385 * @throws DataAccessException
387 public Boolean
exists(UUID uuid
) throws DataAccessException
;
392 * Returns the number of objects of type <T> - which must extend T
397 public int count(Class
<?
extends T
> clazz
);
400 * FIXME Should this method exist : I would expect flushing of a session to be
401 * something that a DAO should hide?
406 * Convenience method which makes it easy to discover what type of object this DAO returns at runtime
410 public Class
<T
> getType();
413 * Method that counts the number of objects matching the example provided.
414 * The includeProperties property is used to specify which properties of the example are used.
416 * If includeProperties is null or empty, then all literal properties are used (restrictions are
417 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
419 * If includeProperties is not empty then only literal properties that are named in the set are used to
420 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
421 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
422 * criteria.createCriteria(property).add(Example.create(relatedObject)))
425 * @param includeProperties
426 * @return a count of matching objects
428 public int count(T example
, Set
<String
> includeProperties
);
431 * Method that lists the objects matching the example provided.
432 * The includeProperties property is used to specify which properties of the example are used.
434 * If includeProperties is null or empty, then all literal properties are used (restrictions are
435 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
437 * If includeProperties is not empty then only literal properties that are named in the set are used to
438 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
439 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
440 * criteria.createCriteria(property).add(Example.create(relatedObject)))
443 * @param includeProperties
444 * @param limit the maximum number of entities returned (can be null to return
446 * @param start The (0-based) offset from the start of the recordset
448 * Supports path like <code>orderHints.propertyNames</code> which
449 * include *-to-one properties like createdBy.username or
450 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
451 * @return a list of matching objects
453 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);