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