svn keyword property "Id" added & getRootTaxa methods cleaned
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 25 Mar 2009 14:11:09 +0000 (14:11 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 25 Mar 2009 14:11:09 +0000 (14:11 +0000)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java

index 78739c81c49c2c166aa5663c52b5d07eb9527048..deaca8f691b3ebd19693688330117e0d7db95c68 100644 (file)
@@ -129,15 +129,15 @@ public class TaxonDaoHibernateImpl extends IdentifiableDaoBase<TaxonBase> implem
                \r
                Hibernate.initialize(taxonBase.getName());\r
                Hibernate.initialize(taxonBase.getSec());\r
-               \r
+\r
                return taxonBase; \r
        }\r
        \r
        /* (non-Javadoc)\r
         * @see eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao#getRootTaxa(eu.etaxonomy.cdm.model.name.Rank, eu.etaxonomy.cdm.model.reference.ReferenceBase, eu.etaxonomy.cdm.persistence.fetch.CdmFetch, java.lang.Boolean, java.lang.Boolean)\r
         */\r
-       public List<Taxon> \r
-       getRootTaxa(Rank rank, ReferenceBase sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications) {\r
+       public List<Taxon> getRootTaxa(Rank rank, ReferenceBase sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications) {\r
+               checkNotInPriorView("TaxonDaoHibernateImpl.getRootTaxa(Rank rank, ReferenceBase sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications)");\r
                if (onlyWithChildren == null){\r
                        onlyWithChildren = true;\r
                }\r
@@ -173,6 +173,17 @@ public class TaxonDaoHibernateImpl extends IdentifiableDaoBase<TaxonBase> implem
                for(Taxon taxon : taxa){\r
                        //childTaxa\r
                        //TODO create restriction instead\r
+                       //Hibernate.initialize(taxon.getName());\r
+                       Hibernate.initialize(taxon.getSec());\r
+                       \r
+                       // (a) not using cache fields\r
+                       /*Hibernate.initialize(taxon.getRelationsFromThisTaxon());\r
+                       if (onlyWithChildren == false || taxon.getRelationsFromThisTaxon().size() > 0){\r
+                               if (withMisapplications == true || ! taxon.isMisappliedName()){\r
+                                       results.add(taxon);\r
+                               }\r
+                       }*/\r
+                       // (b) using cache fields\r
                        if (onlyWithChildren == false || taxon.hasTaxonomicChildren()){\r
                                if (withMisapplications == true || ! taxon.isMisappliedName()){\r
                                        results.add(taxon);\r
@@ -186,51 +197,7 @@ public class TaxonDaoHibernateImpl extends IdentifiableDaoBase<TaxonBase> implem
         * @see eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao#getRootTaxa(eu.etaxonomy.cdm.model.reference.ReferenceBase, eu.etaxonomy.cdm.persistence.fetch.CdmFetch, java.lang.Boolean, java.lang.Boolean)\r
         */\r
        public List<Taxon> getRootTaxa(ReferenceBase sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications) {\r
-               checkNotInPriorView("TaxonDaoHibernateImpl.getRootTaxa(ReferenceBase sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications)");\r
-               if (onlyWithChildren == null){\r
-                       onlyWithChildren = true;\r
-               }\r
-               if (withMisapplications == null){\r
-                       withMisapplications = true;\r
-               }\r
-               if (cdmFetch == null){\r
-                       cdmFetch = CdmFetch.NO_FETCH();\r
-               }\r
-\r
-//             String query = "from Taxon root ";\r
-//             query += " where root.taxonomicParentCache is NULL ";\r
-//             if (sec != null){\r
-//             query += " AND root.sec.id = :sec "; \r
-//             }               \r
-//             Query q = getSession().createQuery(query);\r
-//             if (sec != null){\r
-//             q.setInteger("sec", sec.getId());\r
-//             }\r
-\r
-               Criteria crit = getSession().createCriteria(Taxon.class);\r
-               crit.add(Restrictions.isNull("taxonomicParentCache"));\r
-               if (sec != null){\r
-                       crit.add(Restrictions.eq("sec", sec) );\r
-               }\r
-\r
-               if (! cdmFetch.includes(CdmFetch.FETCH_CHILDTAXA())){\r
-                       logger.warn("no child taxa fetch");\r
-                       //TODO overwrite LAZY (SELECT) does not work (bug in hibernate?)\r
-                       crit.setFetchMode("relationsToThisTaxon.fromTaxon", FetchMode.LAZY);\r
-               }\r
-\r
-               List<Taxon> results = new ArrayList<Taxon>();\r
-               List<Taxon> taxa = crit.list();\r
-               for(Taxon taxon : taxa){\r
-                       //childTaxa\r
-                       //TODO create restriction instead\r
-                       if (onlyWithChildren == false || taxon.hasTaxonomicChildren()){\r
-                               if (withMisapplications == true || ! taxon.isMisappliedName()){\r
-                                       results.add(taxon);\r
-                               }\r
-                       }\r
-               }\r
-               return results;\r
+               return getRootTaxa(null, sec, cdmFetch, onlyWithChildren, withMisapplications);\r
        }\r
        \r
 \r