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
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.hibernate
.Query
;
18 import org
.springframework
.beans
.factory
.annotation
.Qualifier
;
19 import org
.springframework
.stereotype
.Repository
;
21 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonomicTree
;
25 import eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
.IdentifiableDaoBase
;
26 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonomicTreeDao
;
34 @Qualifier("taxonomicTreeDaoHibernateImpl")
35 public class TaxonomicTreeDaoHibernateImpl
extends IdentifiableDaoBase
<TaxonomicTree
>
36 implements ITaxonomicTreeDao
{
37 @SuppressWarnings("unused")
38 private static final Logger logger
= Logger
.getLogger(TaxonomicTreeDaoHibernateImpl
.class);
40 public TaxonomicTreeDaoHibernateImpl() {
41 super(TaxonomicTree
.class);
42 indexedClasses
= new Class
[1];
43 indexedClasses
[0] = TaxonomicTree
.class;
46 @SuppressWarnings("unchecked")
47 public List
<TaxonNode
> loadRankSpecificRootNodes(TaxonomicTree taxonomicTree
, Rank rank
, List
<String
> propertyPaths
){
48 String hql
= "SELECT DISTINCT tn FROM TaxonNode tn LEFT JOIN tn.childNodes as ctn" +
49 " WHERE tn.taxonomicTree = :tree AND (" +
50 " tn.taxon.name.rank = :rank" +
51 " OR (tn.taxon.name.rank < :rank AND tn.parent = null)" +
52 " OR (tn.taxon.name.rank > :rank AND ctn.taxon.name.rank < :rank)" +
54 Query query
= getSession().createQuery(hql
);
55 query
.setParameter("rank", rank
);
56 query
.setParameter("tree", taxonomicTree
);
57 List
<TaxonNode
> results
= query
.list();
58 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);