1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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 }