1 /*
2 * Copyright 2006 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.ole.gl.dataaccess.impl;
17
18 import java.util.Collection;
19
20 import org.apache.ojb.broker.query.Criteria;
21 import org.apache.ojb.broker.query.QueryByCriteria;
22 import org.apache.ojb.broker.query.QueryFactory;
23 import org.kuali.ole.gl.businessobject.SufficientFundBalances;
24 import org.kuali.ole.gl.dataaccess.SufficientFundBalancesDao;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
27
28 /**
29 * An OJB implementation of the SufficientFundBalancesDao
30 */
31 public class SufficientFundBalancesDaoOjb extends PlatformAwareDaoBaseOjb implements SufficientFundBalancesDao {
32 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SufficientFundBalancesDaoOjb.class);
33
34 /**
35 * Builds an OJB query based on the parameter values and returns all the sufficient fund balances that match that record
36 *
37 * @param universityFiscalYear the university fiscal year of sufficient fund balances to find
38 * @param chartOfAccountsCode the chart of accounts code of sufficient fund balances to find
39 * @param financialObjectCode the object code of sufficient fund balances to find
40 * @return a Collection of sufficient fund balances, qualified by the parameter values
41 * @see org.kuali.ole.gl.dataaccess.SufficientFundBalancesDao#getByObjectCode(java.lang.Integer, java.lang.String, java.lang.String)
42 */
43 public Collection getByObjectCode(Integer universityFiscalYear, String chartOfAccountsCode, String financialObjectCode) {
44 LOG.debug("getByObjectCode() started");
45
46 Criteria crit = new Criteria();
47 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
48 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
49 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, financialObjectCode);
50
51 QueryByCriteria qbc = QueryFactory.newQuery(SufficientFundBalances.class, crit);
52 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
53 }
54
55 /**
56 * Deletes sufficient fund balances associated with a given year, chart, and account number
57 *
58 * @param universityFiscalYear the university fiscal year of sufficient fund balances to delete
59 * @param chartOfAccountsCode the chart code of sufficient fund balances to delete
60 * @param accountNumber the account number of sufficient fund balances to delete
61 * @return the number of records deleted
62 * @see org.kuali.ole.gl.dataaccess.SufficientFundBalancesDao#deleteByAccountNumber(java.lang.Integer, java.lang.String, java.lang.String)
63 */
64 public int deleteByAccountNumber(Integer universityFiscalYear, String chartOfAccountsCode, String accountNumber) {
65 LOG.debug("deleteByAccountNumber() started");
66
67 Criteria crit = new Criteria();
68 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
69 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
70 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, accountNumber);
71
72 QueryByCriteria qbc = QueryFactory.newQuery(SufficientFundBalances.class, crit);
73 int count = getPersistenceBrokerTemplate().getCount(qbc);
74 getPersistenceBrokerTemplate().deleteByQuery(qbc);
75
76 // This has to be done because deleteByQuery deletes the rows from the table,
77 // but it doesn't delete them from the cache. If the cache isn't cleared,
78 // later on, you could get an Optimistic Lock Exception because OJB thinks rows
79 // exist when they really don't.
80 getPersistenceBrokerTemplate().clearCache();
81
82 return count;
83 }
84
85 /**
86 * 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
87 * sace for production.
88 *
89 * @return a Collection of all sufficient funds records in the database
90 */
91 public Collection testingGetAllEntries() {
92 LOG.debug("testingGetAllEntries() started");
93
94 Criteria criteria = new Criteria();
95 QueryByCriteria qbc = QueryFactory.newQuery(SufficientFundBalances.class, criteria);
96 qbc.addOrderBy(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, true);
97 qbc.addOrderBy(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, true);
98 qbc.addOrderBy(OLEPropertyConstants.ACCOUNT_NUMBER, true);
99 qbc.addOrderBy(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, true);
100
101 return getPersistenceBrokerTemplate().getCollectionByQuery(qbc);
102 }
103 }