001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.labor.dao.ojb;
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.core.dao.ojb.PlatformAwareDaoBaseOjb;
025: import org.kuali.core.util.TransactionalServiceUtils;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.module.labor.bo.LaborGeneralLedgerEntry;
028: import org.kuali.module.labor.dao.LaborGeneralLedgerEntryDao;
029:
030: /**
031: * This is the data access object for labor general ledger entry
032: *
033: * @see org.kuali.module.labor.bo.LaborGeneralLedgerEntry
034: */
035: public class LaborGeneralLedgerEntryDaoOjb extends
036: PlatformAwareDaoBaseOjb implements LaborGeneralLedgerEntryDao {
037:
038: /**
039: * @see org.kuali.module.labor.dao.LaborGeneralLedgerEntryDao#getMaxSequenceNumber(org.kuali.module.labor.bo.LaborGeneralLedgerEntry)
040: */
041: public Integer getMaxSequenceNumber(
042: LaborGeneralLedgerEntry laborGeneralLedgerEntry) {
043: Criteria criteria = new Criteria();
044:
045: criteria.addEqualTo(
046: KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
047: laborGeneralLedgerEntry.getUniversityFiscalYear());
048: criteria.addEqualTo(
049: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
050: laborGeneralLedgerEntry.getChartOfAccountsCode());
051: criteria.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
052: laborGeneralLedgerEntry.getAccountNumber());
053: criteria.addEqualTo(KFSPropertyConstants.SUB_ACCOUNT_NUMBER,
054: laborGeneralLedgerEntry.getSubAccountNumber());
055: criteria.addEqualTo(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
056: laborGeneralLedgerEntry.getFinancialObjectCode());
057: criteria.addEqualTo(
058: KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE,
059: laborGeneralLedgerEntry.getFinancialSubObjectCode());
060: criteria.addEqualTo(
061: KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
062: laborGeneralLedgerEntry.getFinancialBalanceTypeCode());
063: criteria.addEqualTo(
064: KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE,
065: laborGeneralLedgerEntry.getFinancialObjectTypeCode());
066: criteria
067: .addEqualTo(
068: KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
069: laborGeneralLedgerEntry
070: .getUniversityFiscalPeriodCode());
071: criteria.addEqualTo(
072: KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
073: laborGeneralLedgerEntry.getFinancialDocumentTypeCode());
074: criteria.addEqualTo(
075: KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE,
076: laborGeneralLedgerEntry
077: .getFinancialSystemOriginationCode());
078: criteria.addEqualTo(KFSPropertyConstants.DOCUMENT_NUMBER,
079: laborGeneralLedgerEntry.getDocumentNumber());
080:
081: ReportQueryByCriteria query = QueryFactory.newReportQuery(
082: LaborGeneralLedgerEntry.class, criteria);
083: query
084: .setAttributes(new String[] { "max("
085: + KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER
086: + ")" });
087:
088: Iterator iterator = getPersistenceBrokerTemplate()
089: .getReportQueryIteratorByQuery(query);
090: Integer maxSequenceNumber = Integer.valueOf(0);
091:
092: if (iterator.hasNext()) {
093: Object[] data = (Object[]) TransactionalServiceUtils
094: .retrieveFirstAndExhaustIterator(iterator);
095: if (data[0] != null) {
096: maxSequenceNumber = ((BigDecimal) data[0]).intValue();
097: }
098: }
099: return maxSequenceNumber;
100: }
101:
102: /**
103: * @see org.kuali.module.labor.dao.LaborGeneralLedgerEntryDao#save(org.kuali.module.labor.bo.LaborGeneralLedgerEntry)
104: */
105: public void save(LaborGeneralLedgerEntry laborGeneralLedgerEntry) {
106: getPersistenceBrokerTemplate().store(laborGeneralLedgerEntry);
107: }
108: }
|