1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.gl.dataaccess.impl;
17
18 import java.util.Iterator;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.ojb.broker.query.Criteria;
22 import org.apache.ojb.broker.query.QueryByCriteria;
23 import org.apache.ojb.broker.query.QueryFactory;
24 import org.kuali.ole.gl.GeneralLedgerConstants;
25 import org.kuali.ole.gl.businessobject.ExpenditureTransaction;
26 import org.kuali.ole.gl.businessobject.Transaction;
27 import org.kuali.ole.gl.dataaccess.ExpenditureTransactionDao;
28 import org.kuali.ole.sys.OLEPropertyConstants;
29 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30
31
32
33
34 public class ExpenditureTransactionDaoOjb extends PlatformAwareDaoBaseOjb implements ExpenditureTransactionDao {
35 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExpenditureTransactionDaoOjb.class);
36
37
38
39
40 public ExpenditureTransactionDaoOjb() {
41 super();
42 }
43
44
45
46
47
48
49
50
51
52 public ExpenditureTransaction getByTransaction(Transaction t) {
53 LOG.debug("getByTransaction() started");
54
55 Criteria crit = new Criteria();
56 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, t.getUniversityFiscalYear());
57 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, t.getChartOfAccountsCode());
58 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, t.getAccountNumber());
59 crit.addEqualTo(OLEPropertyConstants.SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
60 crit.addEqualTo(OLEPropertyConstants.OBJECT_CODE, t.getFinancialObjectCode());
61 crit.addEqualTo(OLEPropertyConstants.SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
62 crit.addEqualTo(OLEPropertyConstants.BALANCE_TYPE_CODE, t.getFinancialBalanceTypeCode());
63 crit.addEqualTo(OLEPropertyConstants.OBJECT_TYPE_CODE, t.getFinancialObjectTypeCode());
64 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_ACCOUNTING_PERIOD, t.getUniversityFiscalPeriodCode());
65 crit.addEqualTo(OLEPropertyConstants.PROJECT_CODE, t.getProjectCode());
66
67 if (StringUtils.isBlank(t.getOrganizationReferenceId())) {
68 crit.addEqualTo(OLEPropertyConstants.ORGANIZATION_REFERENCE_ID, GeneralLedgerConstants.getDashOrganizationReferenceId());
69 }
70 else {
71 crit.addEqualTo(OLEPropertyConstants.ORGANIZATION_REFERENCE_ID, t.getOrganizationReferenceId());
72 }
73
74 QueryByCriteria qbc = QueryFactory.newQuery(ExpenditureTransaction.class, crit);
75 return (ExpenditureTransaction) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
76 }
77
78
79
80
81
82
83
84 public Iterator getAllExpenditureTransactions() {
85 LOG.debug("getAllExpenditureTransactions() started");
86 try {
87 Criteria crit = new Criteria();
88
89
90 QueryByCriteria qbc = QueryFactory.newQuery(ExpenditureTransaction.class, crit);
91 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
92 }
93 catch (Exception e) {
94 throw new RuntimeException(e);
95 }
96 }
97
98
99
100
101
102
103
104 public void delete(ExpenditureTransaction et) {
105 LOG.debug("delete() started");
106
107 getPersistenceBrokerTemplate().delete(et);
108 }
109
110
111
112
113
114
115
116
117 public void deleteAllExpenditureTransactions() {
118 LOG.debug("deleteAllExpenditureTransactions() started");
119 try{
120 Iterator<ExpenditureTransaction> i = getAllExpenditureTransactions();
121 while (i.hasNext()) {
122 ExpenditureTransaction et = i.next();
123 if (LOG.isInfoEnabled()) {
124 LOG.info("The following ExpenditureTransaction was deleted: " + et.toString());
125 }
126 delete(et);
127 }
128 }
129 catch (Exception e) {
130 throw new RuntimeException(e);
131 }
132 }
133 }