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_COMPONENT")
45  @SequenceGenerator(name = "componentIdSeq", sequenceName = "COMPONENT_ID_SEQ", initialValue = 1, allocationSize = 1)
46  @NamedQueries( {
47  		@NamedQuery(name = "Component.findByProject", query = "SELECT c FROM Component c WHERE c.project = :project ORDER BY c.name"),
48  		@NamedQuery(name = "Component.findByProjectAndName", query = "SELECT c FROM Component c WHERE c.project = :project AND UPPER(c.name) = UPPER(:name)") })
49  // TODO: Component needs description
50  public class Component {
51  
52  	@Id
53  	@GeneratedValue(generator = "componentIdSeq", strategy = GenerationType.SEQUENCE)
54  	@Column(name = "ID")
55  	private Long id;
56  
57  	@Column(name = "NAME", nullable = false)
58  	private String name;
59  
60  	@OneToMany(mappedBy = "component")
61  	private List<Ticket> ticketsReported;
62  
63  	@ManyToOne
64  	@JoinColumn(name = "PROJECT_ID", nullable = false)
65  	private Project project;
66  
67  	public Component() {
68  		setTicketsReported(new LinkedList<Ticket>());
69  	}
70  
71  	@Transient
72  	public boolean isNew() {
73  		return (id == null);
74  	}
75  
76  	public Long getId() {
77  		return id;
78  	}
79  
80  	public void setId(Long id) {
81  		this.id = id;
82  	}
83  
84  	public String getName() {
85  		return name;
86  	}
87  
88  	public void setName(String name) {
89  		if (name != null) {
90  			this.name = name.trim();
91  		}
92  		this.name = name;
93  	}
94  
95  	public List<Ticket> getTicketsReported() {
96  		return ticketsReported;
97  	}
98  
99  	public void setTicketsReported(List<Ticket> ticketsReported) {
100 		this.ticketsReported = ticketsReported;
101 	}
102 
103 	public Project getProject() {
104 		return project;
105 	}
106 
107 	public void setProject(Project project) {
108 		this.project = project;
109 	}
110 
111 	@Override
112 	public int hashCode() {
113 		final int prime = 31;
114 		int result = 1;
115 		result = prime * result + ((id == null) ? 0 : id.hashCode());
116 		return result;
117 	}
118 
119 	@Override
120 	public boolean equals(Object obj) {
121 		if (this == obj)
122 			return true;
123 		if (obj == null)
124 			return false;
125 		if (getClass() != obj.getClass())
126 			return false;
127 		Component other = (Component) obj;
128 		if (id == null) {
129 			if (other.id != null)
130 				return false;
131 		} else if (!id.equals(other.id))
132 			return false;
133 		return true;
134 	}
135 
136 }