the query of prepareQuery always returns the type, if doNotReturnFullEntities is set
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / taxon / ITaxonDao.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.taxon;
11
12 import java.util.List;
13 import java.util.Set;
14 import java.util.UUID;
15
16 import org.hibernate.criterion.Criterion;
17
18 import eu.etaxonomy.cdm.model.common.RelationshipBase;
19 import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
20 import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
21 import eu.etaxonomy.cdm.model.location.NamedArea;
22 import eu.etaxonomy.cdm.model.name.NonViralName;
23 import eu.etaxonomy.cdm.model.name.Rank;
24 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
25 import eu.etaxonomy.cdm.model.reference.Reference;
26 import eu.etaxonomy.cdm.model.taxon.Synonym;
27 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
28 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
29 import eu.etaxonomy.cdm.model.taxon.Taxon;
30 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
32 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
33 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
34 import eu.etaxonomy.cdm.model.taxon.Classification;
35 import eu.etaxonomy.cdm.persistence.dao.BeanInitializer;
36 import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
37 import eu.etaxonomy.cdm.persistence.dao.common.ITitledDao;
38 import eu.etaxonomy.cdm.persistence.fetch.CdmFetch;
39 import eu.etaxonomy.cdm.persistence.query.MatchMode;
40 import eu.etaxonomy.cdm.persistence.query.OrderHint;
41 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
42
43 /**
44 * @author a.mueller
45 *
46 */
47 public interface ITaxonDao extends IIdentifiableDao<TaxonBase>, ITitledDao<TaxonBase> {
48
49 /**
50 * Returns a list of TaxonBase instances where the taxon.titleCache property matches the name parameter,
51 * and taxon.sec matches the sec parameter.
52 * @param name
53 * @param sec
54 * @return
55 */
56 public List<TaxonBase> getTaxaByName(String name, Reference sec);
57
58 /**
59 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
60 * where the taxonBase.name.nameCache property matches the String queryString, and taxon.sec matches the sec parameter.
61 * @param name
62 * @param sec
63 * @return
64 */
65 public List<TaxonBase> getTaxaByName(String queryString, Boolean accepted, Reference sec);
66
67 /**
68 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
69 * where the taxonBase.name.nameCache property matches the String queryString.
70 * @param queryString
71 * @param matchMode
72 * @param accepted
73 * @param pageSize
74 * @param pageNumber
75 * @return
76 */
77 public List<TaxonBase> getTaxaByName(String queryString, MatchMode matchMode,
78 Boolean accepted, Integer pageSize, Integer pageNumber);
79
80
81 /**
82 * Returns a list of TaxonBase instances (or Taxon instances, if accepted == true, or Synonym instance, if accepted == false)
83 * where the taxonBase.name.nameCache property matches the String queryString.
84 * @param clazz
85 * @param queryString
86 * @param classification TODO
87 * @param matchMode
88 * @param namedAreas TODO
89 * @param pageSize
90 * @param pageNumber
91 * @param propertyPaths TODO
92 * @return list of found taxa
93 */
94 public List<TaxonBase> getTaxaByName(Class<? extends TaxonBase> clazz, String queryString, Classification classification,
95 MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize, Integer pageNumber, List<String> propertyPaths);
96
97 /**
98 * @param clazz
99 * @param queryString
100 * @param classification TODO
101 * @param matchMode
102 * @param namedAreas
103 * @param pageSize
104 * @param pageNumber
105 * @param propertyPaths
106 * @return
107 */
108 public long countTaxaByName(Class<? extends TaxonBase> clazz, String queryString, Classification classification,
109
110 MatchMode matchMode, Set<NamedArea> namedAreas);
111
112 // /**
113 // * @param queryString
114 // * @param matchMode
115 // * @param accepted
116 // * @return
117 // */
118 // public Integer countTaxaByName(String queryString, MatchMode matchMode,
119 // Boolean accepted);
120
121 // /**
122 // * Returns a count of TaxonBase instances where the
123 // * taxon.name properties match the parameters passed.
124 // *
125 // * @param queryString search string
126 // * @param matchMode way how search string shall be matched: exact, beginning, or anywhere
127 // * @param selectModel all taxon base, taxa, or synonyms
128 // */
129 // public Integer countTaxaByName(String queryString, MatchMode matchMode, SelectMode selectMode);
130
131 /**
132 * Returns a count of TaxonBase instances where the
133 * taxon.name properties match the parameters passed.
134 *
135 * @param clazz
136 * @param uninomial
137 * @param infragenericEpithet
138 * @param specificEpithet
139 * @param infraspecificEpithet
140 * @param rank
141 * @return a count of TaxonBase instances
142 */
143 public int countTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet,String specificEpithet, String infraspecificEpithet, Rank rank);
144
145 /**
146 * Returns a list of TaxonBase instances where the
147 * taxon.name properties match the parameters passed. In order to search for any string value, pass '*', passing the string value of
148 * <i>null</i> will search for those taxa with a value of null in that field
149 * <p>
150 * Compare with
151 * {@link #findByName(String, MatchMode, int, int, boolean)}
152 * which searches for {@link TaxonNameBase}<strong><code>.titleCache</code>
153 * </strong>
154 *
155 * @param clazz optionally filter by class (can be null to return all taxa)
156 * @param uninomial
157 * @param infragenericEpithet
158 * @param specificEpithet
159 * @param infraspecificEpithet
160 * @param rank
161 * @param pageSize The maximum number of taxa returned (can be null for all matching taxa)
162 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
163 * @return a list of TaxonBase instances
164 */
165 public List<TaxonBase> findTaxaByName(Class<? extends TaxonBase> clazz, String uninomial, String infragenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber);
166
167 /**
168 * Find taxa by searching for Taxa and Synonyms where the
169 * {@link TaxonNameBase}<strong><code>.titleCache</code></strong> matches
170 * the name specified as queryString <code>taxonName</code>
171 * <P>
172 * Compare with
173 * {@link #findTaxaByName(Class, String, String, String, String, Rank, Integer, Integer)}
174 * which searches for {@link TaxonNameBase}<strong><code>.nameCache</code>
175 * </strong>
176 * @param queryString
177 * the taqxon Name to search for
178 * @param classification TODO
179 * @param matchMode
180 * @param namedAreas TODO
181 * @param pageNumber
182 * @param pageSize
183 * @param onlyAcccepted
184 * @return
185 */
186 public List<TaxonBase> findByNameTitleCache(Class<? extends TaxonBase>clazz, String queryString, Classification classification, MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageNumber, Integer pageSize, List<String> propertyPaths) ;
187
188 public List<TaxonBase> getTaxaByCommonName(String queryString, Classification classification,
189 MatchMode matchMode, Set<NamedArea> namedAreas, Integer pageSize,
190 Integer pageNumber, List<String> propertyPaths);
191
192 /**
193 * Computes all Taxon instances that do not have a taxonomic parent and has at least one child.
194 * @return The List<Taxon> of root taxa.
195 * @deprecated obsolete when using classification
196 */
197 public List<Taxon> getRootTaxa(Reference sec);
198
199
200 /**
201 * Computes all Taxon instances that do not have a taxonomic parent.
202 * @param sec The concept reference that the taxon belongs to
203 * @param cdmFetch not used yet !! TODO
204 * @param onlyWithChildren if true only taxa are returned that have taxonomic children. <Br>Default: true.
205 * @param withMisaplications if false only taxa are returned that have no isMisappliedNameFor relationship.
206 * <Br>Default: true.
207 * @return The List<Taxon> of root taxa.
208 * @deprecated obsolete when using classification
209 */
210 public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications);
211
212
213 /**
214 * Computes all Taxon instances which name is of a certain Rank.
215 *
216 * @param rank
217 * The rank of the taxon name
218 * @param sec
219 * The concept reference that the taxon belongs to
220 * @param cdmFetch
221 * not used yet !! TODO
222 * @param onlyWithChildren
223 * if true only taxa are returned that have taxonomic children. <Br>
224 * Default: true.
225 * @param withMisaplications
226 * if false only taxa are returned that have no
227 * isMisappliedNameFor relationship.
228 * @param propertyPaths
229 * properties to be initialized, For detailed description and
230 * examples <b>please refer to:</b>
231 * {@link BeanInitializer#initialize(Object, List)}. <Br>
232 * Default: true.
233 * @return The List<Taxon> of root taxa.
234 * @deprecated obsolete when using classification
235 */
236 public List<Taxon>
237 getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths);
238
239 /**
240 * TODO necessary?
241 * @param pagesize max maximum number of returned taxa
242 * @param page page to start, with 0 being first page
243 * @return
244 */
245 public List<TaxonBase> getAllTaxonBases(Integer pagesize, Integer page);
246
247
248 /**
249 * @param limit
250 * @param start
251 * @return
252 */
253 public List<Taxon> getAllTaxa(Integer limit, Integer start);
254
255 /**
256 * @param limit
257 * @param start
258 * @return
259 */
260 public List<Synonym> getAllSynonyms(Integer limit, Integer start);
261
262 public List<RelationshipBase> getAllRelationships(Integer limit, Integer start);
263
264 public int countAllRelationships();
265
266 /**
267 * @param queryString
268 * @param matchMode
269 * @param onlyAcccepted
270 * @return
271 */
272 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted);
273
274 /**
275 * @param queryString
276 * @param matchMode
277 * @param onlyAcccepted
278 * @param criteria
279 * @return
280 */
281 public int countMatchesByName(String queryString, MatchMode matchMode, boolean onlyAcccepted, List<Criterion> criteria);
282
283 /**
284 * Returns a count of the TaxonRelationships (of where relationship.type ==
285 * type, if this argument is supplied) where the supplied taxon either is
286 * relatedFrom or relatedTo depending on the <code>direction</code>
287 * parameter.
288 *
289 * @param taxon
290 * The taxon that is relatedFrom
291 * @param type
292 * The type of TaxonRelationship (can be null)
293 * @param direction
294 * specifies the direction of the relationship
295 * @return the number of TaxonRelationship instances
296 */
297 public int countTaxonRelationships(Taxon taxon, TaxonRelationshipType type,
298 Direction direction);
299
300 /**
301 * Returns the TaxonRelationships (of where relationship.type == type, if
302 * this argument is supplied) where the supplied taxon either is
303 * relatedFrom or relatedTo depending on the <code>direction</code>
304 * parameter.
305 *
306 * @param taxon
307 * The taxon that is relatedTo
308 * @param type
309 * The type of TaxonRelationship (can be null)
310 * @param pageSize
311 * The maximum number of relationships returned (can be null for
312 * all relationships)
313 * @param pageNumber
314 * The offset (in pageSize chunks) from the start of the result
315 * set (0 - based)
316 * @param orderHints
317 * Properties to order by
318 * @param propertyPaths
319 * Properties to initialize in the returned entities, following
320 * the syntax described in
321 * {@link BeanInitializer#initialize(Object, List)}
322 * @param direction
323 * specifies the direction of the relationship
324 * @return a List of TaxonRelationship instances
325 */
326 public List<TaxonRelationship> getTaxonRelationships(Taxon taxon,
327 TaxonRelationshipType type, Integer pageSize, Integer pageNumber,
328 List<OrderHint> orderHints, List<String> propertyPaths,
329 Direction direction);
330
331 /**
332 * Returns a count of the SynonymRelationships (of where relationship.type == type,
333 * if this arguement is supplied) where the supplied taxon is relatedTo.
334 *
335 * @param taxon The taxon that is relatedTo
336 * @param type The type of SynonymRelationship (can be null)
337 * @return the number of SynonymRelationship instances
338 */
339 public int countSynonyms(Taxon taxon, SynonymRelationshipType type);
340
341 /**
342 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
343 * where the supplied taxon is relatedTo.
344 *
345 * @param taxon The taxon that is relatedTo
346 * @param type The type of SynonymRelationship (can be null)
347 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
348 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
349 * * @param orderHints Properties to order by
350 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
351 * @return a List of SynonymRelationship instances
352 */
353 public List<SynonymRelationship> getSynonyms(Taxon taxon, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
354
355 /**
356 * Returns a count of the SynonymRelationships (of where relationship.type == type,
357 * if this arguement is supplied) where the supplied synonym is relatedFrom.
358 *
359 * @param taxon The synonym that is relatedFrom
360 * @param type The type of SynonymRelationship (can be null)
361 * @return the number of SynonymRelationship instances
362 */
363 public int countSynonyms(Synonym synonym, SynonymRelationshipType type);
364
365 /**
366 * Returns the SynonymRelationships (of where relationship.type == type, if this arguement is supplied)
367 * where the supplied synonym is relatedFrom.
368 *
369 * @param taxon The synonym that is relatedFrom
370 * @param type The type of SynonymRelationship (can be null)
371 * @param pageSize The maximum number of relationships returned (can be null for all relationships)
372 * @param pageNumber The offset (in pageSize chunks) from the start of the result set (0 - based)
373 * * @param orderHints Properties to order by
374 * @param propertyPaths Properties to initialize in the returned entities, following the syntax described in {@link BeanInitializer#initialize(Object, List)}
375 * @return a List of SynonymRelationship instances
376 */
377 public List<SynonymRelationship> getSynonyms(Synonym synoynm, SynonymRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths);
378
379 /**
380 *
381 * @return
382 */
383 public List<UuidAndTitleCache<TaxonNode>> getTaxonNodeUuidAndTitleCacheOfAcceptedTaxaByClassification(Classification classification);
384
385 /**
386 * Creates all inferred synonyms for the species in the tree and insert it to the database
387 * @param tree
388 * @return List of inferred synonyms
389 */
390 //public List<Synonym> insertAllInferredSynonymy(Classification tree);
391
392 /**
393 * Creates all inferred synonyms for the taxon in the classification, but do not insert it to the database
394 * @param taxon
395 * @param tree
396 * @return list of inferred synonyms
397 */
398 public List<Synonym> createAllInferredSynonyms(Taxon taxon, Classification tree);
399 /**
400 * Creates the specified inferred synonyms for the taxon in the classification, but do not insert it to the database
401 * @param taxon
402 * @param tree
403 * @return list of inferred synonyms
404 */
405 public List<Synonym> createInferredSynonyms(Taxon taxon, Classification tree, SynonymRelationshipType type);
406
407 public List<TaxonNameBase> findIdenticalTaxonNames(List<String> propertyPath);
408 public String getPhylumName(TaxonNameBase name);
409
410 public long countTaxaByCommonName(String searchString,
411 Classification classification, MatchMode matchMode,
412 Set<NamedArea> namedAreas);
413
414 public long deleteSynonymRelationships(Synonym syn);
415
416 public List<UUID> findIdenticalTaxonNameIds(List<String> propertyPath);
417
418 public List<TaxonNameBase> findIdenticalNamesNew(List <String> propertyPaths);
419
420
421 public Integer countSynonymRelationships(TaxonBase taxonBase,
422 SynonymRelationshipType type, Direction relatedfrom);
423
424 public List<SynonymRelationship> getSynonymRelationships(TaxonBase taxonBase,
425 SynonymRelationshipType type, Integer pageSize, Integer pageNumber,
426 List<OrderHint> orderHints, List<String> propertyPaths,
427 Direction relatedfrom);
428
429 /**
430 * @return
431 */
432 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheTaxon();
433
434 /**
435 * @return
436 */
437 public List<UuidAndTitleCache<TaxonBase>> getUuidAndTitleCacheSynonym();
438
439 public List<UuidAndTitleCache<TaxonBase>> getTaxaByNameForEditor(Class<? extends TaxonBase> clazz, String queryString, Classification classification,
440 MatchMode matchMode, Set<NamedArea> namedAreas);
441
442
443 }