1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.api.service;
|
12
|
|
13
|
|
14
|
import java.util.Collection;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.hibernate.LockMode;
|
21
|
import org.hibernate.Session;
|
22
|
import org.springframework.security.core.Authentication;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
25
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
26
|
import eu.etaxonomy.cdm.permission.CdmPermission;
|
27
|
import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
|
28
|
import eu.etaxonomy.cdm.persistence.query.Grouping;
|
29
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
*
|
35
|
*/
|
36
|
/**
|
37
|
* @author a.kohlbecker
|
38
|
* @date 23.03.2009
|
39
|
*
|
40
|
* @param <T>
|
41
|
*/
|
42
|
public interface IService<T extends ICdmBase>{
|
43
|
|
44
|
// FIXME what does this method do?
|
45
|
public void clear();
|
46
|
|
47
|
/**
|
48
|
* Obtain the specified lock mode on the given object t
|
49
|
*/
|
50
|
public void lock(T t, LockMode lockMode);
|
51
|
|
52
|
/**
|
53
|
* Refreshes a given object t using the specified lockmode
|
54
|
*
|
55
|
* All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
|
56
|
* <p>
|
57
|
* For detailed description and examples <b>please refer to:</b>
|
58
|
* {@link BeanInitializer#initialize(Object, List)}
|
59
|
*
|
60
|
* NOTE: in the case of lockmodes that hit the database (e.g. LockMode.READ), you will need to re-initialize
|
61
|
* child propertiesto avoid a HibernateLazyInitializationException (even if the properties of the child
|
62
|
* were initialized prior to the refresh).
|
63
|
*
|
64
|
* @param t
|
65
|
* @param lockMode
|
66
|
*/
|
67
|
public void refresh(T t, LockMode lockMode, List<String> propertyPaths);
|
68
|
|
69
|
/**
|
70
|
* Returns a count of all entities of type <T> optionally restricted
|
71
|
* to objects belonging to a class that that extends <T>
|
72
|
*
|
73
|
* @param clazz the class of entities to be counted (can be null to count all entities of type <T>)
|
74
|
* @return a count of entities
|
75
|
*/
|
76
|
public int count(Class<? extends T> clazz);
|
77
|
|
78
|
/**
|
79
|
* Delete an existing persistent object
|
80
|
*
|
81
|
* @param persistentObject the object to be deleted
|
82
|
* @return the unique identifier of the deleted entity
|
83
|
*/
|
84
|
public UUID delete(T persistentObject);
|
85
|
|
86
|
/**
|
87
|
* Returns true if an entity of type <T> with a unique identifier matching the
|
88
|
* identifier supplied exists in the database, or false if no such entity can be
|
89
|
* found.
|
90
|
* @param uuid the unique identifier of the entity required
|
91
|
* @return an entity of type <T> matching the uuid, or null if that entity does not exist
|
92
|
*/
|
93
|
public boolean exists(UUID uuid);
|
94
|
|
95
|
/**
|
96
|
* Return a list of persisted entities that match the unique identifier
|
97
|
* set supplied as an argument
|
98
|
*
|
99
|
* @param uuidSet the set of unique identifiers of the entities required
|
100
|
* @return a list of entities of type <T>
|
101
|
*/
|
102
|
public List<T> find(Set<UUID> uuidSet);
|
103
|
|
104
|
/**
|
105
|
* Return a persisted entity that matches the unique identifier
|
106
|
* supplied as an argument, or null if the entity does not exist
|
107
|
*
|
108
|
* @param uuid the unique identifier of the entity required
|
109
|
* @return an entity of type <T>, or null if the entity does not exist
|
110
|
*/
|
111
|
public T find(UUID uuid);
|
112
|
|
113
|
// FIXME should we expose this method?
|
114
|
public Session getSession();
|
115
|
|
116
|
/**
|
117
|
* Returns a sublist of objects matching the grouping projections supplied using the groups parameter
|
118
|
*
|
119
|
* It would be nice to be able to return a pager, but for the moment hibernate doesn't
|
120
|
* seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
|
121
|
*
|
122
|
* @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
|
123
|
* @param limit the maximum number of entities returned (can be null to return
|
124
|
* all entities)
|
125
|
* @param start The (0-based) offset from the start of the recordset (can be null, equivalent of starting at the beginning of the recordset)
|
126
|
* @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
|
127
|
* @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
|
128
|
* @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
|
129
|
*/
|
130
|
public List<Object[]> group(Class<? extends T> clazz,Integer limit, Integer start, List<Grouping> groups, List<String> propertyPaths);
|
131
|
|
132
|
/**
|
133
|
* Returns a list of entities of type <T> optionally restricted
|
134
|
* to objects belonging to a class that that extends <T>
|
135
|
*
|
136
|
* @param type The type of entities to return (can be null to count all entities of type <T>)
|
137
|
* @param limit The maximum number of objects returned (can be null for all matching objects)
|
138
|
* @param start The offset from the start of the result set (0 - based, can be null - equivalent of starting at the beginning of the recordset)
|
139
|
* @param orderHints
|
140
|
* Supports path like <code>orderHints.propertyNames</code> which
|
141
|
* include *-to-one properties like createdBy.username or
|
142
|
* authorTeam.persistentTitleCache
|
143
|
* @param propertyPaths properties to be initialized
|
144
|
* @return
|
145
|
*/
|
146
|
public List<T> list(Class<? extends T> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
147
|
|
148
|
/**
|
149
|
* Finds the cdm entity specified by the <code>uuid</code> parameter and
|
150
|
* initializes all its *ToOne relations.
|
151
|
*
|
152
|
* @param uuid
|
153
|
* @return
|
154
|
*/
|
155
|
public T load(UUID uuid);
|
156
|
|
157
|
/**
|
158
|
* Finds the cdm entity specified by the <code>uuid</code> parameter and
|
159
|
* recursively initializes all bean properties given in the
|
160
|
* <code>propertyPaths</code> parameter.
|
161
|
* <p>
|
162
|
* For detailed description and examples <b>please refer to:</b>
|
163
|
* {@link BeanInitializer#initialize(Object, List)}
|
164
|
*
|
165
|
* @param uuid
|
166
|
* @return
|
167
|
*/
|
168
|
public T load(UUID uuid, List<String> propertyPaths);
|
169
|
|
170
|
/**
|
171
|
* Copy the state of the given object onto the persistent object with the same identifier.
|
172
|
*
|
173
|
* @param transientObject the entity to be merged
|
174
|
* @return The unique identifier of the persisted entity
|
175
|
*/
|
176
|
public T merge(T transientObject);
|
177
|
|
178
|
/**
|
179
|
* Returns a paged list of entities of type <T> optionally restricted
|
180
|
* to objects belonging to a class that that extends <T>
|
181
|
*
|
182
|
* @param type The type of entities to return (can be null to count all entities of type <T>)
|
183
|
* @param pageSize The maximum number of objects returned (can be null for all matching objects)
|
184
|
* @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based,
|
185
|
* can be null, equivalent of starting at the beginning of the recordset)
|
186
|
* @param orderHints
|
187
|
* Supports path like <code>orderHints.propertyNames</code> which
|
188
|
* include *-to-one properties like createdBy.username or
|
189
|
* authorTeam.persistentTitleCache
|
190
|
* @param propertyPaths properties to be initialized
|
191
|
* @return a pager of objects of type <T>
|
192
|
*/
|
193
|
public Pager<T> page(Class<? extends T> type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
|
194
|
|
195
|
/**
|
196
|
* Re-read the state of the given instance from the underlying database.
|
197
|
*
|
198
|
* Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
|
199
|
* I don't really see where we would get into a situation where problems as discussed
|
200
|
* this forum thread would apply for our scenario
|
201
|
*
|
202
|
* http://forum.hibernate.org/viewtopic.php?t=974544
|
203
|
*
|
204
|
* @param persistentObject the object to be refreshed
|
205
|
* @return the unique identifier
|
206
|
*/
|
207
|
public UUID refresh(T persistentObject);
|
208
|
|
209
|
public List<T> rows(String tableName, int limit, int start);
|
210
|
|
211
|
/**
|
212
|
* Save a collection containing new entities (persists the entities)
|
213
|
* @param newInstances the new entities to be persisted
|
214
|
* @return A Map containing the new entities, keyed using the generated UUID's
|
215
|
* of those entities
|
216
|
*/
|
217
|
public Map<UUID,T> save(Collection<T> newInstances);
|
218
|
|
219
|
/**
|
220
|
* Save a new entity (persists the entity)
|
221
|
* @param newInstance the new entity to be persisted
|
222
|
* @return A generated UUID for the new persistent entity
|
223
|
*/
|
224
|
public UUID save(T newInstance);
|
225
|
|
226
|
/**
|
227
|
* Save a new entity or update the persistent state of an existing
|
228
|
* transient entity that has been persisted previously
|
229
|
*
|
230
|
* @param transientObject the entity to be persisted
|
231
|
* @return The unique identifier of the persisted entity
|
232
|
*/
|
233
|
public UUID saveOrUpdate(T transientObject);
|
234
|
|
235
|
/**
|
236
|
* Save new entities or update the persistent state of existing
|
237
|
* transient entities that have been persisted previously
|
238
|
*
|
239
|
* @param transientObjects the entities to be persisted
|
240
|
* @return The unique identifier of the persisted entity
|
241
|
*/
|
242
|
public Map<UUID,T> saveOrUpdate(Collection<T> transientObjects);
|
243
|
|
244
|
/**
|
245
|
* Update the persistent state of an existing transient entity
|
246
|
* that has been persisted previously
|
247
|
*
|
248
|
* @param transientObject the entity to be persisted
|
249
|
* @return The unique identifier of the persisted entity
|
250
|
*/
|
251
|
public UUID update(T transientObject);
|
252
|
|
253
|
/**
|
254
|
* Method that lists the objects matching the example provided.
|
255
|
* The includeProperties property is used to specify which properties of the example are used.
|
256
|
*
|
257
|
* If includeProperties is null or empty, then all literal properties are used (restrictions are
|
258
|
* applied as in the Hibernate Query-By-Example API call Example.create(object)).
|
259
|
*
|
260
|
* If includeProperties is not empty then only literal properties that are named in the set are used to
|
261
|
* create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
|
262
|
* their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
|
263
|
* criteria.createCriteria(property).add(Example.create(relatedObject)))
|
264
|
*
|
265
|
* @param example
|
266
|
* @param includeProperties
|
267
|
* @param limit the maximum number of entities returned (can be null to return
|
268
|
* all entities)
|
269
|
* @param start The (0-based) offset from the start of the recordset
|
270
|
* @param orderHints
|
271
|
* Supports path like <code>orderHints.propertyNames</code> which
|
272
|
* include *-to-one properties like createdBy.username or
|
273
|
* @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
|
274
|
* @return a list of matching objects
|
275
|
*/
|
276
|
public List<T> list(T example, Set<String> includeProperties, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
|
277
|
|
278
|
/**
|
279
|
* Evaluates whether the authenticated user has the rights to perform an specific action on the target object
|
280
|
* @param authentication
|
281
|
* @param target
|
282
|
* @param permission
|
283
|
* @return
|
284
|
*/
|
285
|
public boolean hasPermission(Authentication authentication, T target, CdmPermission permission);
|
286
|
|
287
|
}
|