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
.Session
;
21 import org
.springframework
.transaction
.annotation
.Propagation
;
22 import org
.springframework
.transaction
.annotation
.Transactional
;
24 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
25 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.BeanInitializer
;
29 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
37 * @author a.kohlbecker
42 @Transactional(propagation
=Propagation
.SUPPORTS
, readOnly
=true)
43 public interface IService
<T
extends CdmBase
>{
46 * Returns a count of all entities of type <T>
47 * @return a count of all entities
52 * Returns a count of all entities of type <TYPE> that extend <T>
53 * @param clazz the class of entities to be counted
54 * @return a count of entities
56 public <TYPE
extends T
> int count(Class
<TYPE
> clazz
);
59 * Returns a List of entities of type <T>
60 * TODO would like to substitute List with Pager, but we need
61 * to agree on how to implement paging first
63 * @param limit The maximum number of entities returned
64 * @param start The offset from the start of the dataset
65 * @return a List of entities
67 public List
<T
> list(int limit
, int start
);
70 * Returns a List of entities of type <TYPE> which must extend
72 * TODO would like to substitute List with Pager, but we need
73 * to agree on how to implement paging first
75 * @param type The type of entities to return
76 * @param limit The maximum number of entities returned
77 * @param start The offset from the start of the dataset
78 * @return a List of entities
80 public <TYPE
extends T
> List
<TYPE
> list(Class
<TYPE
> type
, int limit
, int start
);
85 * the maximum number of entities returned per page (can be null
86 * to return all entities in a single page)
87 * @param pageNumber the number of the page to be returned, the first page has the
91 public Pager
<T
> list(Integer pageSize
, Integer pageNumber
);
96 * the maximum number of entities returned per page (can be null
97 * to return all entities in a single page)
99 * the number of the page to be returned, the first page has the
105 public Pager
<T
> list(Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
);
108 Returns a paged list of entities of type <TYPE> which must extend
111 * @param type The type of entities to return
114 * @param orderHints may be null
115 * @param propertyPaths properties to initialize - see {@link BeanInitializer#initialize(Object, List)}
118 public <TYPE
extends T
> Pager
<TYPE
> list(Class
<TYPE
> type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
123 * @param orderHints may be null
124 * @param propertyPaths properties to initialize - see {@link BeanInitializer#initialize(Object, List)}
127 public Pager
<T
> list(Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
129 public List
<T
> rows(String tableName
, int limit
, int start
);
132 * Save a new entity (persists the entity)
133 * @param newInstance the new entity to be persisted
134 * @return A generated UUID for the new persistent entity
136 @Transactional(readOnly
=false)
137 public UUID
save(T newInstance
);
140 * Save a new entity or update the persistent state of an existing
141 * transient entity that has been persisted previously
143 * @param transientObject the entity to be persisted
144 * @return The unique identifier of the persisted entity
146 @Transactional(readOnly
=false)
147 public UUID
saveOrUpdate(T transientObject
);
150 * Update the persistent state of an existing transient entity
151 * that has been persisted previously
153 * @param transientObject the entity to be persisted
154 * @return The unique identifier of the persisted entity
156 @Transactional(readOnly
=false)
157 public UUID
update(T transientObject
);
160 * Copy the state of the given object onto the persistent object with the same identifier.
162 * @param transientObject the entity to be merged
163 * @return The unique identifier of the persisted entity
165 @Transactional(readOnly
=false)
166 public UUID
merge(T transientObject
);
169 * Copy the state of the given object onto the persistent object with the same identifier.
171 * @param transientObject the entity to be merged
172 * @return The unique identifier of the persisted entity
174 // @Transactional(readOnly=false)
177 public Session
getSession();
180 * Save a collection containing new entities (persists the entities)
181 * @param newInstances the new entities to be persisted
182 * @return A Map containing the new entities, keyed using the generated UUID's
185 @Transactional(readOnly
=false)
186 public Map
<UUID
,T
> saveAll(Collection
<T
> newInstances
);
189 * Re-read the state of the given instance from the underlying database.
191 * Hibernate claims that it is inadvisable to use refresh in long-running-sessions.
192 * I don't really see where we would get into a situation where problems as discussed
193 * this forum thread would apply for our scenario
195 * http://forum.hibernate.org/viewtopic.php?t=974544
197 * @param persistentObject the object to be refreshed
198 * @return the unique identifier
200 @Transactional(readOnly
=false)
201 public UUID
refresh(T persistentObject
);
204 * Delete an existing persistent object
206 * @param persistentObject the object to be deleted
207 * @return the unique identifier of the deleted entity
209 @Transactional(readOnly
=false)
210 public UUID
delete(T persistentObject
);
213 * Return a persisted entity that matches the unique identifier
214 * supplied as an argument, or null if the entity does not exist
216 * @param uuid the unique identifier of the entity required
217 * @return an entity of type <T>, or null if the entity does not exist
219 public T
findByUuid(UUID uuid
);
222 * Return a list of persisted entities that match the unique identifier
223 * set supplied as an argument
225 * @param uuidSet the set of unique identifiers of the entities required
226 * @return a list of entities of type <T>
228 public List
<T
> findByUuid(Set
<UUID
> uuidSet
);
231 * Finds the cdm entity specified by the <code>uuid</code> parameter and
232 * initializes all its *ToOne relations.
237 public T
load(UUID uuid
);
240 * Finds the cdm entity specified by the <code>uuid</code> parameter and
241 * recursively initializes all bean properties given in the
242 * <code>propertyPaths</code> parameter.
244 * For detailed description and examples <b>please refer to:</b>
245 * {@link BeanInitializer#initialize(Object, List)}
250 public T
load(UUID uuid
, List
<String
> propertyPaths
);
255 * Returns true if an entity of type <T> with a unique identifier matching the
256 * identifier supplied exists in the database, or false if no such entity can be
258 * @param uuid the unique identifier of the entity required
259 * @return an entity of type <T> matching the uuid, or null if that entity does not exist
261 public boolean exists(UUID uuid
);