1
|
/**
|
2
|
* Copyright (C) 2009 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.Hibernate;
|
15
|
import org.hibernate.Query;
|
16
|
import org.springframework.stereotype.Repository;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.common.Group;
|
19
|
import eu.etaxonomy.cdm.persistence.dao.common.IGroupDao;
|
20
|
|
21
|
@Repository
|
22
|
public class GroupDaoImpl extends CdmEntityDaoBase<Group> implements IGroupDao {
|
23
|
|
24
|
public GroupDaoImpl() {
|
25
|
super(Group.class);
|
26
|
}
|
27
|
|
28
|
public Group findGroupByName(String groupName) {
|
29
|
Query query = getSession().createQuery("select g from Group g where g.name = :name");
|
30
|
query.setParameter("name",groupName);
|
31
|
|
32
|
Group group = (Group)query.uniqueResult();
|
33
|
if(group != null) {
|
34
|
Hibernate.initialize(group.getGrantedAuthorities());
|
35
|
Hibernate.initialize(group.getMembers());
|
36
|
}
|
37
|
|
38
|
return group;
|
39
|
}
|
40
|
|
41
|
public List<String> listNames(Integer pageSize, Integer pageNumber) {
|
42
|
Query query = getSession().createQuery("select g.name from Group g");
|
43
|
|
44
|
if(pageSize != null) {
|
45
|
query.setMaxResults(pageSize);
|
46
|
if(pageNumber != null) {
|
47
|
query.setFirstResult(pageNumber * pageSize);
|
48
|
} else {
|
49
|
query.setFirstResult(0);
|
50
|
}
|
51
|
}
|
52
|
|
53
|
return (List<String>)query.list();
|
54
|
}
|
55
|
|
56
|
public List<String> listMembers(Group group, Integer pageSize, Integer pageNumber) {
|
57
|
Query query = getSession().createQuery("select m.username from Group g join g.members m where g = :group");
|
58
|
query.setParameter("group", group);
|
59
|
|
60
|
if(pageSize != null) {
|
61
|
query.setMaxResults(pageSize);
|
62
|
if(pageNumber != null) {
|
63
|
query.setFirstResult(pageNumber * pageSize);
|
64
|
} else {
|
65
|
query.setFirstResult(0);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
return (List<String>)query.list();
|
70
|
}
|
71
|
|
72
|
}
|