0e74071eb38d390d5a0da614a7aa2a1d3ef7bd8d
[cdmlib.git] / cdmlib-persistence / src / main / java / eu / etaxonomy / cdm / persistence / dao / hibernate / common / TermVocabularyDaoImpl.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.hibernate.common;
11
12 import java.util.List;
13
14 import org.hibernate.Query;
15 import org.springframework.stereotype.Repository;
16
17 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
18 import eu.etaxonomy.cdm.model.common.TermVocabulary;
19 import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
20
21 /**
22 * @author a.mueller
23 *
24 */
25 @Repository
26 public class TermVocabularyDaoImpl extends CdmEntityDaoBase<TermVocabulary<DefinedTermBase>> implements
27 ITermVocabularyDao {
28
29
30 /**
31 * @param type
32 */
33 public TermVocabularyDaoImpl() {
34 super((Class)TermVocabulary.class);
35 }
36
37 public int countTerms(TermVocabulary termVocabulary) {
38 Query query = getSession().createQuery("select count(term) from TermVocabulary termVocabulary join termVocabulary.terms term where termVocabulary = :termVocabulary");
39 query.setParameter("termVocabulary", termVocabulary);
40
41 return ((Long)query.uniqueResult()).intValue();
42 }
43
44 public <T extends DefinedTermBase> List<T> getTerms(TermVocabulary<T> termVocabulary, Integer pageSize, Integer pageNumber) {
45 Query query = getSession().createQuery("select term from TermVocabulary termVocabulary join termVocabulary.terms term where termVocabulary = :termVocabulary");
46 query.setParameter("termVocabulary", termVocabulary);
47
48 if(pageSize != null) {
49 query.setMaxResults(pageSize);
50 if(pageNumber != null) {
51 query.setFirstResult(pageNumber * pageSize);
52 }
53 }
54
55 return (List<T>)query.list();
56 }
57
58
59 }