1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.tklm.time.rules.overtime.weekly.dao;
17
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.Query;
24 import org.apache.ojb.broker.query.QueryByCriteria;
25 import org.apache.ojb.broker.query.QueryFactory;
26 import org.joda.time.LocalDate;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 import com.google.common.collect.ImmutableList;
32
33 public class WeeklyOvertimeRuleDaoOjbImpl extends PlatformAwareDaoBaseOjb implements WeeklyOvertimeRuleDao {
34
35 @SuppressWarnings("unchecked")
36 @Override
37 public List<WeeklyOvertimeRule> findWeeklyOvertimeRules(LocalDate asOfDate) {
38 List<WeeklyOvertimeRule> list = new ArrayList<WeeklyOvertimeRule>();
39
40 Criteria root = new Criteria();
41
42 ImmutableList<String> fields = new ImmutableList.Builder<String>()
43 .add("convertFromEarnGroup")
44 .add("convertToEarnCode")
45 .add("maxHoursEarnGroup")
46 .build();
47 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(WeeklyOvertimeRule.class, asOfDate, fields, false));
48 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(WeeklyOvertimeRule.class, fields, false));
49
50
51 Criteria activeFilter = new Criteria();
52 activeFilter.addEqualTo("active", true);
53 root.addAndCriteria(activeFilter);
54
55 QueryByCriteria query = new QueryByCriteria(WeeklyOvertimeRule.class, root);
56 query.addOrderByAscending("step");
57
58 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
59
60 if (c != null) {
61 list.addAll(c);
62 }
63
64 return list;
65 }
66
67 @Override
68 public void saveOrUpdate(WeeklyOvertimeRule weeklyOvertimeRule) {
69 this.getPersistenceBrokerTemplate().store(weeklyOvertimeRule);
70 }
71
72 @Override
73 public void saveOrUpdate(List<WeeklyOvertimeRule> weeklyOvertimeRules) {
74 for (WeeklyOvertimeRule wor : weeklyOvertimeRules) {
75 saveOrUpdate(wor);
76 }
77 }
78
79 @Override
80 public WeeklyOvertimeRule getWeeklyOvertimeRule(String tkWeeklyOvertimeRuleId) {
81 Criteria crit = new Criteria();
82 crit.addEqualTo("tkWeeklyOvertimeRuleId", tkWeeklyOvertimeRuleId);
83
84 Query query = QueryFactory.newQuery(WeeklyOvertimeRule.class, crit);
85 return (WeeklyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
86 }
87
88 }