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.kfs.dao.ojb;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020:
021: import org.apache.log4j.Logger;
022: import org.apache.ojb.broker.metadata.MetadataManager;
023: import org.apache.ojb.broker.query.Criteria;
024: import org.apache.ojb.broker.query.Query;
025: import org.apache.ojb.broker.query.QueryByCriteria;
026: import org.apache.ojb.broker.query.QueryFactory;
027: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.bo.AccountingLine;
030: import org.kuali.kfs.bo.SourceAccountingLine;
031: import org.kuali.kfs.bo.TargetAccountingLine;
032: import org.kuali.kfs.dao.AccountingLineDao;
033: import org.kuali.module.chart.dao.ojb.ChartDaoOjb;
034: import org.springframework.dao.DataAccessException;
035:
036: /**
037: * This class is the OJB implementation of the AccountingLineDao interface.
038: */
039:
040: public class AccountingLineDaoOjb extends PlatformAwareDaoBaseOjb
041: implements AccountingLineDao {
042: private static Logger LOG = Logger.getLogger(ChartDaoOjb.class);
043:
044: /**
045: * Default constructor.
046: */
047: public AccountingLineDaoOjb() {
048: super ();
049: }
050:
051: /**
052: * Saves an accounting line to the DB using OJB.
053: *
054: * @param line
055: */
056: public void save(AccountingLine line) throws DataAccessException {
057: getPersistenceBrokerTemplate().store(line);
058: }
059:
060: /**
061: * Deletes an accounting line from the DB using OJB.
062: */
063: public void deleteAccountingLine(AccountingLine line)
064: throws DataAccessException {
065: getPersistenceBrokerTemplate().delete(line);
066: }
067:
068: /**
069: * Retrieves accounting lines associate with a given document header ID using OJB.
070: *
071: * @param classname
072: * @param id
073: * @return
074: */
075: public ArrayList findByDocumentHeaderId(Class clazz,
076: String documentHeaderId) throws DataAccessException {
077: Criteria criteria = new Criteria();
078: criteria.addEqualTo("FDOC_NBR", documentHeaderId);
079: if (MetadataManager.getInstance().getRepository()
080: .getDescriptorFor(clazz).getFieldDescriptorByName(
081: "financialDocumentLineTypeCode") != null) {
082: if (SourceAccountingLine.class.isAssignableFrom(clazz)) {
083: criteria.addEqualTo("FDOC_LN_TYP_CD",
084: KFSConstants.SOURCE_ACCT_LINE_TYPE_CODE);
085: } else if (TargetAccountingLine.class
086: .isAssignableFrom(clazz)) {
087: criteria.addEqualTo("FDOC_LN_TYP_CD",
088: KFSConstants.TARGET_ACCT_LINE_TYPE_CODE);
089: }
090: }
091:
092: QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
093: Collection lines = findCollection(query);
094:
095: return new ArrayList(lines);
096: }
097:
098: /**
099: * Retrieve a Collection of Document instances found by a query.
100: *
101: * @param query
102: * @return
103: */
104: private Collection findCollection(Query query)
105: throws DataAccessException {
106: return getPersistenceBrokerTemplate().getCollectionByQuery(
107: query);
108: }
109: }
|