Project

General

Profile

« Previous | Next » 

Revision 580b83e6

Added by Patrick Plitzner almost 8 years ago

#5890 Add service method to get the root node for a given classification

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/ClassificationDaoHibernateImpl.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10

  
11
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
12

  
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.UUID;
16

  
17
import org.apache.log4j.Logger;
18
import org.hibernate.Query;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.beans.factory.annotation.Qualifier;
21
import org.springframework.stereotype.Repository;
22

  
23
import eu.etaxonomy.cdm.model.name.Rank;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
28
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
29
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
30

  
31
/**
32
 * @author a.mueller
33
 * @created 16.06.2009
34
 * @version 1.0
35
 */
36
@Repository
37
@Qualifier("classificationDaoHibernateImpl")
38
public class ClassificationDaoHibernateImpl extends IdentifiableDaoBase<Classification>
39
        implements IClassificationDao {
40
    @SuppressWarnings("unused")
41
    private static final Logger logger = Logger.getLogger(ClassificationDaoHibernateImpl.class);
42

  
43
    @Autowired
44
    private ITaxonNodeDao taxonNodeDao;
45

  
46
    public ClassificationDaoHibernateImpl() {
47
        super(Classification.class);
48
        indexedClasses = new Class[1];
49
        indexedClasses[0] = Classification.class;
50
    }
51

  
52
    @Override
53
    @SuppressWarnings("unchecked")
54
    public List<TaxonNode> listRankSpecificRootNodes(Classification classification, Rank rank,
55
            Integer limit, Integer start, List<String> propertyPaths, int queryIndex){
56

  
57
        List<TaxonNode> results = new ArrayList<TaxonNode>();
58
        Query[] queries = prepareRankSpecificRootNodes(classification, rank, false);
59

  
60
        // since this method is using two queries sequentially the handling of limit and start
61
        // is a bit more complex
62
        // the prepareRankSpecificRootNodes returns 1 or 2 queries
63

  
64
        Query q = queries[queryIndex];
65
        if(limit != null) {
66
            q.setMaxResults(limit);
67
            if(start != null) {
68
                q.setFirstResult(start);
69
            }
70
        }
71
//        long start_t = System.currentTimeMillis();
72
        results = q.list();
73
//        System.err.println("dao.listRankSpecificRootNodes() - query[" + queryIndex + "].list() " + (System.currentTimeMillis() - start_t));
74
//        start_t = System.currentTimeMillis();
75
        defaultBeanInitializer.initializeAll(results, propertyPaths);
76
//        System.err.println("dao.listRankSpecificRootNodes() - defaultBeanInitializer.initializeAll() " + (System.currentTimeMillis() - start_t));
77

  
78
        return results;
79

  
80
    }
81

  
82
    @Override
83
    public long[] countRankSpecificRootNodes(Classification classification, Rank rank) {
84

  
85
        long[] result = new long[(rank == null ? 1 : 2)];
86
        Query[] queries = prepareRankSpecificRootNodes(classification, rank, true);
87
        int i = 0;
88
        for(Query q : queries) {
89
            result[i++] = (Long)q.uniqueResult();
90
        }
91
        return result;
92
    }
93

  
94
    /**
95
     * See <a href="http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes">
96
     * http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes</a>
97
     *
98
     * @param classification
99
     * @param rank
100
     * @return
101
     *      one or two Queries as array, depending on the <code>rank</code> parameter:
102
     *      <code>rank == null</code>: array with one item, <code>rank != null</code>: array with two items.
103
     */
104
    private Query[] prepareRankSpecificRootNodes(Classification classification, Rank rank, boolean doCount) {
105
        Query query1;
106
        Query query2 = null;
107

  
108
        String whereClassification = "";
109
        if (classification != null){
110
            whereClassification = " AND tn.classification = :classification ";
111
        }
112

  
113
        String selectWhat = doCount ? "count(distinct tn)" : "distinct tn";
114

  
115
        String joinFetch = doCount ? "" : " JOIN FETCH tn.taxon t JOIN FETCH t.name n LEFT JOIN FETCH n.rank LEFT JOIN FETCH t.sec ";
116

  
117
        if(rank == null){
118
            String hql = "SELECT " + selectWhat + " FROM TaxonNode tn" +
119
                    joinFetch +
120
                    " WHERE tn.parent.parent = null " +
121
                    whereClassification;
122
            query1 = getSession().createQuery(hql);
123
        } else {
124
            // this is for the cases
125
            //   - exact match of the ranks
126
            //   - rank of root node is lower but is has no parents
127
            String hql1 = "SELECT " + selectWhat + " FROM TaxonNode tn " +
128
                    joinFetch +
129
                    " WHERE " +
130
                    " (tn.taxon.name.rank = :rank" +
131
                    "   OR (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND tn.parent.parent = null)" +
132
                    " )"
133
                    + whereClassification ;
134

  
135
            // this is for the case
136
            //   - rank of root node is lower and it has a parent with higher rank
137
            String hql2 = "SELECT " + selectWhat + " FROM TaxonNode tn JOIN tn.parent as parent" +
138
                    joinFetch +
139
                    " WHERE " +
140
                    " (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND parent.taxon.name.rank.orderIndex < :rankOrderIndex )"
141
                    + whereClassification ;
142
            query1 = getSession().createQuery(hql1);
143
            query2 = getSession().createQuery(hql2);
144
            query1.setParameter("rank", rank);
145
            query1.setParameter("rankOrderIndex", rank.getOrderIndex());
146
            query2.setParameter("rankOrderIndex", rank.getOrderIndex());
147
        }
148

  
149
        if (classification != null){
150
            query1.setParameter("classification", classification);
151
            if(query2 != null) {
152
                query2.setParameter("classification", classification);
153
            }
154
        }
155
        if(query2 != null) {
156
            return new Query[]{query1, query2};
157
        } else {
158
            return new Query[]{query1};
159
        }
160
    }
161

  
162
    @Override
163
    public List<TaxonNode> listChildrenOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths){
164
    	 Query query = prepareListChildrenOf(taxon, classification, false);
165

  
166
         setPagingParameter(query, pageSize, pageIndex);
167

  
168
         @SuppressWarnings("unchecked")
169
         List<TaxonNode> result = query.list();
170
         //check if array is "empty" (not containing null objects)
171
         if(!result.isEmpty() && result.iterator().next()==null){
172
         	return java.util.Collections.emptyList();
173
         }
174
         defaultBeanInitializer.initializeAll(result, propertyPaths);
175
         return result;
176
    }
