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.LinkedList;
24  import java.util.List;
25  
26  import javax.persistence.Column;
27  import javax.persistence.Entity;
28  import javax.persistence.GeneratedValue;
29  import javax.persistence.GenerationType;
30  import javax.persistence.Id;
31  import javax.persistence.JoinColumn;
32  import javax.persistence.ManyToOne;
33  import javax.persistence.NamedQueries;
34  import javax.persistence.NamedQuery;
35  import javax.persistence.OneToMany;
36  import javax.persistence.SequenceGenerator;
37  import javax.persistence.Table;
38  import javax.persistence.Transient;
39  
40  /**
41   * @author Elias Gomes [eliasgomes@users.sourceforge.net]
42   */
43  @Entity
44  @Table(name = "TB_VERSION")
45  @SequenceGenerator(name = "versionIdSeq", sequenceName = "VERSION_ID_SEQ", initialValue = 1, allocationSize = 1)
46  @NamedQueries( {
47  		@NamedQuery(name = "Version.findByProject", query = "SELECT v FROM Version v WHERE v.project = :project ORDER BY v.number"),
48  		@NamedQuery(name = "Version.findByProjectAndNumber", query = "SELECT v FROM Version v WHERE v.project = :project AND UPPER(v.number) = UPPER(:number)") })
49  public class Version {
50  
51  	@Id
52  	@GeneratedValue(generator = "versionIdSeq", strategy = GenerationType.SEQUENCE)
53  	@Column(name = "ID")
54  	private Long id;
55  
56  	@Column(name = "NUMBER", nullable = false)
57  	private String number;
58  
59  	@OneToMany(mappedBy = "version")
60  	private List<Ticket> ticketsReported;
61  
62  	@ManyToOne
63  	@JoinColumn(name = "PROJECT_ID", nullable = false)
64  	private Project project;
65  
66  	public Version() {
67  		setTicketsReported(new LinkedList<Ticket>());
68  	}
69  
70  	@Transient
71  	public boolean isNew() {
72  		return (id == null);
73  	}
74  
75  	public Long getId() {
76  		return id;
77  	}
78  
79  	public void setId(Long id) {
80  		this.id = id;
81  	}
82  
83  	public String getNumber() {
84  		return number;
85  	}
86  
87  	public void setNumber(String number) {
88  		if (number != null) {
89  			this.number = number.trim();
90  		}
91  		this.number = number;
92  	}
93  
94  	public List<Ticket> getTicketsReported() {
95  		return ticketsReported;
96  	}
97  
98  	public void setTicketsReported(List<Ticket> ticketsReported) {
99  		this.ticketsReported = ticketsReported;
100 	}
101 
102 	public Project getProject() {
103 		return project;
104 	}
105 
106 	public void setProject(Project project) {
107 		this.project = project;
108 	}
109 
110 	@Override
111 	public int hashCode() {
112 		final int prime = 31;
113 		int result = 1;
114 		result = prime * result + ((id == null) ? 0 : id.hashCode());
115 		return result;
116 	}
117 
118 	@Override
119 	public boolean equals(Object obj) {
120 		if (this == obj)
121 			return true;
122 		if (obj == null)
123 			return false;
124 		if (getClass() != obj.getClass())
125 			return false;
126 		Version other = (Version) obj;
127 		if (id == null) {
128 			if (other.id != null)
129 				return false;
130 		} else if (!id.equals(other.id))
131 			return false;
132 		return true;
133 	}
134 
135 }