Rev 106 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.model; |
| 2 | |||
| 3 | import java.io.Serializable; |
||
| 4 | |||
| 5 | import javax.persistence.Column; |
||
| 6 | import javax.persistence.Entity; |
||
| 7 | import javax.persistence.GeneratedValue; |
||
| 8 | import javax.persistence.GenerationType; |
||
| 9 | import javax.persistence.Id; |
||
| 10 | import javax.persistence.JoinColumn; |
||
| 11 | import javax.persistence.ManyToOne; |
||
| 12 | import javax.persistence.SequenceGenerator; |
||
| 13 | import javax.persistence.Table; |
||
| 14 | import javax.persistence.Transient; |
||
| 15 | import javax.validation.constraints.NotNull; |
||
| 16 | |||
| 17 | import org.hibernate.annotations.ForeignKey; |
||
| 18 | |||
| 195 | espaco | 19 | import br.com.ec.core.interfaces.Alterar; |
| 20 | import br.com.ec.core.interfaces.Cadastrar; |
||
| 21 | import br.com.ec.core.util.VerificadorUtil; |
||
| 106 | espaco | 22 | |
| 23 | @Entity |
||
| 24 | @Table(name="sec_notafiscal_produto", schema="sc_sec") |
||
| 25 | public class NotaFiscalProduto implements Serializable { |
||
| 26 | |||
| 27 | private static final long serialVersionUID = 1L; |
||
| 28 | |||
| 29 | private Long sequencial; |
||
| 30 | private NotaFiscal notaFiscal; |
||
| 31 | private Produto produto; |
||
| 32 | private Integer quantidade; |
||
| 33 | |||
| 34 | @Id |
||
| 35 | @SequenceGenerator(name = "sq_notafiscalproduto") |
||
| 36 | @GeneratedValue(strategy = GenerationType.IDENTITY) |
||
| 37 | @Column(name="seq_notafiscalproduto", nullable=false) |
||
| 38 | public Long getSequencial() { |
||
| 39 | return sequencial; |
||
| 40 | } |
||
| 41 | public void setSequencial(Long sequencial) { |
||
| 42 | this.sequencial = sequencial; |
||
| 43 | } |
||
| 44 | |||
| 45 | @ManyToOne |
||
| 46 | @ForeignKey(name="fk_notafiscalproduto_notafiscal") |
||
| 47 | @JoinColumn(name = "seq_nota_fiscal", referencedColumnName="seq_nota_fiscal", insertable=true, updatable=false, nullable=false) |
||
| 48 | public NotaFiscal getNotaFiscal() { |
||
| 49 | return notaFiscal; |
||
| 50 | } |
||
| 51 | public void setNotaFiscal(NotaFiscal notaFiscal) { |
||
| 52 | this.notaFiscal = notaFiscal; |
||
| 53 | } |
||
| 54 | |||
| 55 | @ManyToOne |
||
| 56 | @ForeignKey(name="fk_notafiscalproduto_produto") |
||
| 57 | @JoinColumn(name = "seq_produto", insertable=true, updatable=false, nullable=false) |
||
| 58 | public Produto getProduto() { |
||
| 59 | return produto; |
||
| 60 | } |
||
| 61 | public void setProduto(Produto produto) { |
||
| 62 | this.produto = produto; |
||
| 63 | } |
||
| 64 | |||
| 65 | @NotNull(message = "Parâmetro obrigatório não preenchido: Quantidade de produtos", groups = {Cadastrar.class, Alterar.class}) |
||
| 66 | @Column(name="qtd_produto") |
||
| 67 | public Integer getQuantidade() { |
||
| 68 | return quantidade; |
||
| 69 | } |
||
| 70 | public void setQuantidade(Integer quantidade) { |
||
| 71 | this.quantidade = quantidade; |
||
| 72 | } |
||
| 73 | |||
| 74 | @Transient |
||
| 75 | public Long getSequencialDaNotaFiscal() { |
||
| 76 | return VerificadorUtil.naoEstaNulo(notaFiscal)? notaFiscal.getSequencial() : null; |
||
| 77 | } |
||
| 78 | |||
| 79 | @Transient |
||
| 80 | public Long getSequencialDoProduto() { |
||
| 81 | return VerificadorUtil.naoEstaNulo(produto)? produto.getSequencial() : null; |
||
| 82 | } |
||
| 83 | |||
| 84 | @Override |
||
| 85 | public int hashCode() { |
||
| 86 | final int prime = 31; |
||
| 87 | int result = 1; |
||
| 88 | result = prime * result + ((sequencial == null) ? 0 : sequencial.hashCode()); |
||
| 89 | return result; |
||
| 90 | } |
||
| 91 | |||
| 92 | @Override |
||
| 93 | public boolean equals(Object obj) { |
||
| 94 | if (this == obj) |
||
| 95 | return true; |
||
| 96 | if (obj == null) |
||
| 97 | return false; |
||
| 98 | if (getClass() != obj.getClass()) |
||
| 99 | return false; |
||
| 100 | NotaFiscalProduto other = (NotaFiscalProduto) obj; |
||
| 101 | if (sequencial == null) { |
||
| 102 | if (other.sequencial != null) |
||
| 103 | return false; |
||
| 104 | } else if (!sequencial.equals(other.sequencial)) |
||
| 105 | return false; |
||
| 106 | return true; |
||
| 107 | } |
||
| 108 | |||
| 109 | } |