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: import java.util.Map;
021:
022: import org.apache.ojb.broker.query.Criteria;
023: import org.apache.ojb.broker.query.QueryByCriteria;
024: import org.apache.ojb.broker.query.QueryFactory;
025: import org.apache.ojb.broker.query.ReportQueryByCriteria;
026: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
027: import org.kuali.core.util.TransactionalServiceUtils;
028: import org.kuali.kfs.KFSPropertyConstants;
029: import org.kuali.module.gl.util.OJBUtility;
030: import org.kuali.module.labor.bo.LedgerEntry;
031: import org.kuali.module.labor.dao.LaborLedgerEntryDao;
032:
033: /**
034: * This is the data access object for ledger entry.
035: *
036: * @see org.kuali.module.labor.bo.LedgerEntry
037: */
038: public class LaborLedgerEntryDaoOjb extends PlatformAwareDaoBaseOjb
039: implements LaborLedgerEntryDao {
040:
041: /**
042: * @see org.kuali.module.labor.dao.LaborLedgerEntryDao#getMaxSquenceNumber(org.kuali.module.labor.bo.LedgerEntry)
043: */
044: public Integer getMaxSquenceNumber(LedgerEntry ledgerEntry) {
045: Criteria criteria = new Criteria();
046:
047: criteria.addEqualTo(
048: KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
049: ledgerEntry.getUniversityFiscalYear());
050: criteria.addEqualTo(
051: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
052: ledgerEntry.getChartOfAccountsCode());
053: criteria.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
054: ledgerEntry.getAccountNumber());
055: criteria.addEqualTo(KFSPropertyConstants.SUB_ACCOUNT_NUMBER,
056: ledgerEntry.getSubAccountNumber());
057: criteria.addEqualTo(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
058: ledgerEntry.getFinancialObjectCode());
059: criteria.addEqualTo(
060: KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE,
061: ledgerEntry.getFinancialSubObjectCode());
062: criteria.addEqualTo(
063: KFSPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE,
064: ledgerEntry.getFinancialBalanceTypeCode());
065: criteria.addEqualTo(
066: KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE,
067: ledgerEntry.getFinancialObjectTypeCode());
068: criteria.addEqualTo(
069: KFSPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE,
070: ledgerEntry.getUniversityFiscalPeriodCode());
071: criteria.addEqualTo(
072: KFSPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE,
073: ledgerEntry.getFinancialDocumentTypeCode());
074: criteria.addEqualTo(
075: KFSPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE,
076: ledgerEntry.getFinancialSystemOriginationCode());
077: criteria.addEqualTo(KFSPropertyConstants.DOCUMENT_NUMBER,
078: ledgerEntry.getDocumentNumber());
079:
080: ReportQueryByCriteria query = QueryFactory.newReportQuery(this
081: .getEntryClass(), criteria);
082: query
083: .setAttributes(new String[] { "max("
084: + KFSPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER
085: + ")" });
086:
087: Iterator iterator = getPersistenceBrokerTemplate()
088: .getReportQueryIteratorByQuery(query);
089: Integer maxSequenceNumber = Integer.valueOf(0);
090:
091: if (iterator.hasNext()) {
092: Object[] data = (Object[]) TransactionalServiceUtils
093: .retrieveFirstAndExhaustIterator(iterator);
094: if (data[0] != null) {
095: maxSequenceNumber = ((BigDecimal) data[0]).intValue();
096: }
097: }
098: return maxSequenceNumber;
099: }
100:
101: /**
102: * @see org.kuali.module.labor.dao.LaborLedgerEntryDao#find(java.util.Map)
103: */
104: public Iterator<LedgerEntry> find(Map<String, String> fieldValues) {
105: Criteria criteria = OJBUtility.buildCriteriaFromMap(
106: fieldValues, new LedgerEntry());
107:
108: QueryByCriteria query = QueryFactory.newQuery(this
109: .getEntryClass(), criteria);
110: return getPersistenceBrokerTemplate().getIteratorByQuery(query);
111: }
112:
113: /**
114: * @see org.kuali.module.labor.dao.LaborLedgerEntryDao#save(org.kuali.module.labor.bo.LedgerEntry)
115: */
116: public void save(LedgerEntry ledgerEntry) {
117: getPersistenceBrokerTemplate().store(ledgerEntry);
118: }
119:
120: /**
121: * @return the Class type of the business object accessed and managed
122: */
123: private Class getEntryClass() {
124: return LedgerEntry.class;
125: }
126: }
|