View Javadoc
1   package myorg.queryex;
2   
3   import java.util.Date;
4   
5   import javax.persistence.*;
6   
7   @Entity
8   @Table(name="QUERYEX_PERSON")
9   public class Person {
10  	@Id 
11  	@Column(name="ID", length=36)
12  	private String id;
13  	
14  	@Column(name="FIRST_NAME", length=16)
15  	private String firstName;
16  	
17  	@Column(name="LAST_NAME", length=16)
18  	private String lastName;
19  	
20  	@Temporal(TemporalType.DATE)
21  	@Column(name="BIRTH_DATE")
22  	private Date birthDate;
23  	
24  	protected Person() {}
25  	public Person(String id) { this.id = id; }
26  	
27  	public String getId() {
28  		return id;
29  	}
30  	public String getFirstName() { return firstName; }
31  	public Person setFirstName(String firstName) {
32  		this.firstName = firstName;
33  		return this;
34  	}
35  	
36  	public String getLastName() { return lastName; }
37  	public Person setLastName(String lastName) {
38  		this.lastName = lastName;
39  		return this;
40  	}
41  	
42  	public Date getBirthDate() { return birthDate; }
43  	public Person setBirthDate(Date birthDate) {
44  		this.birthDate = birthDate;
45  		return this;
46  	}
47  
48  	@Override
49  	public int hashCode() {
50  		return (firstName==null?0:firstName.hashCode()) + 
51  				(lastName==null?0:lastName.hashCode()) +
52  				(birthDate==null?0:birthDate.hashCode());
53  	}
54  	
55  	@Override
56  	public boolean equals(Object obj) {
57  		try {
58  			if (this == obj) { return true; }
59  			if (obj==null) { return false; }
60  			Person rhs = (Person)obj;
61  			if (firstName!=null && lastName!=null && birthDate!=null) {
62  				return firstName.equals(rhs.firstName) && 
63  						lastName.equals(rhs.lastName) &&
64  						birthDate.equals(rhs.birthDate) &&
65  						id==null?true:id.equals(rhs.id);
66  			}
67  			if ((firstName==null && rhs.firstName!=null) ||
68  					(lastName==null && rhs.lastName!=null) ||
69  					(birthDate==null && rhs.birthDate!=null)) { 
70  				return false; 
71  			}
72  			return id==null?true:id.equals(rhs.id);
73  		} catch (Exception ex) { return false; }
74  	}
75  	
76  	@Override
77  	public String toString() {
78  		return firstName + " " + lastName;
79  	}
80  	
81  }