1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.overtime.daily.rule.dao;
17
18 import java.util.Date;
19 import java.util.List;
20
21 import org.apache.ojb.broker.query.Criteria;
22 import org.apache.ojb.broker.query.Query;
23 import org.apache.ojb.broker.query.QueryFactory;
24 import org.apache.ojb.broker.query.ReportQueryByCriteria;
25 import org.kuali.hr.time.overtime.daily.rule.DailyOvertimeRule;
26 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
27
28 public class DailyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements DailyOvertimeRuleDao {
29
30 @Override
31 public DailyOvertimeRule findDailyOvertimeRule(String location, String paytype, String dept, Long workArea, Date asOfDate) {
32 DailyOvertimeRule dailyOvertimeRule;
33
34 Criteria root = new Criteria();
35 Criteria effdt = new Criteria();
36 Criteria timestamp = new Criteria();
37
38 effdt.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
39 effdt.addEqualToField("paytype", Criteria.PARENT_QUERY_PREFIX + "paytype");
40 effdt.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
41 effdt.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
42
43 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
44
45 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(DailyOvertimeRule.class, effdt);
46 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
47
48 timestamp.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
49 timestamp.addEqualToField("paytype", Criteria.PARENT_QUERY_PREFIX + "paytype");
50 timestamp.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
51 timestamp.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
52
53 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
54
55 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(DailyOvertimeRule.class, timestamp);
56 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
57
58 root.addEqualTo("dept", dept);
59 root.addEqualTo("workArea", workArea);
60 root.addEqualTo("location", location);
61 root.addEqualTo("paytype", paytype);
62 root.addEqualTo("effectiveDate", effdtSubQuery);
63 root.addEqualTo("timestamp", timestampSubQuery);
64
65
66 Criteria activeFilter = new Criteria();
67 activeFilter.addEqualTo("active", true);
68 root.addAndCriteria(activeFilter);
69
70
71 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, root);
72 dailyOvertimeRule = (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
73
74 return dailyOvertimeRule;
75 }
76
77 @Override
78 public void saveOrUpdate(DailyOvertimeRule dailyOvertimeRule) {
79 this.getPersistenceBrokerTemplate().store(dailyOvertimeRule);
80 }
81
82 @Override
83 public void saveOrUpdate(List<DailyOvertimeRule> dailyOvertimeRules) {
84 for (DailyOvertimeRule dor : dailyOvertimeRules) {
85 saveOrUpdate(dor);
86 }
87 }
88
89 @Override
90 public DailyOvertimeRule getDailyOvertimeRule(String tkDailyOvertimeRuleId) {
91 Criteria crit = new Criteria();
92 crit.addEqualTo("tkDailyOvertimeRuleId", tkDailyOvertimeRuleId);
93
94 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, crit);
95 return (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
96 }
97
98 }