View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  //		effdt.addEqualTo("active", true);
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  //		timestamp.addEqualTo("active", true);
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  //		root.addEqualTo("active", true);
61  
62  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
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  }