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.overtime.daily.rule.dao;
17  
18  import java.util.Date;
19  import java.util.List;
20  
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.Query;
23  import org.apache.ojb.broker.query.QueryFactory;
24  import org.apache.ojb.broker.query.ReportQueryByCriteria;
25  import org.kuali.hr.time.overtime.daily.rule.DailyOvertimeRule;
26  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
27  
28  public class DailyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements DailyOvertimeRuleDao {
29  
30  	@Override
31  	public DailyOvertimeRule findDailyOvertimeRule(String location, String paytype, String dept, Long workArea, Date asOfDate) {
32  		DailyOvertimeRule dailyOvertimeRule;
33  
34  		Criteria root = new Criteria();
35  		Criteria effdt = new Criteria();
36  		Criteria timestamp = new Criteria();
37  
38  		effdt.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
39  		effdt.addEqualToField("paytype", Criteria.PARENT_QUERY_PREFIX + "paytype");
40  		effdt.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
41  		effdt.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
42  		
43  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
44  		//effdt.addEqualTo("active", true);
45  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(DailyOvertimeRule.class, effdt);
46  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
47  
48  		timestamp.addEqualToField("location", Criteria.PARENT_QUERY_PREFIX + "location");
49  		timestamp.addEqualToField("paytype", Criteria.PARENT_QUERY_PREFIX + "paytype");
50  		timestamp.addEqualToField("dept", Criteria.PARENT_QUERY_PREFIX + "dept");
51  		timestamp.addEqualToField("workArea", Criteria.PARENT_QUERY_PREFIX + "workArea");
52  		
53  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
54  		//timestamp.addEqualTo("active", true);
55  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(DailyOvertimeRule.class, timestamp);
56  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
57  
58  		root.addEqualTo("dept", dept);
59  		root.addEqualTo("workArea", workArea);
60  		root.addEqualTo("location", location);
61  		root.addEqualTo("paytype", paytype);
62  		root.addEqualTo("effectiveDate", effdtSubQuery);
63  		root.addEqualTo("timestamp", timestampSubQuery);
64  		//root.addEqualTo("active", true);
65  
66  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
67  		activeFilter.addEqualTo("active", true);
68  		root.addAndCriteria(activeFilter);
69  
70  		
71  		Query query = QueryFactory.newQuery(DailyOvertimeRule.class, root);
72  		dailyOvertimeRule = (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
73  		
74  		return dailyOvertimeRule;
75  	}
76  
77  	@Override
78  	public void saveOrUpdate(DailyOvertimeRule dailyOvertimeRule) {
79  		this.getPersistenceBrokerTemplate().store(dailyOvertimeRule);
80  	}
81  
82  	@Override
83  	public void saveOrUpdate(List<DailyOvertimeRule> dailyOvertimeRules) {
84  		for (DailyOvertimeRule dor : dailyOvertimeRules) {
85  			saveOrUpdate(dor);
86  		}
87  	}
88  
89  	@Override
90  	public DailyOvertimeRule getDailyOvertimeRule(String tkDailyOvertimeRuleId) {
91  		Criteria crit = new Criteria();
92  		crit.addEqualTo("tkDailyOvertimeRuleId", tkDailyOvertimeRuleId);
93  		
94  		Query query = QueryFactory.newQuery(DailyOvertimeRule.class, crit);
95  		return (DailyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
96  	}
97  
98  }