View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.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   * This class is the OJB implementation of the TravelMileageRate interface.
32   */
33  public class TravelMileageRateDaoOjb extends PlatformAwareDaoBaseOjb implements TravelMileageRateDao {
34      private static Logger LOG = Logger.getLogger(TravelMileageRateDaoOjb.class);
35  
36      /**
37       * @see org.kuali.ole.fp.document.dataaccess.TravelMileageRateDao#retrieveMostEffectiveMileageRates(java.sql.Timestamp)
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  }