177

  
178
    @Override
179
    public List<TaxonNode> listSiblingsOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths){
180
         Query query = prepareListSiblingsOf(taxon, classification, false);
181

  
182
         setPagingParameter(query, pageSize, pageIndex);
183

  
184
         @SuppressWarnings("unchecked")
185
         List<TaxonNode> result = query.list();
186
         //check if array is "empty" (not containing null objects)
187
         if(!result.isEmpty() && result.iterator().next()==null){
188
            return java.util.Collections.emptyList();
189
         }
190
         defaultBeanInitializer.initializeAll(result, propertyPaths);
191
         return result;
192
    }
193

  
194

  
195

  
196
    @Override
197
    public Long countChildrenOf(Taxon taxon, Classification classification){
198
        Query query = prepareListChildrenOf(taxon, classification, true);
199
        Long count = (Long) query.uniqueResult();
200
        return count;
201
    }
202

  
203
    @Override
204
    public Long countSiblingsOf(Taxon taxon, Classification classification){
205
        Query query = prepareListSiblingsOf(taxon, classification, true);
206
        Long count = (Long) query.uniqueResult();
207
        return count;
208
    }
209

  
210
    private Query prepareListChildrenOf(Taxon taxon, Classification classification, boolean doCount){
211

  
212
    	String selectWhat = doCount ? "count(cn)" : "cn";
213

  
214
         String hql = "select " + selectWhat + " from TaxonNode as tn JOIN tn.classification as c JOIN tn.taxon as t JOIN tn.childNodes as cn "
215
                 + "where t = :taxon and c = :classification";
216
         Query query = getSession().createQuery(hql);
217
         query.setParameter("taxon", taxon);
218
         query.setParameter("classification", classification);
219
         return query;
220
    }
221

  
222
    private Query prepareListSiblingsOf(Taxon taxon, Classification classification, boolean doCount){
223

  
224
        String selectWhat = doCount ? "count(tn)" : "tn";
225

  
226
         String subSelect = "SELECT tn.parent FROM TaxonNode as tn JOIN tn.classification as c JOIN tn.taxon as t "
227
                 + "WHERE t = :taxon AND c = :classification";
228
         String hql = "SELECT " + selectWhat + " FROM TaxonNode as tn WHERE tn.parent IN ( " + subSelect + ")";
229
         Query query = getSession().createQuery(hql);
230
         query.setParameter("taxon", taxon);
231
         query.setParameter("classification", classification);
232
         return query;
233
    }
