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
33 * @created 02-Nov-2007 19:36:10
35 public interface ICdmEntityDao
<T
extends CdmBase
> {
38 * @param transientObject
40 * @throws DataAccessException
42 public UUID
saveOrUpdate(T transientObject
) throws DataAccessException
;
45 * @param newOrManagedObject
47 * @throws DataAccessException
49 public T
save(T newOrManagedObject
) throws DataAccessException
;
51 public T
merge(T transientObject
) throws DataAccessException
;
54 * This method allows for the possibility of returning the input transient
55 * entity instead of the merged persistent entity
57 * WARNING : This method should never be used when the objective of the merge
58 * is to attach to an existing session which is the standard use case.
59 * This method should only be used in the case of an external call which does
60 * not use hibernate sessions and is only interested in the entity as a POJO.
61 * This method returns the root merged transient entity as well as all newly merged
62 * persistent entities within the return object.
64 * @param transientObject
65 * @param returnTransientEntity
66 * @return transient or persistent object depending on the value of returnTransientEntity
67 * @throws DataAccessException
69 public MergeResult
<T
> merge(T transientObject
, boolean returnTransientEntity
) throws DataAccessException
;
72 * Obtains the specified LockMode on the supplied object
76 * @throws DataAccessException
78 public void lock(T t
, LockOptions lockOptions
) throws DataAccessException
;
81 * Globally replace all references to instance t1 with t2 (including
83 * NOTE: This replaces all non-bidirectional relationships where type T is on the
84 * "owning" side of the relationship (since the "owned" objects are, in theory,
85 * sub-components of the entity and this kind of global replace doesn't really make sense
87 * Consequently it is a good idea to either map such owned relationships with cascading
88 * semantics (i.e. CascadeType.DELETE, @OneToMany(orphanRemoval=true)) allowing them to be saved,
89 * updated, and deleted along with the owning entity automatically.
91 * @param x the object to replace, must not be null
92 * @param y the object that will replace. If y is null, then x will be removed from all collections
93 * and all properties that refer to x will be replaced with null
94 * @return T the replaced object
96 public T
replace(T x
, T y
);
99 * Refreshes the state of the supplied object using the given LockMode (e.g. use LockMode.READ
100 * to bypass the second-level cache and session cache and query the database directly)
102 * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
104 * For detailed description and examples <b>please refer to:</b>
105 * {@link IBeanInitializer#initialize(Object, List)}
109 * @param propertyPaths
110 * @throws DataAccessException
112 public void refresh(T t
, LockOptions lockOptions
, List
<String
> propertyPaths
) throws DataAccessException
;
114 public void clear() throws DataAccessException
;
116 public Session
getSession() throws DataAccessException
;
118 public Map
<UUID
, T
> saveAll(Collection
<T
> cdmObjCollection
) throws DataAccessException
;
120 public Map
<UUID
, T
> saveOrUpdateAll(Collection
<T
> cdmObjCollection
);
123 * @param transientObject
125 * @throws DataAccessException
127 public UUID
update(T transientObject
) throws DataAccessException
;
130 * @param persistentObject
132 * @throws DataAccessException
134 public UUID
refresh(T persistentObject
) throws DataAccessException
;
137 * @param persistentObject
139 * @throws DataAccessException
141 public UUID
delete(T persistentObject
) throws DataAccessException
;
144 * Returns a sublist of CdmBase instances stored in the database.
145 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
146 * @param limit the maximum number of entities returned (can be null to return all entities)
149 * @throws DataAccessException
151 public List
<T
> list(Integer limit
, Integer start
) throws DataAccessException
;
154 * Returns a sublist of CdmBase instances stored in the database. A maximum
155 * of 'limit' objects are returned, starting at object with index 'start'.
158 * the maximum number of entities returned (can be null to return
162 * Supports path like <code>orderHints.propertyNames</code> which
163 * include *-to-one properties like createdBy.username or
164 * authorTeam.persistentTitleCache
166 * @throws DataAccessException
168 public List
<T
> list(Integer limit
, Integer start
, List
<OrderHint
> orderHints
);
172 * Returns a sublist of CdmBase instances stored in the database. A maximum
173 * of 'limit' objects are returned, starting at object with index 'start'.
177 * the maximum number of entities returned (can be null to return
181 * Supports path like <code>orderHints.propertyNames</code> which
182 * include *-to-one properties like createdBy.username or
183 * authorTeam.persistentTitleCache
185 * @throws DataAccessException
187 public <S
extends T
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
190 * Returns a sublist of CdmBase instances stored in the database. A maximum
191 * of 'limit' objects are returned, starting at object with index 'start'.
192 * The bean properties specified by the parameter <code>propertyPaths</code>
193 * and recursively initialized for each of the entities in the resultset
195 * For detailed description and examples regarding
196 * <code>propertyPaths</code> <b>please refer to:</b>
197 * {@link IBeanInitializer#initialize(Object, List)}
200 * the maximum number of entities returned (can be null to return
204 * Supports path like <code>orderHints.propertyNames</code> which
205 * include *-to-one properties like createdBy.username or
206 * authorTeam.persistentTitleCache
207 * @param propertyPaths
209 * @throws DataAccessException
211 public List
<T
> list(Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
214 * Returns a list of Cdm entities stored in the database filtered by the restrictions defined by
215 * the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>
217 * of 'limit' objects are returned, starting at object with index 'start'.
218 * The bean properties specified by the parameter <code>propertyPaths</code>
219 * and recursively initialized for each of the entities in the resultset
221 * For detailed description and examples regarding
222 * <code>propertyPaths</code> <b>please refer to:</b>
223 * {@link IBeanInitializer#initialize(Object, List)}
226 * Restrict the query to objects of a certain class, or null for
227 * all objects of type T or subclasses
228 * @param restrictions
229 * This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
230 * {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
231 * can be supplied per property, that is the values per property are combined with OR. The per property
232 * restrictions are combined with AND. </br>
233 * <b>NOTE:</b> For non string type properties you must use
234 * {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
237 * the maximum number of entities returned (can be null to return
240 * The list of criterion objects representing the restriction to be applied.
242 * Supports path like <code>orderHints.propertyNames</code> which
243 * include *-to-one properties like createdBy.username or
244 * authorTeam.persistentTitleCache
245 * @param propertyPaths
247 * @throws DataAccessException
249 public List
<T
> list(Class
<?
extends T
> type
, List
<Restriction
<?
>> restrictions
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
252 * Counts the Cdm entities matching the restrictions defined by
253 * the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>.
256 * Restrict the query to objects of a certain class, or null for
257 * all objects of type T or subclasses
258 * @param restrictions
259 * This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
260 * {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
261 * can be supplied per property, that is the values per property are combined with OR. The per property
262 * restrictions are combined with AND. </br>
263 * <b>NOTE:</b> For non string type properties you must use
264 * {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
267 * The list of criterion objects representing the restriction to be applied.
271 public int count(Class
<?
extends T
> type
, List
<Restriction
<?
>> restrictions
);
274 * Returns a sublist of CdmBase instances of type <TYPE> stored in the database.
275 * A maximum of 'limit' objects are returned, starting at object with index 'start'.
276 * @param limit the maximum number of entities returned (can be null to return all entities)
279 * @throws DataAccessException
281 public <S
extends T
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
) throws DataAccessException
;
284 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
286 * It would be nice to have an equivalent countGroups method, but for the moment hibernate doesn't
287 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
289 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
290 * @param limit the maximum number of entities returned (can be null to return
292 * @param start The (0-based) offset from the start of the recordset
293 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
294 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
295 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
297 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
299 public List
<T
> rows(String tableName
, int limit
, int start
) throws DataAccessException
;
304 * @throws DataAccessException
306 public T
findById(int id
) throws DataAccessException
;
309 * Finds the cdm entity specified by the id parameter and
310 * recursively initializes all bean properties given in the
311 * <code>propertyPaths</code> parameter.
313 * For detailed description and examples <b>please refer to:</b>
314 * {@link IBeanInitializer#initialize(Object, List)}
317 * @param propertyPaths properties to be initialized
320 public T
load(int id
, List
<String
> propertyPaths
);
324 * @param propertyPaths
326 * @throws DataAccessException
328 public List
<T
> loadList(Collection
<Integer
> ids
, List
<String
> propertyPaths
) throws DataAccessException
;
333 * @throws DataAccessException
335 public T
findByUuid(UUID Uuid
) throws DataAccessException
;
338 * Method to find CDM Entity by Uuid, by making sure that the underlying
339 * hibernate session is not flushed (Session.FLUSH_MODE set to MANUAL temporarily)
340 * when performing the read query.
344 * @throws DataAccessException
346 public T
findByUuidWithoutFlush(UUID uuid
) throws DataAccessException
;
354 * @param propertyPaths
356 * @throws DataAccessException
358 public List
<T
> list(Collection
<UUID
> uuids
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) throws DataAccessException
;
361 * Finds the cdm entity specified by the <code>uuid</code> parameter and
362 * initializes all its *ToOne relations.
367 public T
load(UUID uuid
);
370 * Finds the cdm entity specified by the <code>uuid</code> parameter and
371 * recursively initializes all bean properties given in the
372 * <code>propertyPaths</code> parameter.
374 * For detailed description and examples <b>please refer to:</b>
375 * {@link IBeanInitializer#initialize(Object, List)}
378 * @param propertyPaths properties to be initialized
381 public T
load(UUID uuid
, List
<String
> propertyPaths
);
386 * @throws DataAccessException
388 public Boolean
exists(UUID uuid
) throws DataAccessException
;
393 * Returns the number of objects of type <T> - which must extend T
398 public int count(Class
<?
extends T
> clazz
);
401 * FIXME Should this method exist : I would expect flushing of a session to be
402 * something that a DAO should hide?
407 * Convenience method which makes it easy to discover what type of object this DAO returns at runtime
411 public Class
<T
> getType();
414 * Method that counts the number of objects matching the example provided.
415 * The includeProperties property is used to specify which properties of the example are used.
417 * If includeProperties is null or empty, then all literal properties are used (restrictions are
418 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
420 * If includeProperties is not empty then only literal properties that are named in the set are used to
421 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
422 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
423 * criteria.createCriteria(property).add(Example.create(relatedObject)))
426 * @param includeProperties
427 * @return a count of matching objects
429 public int count(T example
, Set
<String
> includeProperties
);
432 * Method that lists the objects matching the example provided.
433 * The includeProperties property is used to specify which properties of the example are used.
435 * If includeProperties is null or empty, then all literal properties are used (restrictions are
436 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
438 * If includeProperties is not empty then only literal properties that are named in the set are used to
439 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
440 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
441 * criteria.createCriteria(property).add(Example.create(relatedObject)))
444 * @param includeProperties
445 * @param limit the maximum number of entities returned (can be null to return
447 * @param start The (0-based) offset from the start of the recordset
449 * Supports path like <code>orderHints.propertyNames</code> which
450 * include *-to-one properties like createdBy.username or
451 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
452 * @return a list of matching objects
454 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);