Skip to content

Commit 99c7f25

Browse files
jhoellerunknown
authored and
unknown
committed
Deprecated OracleLobHandler in favor of DefaultLobHandler for the Oracle 10g driver and higher
Issue: SPR-10339
1 parent 2bd584c commit 99c7f25

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/OracleLobHandler.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,14 +49,23 @@
4949
* Note that this LobHandler requires Oracle JDBC driver 9i or higher!
5050
*
5151
* <p>While most databases are able to work with {@link DefaultLobHandler},
52-
* Oracle just accepts Blob/Clob instances created via its own proprietary
53-
* BLOB/CLOB API, and additionally doesn't accept large streams for
54-
* PreparedStatement's corresponding setter methods. Therefore, you need
55-
* to use a strategy like this LobHandler implementation.
52+
* Oracle 9i (or more specifically, the Oracle 9i JDBC driver) just accepts
53+
* Blob/Clob instances created via its own proprietary BLOB/CLOB API,
54+
* and additionally doesn't accept large streams for PreparedStatement's
55+
* corresponding setter methods. Therefore, you need to use a strategy like
56+
* this LobHandler implementation, or upgrade to the Oracle 10g/11g driver
57+
* (which still supports access to Oracle 9i databases).
58+
*
59+
* <p><b>NOTE: As of Oracle 10.2, {@link DefaultLobHandler} should work equally
60+
* well out of the box. On Oracle 11g, JDBC 4.0 based options such as
61+
* {@link DefaultLobHandler#setStreamAsLob} and {@link DefaultLobHandler#setCreateTemporaryLob}
62+
* are available as well, rendering this proprietary OracleLobHandler obsolete.</b>
63+
* Also, consider upgrading to a new driver even when accessing an older database.
64+
* See the {@link LobHandler} interface javadoc for a summary of recommendations.
5665
*
5766
* <p>Needs to work on a native JDBC Connection, to be able to cast it to
5867
* {@code oracle.jdbc.OracleConnection}. If you pass in Connections from a
59-
* connection pool (the usual case in a J2EE environment), you need to set an
68+
* connection pool (the usual case in a Java EE environment), you need to set an
6069
* appropriate {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
6170
* to allow for automatic retrieval of the underlying native JDBC Connection.
6271
* LobHandler and NativeJdbcExtractor are separate concerns, therefore they
@@ -72,8 +81,15 @@
7281
* @author Juergen Hoeller
7382
* @author Thomas Risberg
7483
* @since 04.12.2003
84+
* @see DefaultLobHandler
7585
* @see #setNativeJdbcExtractor
86+
* @deprecated in favor of {@link DefaultLobHandler} for the Oracle 10g driver and
87+
* higher. Consider using the 10g/11g driver even against an Oracle 9i database!
88+
* {@link DefaultLobHandler#setCreateTemporaryLob} is the direct equivalent of this
89+
* OracleLobHandler's implementation strategy, just using standard JDBC 4.0 API.
90+
* That said, in most cases, regular DefaultLobHandler setup will work fine as well.
7691
*/
92+
@Deprecated
7793
public class OracleLobHandler extends AbstractLobHandler {
7894

7995
private static final String BLOB_CLASS_NAME = "oracle.sql.BLOB";
@@ -143,7 +159,7 @@ public void setCache(boolean cache) {
143159
}
144160

145161
/**
146-
* Set whether to agressively release any resources used by the LOB. If set to {@code true}
162+
* Set whether to aggressively release any resources used by the LOB. If set to {@code true}
147163
* then you can only read the LOB values once. Any subsequent reads will fail since the resources
148164
* have been closed.
149165
* <p>Setting this property to {@code true} can be useful when your queries generates large
@@ -283,7 +299,7 @@ protected void initializeResourcesBeforeRead(Connection con, Object lob) {
283299
((BLOB) lob).open(BLOB.MODE_READONLY);
284300
*/
285301
Method open = lob.getClass().getMethod("open", int.class);
286-
open.invoke(lob, modeReadOnlyConstants.get(lob.getClass()));
302+
open.invoke(lob, this.modeReadOnlyConstants.get(lob.getClass()));
287303
}
288304
}
289305
catch (InvocationTargetException ex) {
@@ -366,7 +382,7 @@ protected void releaseResourcesAfterRead(Connection con, Object lob) {
366382
*/
367383
protected class OracleLobCreator implements LobCreator {
368384

369-
private final List createdLobs = new LinkedList();
385+
private final List<Object> temporaryLobs = new LinkedList<Object>();
370386

371387
public void setBlobAsBytes(PreparedStatement ps, int paramIndex, final byte[] content)
372388
throws SQLException {
@@ -495,7 +511,7 @@ protected Object createLob(PreparedStatement ps, boolean clob, LobCallback callb
495511
Object lob = prepareLob(con, clob ? clobClass : blobClass);
496512
callback.populateLob(lob);
497513
lob.getClass().getMethod("close", (Class[]) null).invoke(lob, (Object[]) null);
498-
this.createdLobs.add(lob);
514+
this.temporaryLobs.add(lob);
499515
if (logger.isDebugEnabled()) {
500516
logger.debug("Created new Oracle " + (clob ? "CLOB" : "BLOB"));
501517
}
@@ -556,7 +572,7 @@ protected Object prepareLob(Connection con, Class lobClass) throws Exception {
556572
*/
557573
public void close() {
558574
try {
559-
for (Iterator it = this.createdLobs.iterator(); it.hasNext();) {
575+
for (Iterator it = this.temporaryLobs.iterator(); it.hasNext();) {
560576
/*
561577
BLOB blob = (BLOB) it.next();
562578
blob.freeTemporary();

0 commit comments

Comments
 (0)