234

  
235

  
236
    @Override
237
    public UUID delete(Classification persistentObject){
238
        //delete all childnodes, then delete the tree
239

  
240
        List<TaxonNode> nodes = persistentObject.getChildNodes();
241
        List<TaxonNode> nodesTmp = new ArrayList<TaxonNode>(nodes);
242

  
243
//        Iterator<TaxonNode> nodesIterator = nodes.iterator();
244
        for(TaxonNode node : nodesTmp){
245
            persistentObject.deleteChildNode(node, true);
246
            taxonNodeDao.delete(node, true);
247
        }
248

  
249
        TaxonNode rootNode = persistentObject.getRootNode();
250
        persistentObject.removeRootNode();
251
        taxonNodeDao.delete(rootNode);
252
        super.delete(persistentObject);
253

  
254
        return persistentObject.getUuid();
255
    }
256

  
257

  
258

  
259

  
260
}
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10

  
11
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
12

  
13
import java.util.ArrayList;
14
import java.util.List;
15
import java.util.UUID;
16

  
17
import org.apache.log4j.Logger;
18
import org.hibernate.Query;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.beans.factory.annotation.Qualifier;
21
import org.springframework.stereotype.Repository;
22

  
23
import eu.etaxonomy.cdm.model.name.Rank;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
27
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.IdentifiableDaoBase;
28
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
29
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonNodeDao;
30

  
31
/**
32
 * @author a.mueller
33
 * @created 16.06.2009
34
 * @version 1.0
35
 */
