View Javadoc

1   /**
2    * Copyright 2005-2011 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.core.impl.style;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.ojb.broker.query.Criteria;
22  import org.apache.ojb.broker.query.QueryByCriteria;
23  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
24  
25  /**
26   * An OJB implementation of the {@link StyleDao}.
27   * 
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   *
30   */
31  public class StyleDaoOjb extends PersistenceBrokerDaoSupport implements StyleDao {
32  
33  	@Override
34      public void saveStyle(StyleBo styleData) {
35  		if (styleData == null) {
36  			return;
37  		}
38          this.getPersistenceBrokerTemplate().store(styleData);
39      }
40  
41  	@Override
42      public StyleBo getStyle(String styleName) {
43  		if (styleName == null) {
44  			return null;
45  		}
46          Criteria criteria = new Criteria();
47          criteria.addEqualTo("name", styleName);
48          criteria.addEqualTo("active", Boolean.TRUE);
49          return (StyleBo) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(StyleBo.class, criteria));
50      }
51  	
52  	@Override
53  	public List<String> getAllStyleNames() {
54  		Criteria criteria = new Criteria();
55          criteria.addEqualTo("active", Boolean.TRUE);
56          List<StyleBo> styles = (List<StyleBo>)this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(StyleBo.class, criteria));
57          List<String> styleNames = new ArrayList<String>();
58          for (StyleBo style : styles) {
59          	styleNames.add(style.getName());
60          }
61          return styleNames;
62      }
63  
64  }