1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.ole.gl.dataaccess.impl;
21
22 import java.math.BigDecimal;
23 import java.util.Date;
24 import java.util.Iterator;
25
26 import org.apache.ojb.broker.query.Criteria;
27 import org.apache.ojb.broker.query.QueryByCriteria;
28 import org.apache.ojb.broker.query.QueryFactory;
29 import org.apache.ojb.broker.query.ReportQueryByCriteria;
30 import org.kuali.ole.gl.businessobject.Entry;
31 import org.kuali.ole.gl.businessobject.Reversal;
32 import org.kuali.ole.gl.businessobject.Transaction;
33 import org.kuali.ole.gl.dataaccess.ReversalDao;
34 import org.kuali.ole.sys.OLEPropertyConstants;
35 import org.kuali.ole.sys.util.TransactionalServiceUtils;
36 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
37
38
39
40
41 public class ReversalDaoOjb extends PlatformAwareDaoBaseOjb implements ReversalDao {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ReversalDaoOjb.class);
43
44 private final static String UNIVERISITY_FISCAL_YEAR = "universityFiscalYear";
45 private final static String CHART_OF_ACCOUNTS_CODE = "chartOfAccountsCode";
46 private final static String ACCOUNT_NUMBER = "accountNumber";
47 private final static String SUB_ACCOUNT_NUMBER = "subAccountNumber";
48 private final static String FINANCIAL_OBJECT_CODE = "financialObjectCode";
49 private final static String FINANCIAL_SUB_OBJECT_CODE = "financialSubObjectCode";
50 private final static String FINANCIAL_BALANCE_TYPE_CODE = "financialBalanceTypeCode";
51 private final static String FINANCIAL_OBJECT_TYPE_CODE = "financialObjectTypeCode";
52 private final static String UNIVERISTY_FISCAL_PERIOD_CODE = "universityFiscalPeriodCode";
53 private final static String FINANCIAL_DOCUMENT_TYPE_CODE = "financialDocumentTypeCode";
54 private final static String FINANCIAL_SYSTEM_ORIGINATION_CODE = "financialSystemOriginationCode";
55 private final static String MAX_CONSTANT = "max(documentNumber)";
56
57
58
59
60 public ReversalDaoOjb() {
61 super();
62 }
63
64
65
66
67
68
69
70
71 public int getMaxSequenceNumber(Transaction t) {
72 LOG.debug("getSequenceNumber() ");
73
74 Criteria crit = new Criteria();
75 crit.addEqualTo(UNIVERISITY_FISCAL_YEAR, t.getUniversityFiscalYear());
76 crit.addEqualTo(CHART_OF_ACCOUNTS_CODE, t.getChartOfAccountsCode());
77 crit.addEqualTo(ACCOUNT_NUMBER, t.getAccountNumber());
78 crit.addEqualTo(SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
79 crit.addEqualTo(FINANCIAL_OBJECT_CODE, t.getFinancialObjectCode());
80 crit.addEqualTo(FINANCIAL_SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
81 crit.addEqualTo(FINANCIAL_BALANCE_TYPE_CODE, t.getFinancialBalanceTypeCode());
82 crit.addEqualTo(FINANCIAL_OBJECT_TYPE_CODE, t.getFinancialObjectTypeCode());
83 crit.addEqualTo(UNIVERISTY_FISCAL_PERIOD_CODE, t.getUniversityFiscalPeriodCode());
84 crit.addEqualTo(FINANCIAL_DOCUMENT_TYPE_CODE, t.getFinancialDocumentTypeCode());
85 crit.addEqualTo(FINANCIAL_SYSTEM_ORIGINATION_CODE, t.getFinancialSystemOriginationCode());
86 crit.addEqualTo(OLEPropertyConstants.DOCUMENT_NUMBER, t.getDocumentNumber());
87
88 ReportQueryByCriteria q = QueryFactory.newReportQuery(Entry.class, crit);
89 q.setAttributes(new String[] { "max(transactionLedgerEntrySequenceNumber)" });
90
91 Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
92 if (iter.hasNext()) {
93 Object[] data = (Object[]) TransactionalServiceUtils.retrieveFirstAndExhaustIterator(iter);
94 BigDecimal max = (BigDecimal) data[0];
95
96 if (max == null) {
97 return 0;
98 }
99 else {
100 return max.intValue();
101 }
102 }
103 else {
104 return 0;
105 }
106 }
107
108
109
110
111
112
113
114
115 public Reversal getByTransaction(Transaction t) {
116 LOG.debug("getByTransaction() started");
117
118 Criteria crit = new Criteria();
119 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE, t.getFinancialDocumentReversalDate());
120 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, t.getUniversityFiscalYear());
121 crit.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, t.getChartOfAccountsCode());
122 crit.addEqualTo(OLEPropertyConstants.ACCOUNT_NUMBER, t.getAccountNumber());
123 crit.addEqualTo(OLEPropertyConstants.SUB_ACCOUNT_NUMBER, t.getSubAccountNumber());
124 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, t.getFinancialObjectCode());
125 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE, t.getFinancialSubObjectCode());
126 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, t.getFinancialBalanceTypeCode());
127 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE, t.getFinancialObjectTypeCode());
128 crit.addEqualTo(OLEPropertyConstants.UNIVERSITY_FISCAL_PERIOD_CODE, t.getUniversityFiscalPeriodCode());
129 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_DOCUMENT_TYPE_CODE, t.getFinancialDocumentTypeCode());
130 crit.addEqualTo(OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE, t.getFinancialSystemOriginationCode());
131 crit.addEqualTo(OLEPropertyConstants.DOCUMENT_NUMBER, t.getDocumentNumber());
132 crit.addEqualTo(OLEPropertyConstants.TRANSACTION_ENTRY_SEQUENCE_NUMBER, t.getTransactionLedgerEntrySequenceNumber());
133
134 QueryByCriteria qbc = QueryFactory.newQuery(Reversal.class, crit);
135 return (Reversal) getPersistenceBrokerTemplate().getObjectByQuery(qbc);
136 }
137
138
139
140
141
142
143
144
145
146 public Iterator getByDate(Date before) {
147 LOG.debug("getByDate() started");
148
149 Criteria crit = new Criteria();
150 crit.addLessOrEqualThan(OLEPropertyConstants.FINANCIAL_DOCUMENT_REVERSAL_DATE, new java.sql.Date(before.getTime()));
151
152 QueryByCriteria qbc = QueryFactory.newQuery(Reversal.class, crit);
153 return getPersistenceBrokerTemplate().getIteratorByQuery(qbc);
154 }
155
156
157
158
159
160
161
162 public void delete(Reversal re) {
163 LOG.debug("delete() started");
164
165 getPersistenceBrokerTemplate().delete(re);
166 }
167 }