01: package org.hibernate.action;
02:
03: import java.io.Serializable;
04:
05: /**
06: * Acts as a stand-in for an entity identifier which is supposed to be
07: * generated on insert (like an IDENTITY column) where the insert needed to
08: * be delayed because we were outside a transaction when the persist
09: * occurred (save currently still performs the insert).
10: * <p/>
11: * The stand-in is only used within the {@link org.hibernate.engine.PersistenceContext}
12: * in order to distinguish one instance from another; it is never injected into
13: * the entity instance or returned to the client...
14: *
15: * @author Steve Ebersole
16: */
17: public class DelayedPostInsertIdentifier implements Serializable {
18: private static long SEQUENCE = 0;
19: private final long sequence;
20:
21: public DelayedPostInsertIdentifier() {
22: synchronized (DelayedPostInsertIdentifier.class) {
23: if (SEQUENCE == Long.MAX_VALUE) {
24: SEQUENCE = 0;
25: }
26: this .sequence = SEQUENCE++;
27: }
28: }
29:
30: public boolean equals(Object o) {
31: if (this == o) {
32: return true;
33: }
34: if (o == null || getClass() != o.getClass()) {
35: return false;
36: }
37: final DelayedPostInsertIdentifier that = (DelayedPostInsertIdentifier) o;
38: return sequence == that.sequence;
39: }
40:
41: public int hashCode() {
42: return (int) (sequence ^ (sequence >>> 32));
43: }
44:
45: public String toString() {
46: return "<delayed:" + sequence + ">";
47:
48: }
49: }
|