View Javadoc

1   /**
2    * Copyright 2005-2014 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.rice.edl.impl.dao.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.ojb.broker.query.Criteria;
23  import org.apache.ojb.broker.query.QueryByCriteria;
24  import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
25  import org.kuali.rice.edl.impl.bo.EDocLiteDefinition;
26  import org.kuali.rice.edl.impl.dao.EDocLiteDAO;
27  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
28  
29  
30  public class EDocLiteDAOOjbImpl extends PersistenceBrokerDaoSupport implements EDocLiteDAO {
31  
32      public void saveEDocLiteDefinition(EDocLiteDefinition edocLiteData) {
33      	this.getPersistenceBrokerTemplate().store(edocLiteData);
34      }
35  
36      public void saveEDocLiteAssociation(EDocLiteAssociation assoc) {
37      	this.getPersistenceBrokerTemplate().store(assoc);
38      }
39  
40      public EDocLiteDefinition getEDocLiteDefinition(String defName) {
41          Criteria criteria = new Criteria();
42          criteria.addEqualTo("name", defName);
43          criteria.addEqualTo("activeInd", Boolean.TRUE);
44          return (EDocLiteDefinition) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria));
45      }
46  
47      public EDocLiteAssociation getEDocLiteAssociation(String docTypeName) {
48          Criteria criteria = new Criteria();
49          criteria.addEqualTo("edlName", docTypeName);
50          criteria.addEqualTo("activeInd", Boolean.TRUE);
51          return (EDocLiteAssociation) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria));
52      }
53  
54      public List getEDocLiteDefinitions() {
55          Criteria criteria = new Criteria();
56          criteria.addEqualTo("activeInd", Boolean.TRUE);
57          Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteDefinition.class, criteria));
58          List defs = new ArrayList();
59          while (it.hasNext()) {
60              defs.add(((EDocLiteDefinition) it.next()).getName());
61          }
62          return defs;
63      }
64  
65      public List getEDocLiteAssociations() {
66          Criteria criteria = new Criteria();
67          criteria.addEqualTo("activeInd", Boolean.TRUE);
68          Iterator it = this.getPersistenceBrokerTemplate().getIteratorByQuery(new QueryByCriteria(EDocLiteAssociation.class, criteria));
69          List assocs = new ArrayList();
70          while (it.hasNext()) {
71              assocs.add(it.next());
72          }
73          return assocs;
74      }
75  
76  	public List search(EDocLiteAssociation edocLite) {
77  		Criteria crit = new Criteria();
78  		if (edocLite.getActiveInd() != null) {
79  			crit.addEqualTo("activeInd", edocLite.getActiveInd());
80  		}
81  		if (edocLite.getDefinition() != null) {
82  			crit.addLike("UPPER(definition)", "%"+edocLite.getDefinition().toUpperCase()+"%");
83  		}
84  		if (edocLite.getEdlName() != null) {
85  			crit.addLike("UPPER(edlName)", "%"+edocLite.getEdlName().toUpperCase()+"%");
86  		}
87  		if (edocLite.getStyle() != null) {
88  			crit.addLike("UPPER(style)", "%"+edocLite.getStyle().toUpperCase()+"%");
89  		}
90  		return (List)this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit));
91  	}
92  
93  	public EDocLiteAssociation getEDocLiteAssociation(Long associationId) {
94  		Criteria crit = new Criteria();
95  		crit.addEqualTo("edocLiteAssocId", associationId);
96  		return (EDocLiteAssociation)this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(EDocLiteAssociation.class, crit));
97  	}
98  }