001: /*
002: * Copyright 2005-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.gl.dao.ojb;
017:
018: import java.util.Iterator;
019:
020: import org.apache.ojb.broker.query.Criteria;
021: import org.apache.ojb.broker.query.QueryByCriteria;
022: import org.apache.ojb.broker.query.QueryFactory;
023: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
024: import org.kuali.module.gl.GLConstants;
025: import org.kuali.module.gl.bo.ExpenditureTransaction;
026: import org.kuali.module.gl.bo.Transaction;
027: import org.kuali.module.gl.dao.ExpenditureTransactionDao;
028:
029: /**
030: * The OJB implmentation of ExpenditureTransactionDao
031: */
032: public class ExpenditureTransactionDaoOjb extends
033: PlatformAwareDaoBaseOjb implements ExpenditureTransactionDao {
034: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
035: .getLogger(ExpenditureTransactionDaoOjb.class);
036:
037: private final static String UNIVERISITY_FISCAL_YEAR = "universityFiscalYear";
038: private final static String CHART_OF_ACCOUNTS_CODE = "chartOfAccountsCode";
039: private final static String ACCOUNT_NUMBER = "accountNumber";
040: private final static String SUB_ACCOUNT_NUMBER = "subAccountNumber";
041: private final static String OBJECT_CODE = "objectCode";
042: private final static String BALANCE_TYPE_CODE = "balanceTypeCode";
043: private final static String OBJECT_TYPE_CODE = "objectTypeCode";
044: private final static String UNIVERSITY_FISCAL_ACCOUNTING_PERIOD = "universityFiscalAccountingPeriod";
045: private final static String SUB_OBJECT_CODE = "subObjectCode";
046: private final static String PROJECT_CODE = "projectCode";
047: private final static String ORGANIZATION_REFERENCE_ID = "organizationReferenceId";
048:
049: /**
050: * Constructs a ExpenditureTransactionDaoOjb instance
051: */
052: public ExpenditureTransactionDaoOjb() {
053: super ();
054: }
055:
056: /**
057: * Queries the database to find the expenditure transaction in the database that would be affected if the given transaction is posted
058: *
059: * @param t a transaction to find a related expenditure transaction for
060: * @return the expenditure transaction if found, null otherwise
061: * @see org.kuali.module.gl.dao.ExpenditureTransactionDao#getByTransaction(org.kuali.module.gl.bo.Transaction)
062: */
063: public ExpenditureTransaction getByTransaction(Transaction t) {
064: LOG.debug("getByTransaction() started");
065:
066: Criteria crit = new Criteria();
067: crit.addEqualTo(UNIVERISITY_FISCAL_YEAR, t
068: .getUniversityFiscalYear());
069: crit.addEqualTo(CHART_OF_ACCOUNTS_CODE, t
070: .getChartOfAccountsCode());
071: crit.addEqualTo(ACCOUNT_NUMBER, t.getAccountNumber());
072: crit.addEqualTo(SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
073: crit.addEqualTo(OBJECT_CODE, t.getFinancialObjectCode());
074: crit.addEqualTo(SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
075: crit.addEqualTo(BALANCE_TYPE_CODE, t
076: .getFinancialBalanceTypeCode());
077: crit.addEqualTo(OBJECT_TYPE_CODE, t
078: .getFinancialObjectTypeCode());
079: crit.addEqualTo(UNIVERSITY_FISCAL_ACCOUNTING_PERIOD, t
080: .getUniversityFiscalPeriodCode());
081: crit.addEqualTo(PROJECT_CODE, t.getProjectCode());
082:
083: if (t.getOrganizationReferenceId() == null) {
084: crit.addEqualTo(ORGANIZATION_REFERENCE_ID, GLConstants
085: .getDashOrganizationReferenceId());
086: } else {
087: crit.addEqualTo("organizationReferenceId", t
088: .getOrganizationReferenceId());
089: }
090:
091: QueryByCriteria qbc = QueryFactory.newQuery(
092: ExpenditureTransaction.class, crit);
093: return (ExpenditureTransaction) getPersistenceBrokerTemplate()
094: .getObjectByQuery(qbc);
095: }
096:
097: /**
098: * Fetches all expenditure transactions currently in the database
099: *
100: * @return an Iterator with all expenditure transactions from the database
101: * @see org.kuali.module.gl.dao.ExpenditureTransactionDao#getAllExpenditureTransactions()
102: */
103: public Iterator getAllExpenditureTransactions() {
104: LOG.debug("getAllExpenditureTransactions() started");
105:
106: Criteria crit = new Criteria();
107: // We want them all so no criteria is added
108:
109: QueryByCriteria qbc = QueryFactory.newQuery(
110: ExpenditureTransaction.class, crit);
111: return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
112: }
113:
114: /**
115: * Deletes the given expenditure transaction
116: *
117: * @param et the expenditure transaction that will be removed, as such, from the database
118: * @see org.kuali.module.gl.dao.ExpenditureTransactionDao#delete(org.kuali.module.gl.bo.ExpenditureTransaction)
119: */
120: public void delete(ExpenditureTransaction et) {
121: LOG.debug("delete() started");
122:
123: getPersistenceBrokerTemplate().delete(et);
124: }
125:
126: /**
127: * Saves an expenditure transaction
128: * @param et the expenditure transaction to save
129: * @see org.kuali.module.gl.dao.ExpenditureTransactionDao#save(org.kuali.module.gl.bo.ExpenditureTransaction)
130: */
131: public void save(ExpenditureTransaction et) {
132: LOG.debug("save() started");
133:
134: getPersistenceBrokerTemplate().store(et);
135: }
136:
137: /**
138: * Since expenditure transactions are temporary, just like flies that live for a mere day, this method removes all of the currently existing
139: * expenditure transactions from the database, all expenditure transactions having run through the poster and fulfilled their lifecycle
140: * @see org.kuali.module.gl.dao.ExpenditureTransactionDao#deleteAllExpenditureTransactions()
141: */
142: public void deleteAllExpenditureTransactions() {
143: LOG.debug("deleteAllExpenditureTransactions() started");
144: Iterator<ExpenditureTransaction> i = getAllExpenditureTransactions();
145: while (i.hasNext()) {
146: ExpenditureTransaction et = i.next();
147: if (LOG.isInfoEnabled()) {
148: LOG
149: .info("The following ExpenditureTransaction was deleted: "
150: + et.toString());
151: }
152: delete(et);
153: }
154: }
155: }
|