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.cam.document.dataaccess.impl; 017 018 import java.math.BigDecimal; 019 import java.util.ArrayList; 020 import java.util.Collection; 021 import java.util.Iterator; 022 import java.util.List; 023 024 import org.apache.ojb.broker.query.Criteria; 025 import org.apache.ojb.broker.query.QueryByCriteria; 026 import org.apache.ojb.broker.query.QueryFactory; 027 import org.apache.ojb.broker.query.ReportQueryByCriteria; 028 import org.kuali.kfs.module.cam.CamsConstants; 029 import org.kuali.kfs.module.cam.CamsPropertyConstants; 030 import org.kuali.kfs.module.cam.businessobject.AssetPayment; 031 import org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail; 032 import org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail; 033 import org.kuali.kfs.module.cam.document.dataaccess.AssetPaymentDao; 034 import org.kuali.kfs.sys.KFSConstants; 035 import org.kuali.kfs.sys.KFSPropertyConstants; 036 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb; 037 import org.kuali.rice.kns.util.TransactionalServiceUtils; 038 039 public class AssetPaymentDaoOjb extends PlatformAwareDaoBaseOjb implements AssetPaymentDao { 040 041 /** 042 * 043 * @see org.kuali.kfs.module.cam.document.dataaccess.AssetPaymentDao#getMaxSquenceNumber(java.lang.Long) 044 */ 045 public Integer getMaxSquenceNumber(Long capitalAssetNumber) { 046 Criteria criteria = new Criteria(); 047 criteria.addEqualTo(CamsPropertyConstants.AssetPayment.CAPITAL_ASSET_NUMBER, capitalAssetNumber); 048 ReportQueryByCriteria query = QueryFactory.newReportQuery(AssetPayment.class, criteria); 049 050 query.setAttributes(new String[] { "max(" + CamsPropertyConstants.AssetPayment.PAYMENT_SEQ_NUMBER + ")" }); 051 Iterator<?> iterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); 052 Integer maxSequenceNumber = Integer.valueOf(0); 053 054 if (iterator.hasNext()) { 055 Object[] data = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(iterator); 056 if (data[0] != null) { 057 maxSequenceNumber = ((BigDecimal) data[0]).intValue(); 058 } 059 } 060 return maxSequenceNumber; 061 } 062 }