001/*
002 * Copyright 2008 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 */
016package org.kuali.ole.module.purap.document.dataaccess.impl;
017
018import org.apache.log4j.Logger;
019import org.apache.ojb.broker.query.Criteria;
020import org.apache.ojb.broker.query.Query;
021import org.apache.ojb.broker.query.QueryByCriteria;
022import org.kuali.ole.module.purap.PurapPropertyConstants;
023import org.kuali.ole.module.purap.businessobject.ReceivingAddress;
024import org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao;
025import org.kuali.ole.sys.OLEPropertyConstants;
026import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
027import org.springframework.transaction.annotation.Transactional;
028
029import java.util.Collection;
030
031/**
032 * OJB Implementation of ReceivingAddressDao.
033 */
034@Transactional
035public class ReceivingAddressDaoOjb extends PlatformAwareDaoBaseOjb implements ReceivingAddressDao {
036    private static Logger LOG = Logger.getLogger(ReceivingAddressDaoOjb.class);
037
038    /**
039     * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#findActiveByChartOrg(java.lang.String, java.lang.String)
040     */
041    public Collection<ReceivingAddress> findActiveByChartOrg(String chartCode, String orgCode) {
042        LOG.debug("Entering findActiveByChartOrg(String,String)");
043
044        Criteria criteria = new Criteria();
045        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
046        if (orgCode == null)
047            criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
048        else
049            criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
050        criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
051        Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
052
053        LOG.debug("Leaving findActiveByChartOrg(String,String)");
054        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
055    }
056
057    /**
058     * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#findDefaultByChartOrg(java.lang.String, java.lang.String)
059     */
060    public Collection<ReceivingAddress> findDefaultByChartOrg(String chartCode, String orgCode) {
061        LOG.debug("Entering findDefaultByChartOrg(String,String)");
062
063        Criteria criteria = new Criteria();
064        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
065        if (orgCode == null)
066            criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
067        else
068            criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
069        criteria.addEqualTo(PurapPropertyConstants.RECEIVING_ADDRESS_DEFAULT_INDICATOR, true);
070        criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
071        Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
072
073        LOG.debug("Leaving findDefaultByChartOrg(String,String)");
074        return getPersistenceBrokerTemplate().getCollectionByQuery(query);
075    }
076
077    /**
078     * @see org.kuali.ole.module.purap.document.dataaccess.ReceivingAddressDao#countActiveByChartOrg(java.lang.String, java.lang.String)
079     */
080    public int countActiveByChartOrg(String chartCode, String orgCode) {
081        LOG.debug("Entering countActiveByChartOrg(String,String)");
082
083        Criteria criteria = new Criteria();
084        criteria.addEqualTo(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
085        if (orgCode == null)
086            criteria.addIsNull(OLEPropertyConstants.ORGANIZATION_CODE);
087        else
088            criteria.addEqualTo(OLEPropertyConstants.ORGANIZATION_CODE, orgCode);
089        criteria.addEqualTo(PurapPropertyConstants.BO_ACTIVE, true);
090        Query query = new QueryByCriteria(ReceivingAddress.class, criteria);
091
092        LOG.debug("Leaving countActiveByChartOrg(String,String)");
093        return getPersistenceBrokerTemplate().getCount(query);
094    }
095
096}