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