001    /**
002     * Copyright 2005-2013 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.rice.edl.impl.dao.impl;
017    
018    import java.util.ArrayList;
019    import java.util.Iterator;
020    import java.util.List;
021    
022    import org.apache.ojb.broker.query.Criteria;
023    import org.apache.ojb.broker.query.QueryByCriteria;
024    import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
025    import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
026    import org.kuali.rice.edl.impl.dao.EDocLiteDAO;
027    import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
028    
029    
030    public class EDocLiteDAOOjbImpl extends PersistenceBrokerDaoSupport implements EDocLiteDAO {
031    
032        public void saveEDocLiteDefinition(EDocLiteDefinition edocLiteData) {
033            this.getPersistenceBrokerTemplate().store(edocLiteData);
034        }
035    
036        public void saveEDocLiteAssociation(EDocLiteAssociation assoc) {
037            this.getPersistenceBrokerTemplate().store(assoc);
038        }
039    
040        public EDocLiteDefinition getEDocLiteDefinition(String defName) {
041            Criteria criteria = new Criteria();
042            criteria.addEqualTo("name", defName);
043            criteria.addEqualTo("activeInd", Boolean.TRUE);
044            return (EDocLiteDefinition) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria));
045        }
046    
047        public EDocLiteAssociation getEDocLiteAssociation(String docTypeName) {
048            Criteria criteria = new Criteria();
049            criteria.addEqualTo("edlName", docTypeName);
050            criteria.addEqualTo("activeInd", Boolean.TRUE);
051            return (EDocLiteAssociation) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria));
052        }
053    
054        public List getEDocLiteDefinitions() {
055            Criteria criteria = new Criteria();
056            criteria.addEqualTo("activeInd", Boolean.TRUE);
057            Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria));
058            List defs = new ArrayList();
059            while (it.hasNext()) {
060                defs.add(((EDocLiteDefinition) it.next()).getName());
061            }
062            return defs;
063        }
064    
065        public List getEDocLiteAssociations() {
066            Criteria criteria = new Criteria();
067            criteria.addEqualTo("activeInd", Boolean.TRUE);
068            Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria));
069            List assocs = new ArrayList();
070            while (it.hasNext()) {
071                assocs.add(it.next());
072            }
073            return assocs;
074        }
075    
076            public List search(EDocLiteAssociation edocLite) {
077                    Criteria crit = new Criteria();
078                    if (edocLite.getActiveInd() != null) {
079                            crit.addEqualTo("activeInd", edocLite.getActiveInd());
080                    }
081                    if (edocLite.getDefinition() != null) {
082                            crit.addLike("UPPER(definition)", "%"+edocLite.getDefinition().toUpperCase()+"%");
083                    }
084                    if (edocLite.getEdlName() != null) {
085                            crit.addLike("UPPER(edlName)", "%"+edocLite.getEdlName().toUpperCase()+"%");
086                    }
087                    if (edocLite.getStyle() != null) {
088                            crit.addLike("UPPER(style)", "%"+edocLite.getStyle().toUpperCase()+"%");
089                    }
090                    return (List)this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit));
091            }
092    
093            public EDocLiteAssociation getEDocLiteAssociation(Long associationId) {
094                    Criteria crit = new Criteria();
095                    crit.addEqualTo("edocLiteAssocId", associationId);
096                    return (EDocLiteAssociation)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit));
097            }
098    }