Commit | Line | Data |
---|---|---|
59e4c94a MS |
1 | package org.ufcspa.simdecs.entities; |
2 | ||
3 | import java.io.Serializable; | |
79f1af86 | 4 | import java.util.List; |
59e4c94a | 5 | |
79f1af86 | 6 | import javax.persistence.CascadeType; |
59e4c94a MS |
7 | import javax.persistence.Column; |
8 | import javax.persistence.Entity; | |
9 | import javax.persistence.GeneratedValue; | |
10 | import javax.persistence.GenerationType; | |
11 | import javax.persistence.Id; | |
12 | import javax.persistence.JoinColumn; | |
79f1af86 | 13 | import javax.persistence.JoinTable; |
59e4c94a | 14 | import javax.persistence.ManyToOne; |
79f1af86 | 15 | import javax.persistence.OneToMany; |
59e4c94a MS |
16 | import javax.persistence.SequenceGenerator; |
17 | import javax.persistence.Table; | |
79f1af86 | 18 | import javax.persistence.UniqueConstraint; |
59e4c94a MS |
19 | |
20 | import org.hibernate.annotations.Index; | |
21 | ||
22 | ||
23 | @Entity | |
24 | @Table(name="PerguntaNodo") | |
25 | @SequenceGenerator(name = "sequencePerguntaNodo", sequenceName = "sqPerguntaNodo", initialValue = 1, allocationSize=1) | |
26 | public class PerguntaNodo implements Serializable { | |
27 | ||
28 | private static final long serialVersionUID = 6879782331178330999L; | |
29 | ||
30 | @Id | |
31 | @GeneratedValue(generator="sequencePerguntaNodo", strategy=GenerationType.AUTO) | |
32 | private Long id; | |
33 | ||
34 | @Column(length=100, nullable=false) | |
d1c23fc5 | 35 | private String texto; |
59e4c94a MS |
36 | |
37 | @ManyToOne | |
38 | @JoinColumn(name = "nodo_id", referencedColumnName = "id", nullable = true) | |
39 | @Index(name="pergunta_nodo_fk_i") | |
40 | private Nodo nodo; | |
41 | ||
79f1af86 MS |
42 | @OneToMany(cascade=CascadeType.ALL) |
43 | @JoinTable( name = "PerguntaResposta", | |
44 | joinColumns = {@JoinColumn(name = "pergunta_id")}, | |
45 | inverseJoinColumns = {@JoinColumn(name = "resposta_id")}, | |
46 | uniqueConstraints={@UniqueConstraint(columnNames={"pergunta_id", "resposta_id"})}) | |
47 | private List<RespostaNodo> respostas; | |
48 | ||
59e4c94a MS |
49 | public Long getId() { |
50 | return id; | |
51 | } | |
52 | public void setId(Long id) { | |
53 | this.id = id; | |
54 | } | |
d1c23fc5 MS |
55 | public String getTexto() { |
56 | return texto; | |
59e4c94a | 57 | } |
d1c23fc5 MS |
58 | public void setTexto(String pergunta) { |
59 | this.texto = pergunta; | |
59e4c94a MS |
60 | } |
61 | ||
62 | public Nodo getNodo() { | |
63 | return nodo; | |
64 | } | |
65 | ||
79f1af86 | 66 | public void setNodo(Nodo nodo) { |
59e4c94a MS |
67 | this.nodo = nodo; |
68 | } | |
69 | ||
79f1af86 MS |
70 | public List<RespostaNodo> getRespostas() { |
71 | return respostas; | |
72 | } | |
73 | public void setRespostas(List<RespostaNodo> respostas) { | |
74 | this.respostas = respostas; | |
75 | } | |
59e4c94a | 76 | public String toString() { |
d1c23fc5 | 77 | return id + " - " + texto; |
59e4c94a MS |
78 | } |
79 | ||
80 | @Override | |
81 | public int hashCode() { | |
82 | final int prime = 31; | |
83 | int result = 1; | |
84 | result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
85 | return result; | |
86 | } | |
87 | ||
88 | @Override | |
89 | public boolean equals(Object obj) { | |
90 | if (this == obj) | |
91 | return true; | |
92 | if (obj == null) | |
93 | return false; | |
94 | if (getClass() != obj.getClass()) | |
95 | return false; | |
96 | PerguntaNodo other = (PerguntaNodo) obj; | |
97 | if (id == null) { | |
98 | if (other.id != null) | |
99 | return false; | |
100 | } else if (!id.equals(other.id)) | |
101 | return false; | |
102 | return true; | |
103 | } | |
104 | ||
105 | public PerguntaNodo() { | |
106 | ||
107 | } | |
108 | } |