Project

General

Profile

Download (13.1 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.api.service;
11

    
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.Set;
16
import java.util.UUID;
17

    
18
import org.hibernate.Session;
19

    
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
22
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
23
import eu.etaxonomy.cdm.model.reference.ISourceable;
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;
33

    
34

    
35

    
36
public interface ICommonService /*extends IService<OriginalSourceBase>*/{
37

    
38
//
39
//	/** find cdmBase by UUID**/
40
//	public abstract CdmBase getCdmBaseByUuid(UUID uuid);
41
//
42
//	/** save a reference and return its UUID**/
43
//	public abstract UUID saveCdmBase(CdmBase cdmBase);
44

    
45
	/**
46
	 * Saves all meta data
47
	 * @param metaData
48
	 */
49
	public void saveAllMetaData(Collection<CdmMetaData> metaData);
50

    
51
	/**
52
	 * Returns all meta data.
53
	 * @return
54
	 */
55
	public Map<CdmMetaDataPropertyName, CdmMetaData> getCdmMetaData();
56

    
57
	 /**
58
     * Returns a map of identifiable entities of class <code>clazz</code> which have an original source of
59
     * with namespace <code>idNamespace</code> and with an idInSource in <code>idInSourceSet</code> <BR>
60
     * The key of the map is the idInSource. If there are multiple objects that have the same id an arbitrary one is chosen.
61
     * @param clazz
62
     * @param idInSourceSet
63
     * @param idNamespace
64
     * @return
65
     */
66
	public <S extends ISourceable> Map<String, S> getSourcedObjectsByIdInSourceC(Class<S> clazz, Set<String> idInSourceSet, String idNamespace);
67

    
68
	/**
69
	 * Returns a list of identifiable entities according to their class, idInSource and idNamespace
70
	 * @param clazz
71
	 * @param idInSource
72
	 * @param idNamespace
73
	 * @return
74
	 */
75
	public <S extends ISourceable> S getSourcedObjectByIdInSource(Class<S> clazz, String idInSource, String idNamespace);
76

    
77

    
78
	/**
79
	 * Returns all CdmBase objects that reference the referencedCdmBase.
80
	 * For example, if referencedCdmBase is an agent it may return all taxon names
81
	 * that have this person as an author but also all books, articles, etc. that have
82
	 * this person as an author
83
	 * @param referencedCdmBase
84
	 * @return
85
	 */
86
	public Set<CdmBase> getReferencingObjects(CdmBase referencedCdmBase);
87

    
88

    
89

    
90
	/**
91
	 * Tests if cdmBase2 can be merged into cdmBase1. This is usually the case when both
92
	 * objects are of the same class.
93
	 * If they are not they must have a common super class and all links to CdmBase2 must be
94
	 * re-referenceable to cdmBase1.
95
	 * This is not the case if cdmBase2 is linked by a property which does not support class of cdmBase1.
96
	 * E.g. User.person requires a person so if user u1 exists with u1.person = person1 and we want to
97
	 * merge person1 into team1 this is not possible because team1 is not a valid replacement for person1
98
	 * within the user1.person context.
99
	 * <BR>
100
	 * This method is not expensive if classes are equal but may become more expensive if not, because
101
	 * in this concrete references to cdmBases2 need to be evaluated.
102
	 * @param cdmBase1
103
	 * @param cdmBase2
104
	 * @param mergeStrategy
105
	 * @return
106
	 * @throws MergeException
107
	 */
108
	public <T extends CdmBase> boolean isMergeable(T cdmBase1, T cdmBase2, IMergeStrategy mergeStrategy) throws MergeException;
109

    
110

    
111
	/**
112
	 * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
113
	 * to merge first. If no merge strategy is defined (null), the DefaultMergeStrategy will be taken as default.
114
	 * @param <T>
115
	 * @param mergeFirst
116
	 * @param mergeSecond
117
	 * @param mergeStrategy
118
	 * @throws MergeException
119
	 */
120
	public <T extends IMergable> void merge(T mergeFirst, T mergeSecond, IMergeStrategy mergeStrategy) throws MergeException;
121

    
122
    /**
123
     * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
124
     * to merge first, using a merge strategy defined by the given class.
125
     *
126
     * @param mergeFirst
127
     * @param mergeSecond
128
     * @param clazz
129
     * @throws MergeException
130
     */
131
    public <T extends IMergable> void merge(T mergeFirst, T mergeSecond, Class<? extends CdmBase> clazz) throws MergeException;
132

    
133

    
134
    /**
135
     * Merges mergeSecond into mergeFirst. All references to mergeSecond will be replaced by references
136
     * to merge first, using a merge strategy defined by the mergeFirst type.
137
     * @param mergeFirst
138
     * @param mergeSecond
139
     * @throws MergeException
140
     */
141
    public <T extends IMergable> void merge(T mergeFirst, T mergeSecond) throws MergeException;
142

    
143

    
144
	/**
145
	 * Returns all objects that match the object to match according to the given match strategy.
146
	 * If no match strategy is defined the default match strategy is taken.
147
	 * @param <T>
148
	 * @param objectToMatch
149
	 * @param matchStrategy
150
	 * @return
151
	 * @throws MatchException
152
	 */
153
	public <T extends IMatchable> List<T> findMatching(T objectToMatch, IMatchStrategy matchStrategy) throws MatchException;
154

    
155

    
156
	public <T extends IMatchable> List<T> findMatching(T objectToMatch, MatchStrategyConfigurator.MatchStrategy strategy) throws MatchException;
157

    
158
	public <T extends CdmBase> T findWithUpdate(Class<T> clazz, int id);
159

    
160

    
161
	/**
162
	 * A generic method to retrieve any CdmBase object by its id and class.<BR>
163
	 * @see ICdmGenericDao#find(Class, int)
164
	 * @see Session#get(Class, java.io.Serializable)
165
	 * @param clazz the CdmBase class
166
	 * @param id the cdmBase identifier
167
	 * @return the CdmBase object defined by clazz and id
168
	 * @see #find(Class, int, List)
169
	 */
170
	public <T extends CdmBase> T find(Class<T> clazz, int id);
171

    
172
    /**
173
     * @param clazz the Class of the obejct to find
174
     * @param id
175
     * @param propertyPaths the property path for bean initialization
176
     * @return
177
     * @see #find(Class, int)
178
     */
179
    public <T extends CdmBase> T find(Class<T> clazz, int id, List<String> propertyPaths);
180

    
181
    /**
182
     * A generic method to retrieve any CdmBase object by its uuid and class.<BR>
183
     * @param clazz the Class of the obejct to find
184
     * @param uuid the UUID of the object to find
185
     * @return
186
     */
187
    public <T extends CdmBase> T find(Class<T> clazz, UUID uuid);
188

    
189
    /**
190
     * A generic method to retrieve any CdmBase object by its UUID and class,
191
     * including initialization via property path.<BR>
192
     * @param clazz the Class of the obejct to find
193
     * @param uuid the UUID of the object to find
194
     * @param propertyPaths the property path for bean initialization
195
     * @return
196
     */
197
    public <T extends CdmBase> T find(Class<T> clazz, UUID uuid, List<String> propertyPaths);
198

    
199
	/**
200
	 * Returns the result of an HQL Query which does
201
	 * not inlcude parameters
202
	 * @see #getHqlResult(String, Object[])
203
	 */
204
	@SuppressWarnings("rawtypes")
205
    public List getHqlResult(String hqlQuery);
206

    
207
	/**
208
	 * Returns the result of an HQL Query which inlcudes parameters as
209
	 * ordinal parameters (e.g. a = ?0).
210
	 *
211
	 * @param hqlQuery the HQL query
212
	 * @param params the parameter values
213
	 * @return  the result of the HQL query
214
     * @see #getHqlResult(String)
215
	 */
216
	@SuppressWarnings("rawtypes")
217
    public List getHqlResult(String hqlQuery, Object[] params);
218

    
219

    
220
    /**
221
     * Initializes a collection or map.
222
     *
223
     * @param ownerUuid uuid of owner cdm entity
224
     * @param fieldName field name of collection or map
225
     * @return initialised collection or map
226
     */
227
    public Object initializeCollection(UUID ownerUuid, String fieldName);
228

    
229
    /**
230
     * @param ownerUuid
231
     * @param fieldName
232
     * @param propertyPaths
233
     * @return
234
     */
235
    public Object initializeCollection(UUID ownerUuid, String fieldName, List<String> propertyPaths);
236

    
237
	/**
238
	 * Checks if a collection or map is empty.
239
	 *
240
     * @param ownerUuid uuid of owner cdm entity
241
     * @param fieldName field name of collection or map
242
	 * @return true if the collection of map is empty, else false
243
	 */
244
	public boolean isEmpty(UUID ownerUuid, String fieldName);
245

    
246
	/**
247
	 * Returns the size of requested collection or map.
248
	 *
249
     * @param ownerUuid uuid of owner cdm entity
250
     * @param fieldName field name of collection or map
251
	 * @return the size of the persistent collection
252
	 */
253
	public int size(UUID ownerUuid, String fieldName);
254

    
255
	/**
256
	 * Returns the object contained in a collection or map at the given index.
257
	 *
258
     * @param ownerUuid uuid of owner cdm entity
259
     * @param fieldName field name of collection or map
260
	 * @param index the index of the requested element
261
	 * @return the object at the requested index
262
	 */
263
	public Object get(UUID ownerUuid, String fieldName, int index);
264

    
265
	/**
266
	 * Checks whether an object is contained within a persistent collection.
267
	 *
268
     * @param ownerUuid uuid of owner cdm entity
269
     * @param fieldName field name of collection or map
270
	 * @param element the element to check for
271
	 * @return true if the element exists in the collection, false o/w
272
	 */
273
	public boolean contains(UUID ownerUuid, String fieldName, Object element);
274

    
275
	/**
276
	 * Checks whether an index object exists within a persistent collection
277
	 * (usually a map)
278
	 *
279
     * @param ownerUuid uuid of owner cdm entity
280
     * @param fieldName field name of map
281
	 * @param key the index object to look for.
282
	 * @return true if the index object exists in the collection, false o/w
283
	 */
284
	public boolean containsKey(UUID ownerUuid, String fieldName, Object key);
285

    
286
	/**
287
	 * checks whether an value object exists within a persistent collection
288
	 * (usually a map)
289
	 *
290
     * @param ownerUuid uuid of owner cdm entity
291
     * @param fieldName field name of map
292
	 * @param key the value object to look for.
293
	 * @return true if the value object exists in the collection, false o/w
294
	 */
295
	public boolean containsValue(UUID ownerUuid, String fieldName, Object element);
296

    
297
	public Set<CdmBase> getReferencingObjectsForDeletion(CdmBase referencedCdmBase);
298

    
299
	/**
300
	 * Creates a database that more or less has all tables filled.
301
	 * Preliminary, may be moved to test later
302
	 */
303
	@Deprecated
304
	public void createFullSampleData();
305

    
306

    
307
    /**
308
     * Returns the number of objects that belong to a certain class.
309
     * @param type the CdmBase class
310
     * @return the number of objects in the database
311
     */
312
    public <S extends CdmBase> long count(Class<S> type);
313

    
314

    
315
    /**
316
     * Generic method to retrieve a list of objects. Use only if no specific service class
317
     * can be used.
318
     * @param type
319
     * @param limit
320
     * @param start
321
     * @param orderHints
322
     * @param propertyPaths
323
     * @see IService#list(Class, Integer, Integer, List, List)
324
     * @return
325
     */
326
    public <S extends CdmBase> List<S> list(Class<S> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
327

    
328
    /**
329
     * Save a new entity (persists the entity)
330
     * @param newInstance the new entity to be persisted
331
     * @return A generated UUID for the new persistent entity
332
     */
333
    public CdmBase save(CdmBase newInstance);
334

    
335
    /**
336
     * Save or update a new entity
337
     * @param entity the entity to be persisted
338
     * @return The UUID of the persistent entity
339
     */
340
    public UUID saveOrUpdate(CdmBase entity);
341

    
342
    /**
343
     * Save a collection containing new entities (persists the entities)
344
     * @param newInstances the new entities to be persisted
345
     * @return A Map containing the new entities, keyed using the generated UUID's
346
     *         of those entities
347
     */
348
    public <T extends CdmBase> Map<UUID,T> save(Collection<T> newInstances);
349

    
350
    /**
351
     * Save or update a collection containing entities
352
     * @param entities the entities to be persisted
353
     * @return A Map containing the new entities, keyed using the UUID's
354
     *         of those entities
355
     */
356
    public <T extends CdmBase> Map<UUID,T> saveOrUpdate(Collection<T> entities);
357

    
358
    /**
359
     * @param instance
360
     * @return
361
     */
362
    public UUID delete(CdmBase instance);
363

    
364
    /**
365
     * @param mergeFirstId
366
     * @param mergeSecondId
367
     * @param clazz
368
     * @throws MergeException
369
     * @Deprecated the preferred method is to use uuids {@link #merge(UUID, UUID, Class)}
370
     */
371
    @Deprecated
372
    public <T extends IMergable> void merge(int mergeFirstId, int mergeSecondId, Class<? extends CdmBase> clazz) throws MergeException;
373

    
374
    /**
375
     * @param mergeFirstUuid uuid of the first object to merge
376
     * @param mergeSecondUuid UUID of the second object to merge
377
     * @param clazz
378
     * @throws MergeException
379
     */
380
    public <T extends IMergable> void merge(UUID mergeFirstUuid, UUID mergeSecondUuid, Class<? extends CdmBase> clazz) throws MergeException;
381

    
382
    public long getReferencingObjectsCount(CdmBase referencedCdmBase);
383

    
384
    public List<UUID> listUuid(Class<? extends CdmBase> clazz);
385

    
386

    
387
}
(28-28/100)