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.Administrator;
26:
27: /**
28: * AdministratorDao manage requests from the system to store Administrator into
29: * the database.
30: *
31: * @author Yoann Lopes
32: * @author Martial Lapeyre
33: */
34: public class AdministratorDao extends HibernateDaoSupport {
35:
36: /**
37: * Saves or updates an Administator
38: *
39: * @param _administrator The Administator to be saved or updated
40: */
41: public String saveOrUpdateAdministrator(Administrator _administrator) {
42: if (_administrator != null) {
43: this .getHibernateTemplate().saveOrUpdate(_administrator);
44: return _administrator.getId();
45: }
46: return "";
47: }
48:
49: /**
50: * Returns a list of all the Administator
51: *
52: * @return A list of all the Administator
53: */
54: public List<Administrator> getAllAdministrators() {
55: List<Administrator> administrators = new ArrayList<Administrator>();
56: for (Object obj : this .getHibernateTemplate().loadAll(
57: Administrator.class)) {
58: Administrator a = (Administrator) obj;
59: administrators.add(a);
60: }
61: return administrators;
62: }
63:
64: /**
65: * Returns the Administator which has the specified login
66: *
67: * @param _login The wanted Administator's login
68: * @return The wanted Administator
69: */
70: public Administrator getAdministrator(String _login) {
71: List administrators = this .getHibernateTemplate().find(
72: "from Administrator a where a.login=?", _login);
73: if (administrators.size() > 0) {
74: return (Administrator) administrators.get(0);
75: } else {
76: return null;
77: }
78: }
79:
80: /**
81: * Deletes the Administrator
82: *
83: * @param _administrator The Administrator to be deleted
84: */
85: public void deleteAdministrator(Administrator _administrator) {
86: this.getHibernateTemplate().delete(_administrator);
87: }
88: }
|