View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.dataaccess.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  
21  import org.apache.log4j.Logger;
22  import org.apache.ojb.broker.metadata.MetadataManager;
23  import org.apache.ojb.broker.query.Criteria;
24  import org.apache.ojb.broker.query.Query;
25  import org.apache.ojb.broker.query.QueryByCriteria;
26  import org.apache.ojb.broker.query.QueryFactory;
27  import org.kuali.ole.sys.OLEConstants;
28  import org.kuali.ole.sys.businessobject.AccountingLine;
29  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
30  import org.kuali.ole.sys.businessobject.TargetAccountingLine;
31  import org.kuali.ole.sys.dataaccess.AccountingLineDao;
32  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
33  import org.springframework.dao.DataAccessException;
34  
35  /**
36   * This class is the OJB implementation of the AccountingLineDao interface.
37   */
38  
39  public class AccountingLineDaoOjb extends PlatformAwareDaoBaseOjb implements AccountingLineDao {
40      private static final Logger LOG = Logger.getLogger(AccountingLineDaoOjb.class);
41  
42      /**
43       * Deletes an accounting line from the DB using OJB.
44       */
45      public void deleteAccountingLine(AccountingLine line) throws DataAccessException {
46          getPersistenceBrokerTemplate().delete(line);
47      }
48  
49      /**
50       * Retrieves accounting lines associate with a given document header ID using OJB.
51       * 
52       * @param classname
53       * @param id
54       * @return
55       */
56      public ArrayList findByDocumentHeaderId(Class clazz, String documentHeaderId) throws DataAccessException {
57          Criteria criteria = new Criteria();
58          criteria.addEqualTo("FDOC_NBR", documentHeaderId);
59          if (MetadataManager.getInstance().getRepository().getDescriptorFor(clazz).getFieldDescriptorByName("financialDocumentLineTypeCode") != null) {
60              if (SourceAccountingLine.class.isAssignableFrom(clazz)) {
61                  criteria.addEqualTo("FDOC_LN_TYP_CD", OLEConstants.SOURCE_ACCT_LINE_TYPE_CODE);
62              }
63              else if (TargetAccountingLine.class.isAssignableFrom(clazz)) {
64                  criteria.addEqualTo("FDOC_LN_TYP_CD", OLEConstants.TARGET_ACCT_LINE_TYPE_CODE);
65              }
66          }
67  
68          QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
69          Collection lines = findCollection(query);
70  
71          return new ArrayList(lines);
72      }
73  
74      /**
75       * Retrieve a Collection of Document instances found by a query.
76       * 
77       * @param query
78       * @return
79       */
80      protected Collection findCollection(Query query) throws DataAccessException {
81          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
82      }
83  }