1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.usertype.spi.shared;
17
18 import java.io.Serializable;
19
20 import org.hibernate.HibernateException;
21 import org.hibernate.engine.spi.SharedSessionContractImplementor;
22 import org.hibernate.type.SerializationException;
23
24 public abstract class AbstractUserType implements Serializable {
25
26 private static final long serialVersionUID = -3503387360213242237L;
27
28 public boolean isMutable() {
29 return false;
30 }
31
32 public boolean equals(Object x, Object y) throws HibernateException {
33 if ((x == null) && (y == null)) {
34 return true;
35 }
36 if ((x == null) || (y == null)) {
37 return false;
38 }
39 if (x == y) {
40 return true;
41 }
42 return x.equals(y);
43 }
44
45 public int hashCode(Object x) throws HibernateException {
46 assert (x != null);
47 return x.hashCode();
48 }
49
50 public Object assemble(Serializable cachedValue, Object owner) throws HibernateException {
51 return deepCopy(cachedValue);
52 }
53
54 public Serializable disassemble(Object value) throws HibernateException {
55
56 final Serializable result;
57
58 if (value == null) {
59 result = null;
60 } else {
61 final Object deepCopy = deepCopy(value);
62 if (!(deepCopy instanceof Serializable)) {
63 throw new SerializationException(String.format("deepCopy of %s is not serializable", value), null);
64 }
65 result = (Serializable) deepCopy;
66 }
67
68 return result;
69 }
70
71 public Object replace(Object originalValue, Object target, Object owner) throws HibernateException {
72 return deepCopy(originalValue);
73 }
74
75 public Object deepCopy(Object value) throws HibernateException {
76 return value;
77 }
78
79
80
81
82
83 public void beforeNullSafeOperation(SharedSessionContractImplementor session) {
84
85 ConfigurationHelper.setCurrentSessionFactory(session.getFactory());
86 if (this instanceof IntegratorConfiguredType) {
87 ((IntegratorConfiguredType)this).applyConfiguration(session.getFactory());
88 }
89 }
90
91
92
93
94
95
96 public void afterNullSafeOperation(SharedSessionContractImplementor session) {
97 ConfigurationHelper.setCurrentSessionFactory(null);
98 }
99 }