View Javadoc
1   package info.ejava.examples.ejb.cdisales.bo;
2   
3   import java.io.Serializable;
4   
5   import javax.persistence.*;
6   import javax.validation.constraints.NotNull;
7   
8   @Entity
9   @Table(name="CDISALES_MEMBER")
10  @NamedQueries({
11      @NamedQuery(name="CDIMember.getMemberByLogin", 
12          query="select m from Member m where m.login=:login")
13  })
14  public class Member implements Comparable<Member>, Serializable {
15      private static final long serialVersionUID = -2348898686516963520L;
16  
17      @Id @GeneratedValue
18      @Column(name="MEMBER_ID")
19      private int id;
20      
21      @NotNull
22      @Column(name="LOGIN", length=16, nullable=false, unique=true)
23      private String login;
24      
25      @NotNull
26      @Column(name="NAME", length=32, nullable=false)
27      private String name;
28      
29      @Column(name="EMAIL", length=32)
30      private String email;
31  
32      public Member() {}
33      public Member(int id) {
34          this.id=id;
35      }
36      
37      public int getId() { return id; }
38  
39      public String getLogin() { return login; }
40      public void setLogin(String login) {
41          this.login = login;
42      }
43  
44      public String getName() { return name; }
45      public void setName(String name) {
46          this.name = name;
47      }
48  
49      public String getEmail() { return email; }
50      public void setEmail(String email) {
51          this.email = email;
52      }
53      
54      @Override
55      public int compareTo(Member rhs) {
56          if (rhs==null || name!=null && rhs.name==null) { return -1; }
57          if (name==null || rhs.name!=null) { return 1; }
58          return name.compareTo(rhs.name);
59      }
60  
61      @Override
62      public int hashCode() {
63          final int prime = 31;
64          int result = 1;
65          result = prime * result + ((login == null) ? 0 : login.hashCode());
66          return result;
67      }
68      @Override
69      public boolean equals(Object obj) {
70          if (this == obj) { return true; }
71          if (obj == null) { return false; }
72          if (getClass() != obj.getClass()) { return false; }
73          Member other = (Member) obj;
74          
75          return (login==null ? other.login==null : login.equals(other.login));
76      }
77      @Override
78      public String toString() {
79          StringBuilder builder = new StringBuilder();
80          builder.append("Member [id=").append(id)
81                  .append(", login=").append(login)
82                  .append(", name=").append(name)
83                  .append(", email=").append(email)
84                  .append("]");
85          return builder.toString();
86      }
87      
88      
89  }