1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.paygrade.dao;
17
18 import java.sql.Date;
19
20 import org.apache.ojb.broker.query.Criteria;
21 import org.apache.ojb.broker.query.Query;
22 import org.apache.ojb.broker.query.QueryFactory;
23 import org.apache.ojb.broker.query.ReportQueryByCriteria;
24 import org.kuali.hr.paygrade.PayGrade;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26
27 public class PayGradeDaoSpringObjImpl extends PlatformAwareDaoBaseOjb implements PayGradeDao {
28
29 @Override
30 public PayGrade getPayGrade(String payGrade, Date asOfDate) {
31 Criteria root = new Criteria();
32 Criteria effdt = new Criteria();
33 Criteria timestamp = new Criteria();
34
35 effdt.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
36 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(PayGrade.class, effdt);
38 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
39
40 timestamp.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
41 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
42
43 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(PayGrade.class, timestamp);
44 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
45
46 root.addEqualTo("payGrade", payGrade);
47 root.addEqualTo("effectiveDate", effdtSubQuery);
48 root.addEqualTo("timestamp", timestampSubQuery);
49
50 Criteria activeFilter = new Criteria();
51 activeFilter.addEqualTo("active", true);
52 root.addAndCriteria(activeFilter);
53
54
55 Query query = QueryFactory.newQuery(PayGrade.class, root);
56
57 PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
58
59 return pg;
60 }
61
62 @Override
63 public PayGrade getPayGrade(String hrPayGradeId) {
64 Criteria crit = new Criteria();
65 crit.addEqualTo("hrPayGradeId", hrPayGradeId);
66
67 Query query = QueryFactory.newQuery(PayGrade.class, crit);
68
69 return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
70 }
71
72 public int getPayGradeCount(String payGrade) {
73 Criteria crit = new Criteria();
74 crit.addEqualTo("payGrade", payGrade);
75 Query query = QueryFactory.newQuery(PayGrade.class, crit);
76 return this.getPersistenceBrokerTemplate().getCount(query);
77 }
78
79 }