1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.overtime.weekly.rule.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.QueryByCriteria;
26 import org.apache.ojb.broker.query.QueryFactory;
27 import org.apache.ojb.broker.query.ReportQueryByCriteria;
28 import org.kuali.hr.time.overtime.weekly.rule.WeeklyOvertimeRule;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class WeeklyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements WeeklyOvertimeRuleDao {
32
33 @SuppressWarnings("unchecked")
34 @Override
35 public List<WeeklyOvertimeRule> findWeeklyOvertimeRules(Date asOfDate) {
36 List<WeeklyOvertimeRule> list = new ArrayList<WeeklyOvertimeRule>();
37
38 Criteria root = new Criteria();
39 Criteria effdt = new Criteria();
40 Criteria timestamp = new Criteria();
41
42 effdt.addEqualToField("convertFromEarnGroup", Criteria.PARENT_QUERY_PREFIX + "convertFromEarnGroup");
43 effdt.addEqualToField("convertToEarnCode", Criteria.PARENT_QUERY_PREFIX + "convertToEarnCode");
44 effdt.addEqualToField("maxHoursEarnGroup", Criteria.PARENT_QUERY_PREFIX + "maxHoursEarnGroup");
45 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
46
47 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(WeeklyOvertimeRule.class, effdt);
48 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
49
50 timestamp.addEqualToField("convertFromEarnGroup", Criteria.PARENT_QUERY_PREFIX + "convertFromEarnGroup");
51 timestamp.addEqualToField("convertToEarnCode", Criteria.PARENT_QUERY_PREFIX + "convertToEarnCode");
52 timestamp.addEqualToField("maxHoursEarnGroup", Criteria.PARENT_QUERY_PREFIX + "maxHoursEarnGroup");
53 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
54
55 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(WeeklyOvertimeRule.class, timestamp);
56 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
57
58 root.addEqualTo("effectiveDate", effdtSubQuery);
59 root.addEqualTo("timestamp", timestampSubQuery);
60
61
62 Criteria activeFilter = new Criteria();
63 activeFilter.addEqualTo("active", true);
64 root.addAndCriteria(activeFilter);
65
66 QueryByCriteria query = new QueryByCriteria(WeeklyOvertimeRule.class, root);
67 query.addOrderByAscending("step");
68
69 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
70
71 if (c != null) {
72 list.addAll(c);
73 }
74
75 return list;
76 }
77
78 @Override
79 public void saveOrUpdate(WeeklyOvertimeRule weeklyOvertimeRule) {
80 this.getPersistenceBrokerTemplate().store(weeklyOvertimeRule);
81 }
82
83 @Override
84 public void saveOrUpdate(List<WeeklyOvertimeRule> weeklyOvertimeRules) {
85 for (WeeklyOvertimeRule wor : weeklyOvertimeRules) {
86 saveOrUpdate(wor);
87 }
88 }
89
90 @Override
91 public WeeklyOvertimeRule getWeeklyOvertimeRule(String tkWeeklyOvertimeRuleId) {
92 Criteria crit = new Criteria();
93 crit.addEqualTo("tkWeeklyOvertimeRuleId", tkWeeklyOvertimeRuleId);
94
95 Query query = QueryFactory.newQuery(WeeklyOvertimeRule.class, crit);
96 return (WeeklyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
97 }
98
99 }