36
@Repository
37
@Qualifier("classificationDaoHibernateImpl")
38
public class ClassificationDaoHibernateImpl extends IdentifiableDaoBase<Classification>
39
        implements IClassificationDao {
40
    @SuppressWarnings("unused")
41
    private static final Logger logger = Logger.getLogger(ClassificationDaoHibernateImpl.class);
42

  
43
    @Autowired
44
    private ITaxonNodeDao taxonNodeDao;
45

  
46
    public ClassificationDaoHibernateImpl() {
47
        super(Classification.class);
48
        indexedClasses = new Class[1];
49
        indexedClasses[0] = Classification.class;
50
    }
51

  
52
    @Override
53
    @SuppressWarnings("unchecked")
54
    public List<TaxonNode> listRankSpecificRootNodes(Classification classification, Rank rank,
55
            Integer limit, Integer start, List<String> propertyPaths, int queryIndex){
56

  
57
        List<TaxonNode> results = new ArrayList<TaxonNode>();
58
        Query[] queries = prepareRankSpecificRootNodes(classification, rank, false);
59

  
60
        // since this method is using two queries sequentially the handling of limit and start
61
        // is a bit more complex
62
        // the prepareRankSpecificRootNodes returns 1 or 2 queries
63

  
64
        Query q = queries[queryIndex];
65
        if(limit != null) {
66
            q.setMaxResults(limit);
67
            if(start != null) {
68
                q.setFirstResult(start);
69
            }
70
        }
71
//        long start_t = System.currentTimeMillis();
72
        results = q.list();
73
//        System.err.println("dao.listRankSpecificRootNodes() - query[" + queryIndex + "].list() " + (System.currentTimeMillis() - start_t));
74
//        start_t = System.currentTimeMillis();
75
        defaultBeanInitializer.initializeAll(results, propertyPaths);
76
//        System.err.println("dao.listRankSpecificRootNodes() - defaultBeanInitializer.initializeAll() " + (System.currentTimeMillis() - start_t));
77

  
78
        return results;
79

  
80
    }
81

  
82
    @Override
83
    public long[] countRankSpecificRootNodes(Classification classification, Rank rank) {
84

  
85
        long[] result = new long[(rank == null ? 1 : 2)];
86
        Query[] queries = prepareRankSpecificRootNodes(classification, rank, true);
87
        int i = 0;
88
        for(Query q : queries) {
89
            result[i++] = (Long)q.uniqueResult();
90
        }
91
        return result;
92
    }
93

  
94
    /**
95
     * See <a href="http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes">
96
     * http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes</a>
97
     *
98
     * @param classification
99
     * @param rank
100
     * @return
101
     *      one or two Queries as array, depending on the <code>rank</code> parameter:
102
     *      <code>rank == null</code>: array with one item, <code>rank != null</code>: array with two items.
103
     */
104
    private Query[] prepareRankSpecificRootNodes(Classification classification, Rank rank, boolean doCount) {
105
        Query query1;
106
        Query query2 = null;
107

  
108
        String whereClassification = "";
109
        if (classification != null){
110
            whereClassification = " AND tn.classification = :classification ";
111
        }
112

  
113
        String selectWhat = doCount ? "count(distinct tn)" : "distinct tn";
114

  
115
        String joinFetch = doCount ? "" : " JOIN FETCH tn.taxon t JOIN FETCH t.name n LEFT JOIN FETCH n.rank LEFT JOIN FETCH t.sec ";
116

  
117
        if(rank == null){
118
            String hql = "SELECT " + selectWhat + " FROM TaxonNode tn" +
119
                    joinFetch +
120
                    " WHERE tn.parent.parent = null " +
121
                    whereClassification;
122
            query1 = getSession().createQuery(hql);
123
        } else {
124
            // this is for the cases
125
            //   - exact match of the ranks
126
            //   - rank of root node is lower but is has no parents
127
            String hql1 = "SELECT " + selectWhat + " FROM TaxonNode tn " +
128
                    joinFetch +
129
                    " WHERE " +
130
                    " (tn.taxon.name.rank = :rank" +
131
                    "   OR (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND tn.parent.parent = null)" +
132
                    " )"
133
                    + whereClassification ;
134

  
135
            // this is for the case
136
            //   - rank of root node is lower and it has a parent with higher rank
137
            String hql2 = "SELECT " + selectWhat + " FROM TaxonNode tn JOIN tn.parent as parent" +
138
                    joinFetch +
139
                    " WHERE " +
140
                    " (tn.taxon.name.rank.orderIndex > :rankOrderIndex AND parent.taxon.name.rank.orderIndex < :rankOrderIndex )"
141
                    + whereClassification ;
142
            query1 = getSession().createQuery(hql1);
143
            query2 = getSession().createQuery(hql2);
144
            query1.setParameter("rank", rank);
145
            query1.setParameter("rankOrderIndex", rank.getOrderIndex());
146
            query2.setParameter("rankOrderIndex", rank.getOrderIndex());
147
        }
148

  
149
        if (classification != null){
150
            query1.setParameter("classification", classification);
151
            if(query2 != null) {
152
                query2.setParameter("classification", classification);
153
            }
154
        }
155
        if(query2 != null) {
156
            return new Query[]{query1, query2};
157
        } else {
158
            return new Query[]{query1};
159
        }
160
    }
161

  
162
    @Override
163
    public List<TaxonNode> listChildrenOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths){
164
    	 Query query = prepareListChildrenOf(taxon, classification, false);
165

  
166
         setPagingParameter(query, pageSize, pageIndex);
167

  
168
         @SuppressWarnings("unchecked")
169
         List<TaxonNode> result = query.list();
170
         //check if array is "empty" (not containing null objects)
171
         if(!result.isEmpty() && result.iterator().next()==null){
172
         	return java.util.Collections.emptyList();
173
         }
174
         defaultBeanInitializer.initializeAll(result, propertyPaths);
175
         return result;
176
    }
177

  
178
    @Override
179
    public TaxonNode getRootNode(UUID classificationUuid){
180
        String queryString = "select tn from TaxonNode tn, Classification c where tn = c.rootNode and c.uuid = :classificationUuid";
181

  
182
        Query query = getSession().createQuery(queryString);
183
        query.setParameter("classificationUuid", classificationUuid);
184

  
185

  
186
        List results = query.list();
187
        if(results.size()!=1){
188
            return null;
189
        }
190
        return taxonNodeDao.load(((TaxonNode) results.iterator().next()).getUuid());
191
    }
192

  
193
    @Override
194
    public List<TaxonNode> listSiblingsOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths){
195
         Query query = prepareListSiblingsOf(taxon, classification, false);
196

  
197
         setPagingParameter(query, pageSize, pageIndex);
198

  
199
         @SuppressWarnings("unchecked")
200
         List<TaxonNode> result = query.list();
201
         //check if array is "empty" (not containing null objects)
202
         if(!result.isEmpty() && result.iterator().next()==null){
203
            return java.util.Collections.emptyList();
204
         }
205
         defaultBeanInitializer.initializeAll(result, propertyPaths);
206
         return result;
207
    }
208

  
209

  
210

  
211
    @Override
212
    public Long countChildrenOf(Taxon taxon, Classification classification){
213
        Query query = prepareListChildrenOf(taxon, classification, true);
214
        Long count = (Long) query.uniqueResult();
215
        return count;
216
    }
