View Javadoc
1   /*
2    * Copyright 2005-2009 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.gl.dataaccess.impl;
17  
18  import java.math.BigDecimal;
19  import java.util.Iterator;
20  
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.QueryFactory;
23  import org.apache.ojb.broker.query.ReportQueryByCriteria;
24  import org.kuali.ole.gl.businessobject.EntryHistory;
25  import org.kuali.ole.gl.dataaccess.LedgerEntryHistoryBalancingDao;
26  import org.kuali.ole.sys.OLEPropertyConstants;
27  import org.kuali.ole.sys.util.TransactionalServiceUtils;
28  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
29  import org.kuali.rice.krad.util.ObjectUtils;
30  
31  /**
32   * An OJB implementation of LedgerEntryHistoryBalancingDao
33   */
34  public class EntryHistoryDaoOjb extends PlatformAwareDaoBaseOjb implements LedgerEntryHistoryBalancingDao {
35      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EntryHistoryDaoOjb.class);
36      
37      /**
38       * @see org.kuali.ole.gl.dataaccess.LedgerEntryHistoryBalancingDao#findSumRowCountGreaterOrEqualThan(java.lang.Integer)
39       */
40      public Integer findSumRowCountGreaterOrEqualThan(Integer year) {
41          Criteria criteria = new Criteria();
42          criteria.addGreaterOrEqualThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, year);
43          
44          ReportQueryByCriteria reportQuery = QueryFactory.newReportQuery(EntryHistory.class, criteria);
45          reportQuery.setAttributes(new String[] { "sum(" + OLEPropertyConstants.ROW_COUNT  + ")"});
46          
47          Iterator<Object[]> iterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(reportQuery);
48          Object[] returnResult = TransactionalServiceUtils.retrieveFirstAndExhaustIterator(iterator);
49          
50          return ObjectUtils.isNull(returnResult[0]) ? 0 : ((BigDecimal) returnResult[0]).intValue();
51      }
52  }