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.module.purap.dataaccess.impl;
17  
18  import org.apache.ojb.broker.query.Criteria;
19  import org.apache.ojb.broker.query.QueryByCriteria;
20  import org.apache.ojb.broker.query.QueryFactory;
21  import org.kuali.ole.module.purap.PurapPropertyConstants;
22  import org.kuali.ole.module.purap.businessobject.AccountsPayableSummaryAccount;
23  import org.kuali.ole.module.purap.businessobject.PurApItem;
24  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
25  import org.kuali.ole.module.purap.dataaccess.PurApAccountingDao;
26  import org.kuali.ole.select.businessobject.OleInvoiceAccountsPayableSummaryAccount;
27  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
28  
29  import java.util.ArrayList;
30  import java.util.Collection;
31  import java.util.List;
32  
33  /**
34   * OJB Implementation of PurApAccountingDao.
35   */
36  public class PurApAccountingDaoOjb extends PlatformAwareDaoBaseOjb implements PurApAccountingDao {
37  
38      /**
39       * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#getAccountingLinesForItem(org.kuali.ole.module.purap.businessobject.PurApItem)
40       */
41      public List getAccountingLinesForItem(PurApItem item) {
42          Class clazz = item.getAccountingLineClass();
43          Criteria criteria = new Criteria();
44          criteria.addEqualTo("itemIdentifier", item.getItemIdentifier());
45  
46          // if it's a purchaseOrderItem, we need to make sure we're getting for the right doc number
47          if (item instanceof PurchaseOrderItem) {
48              criteria.addEqualTo("documentNumber", ((PurchaseOrderItem) item).getDocumentNumber());
49          }
50  
51          QueryByCriteria query = QueryFactory.newQuery(clazz, criteria);
52          Collection lines = getPersistenceBrokerTemplate().getCollectionByQuery(query);
53  
54          return new ArrayList(lines);
55  
56      }
57  
58      /**
59       * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyPaymentRequestIdentifier(java.lang.Integer)
60       */
61      public void deleteSummaryAccountsbyPaymentRequestIdentifier(Integer paymentRequestIdentifier) {
62          if (paymentRequestIdentifier != null) {
63              Criteria criteria = new Criteria();
64              criteria.addEqualTo(PurapPropertyConstants.PAYMENT_REQUEST_ID, paymentRequestIdentifier);
65  
66              getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(AccountsPayableSummaryAccount.class, criteria));
67              getPersistenceBrokerTemplate().clearCache();
68          }
69      }
70  
71      /**
72       * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyPaymentRequestIdentifier(java.lang.Integer)
73       */
74      public void deleteSummaryAccountsbyInvoiceIdentifier(Integer invoiceIdentifier) {
75          if (invoiceIdentifier != null) {
76              Criteria criteria = new Criteria();
77              criteria.addEqualTo(PurapPropertyConstants.INVOICE_ID, invoiceIdentifier);
78  
79              getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(OleInvoiceAccountsPayableSummaryAccount.class, criteria));
80              getPersistenceBrokerTemplate().clearCache();
81          }
82      }
83  
84      /**
85       * @see org.kuali.ole.module.purap.dataaccess.PurApAccountingDao#deleteSummaryAccountsbyCreditMemoIdentifier(java.lang.Integer)
86       */
87      public void deleteSummaryAccountsbyCreditMemoIdentifier(Integer creditMemoIdentifier) {
88          if (creditMemoIdentifier != null) {
89              Criteria criteria = new Criteria();
90              criteria.addEqualTo(PurapPropertyConstants.CREDIT_MEMO_ID, creditMemoIdentifier);
91  
92              getPersistenceBrokerTemplate().deleteByQuery(QueryFactory.newQuery(AccountsPayableSummaryAccount.class, criteria));
93              getPersistenceBrokerTemplate().clearCache();
94          }
95      }
96  
97  }