Subversion Repositories Integrator Subversion

Rev

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