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.Date;
24
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.ManyToOne;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.SequenceGenerator;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import javax.persistence.Transient;
39
40
41
42
43 @Entity
44 @Table(name = "TB_COMMENT")
45 @SequenceGenerator(name = "commentIdSeq", sequenceName = "COMMENT_ID_SEQ", initialValue = 1, allocationSize = 1)
46 @NamedQueries(@NamedQuery(name = "Comment.findByTicket", query = "SELECT c FROM Comment c WHERE c.ticket = :ticket ORDER BY c.created"))
47 public class Comment {
48
49 @Id
50 @GeneratedValue(generator = "commentIdSeq", strategy = GenerationType.SEQUENCE)
51 @Column(name = "ID")
52 private Long id;
53
54 @Column(name = "CONTENT", nullable = false)
55 private String content;
56
57 @Temporal(TemporalType.TIMESTAMP)
58 @Column(name = "CREATED", nullable = false)
59 private Date created;
60
61 @ManyToOne
62 @JoinColumn(name = "AUTHOR_USER_ID", nullable = false)
63 private User author;
64
65 @ManyToOne
66 @JoinColumn(name = "TICKET_ID", nullable = false)
67 private Ticket ticket;
68
69 public Comment() {
70 setCreated(new Date());
71 }
72
73 @Transient
74 public boolean isNew() {
75 return (id == null);
76 }
77
78 public Long getId() {
79 return id;
80 }
81
82 public void setId(Long id) {
83 this.id = id;
84 }
85
86 public String getContent() {
87 return content;
88 }
89
90 public void setContent(String content) {
91 if (content != null) {
92 this.content = content.trim();
93 }
94 this.content = content;
95 }
96
97 public Date getCreated() {
98 return created;
99 }
100
101 public void setCreated(Date created) {
102 this.created = created;
103 }
104
105 public User getAuthor() {
106 return author;
107 }
108
109 public void setAuthor(User author) {
110 this.author = author;
111 }
112
113 public Ticket getTicket() {
114 return ticket;
115 }
116
117 public void setTicket(Ticket ticket) {
118 this.ticket = ticket;
119 }
120
121 @Override
122 public int hashCode() {
123 final int prime = 31;
124 int result = 1;
125 result = prime * result + ((id == null) ? 0 : id.hashCode());
126 return result;
127 }
128
129 @Override
130 public boolean equals(Object obj) {
131 if (this == obj)
132 return true;
133 if (obj == null)
134 return false;
135 if (getClass() != obj.getClass())
136 return false;
137 Comment other = (Comment) obj;
138 if (id == null) {
139 if (other.id != null)
140 return false;
141 } else if (!id.equals(other.id))
142 return false;
143 return true;
144 }
145
146 }