1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.department.dao;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22
23 import com.google.common.collect.ImmutableList;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.ojb.broker.query.Criteria;
26 import org.apache.ojb.broker.query.Query;
27 import org.apache.ojb.broker.query.QueryFactory;
28 import org.apache.ojb.broker.query.ReportQueryByCriteria;
29 import org.kuali.hr.core.util.OjbSubQueryUtil;
30 import org.kuali.hr.time.department.Department;
31 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32
33 public class DepartmentDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements DepartmentDao {
34 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
35 .add("dept")
36 .build();
37
38 @Override
39 public void saveOrUpdate(Department dept) {
40 this.getPersistenceBrokerTemplate().store(dept);
41 }
42
43 @Override
44 public Department getDepartment(String department, Date asOfDate) {
45 Criteria root = new Criteria();
46
47 root.addEqualTo("dept", department);
48 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(Department.class, asOfDate, EQUAL_TO_FIELDS, false));
49 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Department.class, EQUAL_TO_FIELDS, false));
50
51 Criteria activeFilter = new Criteria();
52 activeFilter.addEqualTo("active", true);
53 root.addAndCriteria(activeFilter);
54
55 Query query = QueryFactory.newQuery(Department.class, root);
56
57 Department d = (Department)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
58
59 return d;
60 }
61
62 @Override
63 public List<Department> getDepartments(String location, Date asOfDate) {
64 Criteria root = new Criteria();
65
66 root.addEqualTo("location", location);
67 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(Department.class, asOfDate, EQUAL_TO_FIELDS, false));
68 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(Department.class, EQUAL_TO_FIELDS, false));
69
70 Criteria activeFilter = new Criteria();
71 activeFilter.addEqualTo("active", true);
72 root.addAndCriteria(activeFilter);
73
74
75 Query query = QueryFactory.newQuery(Department.class, root);
76
77 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
78 List<Department> d = new ArrayList<Department>(c.size());
79 d.addAll(c);
80
81 return d;
82 }
83
84 @Override
85 @SuppressWarnings("unchecked")
86 public List<Department> getDepartments(String dept, String location, String departmentDescr, String active) {
87 List<Department> results = new ArrayList<Department>();
88
89 Criteria root = new Criteria();
90
91 if (StringUtils.isNotBlank(dept)) {
92 root.addLike("dept", dept);
93 }
94
95 if (StringUtils.isNotBlank(location)) {
96 root.addLike("location", location);
97 }
98
99 if (StringUtils.isNotBlank(departmentDescr)) {
100 root.addLike("description", departmentDescr);
101 }
102
103 if (StringUtils.isNotBlank(active)) {
104 Criteria activeFilter = new Criteria();
105 if (StringUtils.equals(active, "Y")) {
106 activeFilter.addEqualTo("active", true);
107 } else if (StringUtils.equals(active, "N")) {
108 activeFilter.addEqualTo("active", false);
109 }
110 root.addAndCriteria(activeFilter);
111 }
112
113 Query query = QueryFactory.newQuery(Department.class, root);
114 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
115
116 return results;
117 }
118
119 @Override
120 public Department getDepartment(String hrDeptId) {
121 Criteria crit = new Criteria();
122 crit.addEqualTo("hrDeptId", hrDeptId);
123
124 Query query = QueryFactory.newQuery(Department.class, crit);
125 return (Department)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
126 }
127
128 @Override
129 public List<Department> getDepartmentByLocation(String location) {
130 Criteria crit = new Criteria();
131 crit.addEqualTo("location", location);
132
133 Query query = QueryFactory.newQuery(Department.class, crit);
134
135 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
136 List<Department> d = new ArrayList<Department>(c.size());
137 d.addAll(c);
138
139 return d;
140 }
141
142 @Override
143 public int getDepartmentCount(String department) {
144 Criteria crit = new Criteria();
145 crit.addEqualTo("dept", department);
146 Query query = QueryFactory.newQuery(Department.class, crit);
147 return this.getPersistenceBrokerTemplate().getCount(query);
148 }
149 }