Java tutorial
/** * Copyright (C) 2008 University of Pittsburgh * * * This file is part of Open EpiCenter * * Open EpiCenter is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Open EpiCenter is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Open EpiCenter. If not, see <http://www.gnu.org/licenses/>. * * * */ package com.hmsinc.epicenter.model.workflow; import static javax.persistence.GenerationType.AUTO; import java.util.SortedSet; import java.util.TreeSet; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.apache.commons.lang.builder.ToStringBuilder; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortType; /** * A workflow designates how an organization resolves events. * * @author <a href="mailto:steve.kondik@hmsinc.com">Steve Kondik</a> * @version $Id:Workflow.java 205 2007-09-26 16:52:01Z steve.kondik $ */ @Entity @Table(name = "WORKFLOW") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @NamedQueries({ @NamedQuery(name = "getWorkflow", query = "from Workflow w join fetch w.states s join fetch s.transitionsTo tto join fetch s.transitions tfrom where w.name=:name") }) @XmlRootElement(name = "workflow", namespace = "http://epicenter.hmsinc.com/model") @XmlType(name = "Workflow", namespace = "http://epicenter.hmsinc.com/model") @XmlAccessorType(XmlAccessType.NONE) public class Workflow implements WorkflowObject { /** * */ private static final long serialVersionUID = -7564401065696027380L; @XmlAttribute private Long id; @XmlElement(required = true, namespace = "http://epicenter.hmsinc.com/model") private String name; @XmlElement(namespace = "http://epicenter.hmsinc.com/model") private String description; @XmlElementWrapper(name = "workflow-states", namespace = "http://epicenter.hmsinc.com/model") @XmlElement(required = true, name = "workflow-state", namespace = "http://epicenter.hmsinc.com/model") private SortedSet<WorkflowState> states = new TreeSet<WorkflowState>(); /** * @return the id */ @Id @Column(name = "ID", nullable = false, insertable = true, updatable = true) @GenericGenerator(name = "generator", strategy = "native", parameters = { @Parameter(name = "sequence", value = "SEQ_WORKFLOW") }) @GeneratedValue(strategy = AUTO, generator = "generator") public Long getId() { return id; } /** * @param id * the id to set */ public void setId(Long id) { this.id = id; } /** * @return the name */ @Column(name = "NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 80) public String getName() { return name; } /** * @param name * the name to set */ public void setName(String name) { this.name = name; } /** * @return the description */ @Column(name = "DESCRIPTION", unique = false, nullable = true, insertable = true, updatable = true, length = 400) public String getDescription() { return description; } /** * @param description * the description to set */ public void setDescription(String description) { this.description = description; } /** * @return the states */ @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "workflow") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) @Sort(type = SortType.NATURAL) public SortedSet<WorkflowState> getStates() { return states; } /** * @param states * the states to set */ public void setStates(SortedSet<WorkflowState> states) { this.states = states; } /* * (non-Javadoc) * * @see java.lang.Object#toString() */ @Override public String toString() { return new ToStringBuilder(this).append("id", id).append("name", name).append("description", description) .toString(); } }