01: /*
02: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
03: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
04: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
05: *
06: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
07: * General Public License as published by the Free Software Foundation; either version 2 of the License,
08: * or (at your option) any later version.
09: *
10: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
11: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License along with this program; if not,
15: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16: */
17:
18: package wilos.hibernate.spem2.element;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
24:
25: import wilos.model.spem2.element.Element;
26:
27: /**
28: * ElementDao manage requests from the system to store Elements into the database.
29: *
30: * @author deder
31: */
32: public class ElementDao extends HibernateDaoSupport {
33:
34: /**
35: * Saves or updates an Element
36: *
37: * @param _element The Element to be saved or updated
38: */
39: public String saveOrUpdateElement(Element _element) {
40: if (_element != null) {
41: this .getHibernateTemplate().saveOrUpdate(_element);
42: return _element.getId();
43: }
44: return "";
45: }
46:
47: /**
48: * Returns a list of all the Elements
49: *
50: * @return A list of all the Elements
51: */
52: public List<Element> getAllElements() {
53: List<Element> elements = new ArrayList<Element>();
54: for (Object obj : this .getHibernateTemplate().loadAll(
55: Element.class)) {
56: Element e = (Element) obj;
57: elements.add(e);
58: }
59: return elements;
60: }
61:
62: /**
63: * Returns the Element which has the specified ID
64: *
65: * @param _id The wanted Element's ID
66: * @return The wanted Element
67: */
68: public Element getElement(String _id) {
69: if (!_id.equals(""))
70: return (Element) this .getHibernateTemplate().get(
71: Element.class, _id);
72: return null;
73: }
74:
75: /**
76: * Deletes an Element
77: *
78: * @param _element The Element to be deleted
79: */
80: public void deleteElement(Element _element) {
81: this.getHibernateTemplate().delete(_element);
82: }
83: }
|