1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.dataaccess.impl;
17
18 import java.sql.Date;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Iterator;
22
23 import org.apache.log4j.Logger;
24 import org.apache.ojb.broker.query.Criteria;
25 import org.apache.ojb.broker.query.QueryByCriteria;
26 import org.kuali.ole.fp.businessobject.TravelMileageRate;
27 import org.kuali.ole.fp.document.dataaccess.TravelMileageRateDao;
28 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29
30
31
32
33 public class TravelMileageRateDaoOjb extends PlatformAwareDaoBaseOjb implements TravelMileageRateDao {
34 private static Logger LOG = Logger.getLogger(TravelMileageRateDaoOjb.class);
35
36
37
38
39 public Collection retrieveMostEffectiveMileageRates(Date effectiveDate) {
40 Criteria criteria = new Criteria();
41 criteria.addLessOrEqualThan("disbursementVoucherMileageEffectiveDate", effectiveDate);
42
43 QueryByCriteria queryByCriteria = new QueryByCriteria(TravelMileageRate.class, criteria);
44 queryByCriteria.addOrderByDescending("disbursementVoucherMileageEffectiveDate");
45 queryByCriteria.addOrderByDescending("mileageLimitAmount");
46
47 Collection mostEffectiveRates = new ArrayList();
48 Collection rates = getPersistenceBrokerTemplate().getCollectionByQuery(queryByCriteria);
49 Date mostEffectiveDate = ((TravelMileageRate) rates.iterator().next()).getDisbursementVoucherMileageEffectiveDate();
50 for (Iterator iter = rates.iterator(); iter.hasNext();) {
51 TravelMileageRate rate = (TravelMileageRate) iter.next();
52 if (rate.getDisbursementVoucherMileageEffectiveDate().compareTo(mostEffectiveDate) == 0) {
53 mostEffectiveRates.add(rate);
54 }
55 }
56
57 return mostEffectiveRates;
58 }
59
60
61 }