001: /*
002: * Copyright 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 org.apache.ojb.broker.metadata.ClassDescriptor;
019: import org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException;
020: import org.apache.ojb.broker.metadata.DescriptorRepository;
021: import org.apache.ojb.broker.metadata.MetadataManager;
022: import org.apache.ojb.broker.query.Criteria;
023: import org.apache.ojb.broker.query.QueryByCriteria;
024: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
025: import org.kuali.core.exceptions.ClassNotPersistableException;
026: import org.kuali.kfs.KFSPropertyConstants;
027: import org.kuali.module.gl.bo.CollectorDetail;
028: import org.kuali.module.gl.dao.CollectorDetailDao;
029:
030: /**
031: * An OJB implementation of the CollectorDetailDao
032: */
033: public class CollectorDetailDaoOjb extends PlatformAwareDaoBaseOjb
034: implements CollectorDetailDao {
035: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
036: .getLogger(CollectorDetailDaoOjb.class);
037:
038: private DescriptorRepository descriptorRepository;
039:
040: public CollectorDetailDaoOjb() {
041: MetadataManager metadataManager = MetadataManager.getInstance();
042: descriptorRepository = metadataManager.getGlobalRepository();
043: }
044:
045: /**
046: * Purge the table by year/chart. Clears persistence broker template at the end to ensure OJB has to to DB again
047: * to retrieve the post-purged state of the DB.
048: *
049: * @see org.kuali.module.gl.dao.CollectorDetailDao#purgeYearByChart(java.lang.String, int)
050: */
051: public void purgeYearByChart(String chartOfAccountsCode,
052: int universityFiscalYear) {
053: LOG.debug("purgeYearByChart() started");
054:
055: Criteria criteria = new Criteria();
056: criteria.addEqualTo(
057: KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE,
058: chartOfAccountsCode);
059: criteria.addLessThan(
060: KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
061: new Integer(universityFiscalYear));
062:
063: getPersistenceBrokerTemplate().deleteByQuery(
064: new QueryByCriteria(CollectorDetail.class, criteria));
065:
066: // This is required because if any deleted items are in the cache, deleteByQuery doesn't
067: // remove them from the cache so a future select will retrieve these deleted account balances from
068: // the cache and return them. Clearing the cache forces OJB to go to the database again.
069: getPersistenceBrokerTemplate().clearCache();
070: }
071:
072: /**
073: * Save specific collector detail
074: * @param detail the CollectorDetail to save
075: * @see org.kuali.module.gl.dao.CollectorDetailDao#save(org.kuali.module.gl.bo.CollectorDetail)
076: */
077: public void save(CollectorDetail detail) {
078: LOG.debug("saveOriginEntry() started");
079:
080: getPersistenceBrokerTemplate().store(detail);
081: }
082:
083: /**
084: * Retrieves the DB table name that's mapped to instances of CollectorDetail by finding the class descriptor name from the
085: * class descriptor respository
086: * @return the table name where collector details are saved to
087: * @see org.kuali.module.gl.dao.CollectorDetailDao#retrieveCollectorDetailTableName()
088: */
089: public String retrieveCollectorDetailTableName() {
090: ClassDescriptor classDescriptor = null;
091: DescriptorRepository globalRepository = descriptorRepository;
092: try {
093: classDescriptor = globalRepository
094: .getDescriptorFor(CollectorDetail.class);
095: } catch (ClassNotPersistenceCapableException e) {
096: throw new ClassNotPersistableException("class '"
097: + CollectorDetail.class.getName()
098: + "' is not persistable", e);
099: }
100:
101: return classDescriptor.getFullTableName();
102: }
103:
104: }
|