1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.syslunch.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.syslunch.rule.SystemLunchRule;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26
27 public class SystemLunchRuleDaoImpl extends PlatformAwareDaoBaseOjb implements SystemLunchRuleDao {
28
29 @Override
30 public SystemLunchRule getSystemLunchRule(Date asOfDate) {
31 Criteria root = new Criteria();
32 Criteria effdt = new Criteria();
33 Criteria timestamp = new Criteria();
34
35
36 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, effdt);
38 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
39
40
41 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
42 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(SystemLunchRule.class, timestamp);
43 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
44
45 root.addEqualTo("effectiveDate", effdtSubQuery);
46 root.addEqualTo("timestamp", timestampSubQuery);
47
48 Criteria activeFilter = new Criteria();
49 activeFilter.addEqualTo("active", true);
50 root.addAndCriteria(activeFilter);
51
52 Query query = QueryFactory.newQuery(SystemLunchRule.class, root);
53 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
54 }
55
56 @Override
57 public SystemLunchRule getSystemLunchRule(String tkSystemLunchRuleId) {
58 Criteria crit = new Criteria();
59 crit.addEqualTo("tkSystemLunchRuleId", tkSystemLunchRuleId);
60
61 Query query = QueryFactory.newQuery(SystemLunchRule.class, crit);
62
63 return (SystemLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
64 }
65
66 }