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) 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.misc.wilosuser;
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.misc.wilosuser.Participant;
26:
27: /**
28: * ParticipantDao manage requests from the system to store Participant into the
29: * database.
30: */
31: public class ParticipantDao extends HibernateDaoSupport {
32:
33: /**
34: * Saves or updates a Participant
35: *
36: * @param _participant The Participant to be saved or updated
37: */
38: public String saveOrUpdateParticipant(Participant _participant) {
39: if (_participant != null) {
40: this .getHibernateTemplate().saveOrUpdate(_participant);
41: return _participant.getId();
42: }
43: return "";
44: }
45:
46: /**
47: * Returns a list of all the Participant
48: *
49: * @return A list of all the Participant
50: */
51: public List<Participant> getAllParticipants() {
52: List<Participant> participants = new ArrayList<Participant>();
53: for (Object obj : this .getHibernateTemplate().loadAll(
54: Participant.class)) {
55: Participant p = (Participant) obj;
56: participants.add(p);
57: }
58: return participants;
59: }
60:
61: /**
62: * Returns the Participant which has the specified ID
63: *
64: * @param _id The wanted Participant's ID
65: * @return The wanted Participant
66: */
67: public Participant getParticipantById(String _id) {
68: if (!_id.equals(""))
69: return (Participant) this .getHibernateTemplate().get(
70: Participant.class, _id);
71: return null;
72: }
73:
74: /**
75: * Returns the Participant which has the specified login
76: *
77: * @param _login The wanted Participant's login
78: * @return The wanted Participant
79: */
80: public Participant getParticipant(String _login) {
81: List participants = this .getHibernateTemplate().find(
82: "from Participant p where p.login=?", _login);
83: if (participants.size() > 0) {
84: return (Participant) participants.get(0);
85: } else {
86: return null;
87: }
88: }
89:
90: /**
91: * Deletes the Participant
92: *
93: * @param _participant The Participant to be deleted
94: */
95: public void deleteParticipant(Participant _participant) {
96: this.getHibernateTemplate().delete(_participant);
97: }
98: }
|