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.graceperiod.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.graceperiod.rule.GracePeriodRule;
25  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26  
27  public class GracePeriodDaoImpl extends PlatformAwareDaoBaseOjb implements GracePeriodDao {
28  	public GracePeriodRule getGracePeriodRule(Date asOfDate){
29  		GracePeriodRule gracePeriodRule = null;
30  		
31  		Criteria root = new Criteria();
32  		Criteria effdt = new Criteria();
33  		Criteria timestamp = new Criteria();
34  
35  		// OJB's awesome sub query setup part 1
36  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37  //		effdt.addEqualTo("active", true);
38  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, effdt);
39  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
40  
41  		// OJB's awesome sub query setup part 2
42  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
43  //		timestamp.addEqualTo("active", true);
44  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(GracePeriodRule.class, timestamp);
45  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
46  
47  		root.addEqualTo("effectiveDate", effdtSubQuery);
48  		root.addEqualTo("timestamp", timestampSubQuery);
49  
50  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
51  		activeFilter.addEqualTo("active", true);
52  		root.addAndCriteria(activeFilter);
53  		
54  		
55  		Query query = QueryFactory.newQuery(GracePeriodRule.class, root);
56  		Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
57  
58  		if (obj != null) {
59  			gracePeriodRule = (GracePeriodRule) obj;
60  		}
61  		
62  		return gracePeriodRule;
63  	}
64  
65  	@Override
66  	public GracePeriodRule getGracePeriodRule(String tkGracePeriodId) {
67  		Criteria crit = new Criteria();
68  		crit.addEqualTo("tkGracePeriodRuleId", tkGracePeriodId);
69  		
70  		Query query = QueryFactory.newQuery(GracePeriodRule.class, crit);
71  		return (GracePeriodRule)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
72  	}
73  }