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