001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.module.ld.dataaccess.impl; 017 018 import java.math.BigDecimal; 019 import java.util.Iterator; 020 021 import org.apache.ojb.broker.query.Criteria; 022 import org.apache.ojb.broker.query.QueryFactory; 023 import org.apache.ojb.broker.query.ReportQueryByCriteria; 024 import org.kuali.kfs.gl.dataaccess.LedgerEntryHistoryBalancingDao; 025 import org.kuali.kfs.module.ld.businessobject.LaborEntryHistory; 026 import org.kuali.kfs.module.ld.util.ConsolidationUtil; 027 import org.kuali.kfs.sys.KFSPropertyConstants; 028 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; 029 import org.kuali.rice.kns.util.ObjectUtils; 030 import org.kuali.rice.kns.util.TransactionalServiceUtils; 031 032 /** 033 * This is the data access object for ledger entry history 034 * 035 * @see org.kuali.kfs.module.ld.businessobject.LaborEntryHistory 036 */ 037 public class LaborLedgerEntryHistoryDaoOjb extends PlatformAwareDaoBaseOjb implements LedgerEntryHistoryBalancingDao { 038 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(LaborLedgerEntryHistoryDaoOjb.class); 039 040 /** 041 * @see org.kuali.kfs.gl.dataaccess.LedgerEntryBalancingDao#findSumRowCountGreaterOrEqualThan(java.lang.Integer) 042 */ 043 public Integer findSumRowCountGreaterOrEqualThan(Integer year) { 044 Criteria criteria = new Criteria(); 045 criteria.addGreaterOrEqualThan(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR, year); 046 047 ReportQueryByCriteria reportQuery = QueryFactory.newReportQuery(LaborEntryHistory.class, criteria); 048 reportQuery.setAttributes(new String[] { ConsolidationUtil.sum(KFSPropertyConstants.ROW_COUNT)}); 049 050 Iterator<Object[]> iterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(reportQuery); 051 Object[] returnResult = TransactionalServiceUtils.retrieveFirstAndExhaustIterator(iterator); 052 053 return ObjectUtils.isNull(returnResult[0]) ? 0 : ((BigDecimal) returnResult[0]).intValue(); 054 } 055 }