Subversion Repositories Integrator Subversion

Rev

Go to most recent revision | Details | 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.OneToOne;
12
import javax.persistence.SequenceGenerator;
13
import javax.persistence.Table;
14
import javax.persistence.Transient;
15
import javax.validation.constraints.Size;
16
 
17
import org.hibernate.annotations.ForeignKey;
18
 
19
import br.edu.cesmac.core.util.StringUtil;
20
import br.edu.cesmac.core.util.VerificadorUtil;
21
 
22
@Entity
23
@Table(name="sec_vendedor", schema="sc_sec")
24
public class Vendedor implements Serializable {
25
 
26
        private static final long serialVersionUID = 1L;
27
 
28
        private Long sequencial;
29
        private Pessoa pessoa;
30
        private Loja loja;
31
        private String nome;
32
        private Boolean ativo;
33
        private Boolean indicadorColaborador;
34
 
35
        @Id
36
        @SequenceGenerator(name = "sq_vendedor")
37
        @GeneratedValue(strategy=GenerationType.IDENTITY)
38
        @Column(name="seq_vendedor", nullable=false)
39
        public Long getSequencial() {
40
                return sequencial;
41
        }
42
        public void setSequencial(Long sequencial) {
43
                this.sequencial = sequencial;
44
        }
45
 
46
        //TODO: RETIRAR O NULLABLE DEPOIS QUE COLOCAR TODAS AS PESSOAS DOS VENDEDORES
47
        @OneToOne
48
        @ForeignKey(name="fk_vendedor_pessoa")
49
        @JoinColumn(name="seq_pessoa", referencedColumnName="seq_pessoa", nullable=true)
50
        public Pessoa getPessoa() {
51
                return pessoa;
52
        }
53
        public void setPessoa(Pessoa pessoa) {
54
                this.pessoa = pessoa;
55
        }
56
 
57
        @OneToOne
58
        @ForeignKey(name="fk_vendedor_loja")
59
        @JoinColumn(name="seq_loja", referencedColumnName="seq_loja", nullable=true)
60
        public Loja getLoja() {
61
                return loja;
62
        }
63
        public void setLoja(Loja loja) {
64
                this.loja = loja;
65
        }
66
 
67
        @Column(name="dsc_nome")
68
        @Size(max = 120, message = "Limite de caracteres ultrapassado: Nome")
69
        public String getNome() {
70
                return nome;
71
        }
72
        public void setNome(String nome) {
73
                this.nome = StringUtil.setarUpperCaseComTrim(nome);
74
        }
75
 
76
        @Column(name="ind_ativo", nullable=false)
77
        public Boolean getAtivo() {
78
                return ativo;
79
        }
80
        public void setAtivo(Boolean ativo) {
81
                this.ativo = ativo;
82
        }
83
 
84
        @Column(name="ind_colaborador", nullable=false)
85
        public Boolean getIndicadorColaborador() {
86
                return indicadorColaborador;
87
        }
88
        public void setIndicadorColaborador(Boolean indicadorColaborador) {
89
                this.indicadorColaborador = indicadorColaborador;
90
        }
91
 
92
        @Transient
93
        public String getNomeDaPessoa() {
94
                return VerificadorUtil.naoEstaNulo(pessoa)? pessoa.getNome() : null;
95
        }
96
 
97
        @Override
98
        public int hashCode() {
99
                final int prime = 31;
100
                int result = 1;
101
                result = prime * result
102
                                + ((sequencial == null) ? 0 : sequencial.hashCode());
103
                return result;
104
        }
105
 
106
        @Override
107
        public boolean equals(Object obj) {
108
                if (this == obj)
109
                        return true;
110
                if (obj == null)
111
                        return false;
112
                if (getClass() != obj.getClass())
113
                        return false;
114
                Vendedor other = (Vendedor) obj;
115
                if (sequencial == null) {
116
                        if (other.sequencial != null)
117
                                return false;
118
                } else if (!sequencial.equals(other.sequencial))
119
                        return false;
120
                return true;
121
        }
122
 
123
}