1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.dept.lunch.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.dept.lunch.DeptLunchRule;
25 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26
27 public class DepartmentLunchRuleDaoImpl extends PlatformAwareDaoBaseOjb implements DepartmentLunchRuleDao {
28
29 @Override
30 public DeptLunchRule getDepartmentLunchRule(String dept, Long workArea, String principalId,
31 Long jobNumber, Date asOfDate) {
32 Criteria root = new Criteria();
33 Criteria effdt = new Criteria();
34 Criteria timestamp = new Criteria();
35
36 effdt.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
37 effdt.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
38 effdt.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
39 effdt.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
40 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
41
42 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(DeptLunchRule.class, effdt);
43 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
44
45 timestamp.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
46 timestamp.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
47 timestamp.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
48 timestamp.addEqualToField("jobNumber", Criteria.PARENT_QUERY_PREFIX + "jobNumber");
49 timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
50
51 ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(DeptLunchRule.class, timestamp);
52 timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
53
54 root.addEqualTo("dept", dept);
55 root.addEqualTo("workArea", workArea);
56 root.addEqualTo("principalId", principalId);
57 root.addEqualTo("jobNumber", jobNumber);
58 root.addEqualTo("effectiveDate", effdtSubQuery);
59 root.addEqualTo("timestamp", timestampSubQuery);
60
61
62 Criteria activeFilter = new Criteria();
63 activeFilter.addEqualTo("active", true);
64 root.addAndCriteria(activeFilter);
65
66
67 Query query = QueryFactory.newQuery(DeptLunchRule.class, root);
68 return (DeptLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
69
70
71 }
72
73 @Override
74 public DeptLunchRule getDepartmentLunchRule(String tkDeptLunchRuleId) {
75 Criteria crit = new Criteria();
76 crit.addEqualTo("tkDeptLunchRuleId", tkDeptLunchRuleId);
77
78 Query query = QueryFactory.newQuery(DeptLunchRule.class, crit);
79 return (DeptLunchRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
80 }
81
82 }