3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.taxon
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Iterator
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
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
;
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
;
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);
45 private ITaxonNodeDao taxonNodeDao
;
47 public ClassificationDaoHibernateImpl() {
48 super(Classification
.class);
49 indexedClasses
= new Class
[1];
50 indexedClasses
[0] = Classification
.class;
53 @SuppressWarnings("unchecked")
54 public List
<TaxonNode
> loadRankSpecificRootNodes(Classification classification
, Rank rank
,
55 Integer limit
, Integer start
, List
<String
> propertyPaths
){
57 List
<TaxonNode
> results
;
60 String whereClassification
= "";
61 if (classification
!= null){
62 whereClassification
= " AND tn.classification = :classification ";
66 String hql
= "SELECT DISTINCT tn FROM TaxonNode tn LEFT JOIN tn.childNodes as tnc" +
67 " WHERE tn.parent = null " +
69 query
= getSession().createQuery(hql
);
71 String hql
= "SELECT DISTINCT tn FROM TaxonNode tn LEFT JOIN tn.childNodes as tnc" +
73 " (tn.taxon.name.rank = :rank" +
74 " OR (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND tn.parent = null)" +
75 " OR (tn.taxon.name.rank.orderIndex < :rankOrderIndex AND tnc.taxon.name.rank.orderIndex > :rankOrderIndex)" +
78 query
= getSession().createQuery(hql
);
79 query
.setParameter("rank", rank
);
80 query
.setParameter("rankOrderIndex", rank
.getOrderIndex());
83 if (classification
!= null){
84 query
.setParameter("classification", classification
);
88 query
.setMaxResults(limit
);
90 query
.setFirstResult(start
);
94 results
= query
.list();
95 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);
101 public UUID
delete(Classification persistentObject
){
102 //delete all childnodes, then delete the tree
104 Set
<TaxonNode
> nodes
= persistentObject
.getChildNodes();
105 Iterator
<TaxonNode
> nodesIterator
= nodes
.iterator();
107 while(nodesIterator
.hasNext()){
108 TaxonNode node
= nodesIterator
.next();
109 taxonNodeDao
.delete(node
);
112 super.delete(persistentObject
);
114 return persistentObject
.getUuid();