1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.hibernate.Query;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.beans.factory.annotation.Qualifier;
|
23
|
import org.springframework.stereotype.Repository;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
28
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
|
29
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
|
30
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 16.06.2009
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
@Repository
|
38
|
@Qualifier("classificationDaoHibernateImpl")
|
39
|
public class ClassificationDaoHibernateImpl extends IdentifiableDaoBase<Classification>
|
40
|
implements IClassificationDao {
|
41
|
@SuppressWarnings("unused")
|
42
|
private static final Logger logger = Logger.getLogger(ClassificationDaoHibernateImpl.class);
|
43
|
|
44
|
@Autowired
|
45
|
private ITaxonNodeDao taxonNodeDao;
|
46
|
|
47
|
public ClassificationDaoHibernateImpl() {
|
48
|
super(Classification.class);
|
49
|
indexedClasses = new Class[1];
|
50
|
indexedClasses[0] = Classification.class;
|
51
|
}
|
52
|
|
53
|
@SuppressWarnings("unchecked")
|
54
|
public List<TaxonNode> loadRankSpecificRootNodes(Classification classification, Rank rank, List<String> propertyPaths){
|
55
|
List<TaxonNode> results;
|
56
|
if(rank == null){
|
57
|
classification = load(classification.getUuid());
|
58
|
results = new ArrayList();
|
59
|
results.addAll(classification.getChildNodes());
|
60
|
} else {
|
61
|
String hql = "SELECT DISTINCT tn FROM TaxonNode tn LEFT JOIN tn.childNodes as ctn" +
|
62
|
" WHERE tn.classification = :classification AND (" +
|
63
|
" tn.taxon.name.rank = :rank" +
|
64
|
" OR (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND tn.parent = null)" +
|
65
|
" OR (tn.taxon.name.rank.orderIndex < :rankOrderIndex AND ctn.taxon.name.rank.orderIndex > :rankOrderIndex)" +
|
66
|
" )";
|
67
|
Query query = getSession().createQuery(hql);
|
68
|
query.setParameter("rank", rank);
|
69
|
query.setParameter("rankOrderIndex", rank.getOrderIndex());
|
70
|
query.setParameter("classification", classification);
|
71
|
results = query.list();
|
72
|
}
|
73
|
defaultBeanInitializer.initializeAll(results, propertyPaths);
|
74
|
return results;
|
75
|
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public UUID delete(Classification persistentObject){
|
80
|
//delete all childnodes, then delete the tree
|
81
|
|
82
|
Set<TaxonNode> nodes = persistentObject.getChildNodes();
|
83
|
Iterator<TaxonNode> nodesIterator = nodes.iterator();
|
84
|
|
85
|
while(nodesIterator.hasNext()){
|
86
|
TaxonNode node = nodesIterator.next();
|
87
|
taxonNodeDao.delete(node);
|
88
|
}
|
89
|
|
90
|
super.delete(persistentObject);
|
91
|
|
92
|
return persistentObject.getUuid();
|
93
|
}
|
94
|
|
95
|
|
96
|
|
97
|
}
|