2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.Collection
;
13 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.hibernate
.Session
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.ISourceable
;
22 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaData
;
23 import eu
.etaxonomy
.cdm
.model
.metadata
.CdmMetaDataPropertyName
;
24 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ICdmGenericDao
;
25 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
26 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchStrategy
;
27 import eu
.etaxonomy
.cdm
.strategy
.match
.IMatchable
;
28 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchException
;
29 import eu
.etaxonomy
.cdm
.strategy
.match
.MatchStrategyConfigurator
;
30 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergable
;
31 import eu
.etaxonomy
.cdm
.strategy
.merge
.IMergeStrategy
;
32 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
36 public interface ICommonService
/*extends IService<OriginalSourceBase>*/{
39 // /** find cdmBase by UUID**/
40 // public abstract CdmBase getCdmBaseByUuid(UUID uuid);
42 // /** save a reference and return its UUID**/
43 // public abstract UUID saveCdmBase(CdmBase cdmBase);
49 public void saveAllMetaData(Collection
<CdmMetaData
> metaData
);
52 * Returns all meta data.
55 public Map
<CdmMetaDataPropertyName
, CdmMetaData
> getCdmMetaData();
59 * Returns a map of identifiable entities of class <code>clazz</code> which have an original source of
60 * with namespace <code>idNamespace</code> and with an idInSource in <code>idInSourceSet</code> <BR>
61 * The key of the map is the idInSource. If there are multiple objects that have the same id an arbitrary one is chosen.
63 * @param idInSourceSet
67 public Map
<String
, ?
extends ISourceable
> getSourcedObjectsByIdInSource(Class clazz
, Set
<String
> idInSourceSet
, String idNamespace
);
70 * Returns a list of identifiable entities according to their class, idInSource and idNamespace
76 public ISourceable
getSourcedObjectByIdInSource(Class clazz
, String idInSource
, String idNamespace
);
80 * Returns all CdmBase objects that reference the referencedCdmBase.
81 * For example, if referencedCdmBase is an agent it may return all taxon names
82 * that have this person as an author but also all books, articles, etc. that have
83 * this person as an author
84 * @param referencedCdmBase
87 public Set
<CdmBase
> getReferencingObjects(CdmBase referencedCdmBase
);
92 * Tests if cdmBase2 can be merged into cdmBase1. This is usually the case when both
93 * objects are of the same class.
94 * If they are not they must have a common super class and all links to CdmBase2 must be
95 * re-referenceable to cdmBase1.
96 * This is not the case if cdmBase2 is linked by a property which does not support class of cdmBase1.
97 * E.g. User.person requires a person so if user u1 exists with u1.person = person1 and we want to
98 * merge person1 into team1 this is not possible because team1 is not a valid replacement for person1
99 * within the user1.person context.
101 * This method is not expensive if classes are equal but may become more expensive if not, because
102 * in this concrete references to cdmBases2 need to be evaluated.
105 * @param mergeStrategy
107 * @throws MergeException
109 public <T
extends CdmBase
> boolean isMergeable(T cdmBase1
, T cdmBase2
, IMergeStrategy mergeStrategy
) throws MergeException
;
113 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
114 * to merge first. If no merge strategy is defined (null), the DefaultMergeStrategy will be taken as default.
118 * @param mergeStrategy
119 * @throws MergeException
121 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
, IMergeStrategy mergeStrategy
) throws MergeException
;
124 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
125 * to merge first, using a merge strategy defined by the given class.
130 * @throws MergeException
132 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;
136 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
137 * to merge first, using a merge strategy defined by the mergeFirst type.
140 * @throws MergeException
142 public <T
extends IMergable
> void merge(T mergeFirst
, T mergeSecond
) throws MergeException
;
146 * Returns all objects that match the object to match according to the given match strategy.
147 * If no match strategy is defined the default match strategy is taken.
149 * @param objectToMatch
150 * @param matchStrategy
152 * @throws MatchException
154 public <T
extends IMatchable
> List
<T
> findMatching(T objectToMatch
, IMatchStrategy matchStrategy
) throws MatchException
;
157 public <T
extends IMatchable
> List
<T
> findMatching(T objectToMatch
, MatchStrategyConfigurator
.MatchStrategy strategy
) throws MatchException
;
165 public CdmBase
findWithUpdate(Class
<?
extends CdmBase
> clazz
, int id
);
168 * A generic method to retrieve any CdmBase object by its id and class.<BR>
169 * @see ICdmGenericDao#find(Class, int)
170 * @see Session#get(Class, java.io.Serializable)
171 * @param clazz the CdmBase class
172 * @param id the cdmBase identifier
173 * @return the CdmBase object defined by clazz and id
174 * @see #find(Class, int, List)
176 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
);
179 * @param clazz the Class of the obejct to find
181 * @param propertyPaths the property path for bean initialization
183 * @see #find(Class, int)
185 public CdmBase
find(Class
<?
extends CdmBase
> clazz
, int id
, List
<String
> propertyPaths
);
188 * A generic method to retrieve any CdmBase object by its uuid and class.<BR>
189 * @param clazz the Class of the obejct to find
190 * @param uuid the UUID of the object to find
193 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, UUID uuid
);
196 * A generic method to retrieve any CdmBase object by its UUID and class,
197 * including initialization via property path.<BR>
198 * @param clazz the Class of the obejct to find
199 * @param uuid the UUID of the object to find
200 * @param propertyPaths the property path for bean initialization
203 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, UUID uuid
, List
<String
> propertyPaths
);
205 public List
getHqlResult(String hqlQuery
);
209 * Initializes a collection or map.
211 * @param ownerUuid uuid of owner cdm entity
212 * @param fieldName field name of collection or map
213 * @return initialised collection or map
215 public Object
initializeCollection(UUID ownerUuid
, String fieldName
);
220 * @param propertyPaths
223 public Object
initializeCollection(UUID ownerUuid
, String fieldName
, List
<String
> propertyPaths
);
226 * Checks if a collection or map is empty.
228 * @param ownerUuid uuid of owner cdm entity
229 * @param fieldName field name of collection or map
230 * @return true if the collection of map is empty, else false
232 public boolean isEmpty(UUID ownerUuid
, String fieldName
);
235 * Returns the size of requested collection or map.
237 * @param ownerUuid uuid of owner cdm entity
238 * @param fieldName field name of collection or map
239 * @return the size of the persistent collection
241 public int size(UUID ownerUuid
, String fieldName
);
244 * Returns the object contained in a collection or map at the given index.
246 * @param ownerUuid uuid of owner cdm entity
247 * @param fieldName field name of collection or map
248 * @param index the index of the requested element
249 * @return the object at the requested index
251 public Object
get(UUID ownerUuid
, String fieldName
, int index
);
254 * Checks whether an object is contained within a persistent collection.
256 * @param ownerUuid uuid of owner cdm entity
257 * @param fieldName field name of collection or map
258 * @param element the element to check for
259 * @return true if the element exists in the collection, false o/w
261 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
);
264 * Checks whether an index object exists within a persistent collection
267 * @param ownerUuid uuid of owner cdm entity
268 * @param fieldName field name of map
269 * @param key the index object to look for.
270 * @return true if the index object exists in the collection, false o/w
272 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
);
275 * checks whether an value object exists within a persistent collection
278 * @param ownerUuid uuid of owner cdm entity
279 * @param fieldName field name of map
280 * @param key the value object to look for.
281 * @return true if the value object exists in the collection, false o/w
283 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
);
285 public Set
<CdmBase
> getReferencingObjectsForDeletion(CdmBase referencedCdmBase
);
288 * Creates a database that more or less has all tables filled.
289 * Preliminary, may be moved to test later
292 public void createFullSampleData();
296 * Returns the number of objects that belong to a certain class.
297 * @param type the CdmBase class
298 * @return the number of objects in the database
300 public <S
extends CdmBase
> int count(Class
<S
> type
);
304 * Generic method to retrieve a list of objects. Use only if no specific service class
310 * @param propertyPaths
311 * @see IService#list(Class, Integer, Integer, List, List)
314 public <S
extends CdmBase
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
317 * Save a new entity (persists the entity)
318 * @param newInstance the new entity to be persisted
319 * @return A generated UUID for the new persistent entity
321 public CdmBase
save(CdmBase newInstance
);
324 * Save or update a new entity
325 * @param entity the entity to be persisted
326 * @return The UUID of the persistent entity
328 public UUID
saveOrUpdate(CdmBase entity
);
331 * Save a collection containing new entities (persists the entities)
332 * @param newInstances the new entities to be persisted
333 * @return A Map containing the new entities, keyed using the generated UUID's
336 public <T
extends CdmBase
> Map
<UUID
,T
> save(Collection
<T
> newInstances
);
339 * Save or update a collection containing entities
340 * @param entities the entities to be persisted
341 * @return A Map containing the new entities, keyed using the UUID's
344 public <T
extends CdmBase
> Map
<UUID
,T
> saveOrUpdate(Collection
<T
> entities
);
350 public UUID
delete(CdmBase instance
);
353 * @param mergeFirstId
354 * @param mergeSecondId
356 * @throws MergeException
357 * @Deprecated the preferred method is to use uuids {@link #merge(UUID, UUID, Class)}
360 public <T
extends IMergable
> void merge(int mergeFirstId
, int mergeSecondId
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;
363 * @param mergeFirstUuid uuid of the first object to merge
364 * @param mergeSecondUuid UUID of the second object to merge
366 * @throws MergeException
368 public <T
extends IMergable
> void merge(UUID mergeFirstUuid
, UUID mergeSecondUuid
, Class
<?
extends CdmBase
> clazz
) throws MergeException
;
371 * @param referencedCdmBase
374 Integer
getReferencingObjectsCount(CdmBase referencedCdmBase
);