View Javadoc

1   /**
2    * Copyright (c) 2009-2010, Elias Gomes. All rights reserved.
3    * 
4    * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5    * following conditions are met:
6    * 
7    * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8    * disclaimer.
9    * 
10   * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided with the distribution.
12   * 
13   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
14   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
19   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20   */
21  package net.sourceforge.mystique.domain.entity;
22  
23  import java.util.Date;
24  import java.util.LinkedList;
25  import java.util.List;
26  
27  import javax.persistence.Column;
28  import javax.persistence.Entity;
29  import javax.persistence.GeneratedValue;
30  import javax.persistence.GenerationType;
31  import javax.persistence.Id;
32  import javax.persistence.JoinColumn;
33  import javax.persistence.ManyToOne;
34  import javax.persistence.NamedQueries;
35  import javax.persistence.NamedQuery;
36  import javax.persistence.OneToMany;
37  import javax.persistence.SequenceGenerator;
38  import javax.persistence.Table;
39  import javax.persistence.Temporal;
40  import javax.persistence.TemporalType;
41  import javax.persistence.Transient;
42  
43  /**
44   * @author Elias Gomes [eliasgomes@users.sourceforge.net]
45   */
46  @Entity
47  @Table(name = "TB_MILESTONE")
48  @SequenceGenerator(name = "milestoneIdSeq", sequenceName = "MILESTONE_ID_SEQ", initialValue = 1, allocationSize = 1)
49  @NamedQueries( {
50  		@NamedQuery(name = "Milestone.findByProject", query = "SELECT m FROM Milestone m WHERE m.project = :project ORDER BY m.name"),
51  		@NamedQuery(name = "Milestone.findByProjectAndName", query = "SELECT m FROM Milestone m WHERE m.project = :project AND UPPER(m.name) = UPPER(:name)") })
52  // TODO: Milestone needs description
53  public class Milestone {
54  
55  	@Id
56  	@GeneratedValue(generator = "milestoneIdSeq", strategy = GenerationType.SEQUENCE)
57  	@Column(name = "ID")
58  	private Long id;
59  
60  	@Column(name = "NAME", nullable = false)
61  	private String name;
62  
63  	@Temporal(TemporalType.TIMESTAMP)
64  	@Column(name = "DUE")
65  	private Date due;
66  
67  	@Temporal(TemporalType.TIMESTAMP)
68  	@Column(name = "COMPLETED")
69  	private Date completed;
70  
71  	@OneToMany(mappedBy = "milestone")
72  	private List<Ticket> ticketsReported;
73  
74  	@ManyToOne
75  	@JoinColumn(name = "PROJECT_ID", nullable = false)
76  	private Project project;
77  
78  	public Milestone() {
79  		setTicketsReported(new LinkedList<Ticket>());
80  	}
81  
82  	@Transient
83  	public boolean isNew() {
84  		return (id == null);
85  	}
86  
87  	public Long getId() {
88  		return id;
89  	}
90  
91  	public void setId(Long id) {
92  		this.id = id;
93  	}
94  
95  	public String getName() {
96  		return name;
97  	}
98  
99  	public void setName(String name) {
100 		this.name = name;
101 	}
102 
103 	public Date getDue() {
104 		return due;
105 	}
106 
107 	public void setDue(Date due) {
108 		this.due = due;
109 	}
110 
111 	public Date getCompleted() {
112 		return completed;
113 	}
114 
115 	public void setCompleted(Date completed) {
116 		this.completed = completed;
117 	}
118 
119 	public List<Ticket> getTicketsReported() {
120 		return ticketsReported;
121 	}
122 
123 	public void setTicketsReported(List<Ticket> ticketsReported) {
124 		this.ticketsReported = ticketsReported;
125 	}
126 
127 	public Project getProject() {
128 		return project;
129 	}
130 
131 	public void setProject(Project project) {
132 		this.project = project;
133 	}
134 
135 	@Override
136 	public int hashCode() {
137 		final int prime = 31;
138 		int result = 1;
139 		result = prime * result + ((id == null) ? 0 : id.hashCode());
140 		return result;
141 	}
142 
143 	@Override
144 	public boolean equals(Object obj) {
145 		if (this == obj)
146 			return true;
147 		if (obj == null)
148 			return false;
149 		if (getClass() != obj.getClass())
150 			return false;
151 		Milestone other = (Milestone) obj;
152 		if (id == null) {
153 			if (other.id != null)
154 				return false;
155 		} else if (!id.equals(other.id))
156 			return false;
157 		return true;
158 	}
159 
160 }