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