1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.accrual.dao;
17
18 import java.sql.Date;
19 import java.util.Collection;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.apache.log4j.Logger;
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.time.accrual.TimeOffAccrual;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31 public class TimeOffAccrualkDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements TimeOffAccrualDao {
32
33 @SuppressWarnings("unused")
34 private static final Logger LOG = Logger.getLogger(TimeOffAccrualkDaoSpringOjbImpl.class);
35
36 public void saveOrUpdate(TimeOffAccrual timeOffAccrual) {
37 this.getPersistenceBrokerTemplate().store(timeOffAccrual);
38 }
39
40 public void saveOrUpdate(List<TimeOffAccrual> timeOffAccrualList) {
41 if (timeOffAccrualList != null) {
42 for (TimeOffAccrual timeOffAccrual : timeOffAccrualList) {
43 this.getPersistenceBrokerTemplate().store(timeOffAccrual);
44 }
45 }
46 }
47
48 public List<TimeOffAccrual> getTimeOffAccruals (String principalId) {
49
50 List<TimeOffAccrual> timeOffAccruals = new LinkedList<TimeOffAccrual>();
51
52 Criteria root = new Criteria();
53 Criteria effdt = new Criteria();
54
55
56 effdt.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
57 effdt.addEqualToField("accrualCategory", Criteria.PARENT_QUERY_PREFIX + "accrualCategory");
58 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(TimeOffAccrual.class, effdt);
59 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
60
61 root.addEqualTo("principalId", principalId);
62 root.addEqualTo("effectiveDate", effdtSubQuery);
63
64 Query query = QueryFactory.newQuery(TimeOffAccrual.class, root);
65 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
66
67 if (c != null) {
68 timeOffAccruals.addAll(c);
69 }
70
71 return timeOffAccruals;
72 }
73
74 @Override
75 public TimeOffAccrual getTimeOffAccrual(Long laTimeOffAccrualId) {
76 Criteria crit = new Criteria();
77 crit.addEqualTo("lmAccrualId", laTimeOffAccrualId);
78
79 Query query = QueryFactory.newQuery(TimeOffAccrual.class, crit);
80 return (TimeOffAccrual)this.getPersistenceBrokerTemplate().getObjectByQuery(query);
81
82 }
83
84
85 public List<TimeOffAccrual> getActiveTimeOffAccruals (String principalId, Date asOfDate) {
86 List<TimeOffAccrual> timeOffAccruals = new LinkedList<TimeOffAccrual>();
87
88 Criteria root = new Criteria();
89 Criteria effdt = new Criteria();
90
91
92 effdt.addEqualToField("principalId", Criteria.PARENT_QUERY_PREFIX + "principalId");
93 effdt.addEqualToField("accrualCategory", Criteria.PARENT_QUERY_PREFIX + "accrualCategory");
94 effdt.addLessOrEqualThan("effectiveDate", asOfDate);
95 ReportQueryByCriteria effdtSubQuery = QueryFactory.newReportQuery(TimeOffAccrual.class, effdt);
96 effdtSubQuery.setAttributes(new String[] { "max(effdt)" });
97
98 root.addEqualTo("principalId", principalId);
99 root.addEqualTo("effectiveDate", effdtSubQuery);
100
101 Query query = QueryFactory.newQuery(TimeOffAccrual.class, root);
102 Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
103
104 if (c != null) {
105 timeOffAccruals.addAll(c);
106 }
107
108 return timeOffAccruals;
109 }
110
111 @Override
112 public int getTimeOffAccrualCount(String accrualCategory, Date effectiveDate, String principalId, String lmAccrualId) {
113 Criteria crit = new Criteria();
114 crit.addEqualTo("accrualCategory", accrualCategory);
115 crit.addEqualTo("effectiveDate", effectiveDate);
116 crit.addEqualTo("principalId", principalId);
117 if(lmAccrualId != null) {
118 crit.addEqualTo("lmAccrualId", lmAccrualId);
119 }
120 Query query = QueryFactory.newQuery(TimeOffAccrual.class, crit);
121 return this.getPersistenceBrokerTemplate().getCount(query);
122 }
123 }