3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.hibernate
.LockMode
;
21 import org
.hibernate
.Session
;
22 import org
.springframework
.security
.core
.Authentication
;
24 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
25 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
26 import eu
.etaxonomy
.cdm
.persistence
.dao
.BeanInitializer
;
27 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CdmPermission
;
28 import eu
.etaxonomy
.cdm
.persistence
.query
.Grouping
;
29 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
37 * @author a.kohlbecker
42 public interface IService
<T
extends ICdmBase
>{
44 // FIXME what does this method do?
48 * Obtain the specified lock mode on the given object t
50 public void lock(T t
, LockMode lockMode
);
53 * Refreshes a given object t using the specified lockmode
55 * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
57 * For detailed description and examples <b>please refer to:</b>
58 * {@link BeanInitializer#initialize(Object, List)}
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).
67 public void refresh(T t
, LockMode lockMode
, List
<String
> propertyPaths
);
70 * Returns a count of all entities of type <T> optionally restricted
71 * to objects belonging to a class that that extends <T>
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
76 public int count(Class
<?
extends T
> clazz
);
79 * Delete an existing persistent object
81 * @param persistentObject the object to be deleted
82 * @return the unique identifier of the deleted entity
84 public UUID
delete(T persistentObject
);
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
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
93 public boolean exists(UUID uuid
);
96 * Return a list of persisted entities that match the unique identifier
97 * set supplied as an argument
99 * @param uuidSet the set of unique identifiers of the entities required
100 * @return a list of entities of type <T>
102 public List
<T
> find(Set
<UUID
> uuidSet
);
105 * Return a persisted entity that matches the unique identifier
106 * supplied as an argument, or null if the entity does not exist
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
111 public T
find(UUID uuid
);
114 * Return a persisted entity that matches the database identifier
115 * supplied as an argument, or null if the entity does not exist
117 * @param id the database identifier of the entity required
118 * @return an entity of type <T>, or null if the entity does not exist
120 public T
find(int id
);
123 * Returns a set of persisted entities that match the database identifiers.
124 * Returns an empty list if no identifier matches.
128 public List
<T
> findById(Set
<Integer
> idSet
); //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
131 // FIXME should we expose this method?
132 public Session
getSession();
135 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
137 * It would be nice to be able to return a pager, but for the moment hibernate doesn't
138 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
140 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
141 * @param limit the maximum number of entities returned (can be null to return
143 * @param start The (0-based) offset from the start of the recordset (can be null, equivalent of starting at the beginning of the recordset)
144 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
145 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
146 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
148 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
151 * Returns a list of entities of type <T> optionally restricted
152 * to objects belonging to a class that that extends <T>
154 * @param type The type of entities to return (can be null to count all entities of type <T>)
155 * @param limit The maximum number of objects returned (can be null for all matching objects)
156 * @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)
158 * Supports path like <code>orderHints.propertyNames</code> which
159 * include *-to-one properties like createdBy.username or
160 * authorTeam.persistentTitleCache
161 * @param propertyPaths properties to be initialized
164 public List
<T
> list(Class
<?
extends T
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
167 * Finds the cdm entity specified by the <code>uuid</code> parameter and
168 * initializes all its *ToOne relations.
173 public T
load(UUID uuid
);
176 * Finds the cdm entity specified by the <code>uuid</code> parameter and
177 * recursively initializes all bean properties given in the
178 * <code>propertyPaths</code> parameter.
180 * For detailed description and examples <b>please refer to:</b>
181 * {@link BeanInitializer#initialize(Object, List)}
186 public T
load(UUID uuid
, List
<String
> propertyPaths
);
189 * Copy the state of the given object onto the persistent object with the same identifier.
191 * @param transientObject the entity to be merged
192 * @return The unique identifier of the persisted entity
194 public T
merge(T transientObject
);
197 * Returns a paged list of entities of type <T> optionally restricted
198 * to objects belonging to a class that that extends <T>
200 * @param type The type of entities to return (can be null to count all entities of type <T>)
201 * @param pageSize The maximum number of objects returned (can be null for all matching objects)
202 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based,
203 * can be null, equivalent of starting at the beginning of the recordset)
205 * Supports path like <code>orderHints.propertyNames</code> which
206 * include *-to-one properties like createdBy.username or
207 * authorTeam.persistentTitleCache
208 * @param propertyPaths properties to be initialized
209 * @return a pager of objects of type <T>
211 public Pager
<T
> page(Class
<?
extends T
> type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
214 * Re-read the state of the given instance from the underlying database.
216 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
217 * I don't really see where we would get into a situation where problems as discussed
218 * this forum thread would apply for our scenario
220 * http://forum.hibernate.org/viewtopic.php?t=974544
222 * @param persistentObject the object to be refreshed
223 * @return the unique identifier
225 public UUID
refresh(T persistentObject
);
227 public List
<T
> rows(String tableName
, int limit
, int start
);
230 * Save a collection containing new entities (persists the entities)
231 * @param newInstances the new entities to be persisted
232 * @return A Map containing the new entities, keyed using the generated UUID's
235 public Map
<UUID
,T
> save(Collection
<T
> newInstances
);
238 * Save a new entity (persists the entity)
239 * @param newInstance the new entity to be persisted
240 * @return A generated UUID for the new persistent entity
242 public UUID
save(T newInstance
);
245 * Save a new entity or update the persistent state of an existing
246 * transient entity that has been persisted previously
248 * @param transientObject the entity to be persisted
249 * @return The unique identifier of the persisted entity
251 public UUID
saveOrUpdate(T transientObject
);
254 * Save new entities or update the persistent state of existing
255 * transient entities that have been persisted previously
257 * @param transientObjects the entities to be persisted
258 * @return The unique identifier of the persisted entity
260 public Map
<UUID
,T
> saveOrUpdate(Collection
<T
> transientObjects
);
263 * Update the persistent state of an existing transient entity
264 * that has been persisted previously
266 * @param transientObject the entity to be persisted
267 * @return The unique identifier of the persisted entity
269 public UUID
update(T transientObject
);
272 * Method that lists the objects matching the example provided.
273 * The includeProperties property is used to specify which properties of the example are used.
275 * If includeProperties is null or empty, then all literal properties are used (restrictions are
276 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
278 * If includeProperties is not empty then only literal properties that are named in the set are used to
279 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
280 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
281 * criteria.createCriteria(property).add(Example.create(relatedObject)))
284 * @param includeProperties
285 * @param limit the maximum number of entities returned (can be null to return
287 * @param start The (0-based) offset from the start of the recordset
289 * Supports path like <code>orderHints.propertyNames</code> which
290 * include *-to-one properties like createdBy.username or
291 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
292 * @return a list of matching objects
294 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
297 * Evaluates whether the authenticated user has the rights to perform an specific action on the target object
298 * @param authentication
303 public boolean hasPermission(Authentication authentication
, T target
, CdmPermission permission
);