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
.EnumSet
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import org
.hibernate
.LockMode
;
22 import org
.hibernate
.Session
;
23 import org
.springframework
.security
.core
.Authentication
;
25 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
26 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
27 import eu
.etaxonomy
.cdm
.persistence
.dao
.IBeanInitializer
;
28 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CRUD
;
29 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.Operation
;
30 import eu
.etaxonomy
.cdm
.persistence
.query
.Grouping
;
31 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
39 * @author a.kohlbecker
44 public interface IService
<T
extends ICdmBase
>{
46 // FIXME what does this method do?
50 * Obtain the specified lock mode on the given object t
52 public void lock(T t
, LockMode lockMode
);
55 * Refreshes a given object t using the specified lockmode
57 * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
59 * For detailed description and examples <b>please refer to:</b>
60 * {@link IBeanInitializer#initialize(Object, List)}
62 * NOTE: in the case of lockmodes that hit the database (e.g. LockMode.READ), you will need to re-initialize
63 * child propertiesto avoid a HibernateLazyInitializationException (even if the properties of the child
64 * were initialized prior to the refresh).
69 public void refresh(T t
, LockMode lockMode
, List
<String
> propertyPaths
);
72 * Returns a count of all entities of type <T> optionally restricted
73 * to objects belonging to a class that that extends <T>
75 * @param clazz the class of entities to be counted (can be null to count all entities of type <T>)
76 * @return a count of entities
78 public int count(Class
<?
extends T
> clazz
);
81 * Delete an existing persistent object
83 * @param persistentObject the object to be deleted
84 * @return the unique identifier of the deleted entity
86 public UUID
delete(T persistentObject
);
89 * Returns true if an entity of type <T> with a unique identifier matching the
90 * identifier supplied exists in the database, or false if no such entity can be
92 * @param uuid the unique identifier of the entity required
93 * @return an entity of type <T> matching the uuid, or null if that entity does not exist
95 public boolean exists(UUID uuid
);
98 * Return a list of persisted entities that match the unique identifier
99 * set supplied as an argument
101 * @param uuidSet the set of unique identifiers of the entities required
102 * @return a list of entities of type <T>
104 public List
<T
> find(Set
<UUID
> uuidSet
);
107 * Return a persisted entity that matches the unique identifier
108 * supplied as an argument, or null if the entity does not exist
110 * @param uuid the unique identifier of the entity required
111 * @return an entity of type <T>, or null if the entity does not exist
113 public T
find(UUID uuid
);
116 * Return a persisted entity that matches the database identifier
117 * supplied as an argument, or null if the entity does not exist
119 * @param id the database identifier of the entity required
120 * @return an entity of type <T>, or null if the entity does not exist
122 public T
find(int id
);
125 * Returns a <code>List</code> of persisted entities that match the database identifiers.
126 * Returns an empty list if no identifier matches.
131 public List
<T
> findById(Set
<Integer
> idSet
); //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
134 // FIXME should we expose this method?
135 public Session
getSession();
138 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
140 * It would be nice to be able to return a pager, but for the moment hibernate doesn't
141 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
143 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
144 * @param limit the maximum number of entities returned (can be null to return
146 * @param start The (0-based) offset from the start of the recordset (can be null, equivalent of starting at the beginning of the recordset)
147 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
148 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
149 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
151 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
154 * Returns a list of entities of type <T> optionally restricted
155 * to objects belonging to a class that that extends <T>
157 * @param type The type of entities to return (can be null to count all entities of type <T>)
158 * @param limit The maximum number of objects returned (can be null for all matching objects)
159 * @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)
161 * Supports path like <code>orderHints.propertyNames</code> which
162 * include *-to-one properties like createdBy.username or
163 * authorTeam.persistentTitleCache
164 * @param propertyPaths properties to be initialized
167 public List
<T
> list(Class
<?
extends T
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
170 * Finds the cdm entity specified by the <code>uuid</code> parameter and
171 * initializes all its *ToOne relations.
176 public T
load(UUID uuid
);
179 * Finds the cdm entity specified by the <code>uuid</code> parameter and
180 * recursively initializes all bean properties given in the
181 * <code>propertyPaths</code> parameter.
183 * For detailed description and examples <b>please refer to:</b>
184 * {@link IBeanInitializer#initialize(Object, List)}
189 public T
load(UUID uuid
, List
<String
> propertyPaths
);
192 * Copy the state of the given object onto the persistent object with the same identifier.
194 * @param transientObject the entity to be merged
195 * @return The unique identifier of the persisted entity
197 public T
merge(T transientObject
);
200 * Returns a paged list of entities of type <T> optionally restricted
201 * to objects belonging to a class that that extends <T>
203 * @param type The type of entities to return (can be null to count all entities of type <T>)
204 * @param pageSize The maximum number of objects returned (can be null for all matching objects)
205 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based,
206 * can be null, equivalent of starting at the beginning of the recordset)
208 * Supports path like <code>orderHints.propertyNames</code> which
209 * include *-to-one properties like createdBy.username or
210 * authorTeam.persistentTitleCache
211 * @param propertyPaths properties to be initialized
212 * @return a pager of objects of type <T>
214 public Pager
<T
> page(Class
<?
extends T
> type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
217 * Re-read the state of the given instance from the underlying database.
219 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
220 * I don't really see where we would get into a situation where problems as discussed
221 * this forum thread would apply for our scenario
223 * http://forum.hibernate.org/viewtopic.php?t=974544
225 * @param persistentObject the object to be refreshed
226 * @return the unique identifier
228 public UUID
refresh(T persistentObject
);
230 public List
<T
> rows(String tableName
, int limit
, int start
);
233 * Save a collection containing new entities (persists the entities)
234 * @param newInstances the new entities to be persisted
235 * @return A Map containing the new entities, keyed using the generated UUID's
238 public Map
<UUID
,T
> save(Collection
<T
> newInstances
);
241 * Save a new entity (persists the entity)
242 * @param newInstance the new entity to be persisted
243 * @return A generated UUID for the new persistent entity
245 public UUID
save(T newInstance
);
248 * Save a new entity or update the persistent state of an existing
249 * transient entity that has been persisted previously
251 * @param transientObject the entity to be persisted
252 * @return The unique identifier of the persisted entity
254 public UUID
saveOrUpdate(T transientObject
);
257 * Save new entities or update the persistent state of existing
258 * transient entities that have been persisted previously
260 * @param transientObjects the entities to be persisted
261 * @return The unique identifier of the persisted entity
263 public Map
<UUID
,T
> saveOrUpdate(Collection
<T
> transientObjects
);
266 * Update the persistent state of an existing transient entity
267 * that has been persisted previously
269 * @param transientObject the entity to be persisted
270 * @return The unique identifier of the persisted entity
272 public UUID
update(T transientObject
);
275 * Method that lists the objects matching the example provided.
276 * The includeProperties property is used to specify which properties of the example are used.
278 * If includeProperties is null or empty, then all literal properties are used (restrictions are
279 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
281 * If includeProperties is not empty then only literal properties that are named in the set are used to
282 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
283 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
284 * criteria.createCriteria(property).add(Example.create(relatedObject)))
287 * @param includeProperties
288 * @param limit the maximum number of entities returned (can be null to return
290 * @param start The (0-based) offset from the start of the recordset
292 * Supports path like <code>orderHints.propertyNames</code> which
293 * include *-to-one properties like createdBy.username or
294 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
295 * @return a list of matching objects
297 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);