01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.financial.dao.ojb;
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.core.dao.ojb.PlatformAwareDaoBaseOjb;
27: import org.kuali.module.chart.dao.ojb.ChartDaoOjb;
28: import org.kuali.module.financial.bo.TravelMileageRate;
29: import org.kuali.module.financial.dao.TravelMileageRateDao;
30:
31: /**
32: * This class is the OJB implementation of the TravelMileageRate interface.
33: */
34: public class TravelMileageRateDaoOjb extends PlatformAwareDaoBaseOjb
35: implements TravelMileageRateDao {
36: private static Logger LOG = Logger.getLogger(ChartDaoOjb.class);
37:
38: /**
39: * @see org.kuali.module.financial.dao.TravelMileageRateDao#retrieveMostEffectiveMileageRates(java.sql.Timestamp)
40: */
41: public Collection retrieveMostEffectiveMileageRates(
42: Date effectiveDate) {
43: Criteria criteria = new Criteria();
44: criteria.addLessOrEqualThan(
45: "disbursementVoucherMileageEffectiveDate",
46: effectiveDate);
47:
48: QueryByCriteria queryByCriteria = new QueryByCriteria(
49: TravelMileageRate.class, criteria);
50: queryByCriteria
51: .addOrderByDescending("disbursementVoucherMileageEffectiveDate");
52: queryByCriteria.addOrderByDescending("mileageLimitAmount");
53:
54: Collection mostEffectiveRates = new ArrayList();
55: Collection rates = getPersistenceBrokerTemplate()
56: .getCollectionByQuery(queryByCriteria);
57: Date mostEffectiveDate = ((TravelMileageRate) rates.iterator()
58: .next()).getDisbursementVoucherMileageEffectiveDate();
59: for (Iterator iter = rates.iterator(); iter.hasNext();) {
60: TravelMileageRate rate = (TravelMileageRate) iter.next();
61: if (rate.getDisbursementVoucherMileageEffectiveDate()
62: .compareTo(mostEffectiveDate) == 0) {
63: mostEffectiveRates.add(rate);
64: }
65: }
66:
67: return mostEffectiveRates;
68: }
69:
70: }
|