001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.edl.dao;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.ojb.broker.query.Criteria;
024: import org.apache.ojb.broker.query.QueryByCriteria;
025: import org.springmodules.orm.ojb.PersistenceBrokerTemplate;
026: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
027:
028: import edu.iu.uis.eden.edl.EDocLiteAssociation;
029: import edu.iu.uis.eden.edl.EDocLiteDefinition;
030: import edu.iu.uis.eden.edl.EDocLiteStyle;
031:
032: public class EDocLiteDAOOjbImpl extends PersistenceBrokerDaoSupport
033: implements EDocLiteDAO {
034:
035: public void saveEDocLiteStyle(EDocLiteStyle styleData) {
036: this .getPersistenceBrokerTemplate().store(styleData);
037: }
038:
039: public void saveEDocLiteDefinition(EDocLiteDefinition edocLiteData) {
040: this .getPersistenceBrokerTemplate().store(edocLiteData);
041: }
042:
043: public void saveEDocLiteAssociation(EDocLiteAssociation assoc) {
044: this .getPersistenceBrokerTemplate().store(assoc);
045: }
046:
047: public EDocLiteStyle getEDocLiteStyle(String styleName) {
048: Criteria criteria = new Criteria();
049: criteria.addEqualTo("name", styleName);
050: criteria.addEqualTo("activeInd", Boolean.TRUE);
051: return (EDocLiteStyle) this .getPersistenceBrokerTemplate()
052: .getObjectByQuery(
053: new QueryByCriteria(EDocLiteStyle.class,
054: criteria));
055: }
056:
057: public EDocLiteDefinition getEDocLiteDefinition(String defName) {
058: Criteria criteria = new Criteria();
059: criteria.addEqualTo("name", defName);
060: criteria.addEqualTo("activeInd", Boolean.TRUE);
061: return (EDocLiteDefinition) this .getPersistenceBrokerTemplate()
062: .getObjectByQuery(
063: new QueryByCriteria(EDocLiteDefinition.class,
064: criteria));
065: }
066:
067: public EDocLiteAssociation getEDocLiteAssociation(String docTypeName) {
068: Criteria criteria = new Criteria();
069: criteria.addEqualTo("edlName", docTypeName);
070: criteria.addEqualTo("activeInd", Boolean.TRUE);
071: return (EDocLiteAssociation) this
072: .getPersistenceBrokerTemplate().getObjectByQuery(
073: new QueryByCriteria(EDocLiteAssociation.class,
074: criteria));
075: }
076:
077: /**
078: * Returns names of all active Styles
079: */
080: public List<String> getEDocLiteStyleNames() {
081: List<EDocLiteStyle> styles = getEDocLiteStyles();
082: List<String> styleNames = new ArrayList<String>(styles.size());
083: for (EDocLiteStyle style : styles) {
084: styleNames.add(style.getName());
085: }
086: return styleNames;
087: }
088:
089: /**
090: * Returns all active Styles
091: */
092: public List<EDocLiteStyle> getEDocLiteStyles() {
093: Criteria criteria = new Criteria();
094: criteria.addEqualTo("activeInd", Boolean.TRUE);
095: Iterator it = this .getPersistenceBrokerTemplate()
096: .getIteratorByQuery(
097: new QueryByCriteria(EDocLiteStyle.class,
098: criteria));
099: List<EDocLiteStyle> styles = new ArrayList<EDocLiteStyle>();
100: while (it.hasNext()) {
101: styles.add((EDocLiteStyle) it.next());
102: }
103: return styles;
104: }
105:
106: public List getEDocLiteDefinitions() {
107: Criteria criteria = new Criteria();
108: criteria.addEqualTo("activeInd", Boolean.TRUE);
109: Iterator it = this .getPersistenceBrokerTemplate()
110: .getIteratorByQuery(
111: new QueryByCriteria(EDocLiteDefinition.class,
112: criteria));
113: List defs = new ArrayList();
114: while (it.hasNext()) {
115: defs.add(((EDocLiteDefinition) it.next()).getName());
116: }
117: return defs;
118: }
119:
120: public List getEDocLiteAssociations() {
121: Criteria criteria = new Criteria();
122: criteria.addEqualTo("activeInd", Boolean.TRUE);
123: Iterator it = this .getPersistenceBrokerTemplate()
124: .getIteratorByQuery(
125: new QueryByCriteria(EDocLiteAssociation.class,
126: criteria));
127: List assocs = new ArrayList();
128: while (it.hasNext()) {
129: assocs.add(it.next());
130: }
131: return assocs;
132: }
133:
134: public List search(EDocLiteAssociation edocLite) {
135: Criteria crit = new Criteria();
136: if (edocLite.getActiveInd() != null) {
137: crit.addEqualTo("activeInd", edocLite.getActiveInd());
138: }
139: if (edocLite.getDefinition() != null) {
140: crit.addLike("UPPER(definition)", "%"
141: + edocLite.getDefinition().toUpperCase() + "%");
142: }
143: if (edocLite.getEdlName() != null) {
144: crit.addLike("UPPER(edlName)", "%"
145: + edocLite.getEdlName().toUpperCase() + "%");
146: }
147: if (edocLite.getStyle() != null) {
148: crit.addLike("UPPER(style)", "%"
149: + edocLite.getStyle().toUpperCase() + "%");
150: }
151: return (List) this .getPersistenceBrokerTemplate()
152: .getCollectionByQuery(
153: new QueryByCriteria(EDocLiteAssociation.class,
154: crit));
155: }
156:
157: public EDocLiteAssociation getEDocLiteAssociation(Long associationId) {
158: Criteria crit = new Criteria();
159: crit.addEqualTo("eDocLiteAssocId", associationId);
160: return (EDocLiteAssociation) this
161: .getPersistenceBrokerTemplate().getObjectByQuery(
162: new QueryByCriteria(EDocLiteAssociation.class,
163: crit));
164: }
165: }
|