001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2007-2008 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: *
005: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006: * General Public License as published by the Free Software Foundation; either version 2 of the License,
007: * or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License along with this program; if not,
014: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015: */
016:
017: package wilos.hibernate.spem2.milestone;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
023:
024: import wilos.model.spem2.milestone.Milestone;
025:
026: /**
027: * MilestoneDao manage requests from the system to store Milestones into the
028: * database
029: *
030: */
031: public class MilestoneDao extends HibernateDaoSupport {
032:
033: /**
034: * Saves or updates a Milestone
035: *
036: * @param _milestone The Milestone to be saved or updated
037: */
038: public String saveOrUpdateMilestone(Milestone _milestone) {
039: if (_milestone != null) {
040: this .getHibernateTemplate().saveOrUpdate(_milestone);
041: return _milestone.getId();
042: }
043: return "";
044: }
045:
046: /**
047: * Returns a list of all the Milestones
048: *
049: * @return A list of all the Milestones
050: */
051: public List<Milestone> getAllMilestones() {
052: List<Milestone> milestones = new ArrayList<Milestone>();
053: for (Object obj : this .getHibernateTemplate().loadAll(
054: Milestone.class)) {
055: Milestone ms = (Milestone) obj;
056: milestones.add(ms);
057: }
058: return milestones;
059: }
060:
061: /**
062: * Returns the Milestone which has the specified ID
063: *
064: * @param _id The wanted Milestone's ID
065: * @return The wanted Milestone
066: */
067: public Milestone getMilestone(String _id) {
068: if (!_id.equals(""))
069: return (Milestone) this .getHibernateTemplate().get(
070: Milestone.class, _id);
071: return null;
072: }
073:
074: /**
075: * Return a milestone with the given guid If there are many milestones with
076: * the same guid, it returns the first
077: *
078: * @param _guid the given guidance id
079: * @return the wanted Milestone
080: */
081: public Milestone getMilestoneFromGuid(String _guid) {
082: if (!_guid.equals("")) {
083: List milestones = this .getHibernateTemplate().find(
084: "from Milestone a where a.guid=?", _guid);
085: if (milestones.size() > 0)
086: return (Milestone) milestones.get(0);
087: }
088: return null;
089: }
090:
091: /**
092: * Returns the Milestone which has the specified prefix
093: * If there are many Milestones with the same prefix, it returns the first
094: *
095: * @param _prefix The wanted Milestone's prefix
096: * @return The wanted Milestone
097: */
098: public Milestone getMilestoneFromPrefix(String _prefix) {
099: if (!_prefix.equals("")) {
100: List milestones = this .getHibernateTemplate().find(
101: "from Milestone a where a.prefix=?", _prefix);
102: if (milestones.size() > 0)
103: return (Milestone) milestones.get(0);
104: }
105: return null;
106: }
107:
108: /**
109: * Deletes the Milestone
110: *
111: * @param _milestone The Milestone to be deleted
112: */
113: public void deleteMilestone(Milestone _milestone) {
114: this.getHibernateTemplate().delete(_milestone);
115: }
116: }
|