Revision 22abd4ac
Added by Andreas Müller over 7 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java | ||
---|---|---|
66 | 66 |
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao; |
67 | 67 |
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao; |
68 | 68 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
69 |
import eu.etaxonomy.cdm.persistence.fetch.CdmFetch; |
|
70 | 69 |
import eu.etaxonomy.cdm.persistence.query.MatchMode; |
71 | 70 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
72 | 71 |
|
... | ... | |
98 | 97 |
// this.alternativeSpellingSuggestionParser = alternativeSpellingSuggestionParser; |
99 | 98 |
// } |
100 | 99 |
|
101 |
@Override |
|
102 |
public List<Taxon> getRootTaxa(Reference sec) { |
|
103 |
return getRootTaxa(sec, CdmFetch.FETCH_CHILDTAXA(), true, false); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public List<Taxon> getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications, List<String> propertyPaths) { |
|
108 |
checkNotInPriorView("TaxonDaoHibernateImpl.getRootTaxa(Rank rank, Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications)"); |
|
109 |
if (onlyWithChildren == null){ |
|
110 |
onlyWithChildren = true; |
|
111 |
} |
|
112 |
if (withMisapplications == null){ |
|
113 |
withMisapplications = true; |
|
114 |
} |
|
115 |
if (cdmFetch == null){ |
|
116 |
cdmFetch = CdmFetch.NO_FETCH(); |
|
117 |
} |
|
118 |
|
|
119 |
Criteria crit = getSession().createCriteria(Taxon.class); |
|
120 |
|
|
121 |
crit.setFetchMode("name", FetchMode.JOIN); |
|
122 |
crit.createAlias("name", "name"); |
|
123 |
|
|
124 |
if (rank != null) { |
|
125 |
crit.add(Restrictions.eq("name.rank", rank)); |
|
126 |
}else{ |
|
127 |
crit.add(Restrictions.isNull("taxonomicParentCache")); |
|
128 |
} |
|
129 |
|
|
130 |
if (sec != null){ |
|
131 |
crit.add(Restrictions.eq("sec", sec) ); |
|
132 |
} |
|
133 |
|
|
134 |
if (! cdmFetch.includes(CdmFetch.FETCH_CHILDTAXA())){ |
|
135 |
logger.info("Not fetching child taxa"); |
|
136 |
//TODO overwrite LAZY (SELECT) does not work (bug in hibernate?) |
|
137 |
crit.setFetchMode("relationsToThisTaxon.fromTaxon", FetchMode.LAZY); |
|
138 |
} |
|
139 |
|
|
140 |
List<Taxon> results = new ArrayList<Taxon>(); |
|
141 |
@SuppressWarnings("unchecked") |
|
142 |
List<Taxon> taxa = crit.list(); |
|
143 |
for(Taxon taxon : taxa){ |
|
144 |
|
|
145 |
|
|
146 |
//childTaxa |
|
147 |
//TODO create restriction instead |
|
148 |
// (a) not using cache fields |
|
149 |
/*Hibernate.initialize(taxon.getRelationsFromThisTaxon()); |
|
150 |
if (onlyWithChildren == false || taxon.getRelationsFromThisTaxon().size() > 0){ |
|
151 |
if (withMisapplications == true || ! taxon.isMisappliedName()){ |
|
152 |
defaultBeanInitializer.initialize(taxon, propertyPaths); |
|
153 |
results.add(taxon); |
|
154 |
} |
|
155 |
}*/ |
|
156 |
// (b) using cache fields |
|
157 |
if (onlyWithChildren == false || taxon.hasTaxonomicChildren()){ |
|
158 |
if (withMisapplications == true || ! taxon.isMisapplication()){ |
|
159 |
defaultBeanInitializer.initialize(taxon, propertyPaths); |
|
160 |
results.add(taxon); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
|
164 |
return results; |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public List<Taxon> getRootTaxa(Reference sec, CdmFetch cdmFetch, Boolean onlyWithChildren, Boolean withMisapplications) { |
|
169 |
return getRootTaxa(null, sec, cdmFetch, onlyWithChildren, withMisapplications, null); |
|
170 |
} |
|
171 | 100 |
|
172 | 101 |
@Override |
173 | 102 |
public List<TaxonBase> getTaxaByName(String queryString, Reference sec) { |
... | ... | |
979 | 908 |
for (Iterator<TaxonRelationship> iterator = ((Taxon)taxonBase).getRelationsFromThisTaxon().iterator(); iterator.hasNext();){ |
980 | 909 |
TaxonRelationship relationFromThisTaxon = iterator.next(); |
981 | 910 |
|
982 |
// decrease children count of taxonomic parent by one |
|
983 |
if (relationFromThisTaxon.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) { |
|
984 |
Taxon toTaxon = relationFromThisTaxon.getToTaxon(); // parent |
|
985 |
if (toTaxon != null) { |
|
986 |
toTaxon.setTaxonomicChildrenCount(toTaxon.getTaxonomicChildrenCount() - 1); |
|
987 |
} |
|
988 |
} |
|
989 | 911 |
} |
990 | 912 |
} |
991 | 913 |
|
Also available in: Unified diff
ref #6089 Remove all calls and methods for taxonomicChildrenCount and taxonomicParentCache