View Javadoc
1   /*
2    * Copyright 2008 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.document.dataaccess.impl;
17  
18  import org.apache.log4j.Logger;
19  import org.apache.ojb.broker.query.Criteria;
20  import org.apache.ojb.broker.query.Query;
21  import org.apache.ojb.broker.query.QueryByCriteria;
22  import org.kuali.ole.module.purap.PurapPropertyConstants;
23  import org.kuali.ole.module.purap.businessobject.ReceivingAddress;
24  import org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
27  import org.springframework.transaction.annotation.Transactional;
28  
29  import java.util.Collection;
30  
31  /**
32   * OJB Implementation of ReceivingAddressDao.
33   */
34  @Transactional
35  public class ReceivingAddressDaoOjb extends PlatformAwareDaoBaseOjb implements ReceivingAddressDao {
36      private static Logger LOG = Logger.getLogger(ReceivingAddressDaoOjb.class);
37  
38      /**
39       * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#findActiveByChartOrg(java.lang.String, java.lang.String)
40       */
41      public Collection<ReceivingAddress> findActiveByChartOrg(String chartCode, String orgCode) {
42          LOG.debug("Entering findActiveByChartOrg(String,String)");
43  
44          Criteria criteria = new Criteria();
45          criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
46          if (orgCode == null)
47              criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
48          else
49              criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
50          criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
51          Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
52  
53          LOG.debug("Leaving findActiveByChartOrg(String,String)");
54          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
55      }
56  
57      /**
58       * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#findDefaultByChartOrg(java.lang.String, java.lang.String)
59       */
60      public Collection<ReceivingAddress> findDefaultByChartOrg(String chartCode, String orgCode) {
61          LOG.debug("Entering findDefaultByChartOrg(String,String)");
62  
63          Criteria criteria = new Criteria();
64          criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
65          if (orgCode == null)
66              criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
67          else
68              criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
69          criteria.addEqualTo(PurapPropertyConstants.RECEIVING_ADDRESS_DEFAULT_INDICATOR, true);
70          criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
71          Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
72  
73          LOG.debug("Leaving findDefaultByChartOrg(String,String)");
74          return getPersistenceBrokerTemplate().getCollectionByQuery(query);
75      }
76  
77      /**
78       * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#countActiveByChartOrg(java.lang.String, java.lang.String)
79       */
80      public int countActiveByChartOrg(String chartCode, String orgCode) {
81          LOG.debug("Entering countActiveByChartOrg(String,String)");
82  
83          Criteria criteria = new Criteria();
84          criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
85          if (orgCode == null)
86              criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
87          else
88              criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
89          criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
90          Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
91  
92          LOG.debug("Leaving countActiveByChartOrg(String,String)");
93          return getPersistenceBrokerTemplate().getCount(query);
94      }
95  
96  }