01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.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 edu.iu.uis.eden.help.dao;
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.springmodules.orm.ojb.PersistenceBrokerTemplate;
24: import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport;
25:
26: import edu.iu.uis.eden.help.HelpEntry;
27:
28: public class HelpDAOOjbImpl extends PersistenceBrokerDaoSupport
29: 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()
43: .getObjectByQuery(
44: new QueryByCriteria(HelpEntry.class, crit));
45: }
46:
47: public List search(HelpEntry helpEntry) {
48: Criteria crit = new Criteria();
49:
50: if (helpEntry.getHelpId() != null
51: && helpEntry.getHelpId().longValue() != 0) {
52: crit.addEqualTo("helpId", helpEntry.getHelpId());
53: }
54:
55: if (!this .isStringEmpty(helpEntry.getHelpName())) {
56: crit.addLike("UPPER(helpName)", "%"
57: + helpEntry.getHelpName().toUpperCase() + "%");
58: }
59:
60: if (!this .isStringEmpty(helpEntry.getHelpText())) {
61: crit.addLike("UPPER(helpText)", "%"
62: + helpEntry.getHelpText().toUpperCase() + "%");
63: }
64:
65: if (!this .isStringEmpty(helpEntry.getHelpKey())) {
66: crit.addLike("UPPER(helpKey)", "%"
67: + helpEntry.getHelpKey().toUpperCase() + "%");
68: }
69: return (List) this .getPersistenceBrokerTemplate()
70: .getCollectionByQuery(
71: new QueryByCriteria(HelpEntry.class, crit));
72: }
73:
74: private boolean isStringEmpty(String string) {
75: if ((string == null) || string.trim().equals("")) {
76: return true;
77: }
78:
79: return false;
80: }
81:
82: public HelpEntry findByKey(String helpKey) {
83: Criteria crit = new Criteria();
84: crit.addEqualTo("helpKey", helpKey);
85: return (HelpEntry) this .getPersistenceBrokerTemplate()
86: .getObjectByQuery(
87: new QueryByCriteria(HelpEntry.class, crit));
88: }
89: }
|