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.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.module.cam.CamsPropertyConstants;
025 import org.kuali.kfs.module.cam.businessobject.AssetComponent;
026 import org.kuali.kfs.module.cam.document.dataaccess.AssetComponentDao;
027 import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
028 import org.kuali.rice.kns.util.TransactionalServiceUtils;
029
030 public class AssetComponentDaoOjb extends PlatformAwareDaoBaseOjb implements AssetComponentDao {
031
032 public Integer getMaxSquenceNumber(AssetComponent assetComponent) {
033 Criteria criteria = new Criteria();
034
035 criteria.addEqualTo(CamsPropertyConstants.AssetComponent.CAPITAL_ASSET_NUMBER, assetComponent.getCapitalAssetNumber());
036 ReportQueryByCriteria query = QueryFactory.newReportQuery(assetComponent.getClass(), criteria);
037 query.setAttributes(new String[] { "max(" + CamsPropertyConstants.AssetComponent.COMPONENT_NUMBER + ")" });
038 Iterator<?> iterator = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query);
039 Integer maxSequenceNumber = Integer.valueOf(0);
040
041 if (iterator.hasNext()) {
042 Object[] data = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(iterator);
043 if (data[0] != null) {
044 maxSequenceNumber = ((BigDecimal) data[0]).intValue();
045 }
046 }
047 return maxSequenceNumber;
048 }
049
050 }