001/*
002 * Copyright 2006 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.fp.document.dataaccess.impl;
017
018import java.sql.Date;
019import java.util.ArrayList;
020import java.util.Collection;
021import java.util.Iterator;
022
023import org.apache.log4j.Logger;
024import org.apache.ojb.broker.query.Criteria;
025import org.apache.ojb.broker.query.QueryByCriteria;
026import org.kuali.ole.fp.businessobject.TravelMileageRate;
027import org.kuali.ole.fp.document.dataaccess.TravelMileageRateDao;
028import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
029
030/**
031 * This class is the OJB implementation of the TravelMileageRate interface.
032 */
033public class TravelMileageRateDaoOjb extends PlatformAwareDaoBaseOjb implements TravelMileageRateDao {
034    private static Logger LOG = Logger.getLogger(TravelMileageRateDaoOjb.class);
035
036    /**
037     * @see org.kuali.ole.fp.document.dataaccess.TravelMileageRateDao#retrieveMostEffectiveMileageRates(java.sql.Timestamp)
038     */
039    public Collection retrieveMostEffectiveMileageRates(Date effectiveDate) {
040        Criteria criteria = new Criteria();
041        criteria.addLessOrEqualThan("disbursementVoucherMileageEffectiveDate", effectiveDate);
042
043        QueryByCriteria queryByCriteria = new QueryByCriteria(TravelMileageRate.class, criteria);
044        queryByCriteria.addOrderByDescending("disbursementVoucherMileageEffectiveDate");
045        queryByCriteria.addOrderByDescending("mileageLimitAmount");
046
047        Collection mostEffectiveRates = new ArrayList();
048        Collection rates = getPersistenceBrokerTemplate().getCollectionByQuery(queryByCriteria);
049        Date mostEffectiveDate = ((TravelMileageRate) rates.iterator().next()).getDisbursementVoucherMileageEffectiveDate();
050        for (Iterator iter = rates.iterator(); iter.hasNext();) {
051            TravelMileageRate rate = (TravelMileageRate) iter.next();
052            if (rate.getDisbursementVoucherMileageEffectiveDate().compareTo(mostEffectiveDate) == 0) {
053                mostEffectiveRates.add(rate);
054            }
055        }
056
057        return mostEffectiveRates;
058    }
059
060
061}