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
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.DeleteConfiguratorBase
;
24 import eu
.etaxonomy
.cdm
.api
.service
.exception
.ReferencedObjectUndeletableException
;
25 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.initializer
.IBeanInitializer
;
29 import eu
.etaxonomy
.cdm
.persistence
.query
.Grouping
;
30 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
38 * @author a.kohlbecker
43 public interface IService
<T
extends ICdmBase
>{
45 // FIXME what does this method do?
49 * Obtain the specified lock mode on the given object t
51 public void lock(T t
, LockMode lockMode
);
54 * Refreshes a given object t using the specified lockmode
56 * All bean properties given in the <code>propertyPaths</code> parameter are recursively initialized.
58 * For detailed description and examples <b>please refer to:</b>
59 * {@link IBeanInitializer#initialize(Object, List)}
61 * NOTE: in the case of lockmodes that hit the database (e.g. LockMode.READ), you will need to re-initialize
62 * child propertiesto avoid a HibernateLazyInitializationException (even if the properties of the child
63 * were initialized prior to the refresh).
68 public void refresh(T t
, LockMode lockMode
, List
<String
> propertyPaths
);
71 * Returns a count of all entities of type <T> optionally restricted
72 * to objects belonging to a class that that extends <T>
74 * @param clazz the class of entities to be counted (can be null to count all entities of type <T>)
75 * @return a count of entities
77 public int count(Class
<?
extends T
> clazz
);
80 * Delete an existing persistent object
82 * @param persistentObject the object to be deleted
83 * @return the unique identifier of the deleted entity
86 public String
delete(T persistentObject
) ;
91 * Returns true if an entity of type <T> with a unique identifier matching the
92 * identifier supplied exists in the database, or false if no such entity can be
94 * @param uuid the unique identifier of the entity required
95 * @return an entity of type <T> matching the uuid, or null if that entity does not exist
97 public boolean exists(UUID uuid
);
100 * Return a list of persisted entities that match the unique identifier
101 * set supplied as an argument
103 * @param uuidSet the set of unique identifiers of the entities required
104 * @return a list of entities of type <T>
106 public List
<T
> find(Set
<UUID
> uuidSet
);
109 * Return a persisted entity that matches the unique identifier
110 * supplied as an argument, or null if the entity does not exist
112 * @param uuid the unique identifier of the entity required
113 * @return an entity of type <T>, or null if the entity does not exist
115 public T
find(UUID uuid
);
118 public T
findWithoutFlush(UUID uuid
);
121 * Return a persisted entity that matches the database identifier
122 * supplied as an argument, or null if the entity does not exist
124 * @param id the database identifier of the entity required
125 * @return an entity of type <T>, or null if the entity does not exist
127 public T
find(int id
);
130 * Returns a <code>List</code> of persisted entities that match the database identifiers.
131 * Returns an empty list if no identifier matches.
136 public List
<T
> findById(Set
<Integer
> idSet
); //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
139 // FIXME should we expose this method?
140 public Session
getSession();
143 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
145 * It would be nice to be able to return a pager, but for the moment hibernate doesn't
146 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
148 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
149 * @param limit the maximum number of entities returned (can be null to return
151 * @param start The (0-based) offset from the start of the recordset (can be null, equivalent of starting at the beginning of the recordset)
152 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
153 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
154 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
156 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
159 * Returns a list of entities of type <T> optionally restricted
160 * to objects belonging to a class that that extends <T>
162 * @param type The type of entities to return (can be null to count all entities of type <T>)
163 * @param limit The maximum number of objects returned (can be null for all matching objects)
164 * @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)
166 * Supports path like <code>orderHints.propertyNames</code> which
167 * include *-to-one properties like createdBy.username or
168 * authorTeam.persistentTitleCache
169 * @param propertyPaths properties to be initialized
172 //TODO refactor to public <S extends T> List<T> list(Class<S> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
173 public <S
extends T
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
176 * Finds the cdm entity specified by the <code>uuid</code> parameter and
177 * initializes all its *ToOne relations.
182 public T
load(UUID uuid
);
185 * Finds the cdm entity specified by the <code>uuid</code> parameter and
186 * recursively initializes all bean properties given in the
187 * <code>propertyPaths</code> parameter.
189 * For detailed description and examples <b>please refer to:</b>
190 * {@link IBeanInitializer#initialize(Object, List)}
195 public T
load(UUID uuid
, List
<String
> propertyPaths
);
198 * Copy the state of the given object onto the persistent object with the same identifier.
200 * @param transientObject the entity to be merged
201 * @return The unique identifier of the persisted entity
203 public T
merge(T transientObject
);
206 * Returns a paged list of entities of type <T> optionally restricted
207 * to objects belonging to a class that that extends <T>
209 * @param type The type of entities to return (can be null to count all entities of type <T>)
210 * @param pageSize The maximum number of objects returned (can be null for all matching objects)
211 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based,
212 * can be null, equivalent of starting at the beginning of the recordset)
214 * Supports path like <code>orderHints.propertyNames</code> which
215 * include *-to-one properties like createdBy.username or
216 * authorTeam.persistentTitleCache
217 * @param propertyPaths properties to be initialized
218 * @return a pager of objects of type <T>
220 public <S
extends T
> Pager
<S
> page(Class
<S
> type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
223 * Re-read the state of the given instance from the underlying database.
225 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
226 * I don't really see where we would get into a situation where problems as discussed
227 * this forum thread would apply for our scenario
229 * http://forum.hibernate.org/viewtopic.php?t=974544
231 * @param persistentObject the object to be refreshed
232 * @return the unique identifier
234 public UUID
refresh(T persistentObject
);
236 public List
<T
> rows(String tableName
, int limit
, int start
);
239 * Save a collection containing new entities (persists the entities)
240 * @param newInstances the new entities to be persisted
241 * @return A Map containing the new entities, keyed using the generated UUID's
244 public Map
<UUID
,T
> save(Collection
<T
> newInstances
);
247 * Save a new entity (persists the entity)
248 * @param newInstance the new entity to be persisted
249 * @return A generated UUID for the new persistent entity
251 public UUID
save(T newInstance
);
254 * Save a new entity or update the persistent state of an existing
255 * transient entity that has been persisted previously
257 * @param transientObject the entity to be persisted
258 * @return The unique identifier of the persisted entity
260 public UUID
saveOrUpdate(T transientObject
);
263 * Save new entities or update the persistent state of existing
264 * transient entities that have been persisted previously
266 * @param transientObjects the entities to be persisted
267 * @return The unique identifier of the persisted entity
269 public Map
<UUID
,T
> saveOrUpdate(Collection
<T
> transientObjects
);
272 * Update the persistent state of an existing transient entity
273 * that has been persisted previously
275 * @param transientObject the entity to be persisted
276 * @return The unique identifier of the persisted entity
278 public UUID
update(T transientObject
);
281 * Method that lists the objects matching the example provided.
282 * The includeProperties property is used to specify which properties of the example are used.
284 * If includeProperties is null or empty, then all literal properties are used (restrictions are
285 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
287 * If includeProperties is not empty then only literal properties that are named in the set are used to
288 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
289 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
290 * criteria.createCriteria(property).add(Example.create(relatedObject)))
293 * @param includeProperties
294 * @param limit the maximum number of entities returned (can be null to return
296 * @param start The (0-based) offset from the start of the recordset
298 * Supports path like <code>orderHints.propertyNames</code> which
299 * include *-to-one properties like createdBy.username or
300 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
301 * @return a list of matching objects
303 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);