217

  
218
    @Override
219
    public Long countSiblingsOf(Taxon taxon, Classification classification){
220
        Query query = prepareListSiblingsOf(taxon, classification, true);
221
        Long count = (Long) query.uniqueResult();
222
        return count;
223
    }
224

  
225
    private Query prepareListChildrenOf(Taxon taxon, Classification classification, boolean doCount){
226

  
227
    	String selectWhat = doCount ? "count(cn)" : "cn";
228

  
229
         String hql = "select " + selectWhat + " from TaxonNode as tn JOIN tn.classification as c JOIN tn.taxon as t JOIN tn.childNodes as cn "
230
                 + "where t = :taxon and c = :classification";
231
         Query query = getSession().createQuery(hql);
232
         query.setParameter("taxon", taxon);
233
         query.setParameter("classification", classification);
234
         return query;
235
    }
236

  
237
    private Query prepareListSiblingsOf(Taxon taxon, Classification classification, boolean doCount){
238

  
239
        String selectWhat = doCount ? "count(tn)" : "tn";
240

  
241
         String subSelect = "SELECT tn.parent FROM TaxonNode as tn JOIN tn.classification as c JOIN tn.taxon as t "
242
                 + "WHERE t = :taxon AND c = :classification";
243
         String hql = "SELECT " + selectWhat + " FROM TaxonNode as tn WHERE tn.parent IN ( " + subSelect + ")";
244
         Query query = getSession().createQuery(hql);
245
         query.setParameter("taxon", taxon);
246
         query.setParameter("classification", classification);
247
         return query;
248
    }
249

  
250

  
251
    @Override
252
    public UUID delete(Classification persistentObject){
253
        //delete all childnodes, then delete the tree
254

  
255
        List<TaxonNode> nodes = persistentObject.getChildNodes();
256
        List<TaxonNode> nodesTmp = new ArrayList<TaxonNode>(nodes);
257

  
258
//        Iterator<TaxonNode> nodesIterator = nodes.iterator();
259
        for(TaxonNode node : nodesTmp){
260
            persistentObject.deleteChildNode(node, true);
261
            taxonNodeDao.delete(node, true);
262
        }
263

  
264
        TaxonNode rootNode = persistentObject.getRootNode();
265
        persistentObject.removeRootNode();
266
        taxonNodeDao.delete(rootNode);
267
        super.delete(persistentObject);
268

  
269
        return persistentObject.getUuid();
270
    }
271

  
272

  
273

  
274

  
275
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/taxon/IClassificationDao.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.persistence.dao.taxon;
11

  
12
import java.util.List;
13

  
14
import eu.etaxonomy.cdm.model.name.Rank;
15
import eu.etaxonomy.cdm.model.taxon.Classification;
16
import eu.etaxonomy.cdm.model.taxon.Taxon;
17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
18
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
19

  
20
/**
21
 * @author a.mueller
22
 *
23
 */
24
public interface IClassificationDao extends IIdentifiableDao<Classification> {
25

  
26
    /**
27
     * <p>
28
     * Lists all TaxonNodes of the specified tree for a given Rank. If a branch
29
     * does not contain a TaxonNode with a TaxonName at the given Rank the node
30
     * associated with the next lower Rank is taken as root node. If the
31
     * <code>rank</code> is null the absolute root nodes will be returned.
32
     * <p>
33
     * See <a href="http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes">http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes</a>
34
     * <p>
35
     * Since this method is using two queries which need to be run sequentially
36
     * the handling of limit and start is more complex and requires the total
37
     * count of the items matched by the first query is known. Therefore the
38
     * handling of limit and start must be managed in the service method that is
39
     * using this dao method.
40
     *
41
     * @param classification
42
     * @param rank
43
     *            may be null
44
     * @param limit
45
     *            The maximum number of objects returned (can be null for all
46
     *            matching objects)
47
     * @param start
48
     *            The offset from the start of the result set (0 - based, can be
49
     *            null - equivalent of starting at the beginning of the
50
     *            recordset)
51
     * @param propertyPaths
52
     * @param queryIndex
53
     *            0: execute first query, 1: excute second query, the second
54
     *            query is only available when parameter
55
     *            <code>rank != null</code>.
56
     * @return
57
     */
58
    public List<TaxonNode> listRankSpecificRootNodes(Classification classification, Rank rank, Integer limit, Integer start,
59
            List<String> propertyPaths, int queryIndex);
60

  
61
    public long[] countRankSpecificRootNodes(Classification classification, Rank rank);
62

  
63
    public List<TaxonNode> listChildrenOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths);
