View Javadoc

1   /**
2    * Copyright 2004-2013 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.weekly.rule.dao;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.List;
22  
23  import org.apache.ojb.broker.query.Criteria;
24  import org.apache.ojb.broker.query.Query;
25  import org.apache.ojb.broker.query.QueryByCriteria;
26  import org.apache.ojb.broker.query.QueryFactory;
27  import org.apache.ojb.broker.query.ReportQueryByCriteria;
28  import org.kuali.hr.time.overtime.weekly.rule.WeeklyOvertimeRule;
29  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30  
31  public class WeeklyOvertimeRuleDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements WeeklyOvertimeRuleDao {
32  
33  	@SuppressWarnings("unchecked")
34  	@Override
35  	public List<WeeklyOvertimeRule> findWeeklyOvertimeRules(Date asOfDate) {
36  		List<WeeklyOvertimeRule> list = new ArrayList<WeeklyOvertimeRule>();
37  
38  		Criteria root = new Criteria();
39  		Criteria effdt = new Criteria();
40  		Criteria timestamp = new Criteria();
41  		
42  		effdt.addEqualToField("convertFromEarnGroup", Criteria.PARENT_QUERY_PREFIX + "convertFromEarnGroup");
43  		effdt.addEqualToField("convertToEarnCode", Criteria.PARENT_QUERY_PREFIX + "convertToEarnCode");
44  		effdt.addEqualToField("maxHoursEarnGroup", Criteria.PARENT_QUERY_PREFIX + "maxHoursEarnGroup");
45  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
46  //		effdt.addEqualTo("active", true);
47  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(WeeklyOvertimeRule.class, effdt);
48  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
49  
50  		timestamp.addEqualToField("convertFromEarnGroup", Criteria.PARENT_QUERY_PREFIX + "convertFromEarnGroup");
51  		timestamp.addEqualToField("convertToEarnCode", Criteria.PARENT_QUERY_PREFIX + "convertToEarnCode");
52  		timestamp.addEqualToField("maxHoursEarnGroup", Criteria.PARENT_QUERY_PREFIX + "maxHoursEarnGroup");
53  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
54  //		timestamp.addEqualTo("active", true);
55  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(WeeklyOvertimeRule.class, timestamp);
56  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
57  
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  		QueryByCriteria query = new QueryByCriteria(WeeklyOvertimeRule.class, root);
67  		query.addOrderByAscending("step");
68  
69  		Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
70  		
71  		if (c != null) {
72  			list.addAll(c);
73  		}
74  				
75  		return list;
76  	}
77  
78  	@Override
79  	public void saveOrUpdate(WeeklyOvertimeRule weeklyOvertimeRule) {
80  		this.getPersistenceBrokerTemplate().store(weeklyOvertimeRule);
81  	}
82  
83  	@Override
84  	public void saveOrUpdate(List<WeeklyOvertimeRule> weeklyOvertimeRules) {
85  		for (WeeklyOvertimeRule wor : weeklyOvertimeRules) {
86  			saveOrUpdate(wor);
87  		}
88  	}
89  
90  	@Override
91  	public WeeklyOvertimeRule getWeeklyOvertimeRule(String tkWeeklyOvertimeRuleId) {
92  		Criteria crit = new Criteria();
93  		crit.addEqualTo("tkWeeklyOvertimeRuleId", tkWeeklyOvertimeRuleId);
94  		
95  		Query query = QueryFactory.newQuery(WeeklyOvertimeRule.class, crit);
96  		return (WeeklyOvertimeRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
97  	}
98  
99  }