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
.BeanInitializer
;
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 BeanInitializer#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 properties to 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 set of persisted entities that match the database identifiers.
126 * Returns an empty list if no identifier matches.
130 public List
<T
> findById(Set
<Integer
> idSet
); //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
132 // FIXME should we expose this method?
133 public Session
getSession();
136 * Returns a sublist of objects matching the grouping projections supplied using the groups parameter
138 * It would be nice to be able to return a pager, but for the moment hibernate doesn't
139 * seem to support this (HHH-3238 - impossible to get the rowcount for a criteria that has projections)
141 * @param clazz Restrict the query to objects of a certain class, or null for all objects of type T or subclasses
142 * @param limit the maximum number of entities returned (can be null to return
144 * @param start The (0-based) offset from the start of the recordset (can be null, equivalent of starting at the beginning of the recordset)
145 * @param groups The grouping objects representing a projection, plus an optional ordering on that projected property
146 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
147 * @return a list of arrays of objects, each matching the grouping objects supplied in the parameters.
149 public List
<Object
[]> group(Class
<?
extends T
> clazz
,Integer limit
, Integer start
, List
<Grouping
> groups
, List
<String
> propertyPaths
);
152 * Returns a list of entities of type <T> optionally restricted
153 * to objects belonging to a class that that extends <T>
155 * @param type The type of entities to return (can be null to count all entities of type <T>)
156 * @param limit The maximum number of objects returned (can be null for all matching objects)
157 * @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)
159 * Supports path like <code>orderHints.propertyNames</code> which
160 * include *-to-one properties like createdBy.username or
161 * authorTeam.persistentTitleCache
162 * @param propertyPaths properties to be initialized
165 public List
<T
> list(Class
<?
extends T
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
168 * Finds the cdm entity specified by the <code>uuid</code> parameter and
169 * initializes all its *ToOne relations.
174 public T
load(UUID uuid
);
177 * Finds the cdm entity specified by the <code>uuid</code> parameter and
178 * recursively initializes all bean properties given in the
179 * <code>propertyPaths</code> parameter.
181 * For detailed description and examples <b>please refer to:</b>
182 * {@link BeanInitializer#initialize(Object, List)}
187 public T
load(UUID uuid
, List
<String
> propertyPaths
);
190 * Copy the state of the given object onto the persistent object with the same identifier.
192 * @param transientObject the entity to be merged
193 * @return The unique identifier of the persisted entity
195 public T
merge(T transientObject
);
198 * Returns a paged list of entities of type <T> optionally restricted
199 * to objects belonging to a class that that extends <T>
201 * @param type The type of entities to return (can be null to count all entities of type <T>)
202 * @param pageSize The maximum number of objects returned (can be null for all matching objects)
203 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based,
204 * can be null, equivalent of starting at the beginning of the recordset)
206 * Supports path like <code>orderHints.propertyNames</code> which
207 * include *-to-one properties like createdBy.username or
208 * authorTeam.persistentTitleCache
209 * @param propertyPaths properties to be initialized
210 * @return a pager of objects of type <T>
212 public Pager
<T
> page(Class
<?
extends T
> type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
215 * Re-read the state of the given instance from the underlying database.
217 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
218 * I don't really see where we would get into a situation where problems as discussed
219 * this forum thread would apply for our scenario
221 * http://forum.hibernate.org/viewtopic.php?t=974544
223 * @param persistentObject the object to be refreshed
224 * @return the unique identifier
226 public UUID
refresh(T persistentObject
);
228 public List
<T
> rows(String tableName
, int limit
, int start
);
231 * Save a collection containing new entities (persists the entities)
232 * @param newInstances the new entities to be persisted
233 * @return A Map containing the new entities, keyed using the generated UUID's
236 public Map
<UUID
,T
> save(Collection
<T
> newInstances
);
239 * Save a new entity (persists the entity)
240 * @param newInstance the new entity to be persisted
241 * @return A generated UUID for the new persistent entity
243 public UUID
save(T newInstance
);
246 * Save a new entity or update the persistent state of an existing
247 * transient entity that has been persisted previously
249 * @param transientObject the entity to be persisted
250 * @return The unique identifier of the persisted entity
252 public UUID
saveOrUpdate(T transientObject
);
255 * Save new entities or update the persistent state of existing
256 * transient entities that have been persisted previously
258 * @param transientObjects the entities to be persisted
259 * @return The unique identifier of the persisted entity
261 public Map
<UUID
,T
> saveOrUpdate(Collection
<T
> transientObjects
);
264 * Update the persistent state of an existing transient entity
265 * that has been persisted previously
267 * @param transientObject the entity to be persisted
268 * @return The unique identifier of the persisted entity
270 public UUID
update(T transientObject
);
273 * Method that lists the objects matching the example provided.
274 * The includeProperties property is used to specify which properties of the example are used.
276 * If includeProperties is null or empty, then all literal properties are used (restrictions are
277 * applied as in the Hibernate Query-By-Example API call Example.create(object)).
279 * If includeProperties is not empty then only literal properties that are named in the set are used to
280 * create restrictions, *PLUS* any *ToOne related entities. Related entities are matched on ID, not by
281 * their internal literal values (e.g. the call is criteria.add(Restrictions.eq(property,relatedObject)), not
282 * criteria.createCriteria(property).add(Example.create(relatedObject)))
285 * @param includeProperties
286 * @param limit the maximum number of entities returned (can be null to return
288 * @param start The (0-based) offset from the start of the recordset
290 * Supports path like <code>orderHints.propertyNames</code> which
291 * include *-to-one properties like createdBy.username or
292 * @param propertyPaths paths initialized on the returned objects - only applied to the objects returned from the first grouping
293 * @return a list of matching objects
295 public List
<T
> list(T example
, Set
<String
> includeProperties
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);