01: package org.osbl.persistence.model;
02:
03: import org.conform.Property;
04:
05: import java.sql.Timestamp;
06:
07: public abstract class Entity implements Comparable {
08: Long id;
09: @Property(writable="false")
10: int version;
11: @Property(writable="false",mandatory="true")
12: String key;
13: @Property(writable="false")
14: Timestamp created;
15: @Property(writable="false")
16: String createdBy;
17:
18: public Long getId() {
19: return id;
20: }
21:
22: public void setId(Long id) {
23: this .id = id;
24: }
25:
26: public int getVersion() {
27: return version;
28: }
29:
30: public void setVersion(int version) {
31: this .version = version;
32: }
33:
34: public String getKey() {
35: return key;
36: }
37:
38: public void setKey(String key) {
39: this .key = key;
40: }
41:
42: public Timestamp getCreated() {
43: return created;
44: }
45:
46: public void setCreated(Timestamp created) {
47: this .created = created;
48: }
49:
50: public String getCreatedBy() {
51: return createdBy;
52: }
53:
54: public void setCreatedBy(String createdBy) {
55: this .createdBy = createdBy;
56: }
57:
58: public int compareTo(Object o) {
59: Entity e = (Entity) o;
60: if (id == null && e.id != null)
61: return 1;
62: else if (id != null && e.id == null)
63: return -1;
64: else if (id == null && e.id == null)
65: return 0;
66: else
67: return id.compareTo(e.id);
68: }
69:
70: public boolean equals(Object o) {
71: if (this == o)
72: return true;
73: if (o == null || !(o instanceof Entity))
74: return false;
75:
76: Entity entity = (Entity) o;
77:
78: if (getKey() != null ? !getKey().equals(entity.getKey())
79: : entity.getKey() != null)
80: return false;
81:
82: return true;
83: }
84:
85: public int hashCode() {
86: return (getKey() != null ? getKey().hashCode() : 0);
87: }
88:
89: public String toString() {
90: return getKey();
91: }
92: }
|