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.math.BigDecimal;
19 import java.sql.Date;
20 import java.util.Iterator;
21
22 import org.apache.ojb.broker.metadata.ClassDescriptor;
23 import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
24 import org.apache.ojb.broker.metadata.DescriptorRepository;
25 import org.apache.ojb.broker.metadata.MetadataManager;
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.CollectorDetail;
31 import org.kuali.ole.gl.dataaccess.CollectorDetailDao;
32 import org.kuali.ole.sys.OLEPropertyConstants;
33 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
34 import org.kuali.rice.krad.exception.ClassNotPersistableException;
35
36
37
38
39 public class CollectorDetailDaoOjb extends PlatformAwareDaoBaseOjb implements CollectorDetailDao {
40 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CollectorDetailDaoOjb.class);
41
42 private DescriptorRepository descriptorRepository;
43
44 public CollectorDetailDaoOjb() {
45 MetadataManager metadataManager = MetadataManager.getInstance();
46 descriptorRepository = metadataManager.getGlobalRepository();
47 }
48
49
50
51
52
53
54
55 public void purgeYearByChart(String chartOfAccountsCode, int universityFiscalYear) {
56 LOG.debug("purgeYearByChart() started");
57
58 Criteria criteria = new Criteria();
59 criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
60 criteria.addLessThan(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, new Integer(universityFiscalYear));
61
62 getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(CollectorDetail.class, criteria));
63
64
65
66
67 getPersistenceBrokerTemplate().clearCache();
68 }
69
70
71
72
73
74
75
76 public String retrieveCollectorDetailTableName() {
77 ClassDescriptor classDescriptor = null;
78 DescriptorRepository globalRepository = descriptorRepository;
79 try {
80 classDescriptor = globalRepository.getDescriptorFor(CollectorDetail.class);
81 }
82 catch (ClassNotPersistenceCapableException e) {
83 throw new ClassNotPersistableException("class '" + CollectorDetail.class.getName() + "' is not persistable", e);
84 }
85
86 return classDescriptor.getFullTableName();
87 }
88
89
90 public Integer getMaxCreateSequence(Date date) {
91 Criteria crit = new Criteria();
92 crit.addEqualTo("CREATE_DT", date);
93
94 ReportQueryByCriteria q = QueryFactory.newReportQuery(CollectorDetail.class, crit);
95 q.setAttributes(new String[] { "max(transactionLedgerEntrySequenceNumber)" });
96
97 Iterator<Object[]> iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(q);
98 if (iter.hasNext()) {
99 Object[] result = iter.next();
100 if (result[0] != null) {
101 return new Integer(((BigDecimal)result[0]).intValue());
102 }
103 }
104 return null;
105 }
106
107
108 }