001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.module.ld.dataaccess.impl;
017    
018    import java.util.ArrayList;
019    import java.util.Collection;
020    
021    import org.apache.log4j.Logger;
022    import org.apache.ojb.broker.query.Criteria;
023    import org.apache.ojb.broker.query.Query;
024    import org.apache.ojb.broker.query.QueryByCriteria;
025    import org.apache.ojb.broker.query.QueryFactory;
026    import org.kuali.kfs.coa.dataaccess.impl.ChartDaoOjb;
027    import org.kuali.kfs.sys.businessobject.AccountingLine;
028    import org.kuali.kfs.sys.dataaccess.AccountingLineDao;
029    import org.kuali.rice.kns.dao.impl.PlatformAwareDaoBaseOjb;
030    import org.springframework.dao.DataAccessException;
031    
032    /**
033     * This class is the OJB implementation of the AccountingLineDao interface.
034     */
035    
036    public class ExpenseTransferAccountingLineDaoOjb extends PlatformAwareDaoBaseOjb implements AccountingLineDao {
037        private static Logger LOG = Logger.getLogger(ChartDaoOjb.class);
038    
039        /**
040         * Default constructor.
041         */
042        public ExpenseTransferAccountingLineDaoOjb() {
043            super();
044        }
045    
046        /**
047         * Saves an accounting line to the DB using OJB.
048         * 
049         * @param line
050         */
051        public void save(AccountingLine line) throws DataAccessException {
052            getPersistenceBrokerTemplate().store(line);
053        }
054    
055        /**
056         * Deletes an accounting line from the DB using OJB.
057         */
058        public void deleteAccountingLine(AccountingLine line) throws DataAccessException {
059            getPersistenceBrokerTemplate().delete(line);
060        }
061    
062        /**
063         * Retrieves accounting lines associate with a given document header ID using OJB.
064         * 
065         * @param classname
066         * @param id
067         * @return
068         */
069        public ArrayList findByDocumentHeaderId(Class clazz, String documentHeaderId) throws DataAccessException {
070            Criteria criteria = new Criteria();
071            criteria.addEqualTo("FDOC_NBR", documentHeaderId);
072    
073            QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
074    
075            Collection lines = findCollection(query);
076    
077            return new ArrayList(lines);
078        }
079    
080        /**
081         * Retrieve a Collection of Document instances found by a query.
082         * 
083         * @param query
084         * @return
085         */
086        protected Collection findCollection(Query query) throws DataAccessException {
087            return getPersistenceBrokerTemplate().getCollectionByQuery(query);
088        }
089    }