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.paygrade.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.paygrade.PayGrade;
25  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
26  
27  public class PayGradeDaoSpringObjImpl  extends PlatformAwareDaoBaseOjb implements PayGradeDao {
28  
29  	@Override
30  	public PayGrade getPayGrade(String payGrade, Date asOfDate) {
31  		Criteria root = new Criteria();
32  		Criteria effdt = new Criteria();
33  		Criteria timestamp = new Criteria();
34  
35  		effdt.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
36  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
37  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(PayGrade.class, effdt);
38  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
39  
40  		timestamp.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
41  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
42  
43  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(PayGrade.class, timestamp);
44  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
45  
46  		root.addEqualTo("payGrade", payGrade);
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(PayGrade.class, root);
56  		
57  		PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
58  		
59  		return pg;
60  	}
61  
62  	@Override
63  	public PayGrade getPayGrade(String hrPayGradeId) {
64  		Criteria crit = new Criteria();
65  		crit.addEqualTo("hrPayGradeId", hrPayGradeId);
66  		
67  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
68  		
69  		return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
70  	}
71  	
72  	public int getPayGradeCount(String payGrade) {
73  		Criteria crit = new Criteria();
74  		crit.addEqualTo("payGrade", payGrade);
75  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
76  		return this.getPersistenceBrokerTemplate().getCount(query);
77  	}
78  
79  }