001: /*
002: * Copyright 2006-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.Collection;
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.kfs.KFSPropertyConstants;
025: import org.kuali.module.gl.bo.SufficientFundBalances;
026: import org.kuali.module.gl.dao.SufficientFundBalancesDao;
027:
028: /**
029: * An OJB implementation of the SufficientFundBalancesDao
030: */
031: public class SufficientFundBalancesDaoOjb extends
032: PlatformAwareDaoBaseOjb implements SufficientFundBalancesDao {
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(SufficientFundBalancesDaoOjb.class);
035:
036: /**
037: * Builds an OJB primary key query from the given parameters and returns the result
038: *
039: * @param universityFiscalYear the university fiscal year of the sufficient funds balance to return
040: * @param chartOfAccountsCode the chart of accounts code of the sufficient funds balance to return
041: * @param accountNumber the account number of the sufficient funds balance to return
042: * @param financialObjectCode the object code of the sufficient funds balance to return
043: * @return the qualifying sufficient funds balance record, or null no suitable record can be found
044: * @see org.kuali.module.gl.dao.SufficientFundBalancesDao#getByPrimaryId(java.lang.Integer, java.lang.String, java.lang.String, java.lang.String)
045: */
046: public SufficientFundBalances getByPrimaryId(
047: Integer universityFiscalYear, String chartOfAccountsCode,
048: String accountNumber, String financialObjectCode) {
049: LOG.debug("getByPrimaryId() started");
050:
051: Criteria crit = new Criteria();
052: crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
053: universityFiscalYear);
054: crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
055: chartOfAccountsCode);
056: crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
057: accountNumber);
058: crit.addEqualTo(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
059: financialObjectCode);
060:
061: QueryByCriteria qbc = QueryFactory.newQuery(
062: SufficientFundBalances.class, crit);
063: return (SufficientFundBalances) getPersistenceBrokerTemplate()
064: .getObjectByQuery(qbc);
065: }
066:
067: /**
068: * Saves a sufficient fund balance record
069: * @param sfb the sufficient funds balance record to save
070: * @see org.kuali.module.gl.dao.SufficientFundBalancesDao#save(org.kuali.module.gl.bo.SufficientFundBalances)
071: */
072: public void save(SufficientFundBalances sfb) {
073: LOG.debug("save() started");
074:
075: getPersistenceBrokerTemplate().store(sfb);
076: }
077:
078: /**
079: * Builds an OJB query based on the parameter values and returns all the sufficient fund balances that match that record
080: *
081: * @param universityFiscalYear the university fiscal year of sufficient fund balances to find
082: * @param chartOfAccountsCode the chart of accounts code of sufficient fund balances to find
083: * @param financialObjectCode the object code of sufficient fund balances to find
084: * @return a Collection of sufficient fund balances, qualified by the parameter values
085: * @see org.kuali.module.gl.dao.SufficientFundBalancesDao#getByObjectCode(java.lang.Integer, java.lang.String, java.lang.String)
086: */
087: public Collection getByObjectCode(Integer universityFiscalYear,
088: String chartOfAccountsCode, String financialObjectCode) {
089: LOG.debug("getByObjectCode() started");
090:
091: Criteria crit = new Criteria();
092: crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
093: universityFiscalYear);
094: crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
095: chartOfAccountsCode);
096: crit.addEqualTo(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
097: financialObjectCode);
098:
099: QueryByCriteria qbc = QueryFactory.newQuery(
100: SufficientFundBalances.class, crit);
101: return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
102: }
103:
104: /**
105: * Deletes sufficient fund balances associated with a given year, chart, and account number
106: *
107: * @param universityFiscalYear the university fiscal year of sufficient fund balances to delete
108: * @param chartOfAccountsCode the chart code of sufficient fund balances to delete
109: * @param accountNumber the account number of sufficient fund balances to delete
110: * @see org.kuali.module.gl.dao.SufficientFundBalancesDao#deleteByAccountNumber(java.lang.Integer, java.lang.String, java.lang.String)
111: */
112: public void deleteByAccountNumber(Integer universityFiscalYear,
113: String chartOfAccountsCode, String accountNumber) {
114: LOG.debug("deleteByAccountNumber() started");
115:
116: Criteria crit = new Criteria();
117: crit.addEqualTo(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
118: universityFiscalYear);
119: crit.addEqualTo(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
120: chartOfAccountsCode);
121: crit.addEqualTo(KFSPropertyConstants.ACCOUNT_NUMBER,
122: accountNumber);
123:
124: QueryByCriteria qbc = QueryFactory.newQuery(
125: SufficientFundBalances.class, crit);
126: getPersistenceBrokerTemplate().deleteByQuery(qbc);
127:
128: // This has to be done because deleteByQuery deletes the rows from the table,
129: // but it doesn't delete them from the cache. If the cache isn't cleared,
130: // later on, you could get an Optimistic Lock Exception because OJB thinks rows
131: // exist when they really don't.
132: getPersistenceBrokerTemplate().clearCache();
133: }
134:
135: /**
136: * This method should only be used in unit tests. It loads all the gl_sf_balances_t rows in memory into a collection. This won't
137: * sace for production.
138: *
139: * @return a Collection of all sufficient funds records in the database
140: */
141: public Collection testingGetAllEntries() {
142: LOG.debug("testingGetAllEntries() started");
143:
144: Criteria criteria = new Criteria();
145: QueryByCriteria qbc = QueryFactory.newQuery(
146: SufficientFundBalances.class, criteria);
147: qbc.addOrderBy(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
148: true);
149: qbc.addOrderBy(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
150: true);
151: qbc.addOrderBy(KFSPropertyConstants.ACCOUNT_NUMBER, true);
152: qbc
153: .addOrderBy(KFSPropertyConstants.FINANCIAL_OBJECT_CODE,
154: true);
155:
156: return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
157: }
158: }
|