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.paygrade.dao;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.ojb.broker.query.Criteria;
24  import org.apache.ojb.broker.query.Query;
25  import org.apache.ojb.broker.query.QueryFactory;
26  import org.apache.ojb.broker.query.ReportQueryByCriteria;
27  import org.kuali.hr.paygrade.PayGrade;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  
30  public class PayGradeDaoSpringObjImpl  extends PlatformAwareDaoBaseOjb implements PayGradeDao {
31  
32  	@Override
33  	public PayGrade getPayGrade(String payGrade, Date asOfDate) {
34  		Criteria root = new Criteria();
35  		Criteria effdt = new Criteria();
36  		Criteria timestamp = new Criteria();
37  
38  		effdt.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
39  		effdt.addLessOrEqualThan("effectiveDate", asOfDate);
40  		ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(PayGrade.class, effdt);
41  		effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
42  
43  		timestamp.addEqualToField("payGrade", Criteria.PARENT_QUERY_PREFIX + "payGrade");
44  		timestamp.addEqualToField("effectiveDate", Criteria.PARENT_QUERY_PREFIX + "effectiveDate");
45  
46  		ReportQueryByCriteria timestampSubQuery = QueryFactory.newReportQuery(PayGrade.class, timestamp);
47  		timestampSubQuery.setAttributes(new String[] { "max(timestamp)" });
48  
49  		root.addEqualTo("payGrade", payGrade);
50  		root.addEqualTo("effectiveDate", effdtSubQuery);
51  		root.addEqualTo("timestamp", timestampSubQuery);
52  
53  		Criteria activeFilter = new Criteria(); // Inner Join For Activity
54  		activeFilter.addEqualTo("active", true);
55  		root.addAndCriteria(activeFilter);
56  
57  		
58  		Query query = QueryFactory.newQuery(PayGrade.class, root);
59  		
60  		PayGrade pg = (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
61  		
62  		return pg;
63  	}
64  
65  	@Override
66  	public PayGrade getPayGrade(String hrPayGradeId) {
67  		Criteria crit = new Criteria();
68  		crit.addEqualTo("hrPayGradeId", hrPayGradeId);
69  		
70  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
71  		
72  		return (PayGrade)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
73  	}
74  	
75  	public int getPayGradeCount(String payGrade) {
76  		Criteria crit = new Criteria();
77  		crit.addEqualTo("payGrade", payGrade);
78  		Query query = QueryFactory.newQuery(PayGrade.class, crit);
79  		return this.getPersistenceBrokerTemplate().getCount(query);
80  	}
81  
82  	@Override
83      @SuppressWarnings("unchecked")
84      public List<PayGrade> getPayGrades(String payGrade, String payGradeDescr, String active) {
85          List<PayGrade> results = new ArrayList<PayGrade>();
86      	
87      	Criteria root = new Criteria();
88  
89          if (StringUtils.isNotBlank(payGrade)) {
90              root.addLike("payGrade", payGrade);
91          }
92          
93          if (StringUtils.isNotBlank(payGradeDescr)) {
94              root.addLike("description", payGradeDescr);
95          }
96          
97          if (StringUtils.isNotBlank(active)) {
98          	Criteria activeFilter = new Criteria();
99              if (StringUtils.equals(active, "Y")) {
100                 activeFilter.addEqualTo("active", true);
101             } else if (StringUtils.equals(active, "N")) {
102                 activeFilter.addEqualTo("active", false);
103             }
104             root.addAndCriteria(activeFilter);
105         }
106         
107         Query query = QueryFactory.newQuery(PayGrade.class, root);
108         results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query));
109 
110         return results;
111     }
112 
113 }