update javadoc and override
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / common / ICdmGenericDao.java
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.Map;
14 import java.util.Set;
15 import java.util.UUID;
16
17 import org.hibernate.Query;
18 import org.hibernate.Session;
19 import org.springframework.dao.DataAccessException;
20
21 import eu.etaxonomy.cdm.model.common.CdmBase;
22 import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
23 import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
24 import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
25 import eu.etaxonomy.cdm.strategy.match.IMatchable;
26 import eu.etaxonomy.cdm.strategy.match.MatchException;
27 import eu.etaxonomy.cdm.strategy.merge.IMergeStrategy;
28 import eu.etaxonomy.cdm.strategy.merge.MergeException;
29
30 public interface ICdmGenericDao {
31
32 public UUID saveOrUpdate(CdmBase transientObject) throws DataAccessException;
33
34 public UUID save(CdmBase newOrManagedObject) throws DataAccessException;
35
36 public UUID update(CdmBase transientObject) throws DataAccessException;
37
38 public UUID delete(CdmBase persistentObject) throws DataAccessException;
39
40 public void saveMetaData(CdmMetaData cdmMetaData);
41
42 public List<CdmMetaData> getMetaData();
43
44 /**
45 * Returns a CdmBase object of class <code>clazz</code> that has a property with name
46 * <code>propertyName</code> that references the CdmBase object <code>referencedCdmBase</code>.
47 * @param clazz
48 * @param propertyName
49 * @param value
50 * @return
51 */
52 public List<CdmBase> getCdmBasesByFieldAndClass(Class clazz, String propertyName, CdmBase referencedCdmBase);
53
54 /**
55 * Returns ...
56 * @param thisClass
57 * @param otherClazz
58 * @param propertyName
59 * @param referencedCdmBase
60 * @return
61 */
62 public List<CdmBase> getCdmBasesWithItemInCollection(Class itemClass, Class clazz, String propertyName, CdmBase item);
63
64 /**
65 * Returns all CDM classes. If includeAbstractClasses is false the abstract classes
66 * will not be in the resultset.
67 * @param includeAbstractClasses
68 * @return
69 */
70 public Set<Class<? extends CdmBase>> getAllCdmClasses(boolean includeAbstractClasses);
71
72 /**
73 * Returns all CdmBase objects that reference the referencedCdmBase.
74 * For example, if referencedCdmBase is an agent it may return all taxon names
75 * that have this person as an author but also all books, articles, etc. that have
76 * this person as an author
77 * @param referencedCdmBase
78 * @return
79 */
80 public Set<CdmBase> getReferencingObjects(CdmBase referencedCdmBase);
81
82 /**
83 * Merges cdmBase2 into cdmBase2 and rearranges all reference to cdmBase2 by letting them point to
84 * cdmBase1. If the merge strategy is not defined (<code>null</code>) the default merge strategy is taken instead.
85 * @param <T>
86 * @param cdmBase1
87 * @param cdmBase2
88 * @param mergeStrategy
89 * @throws IllegalArgumentException
90 * @throws NullPointerException
91 * @throws MergeException
92 */
93 public <T extends CdmBase> void merge(T cdmBase1, T cdmBase2, IMergeStrategy mergeStrategy) throws MergeException;
94
95 /**
96 * Returns a List of matching persistent objects according to the match strategy
97 * @param <T>
98 * @param objectToMatch
99 * @param matchStrategy
100 * @return
101 * @throws MatchException
102 */
103 public <T extends IMatchable> List<T> findMatching(T objectToMatch, IMatchStrategy matchStrategy) throws MatchException;
104
105
106 /**
107 * A generic method to retrieve any CdmBase object by its id and class.<BR>
108 * Return the persistent instance of the given entity class with the given identifier,
109 * or null if there is no such persistent instance. (If the instance is already
110 * associated with the session, return that instance. This method never returns
111 * an uninitialized instance.)
112 * TODO: the behaviour for abstract high level classes (such as CdmBase itself)
113 * is not yet tested.
114 * @see Session#get(Class, java.io.Serializable)
115 * @param clazz the CdmBase class
116 * @param id the identifier
117 * @return the CdmBase instance
118 */
119 public <T extends CdmBase> T find(Class<T> clazz, int id);
120
121 /**
122 * Returns the result of an hql query
123 * TODO implement parameters
124 * @deprecated this is not clean implemantation as it is hibernate related.
125 * @param hqlQuery
126 * @return
127 */
128 @Deprecated
129 public List getHqlResult(String hqlQuery);
130
131 /**
132 * TODO remove as this is Hibernate specific.
133 * Returns a Query
134 * @deprecated this is not clean implemantation as it is hibernate related.
135 * Will be replaced in future
136 * @param hqlQuery
137 * @return
138 */
139 @Deprecated
140 public Query getHqlQuery(String hqlQuery);
141 }