64

  
65

  
66
    public abstract Long countChildrenOf(Taxon taxon, Classification classification);
67

  
68
    /**
69
     * @param taxon
70
     * @param classification
71
     * @param pageSize
72
     * @param pageIndex
73
     * @param propertyPaths
74
     * @return
75
     */
76
    List<TaxonNode> listSiblingsOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex,
77
            List<String> propertyPaths);
78

  
79
    /**
80
     * @param taxon
81
     * @param classification
82
     * @return
83
     */
84
    Long countSiblingsOf(Taxon taxon, Classification classification);
85

  
86

  
87
}
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.persistence.dao.taxon;
11

  
12
import java.util.List;
13
import java.util.UUID;
14

  
15
import eu.etaxonomy.cdm.model.name.Rank;
16
import eu.etaxonomy.cdm.model.taxon.Classification;
17
import eu.etaxonomy.cdm.model.taxon.Taxon;
18
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
19
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
20

  
21
/**
22
 * @author a.mueller
23
 *
24
 */
25
public interface IClassificationDao extends IIdentifiableDao<Classification> {
26

  
27
    /**
28
     * <p>
29
     * Lists all TaxonNodes of the specified tree for a given Rank. If a branch
30
     * does not contain a TaxonNode with a TaxonName at the given Rank the node
31
     * associated with the next lower Rank is taken as root node. If the
32
     * <code>rank</code> is null the absolute root nodes will be returned.
33
     * <p>
34
     * See <a href="http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes">http://dev.e-taxonomy.eu/trac/wiki/CdmClassificationRankSpecificRootnodes</a>
35
     * <p>
36
     * Since this method is using two queries which need to be run sequentially
37
     * the handling of limit and start is more complex and requires the total
38
     * count of the items matched by the first query is known. Therefore the
39
     * handling of limit and start must be managed in the service method that is
40
     * using this dao method.
41
     *
42
     * @param classification
43
     * @param rank
44
     *            may be null
45
     * @param limit
46
     *            The maximum number of objects returned (can be null for all
47
     *            matching objects)
48
     * @param start
49
     *            The offset from the start of the result set (0 - based, can be
50
     *            null - equivalent of starting at the beginning of the
51
     *            recordset)
52
     * @param propertyPaths
53
     * @param queryIndex
54
     *            0: execute first query, 1: excute second query, the second
55
     *            query is only available when parameter
56
     *            <code>rank != null</code>.
57
     * @return
58
     */
59
    public List<TaxonNode> listRankSpecificRootNodes(Classification classification, Rank rank, Integer limit, Integer start,
60
            List<String> propertyPaths, int queryIndex);
61

  
62
    public long[] countRankSpecificRootNodes(Classification classification, Rank rank);
63

  
64
    public List<TaxonNode> listChildrenOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex, List<String> propertyPaths);
65

  
66
    public TaxonNode getRootNode(UUID classificationUuid);
67

  
68
    public abstract Long countChildrenOf(Taxon taxon, Classification classification);
69

  
70
    /**
71
     * @param taxon
72
     * @param classification
73
     * @param pageSize
74
     * @param pageIndex
75
     * @param propertyPaths
76
     * @return
77
     */
78
    List<TaxonNode> listSiblingsOf(Taxon taxon, Classification classification, Integer pageSize, Integer pageIndex,
79
            List<String> propertyPaths);
80

  
81
    /**
82
     * @param taxon
83
     * @param classification
84
     * @return
85
     */
86
    Long countSiblingsOf(Taxon taxon, Classification classification);
87

  
88

  
89
}
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ClassificationServiceImpl.java
277 277
        return treeNode;
278 278
    }
279 279

  
280
    @Override
281
    public TaxonNode getRootNode(UUID classificationUuid){
282
        return dao.getRootNode(classificationUuid);
283
    }
284

  
280 285
    @Override
281 286
    public List<Classification> listClassifications(Integer limit, Integer start, List<OrderHint> orderHints, List<String> propertyPaths) {
282 287
        return dao.list(limit, start, orderHints, propertyPaths);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IClassificationService.java
47 47
     */
48 48
    public ITaxonTreeNode getTreeNodeByUuid(UUID uuid);
49 49

  
50
    public TaxonNode getRootNode(UUID classificationUuid);
51

  
50 52
    /**
51 53
     *
52 54
     * @param limit

Also available in: Unified diff