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.lm.leaveadjustment.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 edu.emory.mathcs.backport.java.util.Collections;
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.lm.leaveadjustment.LeaveAdjustment;
30  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31  
32  public class LeaveAdjustmentDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveAdjustmentDao{
33  
34  	@SuppressWarnings("unchecked")
35  	@Override
36  	public List<LeaveAdjustment> getLeaveAdjustments(String principalId, Date asOfDate) {
37          List<LeaveAdjustment> leaveAdjustments = new ArrayList<LeaveAdjustment>();
38          Criteria root = new Criteria();
39  
40          java.sql.Date effDate = asOfDate == null ? null : new java.sql.Date(asOfDate.getTime());
41          root.addEqualTo("principalId", principalId);
42          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(LeaveAdjustment.class, effDate, Collections.singletonList("principalId"), false));
43          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveAdjustment.class, Collections.singletonList("principalId"), false));
44  
45          Criteria activeFilter = new Criteria(); // Inner Join For Activity
46          activeFilter.addEqualTo("active", true);
47          root.addAndCriteria(activeFilter);
48  
49          Query query = QueryFactory.newQuery(LeaveAdjustment.class, root);
50          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
51  
52          if (c != null) {
53          	leaveAdjustments.addAll(c);
54          }
55          return leaveAdjustments;
56      }
57  
58  	@Override
59  	public LeaveAdjustment getLeaveAdjustment(String lmLeaveAdjustmentId) {
60  		Criteria crit = new Criteria();
61          crit.addEqualTo("lmLeaveAdjustmentId", lmLeaveAdjustmentId);
62          Query query = QueryFactory.newQuery(LeaveAdjustment.class, crit);
63          return (LeaveAdjustment) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
64  	}
65  
66  }