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 org.apache.ojb.broker.query.Criteria;
24 import org.apache.ojb.broker.query.Query;
25 import org.apache.ojb.broker.query.QueryFactory;
26 import org.apache.ojb.broker.query.ReportQueryByCriteria;
27 import org.kuali.hr.time.department.Department;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class DepartmentDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements DepartmentDao {
31
32 @Override
33 public void saveOrUpdate(Department dept) {
34 this.getPersistenceBrokerTemplate().store(dept);
35 }
36
37 @Override
38 public Department getDepartment(String department, Date asOfDate) {
39 Criteria root = new Criteria();
40 Criteria effdt = new Criteria();
41 Criteria timestamp = new Criteria();
42
43 effdt.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
44 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
45 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(Department.class, effdt);
46 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
47
48 timestamp.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
49 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
50 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(Department.class, timestamp);
51 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
52
53 root.addEqualTo("dept", department);
54 root.addEqualTo("effectiveDate", effdtSubQuery);
55 root.addEqualTo("timestamp", timestampSubQuery);
56
57 Criteria activeFilter = new Criteria();
58 activeFilter.addEqualTo("active", true);
59 root.addAndCriteria(activeFilter);
60
61 Query query = QueryFactory.newQuery(Department.class, root);
62
63 Department d = (Department)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
64
65 return d;
66 }
67
68 @Override
69 public List<Department> getDepartments(String location, Date asOfDate) {
70 Criteria root = new Criteria();
71 Criteria effdt = new Criteria();
72 Criteria timestamp = new Criteria();
73
74 effdt.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
75 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
76 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(Department.class, effdt);
77 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
78
79 timestamp.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
80 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
81 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(Department.class, timestamp);
82 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
83
84 root.addEqualTo("location", location);
85 root.addEqualTo("effectiveDate", effdtSubQuery);
86 root.addEqualTo("timestamp", timestampSubQuery);
87
88 Criteria activeFilter = new Criteria();
89 activeFilter.addEqualTo("active", true);
90 root.addAndCriteria(activeFilter);
91
92
93 Query query = QueryFactory.newQuery(Department.class, root);
94
95 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
96 List<Department> d = new ArrayList<Department>(c.size());
97 d.addAll(c);
98
99 return d;
100 }
101
102 @Override
103 public Department getDepartment(String hrDeptId) {
104 Criteria crit = new Criteria();
105 crit.addEqualTo("hrDeptId", hrDeptId);
106
107 Query query = QueryFactory.newQuery(Department.class, crit);
108 return (Department)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
109 }
110
111 @Override
112 public List<Department> getDepartmentByLocation(String location) {
113 Criteria crit = new Criteria();
114 crit.addEqualTo("location", location);
115
116 Query query = QueryFactory.newQuery(Department.class, crit);
117
118 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
119 List<Department> d = new ArrayList<Department>(c.size());
120 d.addAll(c);
121
122 return d;
123 }
124
125 @Override
126 public int getDepartmentCount(String department) {
127 Criteria crit = new Criteria();
128 crit.addEqualTo("dept", department);
129 Query query = QueryFactory.newQuery(Department.class, crit);
130 return this.getPersistenceBrokerTemplate().getCount(query);
131 }
132 }