1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.persistence.dao.common;
|
11
|
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.hibernate.LockOptions;
|
19
|
import org.hibernate.Session;
|
20
|
import org.hibernate.criterion.Criterion;
|
21
|
import org.springframework.dao.DataAccessException;
|
22
|
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;
|
25
|
import eu.etaxonomy.cdm.persistence.dto.MergeResult;
|
26
|
import eu.etaxonomy.cdm.persistence.query.Grouping;
|
27
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
28
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
29
|
|
30
|
/**
|
31
|
* An data access interface that all data access classes implement
|
32
|
* @author m.doering
|
33
|
* @since 02-Nov-2007 19:36:10
|
34
|
*/
|
35
|
public interface ICdmEntityDao<T extends CdmBase> {
|
36
|
|
37
|
public UUID saveOrUpdate(T transientObject) throws DataAccessException;
|
38
|
|
39
|
/**
|
40
|
* @param newOrManagedObject
|
41
|
* @return
|
42
|
* @throws DataAccessException
|
43
|
*/
|
44
|
public T save(T newOrManagedObject) throws DataAccessException;
|
45
|
|
46
|
public T merge(T transientObject) throws DataAccessException;
|
47
|
|
48
|
/**
|
49
|
* This method allows for the possibility of returning the input transient
|
50
|
* entity instead of the merged persistent entity
|
51
|
*
|
52
|
* WARNING : This method should never be used when the objective of the merge
|
53
|
* is to attach to an existing session which is the standard use case.
|
54
|
* This method should only be used in the case of an external call which does
|
55
|
* not use hibernate sessions and is only interested in the entity as a POJO.
|
56
|
* This method returns the root merged transient entity as well as all newly merged
|
57
|
* persistent entities within the return object.
|
58
|
*
|
59
|
* @param transientObject
|
60
|
* @param returnTransientEntity
|
61
|
* @return transient or persistent object depending on the value of returnTransientEntity
|
62
|
* @throws DataAccessException
|
63
|
*/
|
64
|
public MergeResult<T> merge(T transientObject, boolean returnTransientEntity) throws DataAccessException;
|
65
|
|
66
|
/**
|
67
|
* Obtains the specified LockMode on the supplied object
|
68
|
*
|
69
|
* @param t
|
70
|
* @param lockOptions
|
71
|
* @throws DataAccessException
|
72
|
*/
|
73
|
public void lock(T t, LockOptions lockOptions) throws DataAccessException;
|
74
|
|
75
|
/**
|
76
|
* Globally replace all references to instance t1 with t2 (including
|
77
|
*
|
78
|
* NOTE: This replaces all non-bidirectional relationships where type T is on the
|
79
|
* "owning" side of the relationship (since the "owned" objects are, in theory,
|
80
|
* sub-components of the entity and this kind of global replace doesn't really make sense
|
81
|
*
|
82
|
* Consequently it is a good idea to either map such owned relationships with cascading
|
83
|
* semantics (i.e. CascadeType.DELETE, @OneToMany(orphanRemoval=true)) allowing them to be saved,
|
84
|
* updated, and deleted along with the owning entity automatically.
|
85
|
*
|
86
|
* @param x the object to replace, must not be null
|
87
|
* @param y the object that will replace. If y is null, then x will be removed from all collections
|
88
|
* and all properties that refer to x will be replaced with null
|
89
|
* @return T the replaced object
|
90
|
*/
|
91
|
public T replace(T x, T y);
|
92
|
|
93
|
/**
|
94
|
* Refreshes the state of the supplied object using the given LockMode (e.g. use LockMode.READ
|
95
|
* to bypass the second-level cache and session cache and query the database directly)
|
96
|
*
|
97
|
* All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
|
98
|
* <p>
|
99
|
* For detailed description and examples <b>please refer to:</b>
|
100
|
* {@link IBeanInitializer#initialize(Object, List)}
|
101
|
*
|
102
|
* @param t
|
103
|
* @param lockMode
|
104
|
* @param propertyPaths
|
105
|
* @throws DataAccessException
|
106
|
*/
|
107
|
public void refresh(T t, LockOptions lockOptions, List<String> propertyPaths) throws DataAccessException;
|
108
|
|
109
|
public void clear() throws DataAccessException;
|
110
|
|
111
|
public Session getSession() throws DataAccessException;
|
112
|
|
113
|
public Map<UUID, T> saveAll(Collection<T> cdmObjCollection) throws DataAccessException;
|
114
|
|
115
|
public Map<UUID, T> saveOrUpdateAll(Collection<T> cdmObjCollection);
|
116
|
|
117
|
/**
|
118
|
* @param transientObject
|
119
|
* @return
|
120
|
* @throws DataAccessException
|
121
|
*/
|
122
|
public UUID update(T transientObject) throws DataAccessException;
|
123
|
|
124
|
/**
|
125
|
* @param persistentObject
|
126
|
* @return
|
127
|
* @throws DataAccessException
|
128
|
*/
|
129
|
public UUID refresh(T persistentObject) throws DataAccessException;
|
130
|
|
131
|
/**
|
132
|
* @param persistentObject
|
133
|
* @return
|
134
|
* @throws DataAccessException
|
135
|
*/
|
136
|
public UUID delete(T persistentObject) throws DataAccessException;
|
137
|
|
138
|
/**
|
139
|
* Returns a sublist of CdmBase instances stored in the database.
|
140
|
* A maximum of 'limit' objects are returned, starting at object with index 'start'.
|
141
|
* @param limit the maximum number of entities returned (can be null to return all entities)
|
142
|
* @param start
|
143
|
* @return
|
144
|
* @throws DataAccessException
|
145
|
*/
|
146
|
public List<T> list(Integer limit, Integer start) throws DataAccessException;
|
147
|
|
148
|
/**
|
149
|
* Returns a sublist of CdmBase instances stored in the database. A maximum
|
150
|
* of 'limit' objects are returned, starting at object with index 'start'.
|
151
|
*
|
152
|
* @param limit
|
153
|
* the maximum number of entities returned (can be null to return
|
154
|
* all entities)
|
155
|
* @param start
|
156
|
* @param orderHints
|
157
|
* Supports path like <code>orderHints.propertyNames</code> which
|
158
|
* include *-to-one properties like createdBy.username or
|
159
|
* authorTeam.persistentTitleCache
|
160
|
* @return
|
161
|
* @throws DataAccessException
|
162
|
*/
|
163
|
public List<T> list(Integer limit, Integer start, List<OrderHint> orderHints);
|
164
|
|
165
|
|
166
|
/**
|
167
|
* Returns a sublist of CdmBase instances stored in the database. A maximum
|
168
|
* of 'limit' objects are returned, starting at object with index 'start'.
|
169
|
*
|
170
|
* @param type
|
171
|
* @param limit
|
172
|
* the maximum number of entities returned (can be null to return
|
173
|
* all entities)
|
174
|
* @param start
|
175
|
* @param orderHints
|
176
|
* Supports path like <code>orderHints.propertyNames</code> which
|
177
|
* include *-to-one properties like createdBy.username or
|
178
|
* authorTeam.persistentTitleCache
|
179
|
* @return
|
180
|
* @throws DataAccessException
|
181
|
*/
|
182
|
public <S extends T> List<S> list(Class<S> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
183
|
|
184
|
/**
|
185
|
* Returns a sublist of CdmBase instances stored in the database. A maximum
|
186
|
* of 'limit' objects are returned, starting at object with index 'start'.
|
187
|
* The bean properties specified by the parameter <code>propertyPaths</code>
|
188
|
* and recursively initialized for each of the entities in the resultset
|
189
|
*
|
190
|
* For detailed description and examples regarding
|
191
|
* <code>propertyPaths</code> <b>please refer to:</b>
|
192
|
* {@link IBeanInitializer#initialize(Object, List)}
|
193
|
*
|
194
|
* @param limit
|
195
|
* the maximum number of entities returned (can be null to return
|
196
|
* all entities)
|
197
|
* @param start
|
198
|
* @param orderHints
|
199
|
* Supports path like <code>orderHints.propertyNames</code> which
|
200
|
* include *-to-one properties like createdBy.username or
|
201
|
* authorTeam.persistentTitleCache
|
202
|
* @param propertyPaths
|
203
|
* @return
|
204
|
* @throws DataAccessException
|
205
|
*/
|
206
|
public List<T> list(Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
207
|
|
208
|
/**
|
209
|
* Returns a list of Cdm entities stored in the database filtered by the restrictions defined by
|
210
|
* the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>
|
211
|
* A maximum
|
212
|
* of 'limit' objects are returned, starting at object with index 'start'.
|
213
|
* The bean properties specified by the parameter <code>propertyPaths</code>
|
214
|
* and recursively initialized for each of the entities in the resultset
|
215
|
*
|
216
|
* For detailed description and examples regarding
|
217
|
* <code>propertyPaths</code> <b>please refer to:</b>
|
218
|
* {@link IBeanInitializer#initialize(Object, List)}
|
219
|
*
|
220
|
* @param type
|
221
|
* Restrict the query to objects of a certain class, or null for
|
222
|
* all objects of type T or subclasses
|
223
|
* @param restrictions
|
224
|
* This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
|
225
|
* {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
|
226
|
* can be supplied per property, that is the values per property are combined with OR. The per property
|
227
|
* restrictions are combined with AND. </br>
|
228
|
* <b>NOTE:</b> For non string type properties you must use
|
229
|
* {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
|
230
|
* as default.
|
231
|
* @param limit
|
232
|
* the maximum number of entities returned (can be null to return
|
233
|
* all entities)
|
234
|
* @param start
|
235
|
* The list of criterion objects representing the restriction to be applied.
|
236
|
* @param orderHints
|
237
|
* Supports path like <code>orderHints.propertyNames</code> which
|
238
|
* include *-to-one properties like createdBy.username or
|
239
|
* authorTeam.persistentTitleCache
|
240
|
* @param propertyPaths
|
241
|
* @return
|
242
|
* @throws DataAccessException
|
243
|
*/
|
244
|
public <S extends T> List<S> list(Class<S> type, List<Restriction<?>> restrictions, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
245
|
|
246
|
/**
|
247
|
* Counts the Cdm entities matching the restrictions defined by
|
248
|
* the <code>parameters</code> <code>propertyName</code>, value and <code>matchMode</code>.
|
249
|
*
|
250
|
* @param type
|
251
|
* Restrict the query to objects of a certain class, or null for
|
252
|
* all objects of type T or subclasses
|
253
|
* @param restrictions
|
254
|
* This defines a filter for multiple properties represented by the map keys. Sine the keys are of the type
|
255
|
* {@link Restriction} for each property a single MatchMode is defined. Multiple alternative values
|
256
|
* can be supplied per property, that is the values per property are combined with OR. The per property
|
257
|
* restrictions are combined with AND. </br>
|
258
|
* <b>NOTE:</b> For non string type properties you must use
|
259
|
* {@link MatchMode#EXACT}. If set <code>null</code> {@link MatchMode#EXACT} will be used
|
260
|
* as default.
|
261
|
* @param criteria
|
262
|
* The list of criterion objects representing the restriction to be applied.
|
263
|
*
|
264
|
* @return
|
265
|
*/
|
266
|
public long count(Class<? extends T> type, List<Restriction<?>> restrictions);
|
267
|
|
268
|
/**
|
269
|
* Returns a sublist of CdmBase instances of type <TYPE> stored in the database.
|
270
|
* A maximum of 'limit' objects are returned, starting at object with index 'start'.
|
271
|
* @param limit the maximum number of entities returned (can be null to return all entities)
|
272
|
* @param start
|
273
|
* @return
|
274
|
* @throws DataAccessException
|
275
|
*/
|
276
|
public <S extends T> List<S> list(Class<S> type, Integer limit, Integer start) throws DataAccessException;
|
277
|
|
278
|
/**
|
279
|
* Returns a sublist of objects matching the grouping projections supplied using the groups parameter
|
280
|
*
|
281
|
* It would be nice to have an equivalent countGroups method, but for the moment hibernate doesn't
|
282
|
* seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
|
283
|
*
|
284
|
* @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
|
285
|
* @param limit the maximum number of entities returned (can be null to return
|
286
|
* all entities)
|
287
|
* @param start The (0-based) offset from the start of the recordset
|
288
|
* @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
|
289
|
* @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
|
290
|
* @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
|
291
|
*/
|
292
|
public List<Object[]> group(Class<? extends T> clazz,Integer limit, Integer start, List<Grouping> groups, List<String> propertyPaths);
|
293
|
|
294
|
/**
|
295
|
* @param id
|
296
|
* @return
|
297
|
* @throws DataAccessException
|
298
|
*/
|
299
|
public T findById(int id) throws DataAccessException;
|
300
|
|
301
|
/**
|
302
|
* Finds the cdm entity specified by the id parameter and
|
303
|
* recursively initializes all bean properties given in the
|
304
|
* <code>propertyPaths</code> parameter.
|
305
|
* <p>
|
306
|
* For detailed description and examples <b>please refer to:</b>
|
307
|
* {@link IBeanInitializer#initialize(Object, List)}
|
308
|
*
|
309
|
* @param id
|
310
|
* @param propertyPaths properties to be initialized
|
311
|
* @return
|
312
|
*/
|
313
|
public T load(int id, List<String> propertyPaths);
|
314
|
|
315
|
/**
|
316
|
* @param ids
|
317
|
* @param propertyPaths
|
318
|
* @return
|
319
|
* @throws DataAccessException
|
320
|
*/
|
321
|
public List<T> loadList(Collection<Integer> ids, List<OrderHint> orderHints, List<String> propertyPaths) throws DataAccessException;
|
322
|
|
323
|
/**
|
324
|
* @param Uuid
|
325
|
* @return
|
326
|
* @throws DataAccessException
|
327
|
*/
|
328
|
public T findByUuid(UUID Uuid) throws DataAccessException;
|
329
|
|
330
|
/**
|
331
|
* Method to find CDM Entity by Uuid, by making sure that the underlying
|
332
|
* hibernate session is not flushed (Session.FLUSH_MODE set to MANUAL temporarily)
|
333
|
* when performing the read query.
|
334
|
*
|
335
|
* @param Uuid
|
336
|
* @return
|
337
|
* @throws DataAccessException
|
338
|
*/
|
339
|
public T findByUuidWithoutFlush(UUID uuid) throws DataAccessException;
|
340
|
|
341
|
|
342
|
/**
|
343
|
* @param uuids
|
344
|
* @param pageSize
|
345
|
* @param pageNumber
|
346
|
* @param orderHints
|
347
|
* @param propertyPaths
|
348
|
* @return
|
349
|
* @throws DataAccessException
|
350
|
*/
|
351
|
public List<T> list(Collection<UUID> uuids, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws DataAccessException;
|
352
|
|
353
|
|
354
|
/**
|
355
|
* @param clazz
|
356
|
* @param uuids
|
357
|
* @param pageSize
|
358
|
* @param pageNumber
|
359
|
* @param orderHints
|
360
|
* @param propertyPaths
|
361
|
* @return
|
362
|
* @throws DataAccessException
|
363
|
*/
|
364
|
public <S extends T> List<S> list(Class<S> clazz, Collection<UUID> uuids, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws DataAccessException;
|
365
|
|
366
|
|
367
|
|
368
|
/**
|
369
|
* Finds the cdm entity specified by the <code>uuid</code> parameter and
|
370
|
* initializes all its *ToOne relations.
|
371
|
*
|
372
|
* @param uuid
|
373
|
* @return
|
374
|
*/
|
375
|
public T load(UUID uuid);
|
376
|
|
377
|
/**
|
378
|
* Finds the cdm entity specified by the <code>uuid</code> parameter and
|
379
|
* recursively initializes all bean properties given in the
|
380
|
* <code>propertyPaths</code> parameter.
|
381
|
* <p>
|
382
|
* For detailed description and examples <b>please refer to:</b>
|
383
|
* {@link IBeanInitializer#initialize(Object, List)}
|
384
|
*
|
385
|
* @param uuid
|
386
|
* @param propertyPaths properties to be initialized
|
387
|
* @return
|
388
|
*/
|
389
|
public T load(UUID uuid, List<String> propertyPaths);
|
390
|
|
391
|
/**
|
392
|
* @param uuid
|
393
|
* @return
|
394
|
* @throws DataAccessException
|
395
|
*/
|
396
|
public Boolean exists(UUID uuid) throws DataAccessException;
|
397
|
|
398
|
public long count();
|
399
|
|
400
|
/**
|
401
|
* Returns the number of objects of type <T> - which must extend T
|
402
|
* @param <T>
|
403
|
* @param clazz
|
404
|
* @return
|
405
|
*/
|
406
|
public long count(Class<? extends T> clazz);
|
407
|
|
408
|
/**
|
409
|
* FIXME Should this method exist : I would expect flushing of a session to be
|
410
|
* something that a DAO should hide?
|
411
|
*/
|
412
|
public void flush();
|
413
|
|
414
|
/**
|
415
|
* Convenience method which makes it easy to discover what type of object this DAO returns at runtime
|
416
|
*
|
417
|
* @return
|
418
|
*/
|
419
|
public Class<T> getType();
|
420
|
|
421
|
/**
|
422
|
* Method that counts the number of objects matching the example provided.
|
423
|
* The includeProperties property is used to specify which properties of the example are used.
|
424
|
*
|
425
|
* If includeProperties is null or empty, then all literal properties are used (restrictions are
|
426
|
* applied as in the Hibernate Query-By-Example API call Example.create(object)).
|
427
|
*
|
428
|
* If includeProperties is not empty then only literal properties that are named in the set are used to
|
429
|
* create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
|
430
|
* their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
|
431
|
* criteria.createCriteria(property).add(Example.create(relatedObject)))
|
432
|
*
|
433
|
* @param example
|
434
|
* @param includeProperties
|
435
|
* @return a count of matching objects
|
436
|
*/
|
437
|
public long count(T example, Set<String> includeProperties);
|
438
|
|
439
|
/**
|
440
|
* Method that lists the objects matching the example provided.
|
441
|
* The includeProperties property is used to specify which properties of the example are used.
|
442
|
*
|
443
|
* If includeProperties is null or empty, then all literal properties are used (restrictions are
|
444
|
* applied as in the Hibernate Query-By-Example API call Example.create(object)).
|
445
|
*
|
446
|
* If includeProperties is not empty then only literal properties that are named in the set are used to
|
447
|
* create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
|
448
|
* their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
|
449
|
* criteria.createCriteria(property).add(Example.create(relatedObject)))
|
450
|
*
|
451
|
* @param example
|
452
|
* @param includeProperties
|
453
|
* @param limit the maximum number of entities returned (can be null to return
|
454
|
* all entities)
|
455
|
* @param start The (0-based) offset from the start of the recordset
|
456
|
* @param orderHints
|
457
|
* Supports path like <code>orderHints.propertyNames</code> which
|
458
|
* include *-to-one properties like createdBy.username or
|
459
|
* @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
|
460
|
* @return a list of matching objects
|
461
|
*/
|
462
|
public <S extends T> List<S> list(S example, Set<String> includeProperties, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
463
|
|
464
|
public <S extends T> List<S> findByParamWithRestrictions(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize,
|
465
|
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
|
466
|
|
467
|
public long countByParamWithRestrictions(Class<? extends T> clazz, String param, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions);
|
468
|
|
469
|
public long countByParam(Class<? extends T> clazz, String param, String queryString, MatchMode matchmode, List<Criterion> criterion);
|
470
|
|
471
|
public <S extends T> List<S> findByParam(Class<S> clazz, String param, String queryString, MatchMode matchmode, List<Criterion> criterion, Integer pageSize, Integer pageNumber,
|
472
|
List<OrderHint> orderHints, List<String> propertyPaths);
|
473
|
|
474
|
public <S extends T> List<S> findByParam(Class<S> clazz, Set<String> params, String queryString, MatchMode matchmode,
|
475
|
List<Criterion> criterion, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
|
476
|
List<String> propertyPaths);
|
477
|
|
478
|
}
|