1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.connector.store.jpa.model.common;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.Lob;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.Table;
35 import org.hibernate.annotations.Index;
36 import org.modeshape.graph.property.DateTime;
37 import org.modeshape.graph.property.basic.JodaDateTime;
38
39
40
41
42
43 @Entity
44 @Table( name = "DNA_CHANGELOG" )
45 @org.hibernate.annotations.Table( appliesTo = "DNA_CHANGELOG", indexes = @Index( name = "NS_CHANGE_TS_INX", columnNames = {"UTC_TIMESTAMP"} ) )
46 @NamedQueries( {
47 @NamedQuery( name = "ChangeLogEntity.findBetween", query = "select entry from ChangeLogEntity as entry where entry.timestampInUtc >= :start and entry.timestampInUtc <= :end" ),
48 @NamedQuery( name = "ChangeLogEntity.deleteBefore", query = "delete ChangeLogEntity entry where entry.timestampInUtc < :timestamp" )} )
49 public class ChangeLogEntity {
50
51 @Id
52 @GeneratedValue( strategy = GenerationType.AUTO )
53 @Column( name = "ID", updatable = false )
54 private Long id;
55
56 @Column( name = "USERNAME", updatable = false, nullable = false, length = 64, unique = false )
57 private String username;
58
59 @Column( name = "UTC_TIMESTAMP", updatable = false, nullable = false, unique = false )
60 private long timestampInUtc;
61
62 @Column( name = "CHANGE_COUNT", updatable = false, nullable = false, unique = false )
63 private int numChanges;
64
65 @Lob
66 @Column( name = "CHANGES", updatable = false, nullable = false, unique = false )
67 private byte[] changes;
68
69 public ChangeLogEntity( String username,
70 DateTime timestamp,
71 int numChanges,
72 byte[] changes ) {
73 this.username = username;
74 this.timestampInUtc = timestamp.toUtcTimeZone().getMilliseconds();
75 this.numChanges = numChanges;
76 this.changes = changes;
77 }
78
79
80
81
82 public Long getId() {
83 return id;
84 }
85
86
87
88
89 public String getUsername() {
90 return username;
91 }
92
93
94
95
96 public long getTimestampInUtc() {
97 return timestampInUtc;
98 }
99
100
101
102
103 public byte[] getChanges() {
104 return changes;
105 }
106
107
108
109
110 public int getNumChanges() {
111 return numChanges;
112 }
113
114
115
116
117
118
119 @Override
120 public int hashCode() {
121 return id.hashCode();
122 }
123
124
125
126
127
128
129 @Override
130 public boolean equals( Object obj ) {
131 if (obj == this) return true;
132 if (obj instanceof ChangeLogEntity) {
133 ChangeLogEntity that = (ChangeLogEntity)obj;
134 return id.equals(that.id);
135 }
136 return false;
137 }
138
139
140
141
142
143
144 @Override
145 public String toString() {
146 return "" + numChanges + " changes by " + username + " at " + new JodaDateTime(timestampInUtc);
147 }
148 }