View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    * 
4    * 
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    * 
9    * http://www.opensource.org/licenses/ecl2.php
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.kuali.rice.kew.help.dao.impl;
18  
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.kew.help.HelpEntry;
24  import org.kuali.rice.kew.help.dao.HelpDAO;
25  import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
26  
27  
28  
29  public class HelpDAOOjbImpl extends PersistenceBrokerDaoSupport implements HelpDAO {
30  	
31      public void save(HelpEntry helpEntry){
32          this.getPersistenceBrokerTemplate().store(helpEntry);
33      }
34      
35      public void deleteEntry(HelpEntry helpEntry) {
36      	this.getPersistenceBrokerTemplate().delete(helpEntry);
37      }
38      
39      public HelpEntry findById(Long helpId){
40          Criteria crit = new Criteria();
41          crit.addEqualTo("helpId", helpId);
42  		return (HelpEntry) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(HelpEntry.class, crit)); 
43      }
44      
45      public List search(HelpEntry helpEntry){
46          Criteria crit = new Criteria();
47  
48          if (helpEntry.getHelpId() != null && helpEntry.getHelpId().longValue() != 0) {
49              crit.addEqualTo("helpId", helpEntry.getHelpId());
50          }
51  
52          if (!this.isStringEmpty(helpEntry.getHelpName())) {
53              crit.addLike("UPPER(helpName)", "%" + helpEntry.getHelpName().toUpperCase() + "%");
54          }
55  
56          if (!this.isStringEmpty(helpEntry.getHelpText())) {
57              crit.addLike("UPPER(helpText)", "%" + helpEntry.getHelpText().toUpperCase() + "%");
58          }
59          
60          if (!this.isStringEmpty(helpEntry.getHelpKey())) {
61              crit.addLike("UPPER(helpKey)", "%" + helpEntry.getHelpKey().toUpperCase() + "%"); 	
62          }
63          return (List) this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(HelpEntry.class, crit));
64      }
65      
66      private boolean isStringEmpty(String string) {
67          if ((string == null) || string.trim().equals("")) {
68              return true;
69          }
70  
71          return false;
72      }
73      
74      public HelpEntry findByKey(String helpKey){
75          Criteria crit = new Criteria();
76          crit.addEqualTo("helpKey", helpKey);
77  		return  (HelpEntry) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(HelpEntry.class, crit)); 
78      }
79  }