1 package myorg.relex.collection;
2
3 import java.util.Date;
4 import java.util.concurrent.atomic.AtomicInteger;
5
6 import javax.persistence.Column;
7 import javax.persistence.GeneratedValue;
8 import javax.persistence.Id;
9 import javax.persistence.MappedSuperclass;
10 import javax.persistence.Temporal;
11 import javax.persistence.TemporalType;
12 import javax.persistence.Transient;
13
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17
18
19
20
21 @MappedSuperclass
22 public abstract class Ship {
23 @Transient
24 protected final Logger log = LoggerFactory.getLogger(getClass());
25 private static AtomicInteger instanceId = new AtomicInteger();
26 @Transient
27 private int oid = instanceId.getAndAdd(1);
28
29 @Id
30 @GeneratedValue
31 protected int id;
32
33 @Column(length = 16)
34 protected String name;
35
36 @Temporal(TemporalType.TIMESTAMP)
37 protected Date created;
38
39
40 public int getId() { return id; }
41 public Ship setId(int id) {
42 this.id = id;
43 return this;
44 }
45
46 public String getName() { return name; }
47 public Ship setName(String name) {
48 this.name = name;
49 return this;
50 }
51
52 public Date getCreated() { return created; }
53 public Ship setCreated(Date created) {
54 this.created = created;
55 return this;
56 }
57
58 public abstract int peekHashCode();
59 protected int objectHashCode() {
60 return super.hashCode();
61 }
62
63 @Override
64 public int hashCode() {
65 return logHashCode(peekHashCode());
66 }
67
68 public int logHashCode(int hashCode) {
69 log.info(toString() +
70 ".hashCode=" + hashCode);
71 return hashCode;
72 }
73
74 public boolean logEquals(Object obj, boolean equals) {
75 log.info(new StringBuilder()
76 .append(toString())
77 .append(".equals(id=")
78 .append(obj==null?null : ((Ship)obj).id + ",oid=" + ((Ship)obj).oid)
79 .append(")=")
80 .append(equals)
81 .toString());
82 return equals;
83 }
84
85 public String toString() {
86 return getClass().getSimpleName() + "(id=" + id + ",oid=" + oid + ")";
87 }
88 }