1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.paygrade.dao;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
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.joda.time.LocalDate;
26 import org.kuali.kpme.core.paygrade.PayGrade;
27 import org.kuali.kpme.core.util.OjbSubQueryUtil;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30 public class PayGradeDaoObjImpl extends PlatformAwareDaoBaseOjb implements PayGradeDao {
31
32 @Override
33 public PayGrade getPayGrade(String payGrade, String salGroup, LocalDate asOfDate) {
34 Criteria root = new Criteria();
35
36 root.addEqualTo("payGrade", payGrade);
37 root.addEqualTo("salGroup", salGroup);
38 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PayGrade.class, asOfDate, PayGrade.EQUAL_TO_FIELDS, false));
39 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, PayGrade.EQUAL_TO_FIELDS, false));
40
41 Criteria activeFilter = new Criteria();
42 activeFilter.addEqualTo("active", true);
43 root.addAndCriteria(activeFilter);
44
45
46 Query query = QueryFactory.newQuery(PayGrade.class, root);
47
48 PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
49
50 return pg;
51 }
52
53 @Override
54 public PayGrade getPayGrade(String hrPayGradeId) {
55 Criteria crit = new Criteria();
56 crit.addEqualTo("hrPayGradeId", hrPayGradeId);
57
58 Query query = QueryFactory.newQuery(PayGrade.class, crit);
59
60 return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
61 }
62
63 public int getPayGradeCount(String payGrade) {
64 Criteria crit = new Criteria();
65 crit.addEqualTo("payGrade", payGrade);
66 Query query = QueryFactory.newQuery(PayGrade.class, crit);
67 return this.getPersistenceBrokerTemplate().getCount(query);
68 }
69
70 @Override
71 @SuppressWarnings("unchecked")
72 public List<PayGrade> getPayGrades(String payGrade, String payGradeDescr, String salGroup, String active, String showHistory) {
73 List<PayGrade> results = new ArrayList<PayGrade>();
74
75 Criteria root = new Criteria();
76
77 if (StringUtils.isNotBlank(payGrade)) {
78 root.addLike("UPPER(`pay_grade`)", payGrade.toUpperCase());
79 }
80
81 if (StringUtils.isNotBlank(payGradeDescr)) {
82 root.addLike("UPPER(`description`)", payGradeDescr.toUpperCase());
83 }
84
85
86 if (StringUtils.isNotBlank(salGroup)) {
87 root.addLike("UPPER(`sal_group`)", salGroup.toUpperCase());
88 }
89
90 if (StringUtils.isNotBlank(active)) {
91 Criteria activeFilter = new Criteria();
92 if (StringUtils.equals(active, "Y")) {
93 activeFilter.addEqualTo("active", true);
94 } else if (StringUtils.equals(active, "N")) {
95 activeFilter.addEqualTo("active", false);
96 }
97 root.addAndCriteria(activeFilter);
98 }
99
100 if (StringUtils.equals(showHistory, "N")) {
101 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithoutFilter(PayGrade.class, PayGrade.EQUAL_TO_FIELDS, false));
102 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, PayGrade.EQUAL_TO_FIELDS, false));
103 }
104
105 Query query = QueryFactory.newQuery(PayGrade.class, root);
106 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
107
108 return results;
109 }
110
111 @Override
112 @SuppressWarnings("unchecked")
113 public List<PayGrade> getPayGradesForSalaryGroup(String salaryGroup,
114 LocalDate asOfDate) {
115 List<PayGrade> results = new ArrayList<PayGrade>();
116
117 Criteria root = new Criteria();
118
119 root.addEqualTo("salGroup", salaryGroup);
120 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PayGrade.class, asOfDate, PayGrade.EQUAL_TO_FIELDS, false));
121 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PayGrade.class, PayGrade.EQUAL_TO_FIELDS, false));
122
123 Criteria activeFilter = new Criteria();
124 activeFilter.addEqualTo("active", true);
125 root.addAndCriteria(activeFilter);
126
127
128 Query query = QueryFactory.newQuery(PayGrade.class, root);
129
130 results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
131
132 return results;
133 }
134
135 }