1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavecode.dao;
17
18
19 import java.sql.Date;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23
24 import com.google.common.collect.ImmutableList;
25 import org.apache.log4j.Logger;
26 import org.apache.ojb.broker.query.Criteria;
27 import org.apache.ojb.broker.query.Query;
28 import org.apache.ojb.broker.query.QueryFactory;
29 import org.apache.ojb.broker.query.ReportQueryByCriteria;
30 import org.kuali.hr.core.util.OjbSubQueryUtil;
31 import org.kuali.hr.lm.leavecode.LeaveCode;
32 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
33
34 public class LeaveCodeDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveCodeDao {
35 private static final ImmutableList<String> EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
36 .add("leaveCode")
37 .add("leavePlan")
38 .add("principalId")
39 .build();
40 private static final Logger LOG = Logger.getLogger(LeaveCodeDaoSpringOjbImpl.class);
41
42 @Override
43 public LeaveCode getLeaveCode(String lmLeaveCodeId) {
44 Criteria crit = new Criteria();
45 crit.addEqualTo("lmLeaveCodeId", lmLeaveCodeId);
46 Query query = QueryFactory.newQuery(LeaveCode.class, crit);
47 return (LeaveCode) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
48 }
49
50 public List<LeaveCode> getLeaveCodes(String leavePlan, Date asOfDate){
51 List<LeaveCode> leaveCodes = new ArrayList<LeaveCode>();
52 Criteria root = new Criteria();
53
54 java.sql.Date effDate = asOfDate == null ? null : new java.sql.Date(asOfDate.getTime());
55 root.addEqualTo("leavePlan", leavePlan);
56 root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(LeaveCode.class, effDate, EQUAL_TO_FIELDS, false));
57 root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(LeaveCode.class, EQUAL_TO_FIELDS, false));
58
59 Criteria activeFilter = new Criteria();
60 activeFilter.addEqualTo("active", true);
61 root.addAndCriteria(activeFilter);
62
63
64 Query query = QueryFactory.newQuery(LeaveCode.class, root);
65 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
66
67 if (c != null) {
68 leaveCodes.addAll(c);
69 }
70 return leaveCodes;
71 }
72
73 @Override
74 public LeaveCode getLeaveCode(String leaveCode, Date asOfDate) {
75 LeaveCode myleaveCode = null;
76 Criteria root = new Criteria();
77 root.addEqualTo("leaveCode", leaveCode);
78 root.addLessOrEqualThan("effectiveDate", asOfDate);
79 root.addEqualTo("active",true);
80
81 Query query = QueryFactory.newQuery(LeaveCode.class, root);
82 Object obj = this.getPersistenceBrokerTemplate().getObjectByQuery(query);
83 if (obj != null) {
84 myleaveCode = (LeaveCode) obj;
85 }
86
87 return myleaveCode;
88 }
89 }