1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.orm.hibernate3.support;
18
19 import java.io.IOException;
20 import java.io.Serializable;
21 import java.sql.PreparedStatement;
22 import java.sql.ResultSet;
23 import java.sql.SQLException;
24 import javax.transaction.TransactionManager;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.hibernate.HibernateException;
29 import org.hibernate.usertype.UserType;
30 import org.hibernate.util.EqualsHelper;
31
32 import org.springframework.jdbc.support.lob.LobCreator;
33 import org.springframework.jdbc.support.lob.LobCreatorUtils;
34 import org.springframework.jdbc.support.lob.LobHandler;
35 import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public abstract class AbstractLobType implements UserType {
57
58 protected final Log logger = LogFactory.getLog(getClass());
59
60 private final LobHandler lobHandler;
61
62 private final TransactionManager jtaTransactionManager;
63
64
65
66
67
68
69
70
71 protected AbstractLobType() {
72 this(LocalSessionFactoryBean.getConfigTimeLobHandler(),
73 LocalSessionFactoryBean.getConfigTimeTransactionManager());
74 }
75
76
77
78
79
80 protected AbstractLobType(LobHandler lobHandler, TransactionManager jtaTransactionManager) {
81 this.lobHandler = lobHandler;
82 this.jtaTransactionManager = jtaTransactionManager;
83 }
84
85
86
87
88
89 @Override
90 public boolean isMutable() {
91 return false;
92 }
93
94
95
96
97
98 @Override
99 public boolean equals(Object x, Object y) throws HibernateException {
100 return EqualsHelper.equals(x, y);
101 }
102
103
104
105
106 @Override
107 public int hashCode(Object x) throws HibernateException {
108 return x.hashCode();
109 }
110
111
112
113
114 @Override
115 public Object deepCopy(Object value) throws HibernateException {
116 return value;
117 }
118
119
120
121
122 @Override
123 public Serializable disassemble(Object value) throws HibernateException {
124 return (Serializable) value;
125 }
126
127
128
129
130 @Override
131 public Object assemble(Serializable cached, Object owner) throws HibernateException {
132 return cached;
133 }
134
135
136
137
138 @Override
139 public Object replace(Object original, Object target, Object owner) throws HibernateException {
140 return original;
141 }
142
143
144
145
146
147
148
149 @Override
150 @Deprecated
151 public final Object nullSafeGet(ResultSet rs, String[] names, Object owner)
152 throws HibernateException, SQLException {
153
154 if (this.lobHandler == null) {
155 throw new IllegalStateException("No LobHandler found for configuration - " +
156 "lobHandler property must be set on LocalSessionFactoryBean");
157 }
158
159 try {
160 return nullSafeGetInternal(rs, names, owner, this.lobHandler);
161 }
162 catch (IOException ex) {
163 throw new HibernateException("I/O errors during LOB access", ex);
164 }
165 }
166
167
168
169
170
171
172
173 @Override
174 @Deprecated
175 public final void nullSafeSet(PreparedStatement st, Object value, int index)
176 throws HibernateException, SQLException {
177
178 if (this.lobHandler == null) {
179 throw new IllegalStateException("No LobHandler found for configuration - " +
180 "lobHandler property must be set on LocalSessionFactoryBean");
181 }
182
183 LobCreator lobCreator = this.lobHandler.getLobCreator();
184 try {
185 nullSafeSetInternal(st, index, value, lobCreator);
186 }
187 catch (IOException ex) {
188 throw new HibernateException("I/O errors during LOB access", ex);
189 }
190 LobCreatorUtils.registerTransactionSynchronization(lobCreator, this.jtaTransactionManager);
191 }
192
193
194
195
196
197
198
199
200
201
202
203
204 protected abstract Object nullSafeGetInternal(
205 ResultSet rs, String[] names, Object owner, LobHandler lobHandler)
206 throws SQLException, IOException, HibernateException;
207
208
209
210
211
212
213
214
215
216
217
218 protected abstract void nullSafeSetInternal(
219 PreparedStatement ps, int index, Object value, LobCreator lobCreator)
220 throws SQLException, IOException, HibernateException;
221
222 }