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 com.google.common.collect.ImmutableList;
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.Query;
24 import org.apache.ojb.broker.query.QueryFactory;
25 import org.apache.ojb.broker.query.ReportQueryByCriteria;
26 import org.kuali.hr.core.util.OjbSubQueryUtil;
27 import org.kuali.hr.time.overtime.daily.rule.DailyOvertimeRule;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class DailyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements DailyOvertimeRuleDao {
31 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
32 .add("location")
33 .add("payType")
34 .add("dept")
35 .add("workArea")
36 .build();
37
38 @Override
39 public DailyOvertimeRule findDailyOvertimeRule(String location, String paytype, String dept, Long workArea, Date asOfDate) {
40 DailyOvertimeRule dailyOvertimeRule;
41
42 Criteria root = new Criteria();
43 java.sql.Date effDate = null;
44 if (asOfDate != null) {
45 effDate = new java.sql.Date(asOfDate.getTime());
46 }
47 root.addEqualTo("dept", dept);
48 root.addEqualTo("workArea", workArea);
49 root.addEqualTo("location", location);
50 root.addEqualTo("paytype", paytype);
51 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(DailyOvertimeRule.class, effDate, EQUAL_TO_FIELDS, false));
52 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(DailyOvertimeRule.class, EQUAL_TO_FIELDS, false));
53
54 Criteria activeFilter = new Criteria();
55 activeFilter.addEqualTo("active", true);
56 root.addAndCriteria(activeFilter);
57
58
59 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, root);
60 dailyOvertimeRule = (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
61
62 return dailyOvertimeRule;
63 }
64
65 @Override
66 public void saveOrUpdate(DailyOvertimeRule dailyOvertimeRule) {
67 this.getPersistenceBrokerTemplate().store(dailyOvertimeRule);
68 }
69
70 @Override
71 public void saveOrUpdate(List<DailyOvertimeRule> dailyOvertimeRules) {
72 for (DailyOvertimeRule dor : dailyOvertimeRules) {
73 saveOrUpdate(dor);
74 }
75 }
76
77 @Override
78 public DailyOvertimeRule getDailyOvertimeRule(String tkDailyOvertimeRuleId) {
79 Criteria crit = new Criteria();
80 crit.addEqualTo("tkDailyOvertimeRuleId", tkDailyOvertimeRuleId);
81
82 Query query = QueryFactory.newQuery(DailyOvertimeRule.class, crit);
83 return (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
84 }
85
86 }