1
2
3
4
5
6
7
8
9
10
11
12
13
14
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();
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 }