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
.persistence
.dao
.common
;
12 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.hibernate
.Query
;
17 import org
.hibernate
.Session
;
18 import org
.springframework
.dao
.DataAccessException
;
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
;
29 public interface ICdmGenericDao
{
31 public UUID
saveOrUpdate(CdmBase transientObject
) throws DataAccessException
;
33 public CdmBase
save(CdmBase newOrManagedObject
) throws DataAccessException
;
35 public UUID
update(CdmBase transientObject
) throws DataAccessException
;
37 public UUID
delete(CdmBase persistentObject
) throws DataAccessException
;
39 public void saveMetaData(CdmMetaData cdmMetaData
);
41 public List
<CdmMetaData
> getMetaData();
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>.
51 public List
<CdmBase
> getCdmBasesByFieldAndClass(Class clazz
, String propertyName
, CdmBase referencedCdmBase
, Integer limit
);
58 * @param referencedCdmBase
61 public List
<CdmBase
> getCdmBasesWithItemInCollection(Class itemClass
, Class clazz
, String propertyName
, CdmBase item
, Integer limit
);
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)
68 * @param includeAbstractClasses if <code>false</code> the abstract classes
69 * will not be in the result set.
72 public Set
<Class
<?
extends CdmBase
>> getAllPersistedClasses(boolean includeAbstractClasses
);
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
82 public Set
<CdmBase
> getReferencingObjects(CdmBase referencedCdmBase
);
85 * Merges cdmBase2 into cdmBase1 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.
90 * @param mergeStrategy
91 * @throws IllegalArgumentException
92 * @throws NullPointerException
93 * @throws MergeException
95 public <T
extends CdmBase
> void merge(T cdmBase1
, T cdmBase2
, IMergeStrategy mergeStrategy
) throws MergeException
;
98 * Computes if cdmBase2 can be merged into cdmBase1. This is usually the case when both
99 * objects are of the same class.
100 * If they are not they must have a common super class and all links to CdmBase2 must be
101 * re-referenceable to cdmBase1.
102 * This is not the case if cdmBase2 is linked by a property which does not support class of cdmBase1.
103 * E.g. User.person requires a person so if user u1 exists with u1.person = person1 and we want to
104 * merge person1 into team1 this is not possible because team1 is not a valid replacement for person1
105 * within the user1.person context.
108 * @param mergeStrategy
109 * @return true if objects are mergeable
110 * @throws IllegalArgumentException
111 * @throws NullPointerException
112 * @throws MergeException
114 public <T
extends CdmBase
> boolean isMergeable(T cdmBase1
, T cdmBase2
, IMergeStrategy mergeStrategy
) throws MergeException
;
118 * Returns a List of matching persistent objects according to the match strategy
120 * @param objectToMatch
121 * @param matchStrategy
123 * @throws MatchException
125 public <T
extends IMatchable
> List
<T
> findMatching(T objectToMatch
, IMatchStrategy matchStrategy
) throws MatchException
;
129 * A generic method to retrieve any CdmBase object by its id and class.<BR>
130 * Return the persistent instance of the given entity class with the given identifier,
131 * or null if there is no such persistent instance. (If the instance is already
132 * associated with the session, return that instance. This method never returns
133 * an uninitialized instance.)<BR>
134 * TODO: the behaviour for abstract high level classes (such as CdmBase itself)
136 * @see Session#get(Class, java.io.Serializable)
137 * @param clazz the CdmBase class
138 * @param id the identifier
139 * @return the CdmBase instance
140 * @see #find(Class, UUID)
141 * @see #find(Class, int, List)
143 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, int id
);
146 * A generic method to retrieve any CdmBase object by its id and class.<BR>
147 * Return the persistent instance of the given entity class with the given identifier,
148 * or <code>null</code> if there is no such persistent instance. (If the instance is already
149 * associated with the session, return that instance. This method never returns
150 * an uninitialized instance.)
151 * @see Session#get(Class, java.io.Serializable)
152 * @param clazz the CdmBase class
153 * @param uuid the identifier
154 * @return the CdmBase instance
155 * @see #find(Class, int)
156 * @see #find(Class, UUID, List)
158 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, UUID uuid
);
161 * Does the same as {@link #find(Class, int)} but also initializes the returned
162 * object according to the property path.
164 * @param clazz class of the object to be loaded and initialized
165 * @param id the identifier
166 * @param propertyPaths the property path for initialization
167 * @return The initialized object
168 * @see #find(Class, UUID)
170 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, int id
, List
<String
> propertyPaths
);
173 * Does the same as {@link #find(Class, UUID)} but also initializes the returned
174 * object according to the property path.
177 * @param propertyPaths
179 * @see #find(Class, UUID)
181 public <T
extends CdmBase
> T
find(Class
<T
> clazz
, UUID uuid
, List
<String
> propertyPaths
);
184 * Returns the result of an hql query
185 * TODO implement parameters
186 * @deprecated this is not clean implementation as it is hibernate related.
191 public List
getHqlResult(String hqlQuery
) throws UnsupportedOperationException
;
194 * TODO remove as this is Hibernate specific.
196 * @deprecated this is not clean implemantation as it is hibernate related.
197 * Will be replaced in future
202 public Query
getHqlQuery(String hqlQuery
) throws UnsupportedOperationException
;
205 public Set
<CdmBase
> getReferencingObjectsForDeletion(CdmBase referencedCdmBase
);
207 public void createFullSampleData();
211 * Returns the number of objects belonging to a certain class being stored
216 public long count(Class
<?
extends CdmBase
> type
);
220 * Returns a sublist of CdmBase instances stored in the database. A maximum
221 * of 'limit' objects are returned, starting at object with index 'start'.
225 * the maximum number of entities returned (can be null to return
229 * Supports path like <code>orderHints.propertyNames</code> which
230 * include *-to-one properties like createdBy.username or
231 * authorTeam.persistentTitleCache
233 * @throws DataAccessException
235 public <S
extends CdmBase
> List
<S
> list(Class
<S
> type
, Integer limit
, Integer start
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
);
241 * @param appendedPropertyPaths
244 public Object
initializeCollection(UUID ownerUuid
, String fieldName
, List
<String
> appendedPropertyPaths
);
247 * Initializes a collection or map.
249 * @param ownerUuid uuid of owner cdm entity
250 * @param fieldName field name of collection or map
251 * @return initialised collection or map
253 public Object
initializeCollection(UUID ownerUuid
, String fieldName
);
256 * Checks if a collection or map is empty.
258 * @param ownerUuid uuid of owner cdm entity
259 * @param fieldName field name of collection or map
260 * @return true if the collection of map is empty, else false
262 public boolean isEmpty(UUID ownerUuid
, String fieldName
);
265 * Returns the size of requested collection or map.
267 * @param ownerUuid uuid of owner cdm entity
268 * @param fieldName field name of collection or map
269 * @return the size of the persistent collection
271 public int size(UUID ownerUuid
, String fieldName
);
274 * Returns the object contained in a collection or map at the given index.
276 * @param ownerUuid uuid of owner cdm entity
277 * @param fieldName field name of collection or map
278 * @param index the index of the requested element
279 * @return the object at the requested index
281 public Object
get(UUID ownerUuid
, String fieldName
, int index
);
284 * Checks whether an object is contained within a persistent collection.
286 * @param ownerUuid uuid of owner cdm entity
287 * @param fieldName field name of collection or map
288 * @param element the element to check for
289 * @return true if the element exists in the collection, false o/w
291 public boolean contains(UUID ownerUuid
, String fieldName
, Object element
);
294 * Checks whether an index object exists within a persistent collection
297 * @param ownerUuid uuid of owner cdm entity
298 * @param fieldName field name of map
299 * @param key the index object to look for.
300 * @return true if the index object exists in the collection, false o/w
302 public boolean containsKey(UUID ownerUuid
, String fieldName
, Object key
);
305 * checks whether an value object exists within a persistent collection
308 * @param ownerUuid uuid of owner cdm entity
309 * @param fieldName field name of map
310 * @param key the value object to look for.
311 * @return true if the value object exists in the collection, false o/w
313 public boolean containsValue(UUID ownerUuid
, String fieldName
, Object element
);
318 * @param propertyName
322 public long getCountWithItemInCollection(Class itemClass
, Class clazz
, String propertyName
, CdmBase item
);
326 * @param propertyName
327 * @param referencedCdmBase
330 public long getCountByFieldAndClass(Class clazz
, String propertyName
, CdmBase referencedCdmBase
);
333 * @param referencedCdmBase
336 public Long
getReferencingObjectsCount(CdmBase referencedCdmBase
);