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 public List
<TaxonNode
> loadRankSpecificRootNodes(TaxonomicTree taxonomicTree
, Rank rank
, List
<String
> propertyPaths
){
47 String hql
= "SELECT tn FROM TaxonNode tn LEFT JOIN tn.childNodes as ctn" +
48 " WHERE tn.taxonomicTree = :tree AND (" +
49 " tn.taxon.name.rank = :rank" +
50 " OR (tn.taxon.name.rank < :rank AND tn.parent = null)" +
51 " OR (tn.taxon.name.rank > :rank AND ctn.taxon.name.rank < :rank)" +
53 Query query
= getSession().createQuery(hql
);
54 query
.setParameter("rank", rank
);
55 query
.setParameter("tree", taxonomicTree
);
56 List
<TaxonNode
> results
= query
.list();
57 defaultBeanInitializer
.initializeAll(results
, propertyPaths
);