Project

General

Profile

Download (11 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.persistence.dao.common;
11

    
12
import java.util.List;
13
import java.util.Set;
14
import java.util.UUID;
15

    
16
import org.hibernate.Query;
17
import org.hibernate.Session;
18
import org.springframework.dao.DataAccessException;
19

    
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
22
import eu.etaxonomy.cdm.persistence.query.OrderHint;
23
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
24
import eu.etaxonomy.cdm.strategy.match.IMatchable;
25
import eu.etaxonomy.cdm.strategy.match.MatchException;
26
import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
27
import eu.etaxonomy.cdm.strategy.merge.MergeException;
28

    
29
public interface ICdmGenericDao {
30

    
31
	public UUID saveOrUpdate(CdmBase transientObject) throws DataAccessException;
32

    
33
	public CdmBase save(CdmBase newOrManagedObject) throws DataAccessException;
34

    
35
	public UUID update(CdmBase transientObject) throws DataAccessException;
36

    
37
	public UUID delete(CdmBase persistentObject) throws DataAccessException;
38

    
39
	public void saveMetaData(CdmMetaData cdmMetaData);
40

    
41
	public List<CdmMetaData> getMetaData();
42

    
43
	/**
44
	 * Returns a CdmBase object of class <code>clazz</code> that has a property with name
45
	 * <code>propertyName</code> that references the CdmBase object <code>referencedCdmBase</code>.
46
	 * @param clazz
47
	 * @param propertyName
48
	 * @param value
49
	 * @return
50
	 */
51
	public List<CdmBase> getCdmBasesByFieldAndClass(Class clazz, String propertyName, CdmBase referencedCdmBase);
52

    
53
	/**
54
	 * Returns ...
55
	 * @param thisClass
56
	 * @param otherClazz
57
	 * @param propertyName
58
	 * @param referencedCdmBase
59
	 * @return
60
	 */
61
	public List<CdmBase> getCdmBasesWithItemInCollection(Class itemClass, Class clazz, String propertyName, CdmBase item);
62

    
63
	/**
64
	 * Returns all classes that are persisted via the persisting framework.
65
	 * E.g. in hibernate these are all classes registered in the session factory
66
	 * (via e.g. hibernate.cfg.xml)
67
	 * <BR>
68
	 * @param includeAbstractClasses if <code>false</code> the abstract classes
69
	 * will not be in the result set.
70
	 * @return
71
	 */
72
	public Set<Class<? extends CdmBase>> getAllPersistedClasses(boolean includeAbstractClasses);
73

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

    
84
	/**
85
	 * Merges cdmBase2 into cdmBase2 and rearranges all reference to cdmBase2 by letting them point to
86
	 * cdmBase1. If the merge strategy is not defined (<code>null</code>)  the default merge strategy is taken instead.
87
	 * @param cdmBase1
88
	 * @param cdmBase2
89
	 * @param mergeStrategy
90
	 * @throws IllegalArgumentException
91
	 * @throws NullPointerException
92
	 * @throws MergeException
93
	 */
94
	public <T extends CdmBase> void   merge(T cdmBase1, T cdmBase2, IMergeStrategy mergeStrategy) throws MergeException;
95

    
96
	/**
97
	 * Computes if cdmBase2 can be merged into cdmBase1. This is usually the case when both
98
	 * objects are of the same class.
99
	 * If they are not they must have a common super class and all links to CdmBase2 must be
100
	 * re-referenceable to cdmBase1.
101
	 * This is not the case if cdmBase2 is linked by a property which does not support class of cdmBase1.
102
	 * E.g. User.person requires a person so if user u1 exists with u1.person = person1 and we want to
103
	 * merge person1 into team1 this is not possible because team1 is not a valid replacement for person1
104
	 * within the user1.person context.
105
	 * @param cdmBase1
106
	 * @param cdmBase2
107
	 * @param mergeStrategy
108
	 * @return true if objects are mergeable
109
	 * @throws IllegalArgumentException
110
	 * @throws NullPointerException
111
	 * @throws MergeException
112
	 */
113
	public <T extends CdmBase> boolean  isMergeable(T cdmBase1, T cdmBase2, IMergeStrategy mergeStrategy) throws MergeException;
114

    
115

    
116
	/**
117
	 * Returns a List of matching persistent objects according to the match strategy
118
	 * @param <T>
119
	 * @param objectToMatch
120
	 * @param matchStrategy
121
	 * @return
122
	 * @throws MatchException
123
	 */
124
	public <T extends IMatchable> List<T> findMatching(T objectToMatch, IMatchStrategy matchStrategy) throws MatchException;
125

    
126

    
127
	/**
128
	 * A generic method to retrieve any CdmBase object by its id and class.<BR>
129
	 * Return the persistent instance of the given entity class with the given identifier,
130
	 * or null if there is no such persistent instance. (If the instance is already
131
	 * associated with the session, return that instance. This method never returns
132
	 * an uninitialized instance.)<BR>
133
	 * TODO: the behaviour for abstract high level classes (such as CdmBase itself)
134
	 * is not yet tested.
135
	 * @see Session#get(Class, java.io.Serializable)
136
	 * @param clazz the CdmBase class
137
	 * @param id the identifier
138
	 * @return the CdmBase instance
139
	 * @see #find(Class, UUID)
140
     * @see #find(Class, int, List)
141
	 */
142
	public <T extends CdmBase> T find(Class<T> clazz, int id);
143

    
144
	/**
145
     * A generic method to retrieve any CdmBase object by its id and class.<BR>
146
     * Return the persistent instance of the given entity class with the given identifier,
147
     * or null if there is no such persistent instance. (If the instance is already
148
     * associated with the session, return that instance. This method never returns
149
     * an uninitialized instance.)
150
     * @see Session#get(Class, java.io.Serializable)
151
     * @param clazz the CdmBase class
152
     * @param uuid the identifier
153
     * @return the CdmBase instance
154
     * @see #find(Class, int)
155
     * @see #find(Class, UUID, List)
156
     */
157
    public <T extends CdmBase> T find(Class<T> clazz, UUID uuid);
158

    
159
	/**
160
     * Does the same as {@link #find(Class, int)} but also initializes the returned
161
     * object according to the property path.
162
     *
163
     * @param clazz class of the object to be loaded and initialized
164
     * @param id the identifier
165
     * @param propertyPaths the property path for initialization
166
     * @return The initialized object
167
     * @see #find(Class, UUID)
168
     */
169
    public <T extends CdmBase> T find(Class<T> clazz, int id, List<String> propertyPaths);
170

    
171
    /**
172
     * Does the same as {@link #find(Class, UUID)} but also initializes the returned
173
     * object according to the property path.
174
     * @param clazz
175
     * @param uuid
176
     * @param propertyPaths
177
     * @return
178
     * @see #find(Class, UUID)
179
     */
180
    public <T extends CdmBase> T find(Class<T> clazz, UUID uuid, List<String> propertyPaths);
181

    
182
	/**
183
	 * Returns the result of an hql query
184
	 * TODO implement parameters
185
	 * @deprecated this is not clean implementation as it is hibernate related.
186
	 * @param hqlQuery
187
	 * @return
188
	 */
189
	@Deprecated
190
	public List getHqlResult(String hqlQuery) throws UnsupportedOperationException;
191

    
192
	/**
193
	 * TODO remove as this is Hibernate specific.
194
	 * Returns a Query
195
	 * @deprecated this is not clean implemantation as it is hibernate related.
196
	 * Will be replaced in future
197
	 * @param hqlQuery
198
	 * @return
199
	 */
200
	@Deprecated
201
	public Query getHqlQuery(String hqlQuery) throws UnsupportedOperationException;
202

    
203

    
204
	public Set<CdmBase> getReferencingObjectsForDeletion(CdmBase referencedCdmBase);
205

    
206
	public void createFullSampleData();
207

    
208

    
209
    /**
210
     * Returns the number of objects belonging to a certain class being stored
211
     * in the database
212
     * @param type
213
     * @return
214
     */
215
    public int count(Class<? extends CdmBase> type);
216

    
217

    
218
	   /**
219
     * Returns a sublist of CdmBase instances stored in the database. A maximum
220
     * of 'limit' objects are returned, starting at object with index 'start'.
221
     *
222
     * @param type
223
     * @param limit
224
     *            the maximum number of entities returned (can be null to return
225
     *            all entities)
226
     * @param start
227
     * @param orderHints
228
     *            Supports path like <code>orderHints.propertyNames</code> which
229
     *            include *-to-one properties like createdBy.username or
230
     *            authorTeam.persistentTitleCache
231
     * @return
232
     * @throws DataAccessException
233
     */
234
    public <S extends CdmBase> List<S> list(Class<S> type, Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths);
235

    
236

    
237
    /**
238
     * @param ownerUuid
239
     * @param fieldName
240
     * @param appendedPropertyPaths
241
     * @return
242
     */
243
    public Object initializeCollection(UUID ownerUuid, String fieldName, List<String> appendedPropertyPaths);
244

    
245
    /**
246
     * Initializes a collection or map.
247
     *
248
     * @param ownerUuid uuid of owner cdm entity
249
     * @param fieldName field name of collection or map
250
     * @return initialised collection or map
251
     */
252
    public Object initializeCollection(UUID ownerUuid, String fieldName);
253

    
254
    /**
255
     * Checks if a collection or map is empty.
256
     *
257
     * @param ownerUuid uuid of owner cdm entity
258
     * @param fieldName field name of collection or map
259
     * @return true if the collection of map is empty, else false
260
     */
261
    public boolean isEmpty(UUID ownerUuid, String fieldName);
262

    
263
    /**
264
     * Returns the size of requested collection or map.
265
     *
266
     * @param ownerUuid uuid of owner cdm entity
267
     * @param fieldName field name of collection or map
268
     * @return the size of the persistent collection
269
     */
270
    public int size(UUID ownerUuid, String fieldName);
271

    
272
    /**
273
     * Returns the object contained in a collection or map at the given index.
274
     *
275
     * @param ownerUuid uuid of owner cdm entity
276
     * @param fieldName field name of collection or map
277
     * @param index the index of the requested element
278
     * @return the object at the requested index
279
     */
280
    public Object get(UUID ownerUuid, String fieldName, int index);
281

    
282
    /**
283
     * Checks whether an object is contained within a persistent collection.
284
     *
285
     * @param ownerUuid uuid of owner cdm entity
286
     * @param fieldName field name of collection or map
287
     * @param element the element to check for
288
     * @return true if the element exists in the collection, false o/w
289
     */
290
    public boolean contains(UUID ownerUuid, String fieldName, Object element);
291

    
292
    /**
293
     * Checks whether an index object exists within a persistent collection
294
     * (usually a map)
295
     *
296
     * @param ownerUuid uuid of owner cdm entity
297
     * @param fieldName field name of map
298
     * @param key the index object to look for.
299
     * @return true if the index object exists in the collection, false o/w
300
     */
301
    public boolean containsKey(UUID ownerUuid, String fieldName, Object key);
302

    
303
    /**
304
     * checks whether an value object exists within a persistent collection
305
     * (usually a map)
306
     *
307
     * @param ownerUuid uuid of owner cdm entity
308
     * @param fieldName field name of map
309
     * @param key the value object to look for.
310
     * @return true if the value object exists in the collection, false o/w
311
     */
312
    public boolean containsValue(UUID ownerUuid, String fieldName, Object element);
313

    
314

    
315

    
316

    
317

    
318
}
(5-5/25)