2 * Copyright (C) 2008 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
7 package eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.media
;
9 import java
.util
.HashSet
;
10 import java
.util
.List
;
13 import org
.hibernate
.Criteria
;
14 import org
.hibernate
.criterion
.Projections
;
15 import org
.hibernate
.criterion
.Restrictions
;
16 import org
.springframework
.stereotype
.Repository
;
18 import eu
.etaxonomy
.cdm
.model
.description
.IdentificationKey
;
19 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
20 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.cdm
.persistence
.dao
.hibernate
.common
.AnnotatableDaoImpl
;
23 import eu
.etaxonomy
.cdm
.persistence
.dao
.media
.IMediaDao
;
26 * @author a.babadshanjan
30 public class MediaDaoHibernateImpl
extends AnnotatableDaoImpl
<Media
>
31 implements IMediaDao
{
33 public MediaDaoHibernateImpl() {
37 public int countIdentificationKeys(Set
<Taxon
> taxonomicScope
, Set
<NamedArea
> geoScopes
) {
38 checkNotInPriorView("MediaDaoHibernateImpl.countIdentificationKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes)");
39 Criteria criteria
= getSession().createCriteria(IdentificationKey
.class);
41 if(taxonomicScope
!= null && !taxonomicScope
.isEmpty()) {
42 Set
<Integer
> taxonomicScopeIds
= new HashSet
<Integer
>();
43 for(Taxon n
: taxonomicScope
) {
44 taxonomicScopeIds
.add(n
.getId());
46 criteria
.createCriteria("taxonomicScope").add(Restrictions
.in("id", taxonomicScopeIds
));
49 if(geoScopes
!= null && !geoScopes
.isEmpty()) {
50 Set
<Integer
> geoScopeIds
= new HashSet
<Integer
>();
51 for(NamedArea n
: geoScopes
) {
52 geoScopeIds
.add(n
.getId());
54 criteria
.createCriteria("geoScopes").add(Restrictions
.in("id", geoScopeIds
));
57 criteria
.setProjection(Projections
.countDistinct("id"));
59 return (Integer
)criteria
.uniqueResult();
62 public List
<IdentificationKey
> getIdentificationKeys(Set
<Taxon
> taxonomicScope
, Set
<NamedArea
> geoScopes
, Integer pageSize
, Integer pageNumber
) {
63 checkNotInPriorView("MediaDaoHibernateImpl.getIdentificationKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber)");
64 Criteria inner
= getSession().createCriteria(IdentificationKey
.class);
66 if(taxonomicScope
!= null && !taxonomicScope
.isEmpty()) {
67 Set
<Integer
> taxonomicScopeIds
= new HashSet
<Integer
>();
68 for(Taxon n
: taxonomicScope
) {
69 taxonomicScopeIds
.add(n
.getId());
71 inner
.createCriteria("taxonomicScope").add(Restrictions
.in("id", taxonomicScopeIds
));
74 if(geoScopes
!= null && !geoScopes
.isEmpty()) {
75 Set
<Integer
> geoScopeIds
= new HashSet
<Integer
>();
76 for(NamedArea n
: geoScopes
) {
77 geoScopeIds
.add(n
.getId());
79 inner
.createCriteria("geoScopes").add(Restrictions
.in("id", geoScopeIds
));
82 inner
.setProjection(Projections
.distinct(Projections
.id()));
84 Criteria criteria
= getSession().createCriteria(IdentificationKey
.class);
85 criteria
.add(Restrictions
.in("id", (List
<Integer
>)inner
.list()));
87 if(pageSize
!= null) {
88 criteria
.setMaxResults(pageSize
);
89 if(pageNumber
!= null) {
90 criteria
.setFirstResult(pageNumber
* pageSize
);
94 return (List
<IdentificationKey
>)criteria
.list();