1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.graceperiod.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.time.graceperiod.rule.GracePeriodRule;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26
27 public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao {
28 public GracePeriodRule getGracePeriodRule(Date asOfDate){
29 GracePeriodRule gracePeriodRule = null;
30
31 Criteria root = new Criteria();
32 Criteria effdt = new Criteria();
33 Criteria timestamp = new Criteria();
34
35
36 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37
38 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, effdt);
39 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
40
41
42 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
43
44 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, timestamp);
45 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
46
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(GracePeriodRule.class, root);
56 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
57
58 if (obj != null) {
59 gracePeriodRule = (GracePeriodRule) obj;
60 }
61
62 return gracePeriodRule;
63 }
64
65 @Override
66 public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
67 Criteria crit = new Criteria();
68 crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId);
69
70 Query query = QueryFactory.newQuery(GracePeriodRule.class, crit);
71 return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
72 }
73 }