1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncode.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.log4j.Logger;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.Query;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.apache.ojb.broker.query.ReportQueryByCriteria;
28 import org.kuali.hr.time.earncode.EarnCode;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class EarnCodeDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements EarnCodeDao {
32
33 @SuppressWarnings("unused")
34 private static final Logger LOG = Logger.getLogger(EarnCodeDaoSpringOjbImpl.class);
35
36 public void saveOrUpdate(EarnCode earnCode) {
37 this.getPersistenceBrokerTemplate().store(earnCode);
38 }
39
40 public void saveOrUpdate(List<EarnCode> earnCodeList) {
41 if (earnCodeList != null) {
42 for (EarnCode earnCode : earnCodeList) {
43 this.getPersistenceBrokerTemplate().store(earnCode);
44 }
45 }
46 }
47
48 public EarnCode getEarnCodeById(String earnCodeId) {
49 Criteria crit = new Criteria();
50 crit.addEqualTo("hrEarnCodeId", earnCodeId);
51 return (EarnCode) this.getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(EarnCode.class, crit));
52 }
53
54 @Override
55 public EarnCode getEarnCode(String earnCode, Date asOfDate) {
56 EarnCode ec = null;
57
58 Criteria root = new Criteria();
59 Criteria effdt = new Criteria();
60 Criteria timestamp = new Criteria();
61
62
63 effdt.addEqualToField("earnCode", Criteria.PARENT_QUERY_PREFIX + "earnCode");
64 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
65
66 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(EarnCode.class, effdt);
67 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
68
69
70 timestamp.addEqualToField("earnCode", Criteria.PARENT_QUERY_PREFIX + "earnCode");
71 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
72
73 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(EarnCode.class, timestamp);
74 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
75
76 root.addEqualTo("earnCode", earnCode);
77 root.addEqualTo("effectiveDate", effdtSubQuery);
78 root.addEqualTo("timestamp", timestampSubQuery);
79
80
81 Criteria activeFilter = new Criteria();
82 activeFilter.addEqualTo("active", true);
83 root.addAndCriteria(activeFilter);
84
85
86 Query query = QueryFactory.newQuery(EarnCode.class, root);
87 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
88
89 if (obj != null) {
90 ec = (EarnCode) obj;
91 }
92
93 return ec;
94 }
95
96 @Override
97 public List<EarnCode> getOvertimeEarnCodes(Date asOfDate) {
98 Criteria root = new Criteria();
99 Criteria effdt = new Criteria();
100 Criteria timestamp = new Criteria();
101
102
103 effdt.addEqualToField("earnCode", Criteria.PARENT_QUERY_PREFIX + "earnCode");
104 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
105
106 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(EarnCode.class, effdt);
107 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
108
109
110 timestamp.addEqualToField("earnCode", Criteria.PARENT_QUERY_PREFIX + "earnCode");
111 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
112
113 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(EarnCode.class, timestamp);
114 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
115
116 root.addEqualTo("ovtEarnCode", "Y");
117 root.addEqualTo("effectiveDate", effdtSubQuery);
118 root.addEqualTo("timestamp", timestampSubQuery);
119
120
121 Criteria activeFilter = new Criteria();
122 activeFilter.addEqualTo("active", true);
123 root.addAndCriteria(activeFilter);
124
125
126 Query query = QueryFactory.newQuery(EarnCode.class, root);
127 List<EarnCode> ovtEarnCodes = (List<EarnCode>)this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
128 return ovtEarnCodes;
129 }
130
131 @Override
132 public int getEarnCodeCount(String earnCode) {
133 Criteria crit = new Criteria();
134 crit.addEqualTo("earnCode", earnCode);
135 Query query = QueryFactory.newQuery(EarnCode.class, crit);
136 return this.getPersistenceBrokerTemplate().getCount(query);
137 }
138
139 @Override
140 public int getNewerEarnCodeCount(String earnCode, Date effdt) {
141 Criteria crit = new Criteria();
142 crit.addEqualTo("earnCode", earnCode);
143 crit.addEqualTo("active", "Y");
144 crit.addGreaterThan("effectiveDate", effdt);
145 Query query = QueryFactory.newQuery(EarnCode.class, crit);
146 return this.getPersistenceBrokerTemplate().getCount(query);
147 }
148 }