1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.earncodegroup.dao;
17
18 import java.sql.Date;
19
20 import com.google.common.collect.ImmutableList;
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.core.util.OjbSubQueryUtil;
26 import org.kuali.hr.time.earncode.EarnCode;
27 import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
28 import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class EarnCodeGroupDaoServiceImpl extends PlatformAwareDaoBaseOjb implements EarnCodeGroupDaoService {
32 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
33 .add("earnCodeGroup")
34 .build();
35
36 @Override
37 public EarnCodeGroup getEarnCodeGroup(String earnGroup, Date asOfDate) {
38 Criteria root = new Criteria();
39
40 root.addEqualTo("earnCodeGroup", earnGroup);
41 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
42 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
43
44
45
46 Criteria activeFilter = new Criteria();
47 activeFilter.addEqualTo("active", true);
48 root.addAndCriteria(activeFilter);
49
50 Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
51 EarnCodeGroup earnGroupObj = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
52 return earnGroupObj;
53 }
54
55 @Override
56 public EarnCodeGroup getEarnCodeGroupSummaryForEarnCode(String earnCode, Date asOfDate) {
57 Criteria root = new Criteria();
58 Criteria earnCodeJoin = new Criteria();
59
60 earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
61 earnCodeJoin.addEqualTo("earnCode", earnCode);
62 ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
63 earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
64
65 root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
66 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
67 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
68
69 root.addEqualTo("showSummary", true);
70
71 Criteria activeFilter = new Criteria();
72 activeFilter.addEqualTo("active", true);
73 root.addAndCriteria(activeFilter);
74
75 Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
76 EarnCodeGroup earnGroupObj = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
77 return earnGroupObj;
78 }
79
80 @Override
81 public EarnCodeGroup getEarnCodeGroupForEarnCode(String earnCode, Date asOfDate) {
82 Criteria root = new Criteria();
83 Criteria earnCodeJoin = new Criteria();
84
85 earnCodeJoin.addEqualToField("hrEarnCodeGroupId", Criteria.PARENT_QUERY_PREFIX + "hrEarnCodeGroupId");
86 earnCodeJoin.addEqualTo("earnCode", earnCode);
87 ReportQueryByCriteria earnCodeSubQuery = QueryFactory.newReportQuery(EarnCodeGroupDefinition.class, earnCodeJoin);
88 earnCodeSubQuery.setAttributes(new String[]{"hr_earn_code_group_id"});
89
90 root.addEqualTo("hrEarnCodeGroupId",earnCodeSubQuery);
91 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(EarnCodeGroup.class, asOfDate, EQUAL_TO_FIELDS, false));
92 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(EarnCodeGroup.class, EQUAL_TO_FIELDS, false));
93
94
95 Criteria activeFilter = new Criteria();
96 activeFilter.addEqualTo("active", true);
97 root.addAndCriteria(activeFilter);
98
99 Query query = QueryFactory.newQuery(EarnCodeGroup.class, root);
100 EarnCodeGroup earnGroupObj = (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
101 return earnGroupObj;
102 }
103
104 @Override
105 public EarnCodeGroup getEarnCodeGroup(String hrEarnCodeGroupId) {
106 Criteria crit = new Criteria();
107 crit.addEqualTo("hrEarnCodeGroupId", hrEarnCodeGroupId);
108
109 Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
110 return (EarnCodeGroup)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
111 }
112
113 @Override
114 public int getEarnCodeGroupCount(String earnCodeGroup) {
115 Criteria crit = new Criteria();
116 crit.addEqualTo("earnCodeGroup", earnCodeGroup);
117 Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
118 return this.getPersistenceBrokerTemplate().getCount(query);
119 }
120 @Override
121 public int getNewerEarnCodeGroupCount(String earnCodeGroup, Date effdt) {
122 Criteria crit = new Criteria();
123 crit.addEqualTo("earnCodeGroup", earnCodeGroup);
124 crit.addEqualTo("active", "Y");
125 crit.addGreaterThan("effectiveDate", effdt);
126 Query query = QueryFactory.newQuery(EarnCodeGroup.class, crit);
127 return this.getPersistenceBrokerTemplate().getCount(query);
128 }
129 }