|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2012 the original author or authors. |
| 2 | + * Copyright 2002-2013 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
49 | 49 | * Note that this LobHandler requires Oracle JDBC driver 9i or higher!
|
50 | 50 | *
|
51 | 51 | * <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. |
56 | 65 | *
|
57 | 66 | * <p>Needs to work on a native JDBC Connection, to be able to cast it to
|
58 | 67 | * {@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 |
60 | 69 | * appropriate {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
|
61 | 70 | * to allow for automatic retrieval of the underlying native JDBC Connection.
|
62 | 71 | * LobHandler and NativeJdbcExtractor are separate concerns, therefore they
|
|
72 | 81 | * @author Juergen Hoeller
|
73 | 82 | * @author Thomas Risberg
|
74 | 83 | * @since 04.12.2003
|
| 84 | + * @see DefaultLobHandler |
75 | 85 | * @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. |
76 | 91 | */
|
| 92 | +@Deprecated |
77 | 93 | public class OracleLobHandler extends AbstractLobHandler {
|
78 | 94 |
|
79 | 95 | private static final String BLOB_CLASS_NAME = "oracle.sql.BLOB";
|
@@ -143,7 +159,7 @@ public void setCache(boolean cache) {
|
143 | 159 | }
|
144 | 160 |
|
145 | 161 | /**
|
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} |
147 | 163 | * then you can only read the LOB values once. Any subsequent reads will fail since the resources
|
148 | 164 | * have been closed.
|
149 | 165 | * <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) {
|
283 | 299 | ((BLOB) lob).open(BLOB.MODE_READONLY);
|
284 | 300 | */
|
285 | 301 | 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())); |
287 | 303 | }
|
288 | 304 | }
|
289 | 305 | catch (InvocationTargetException ex) {
|
@@ -366,7 +382,7 @@ protected void releaseResourcesAfterRead(Connection con, Object lob) {
|
366 | 382 | */
|
367 | 383 | protected class OracleLobCreator implements LobCreator {
|
368 | 384 |
|
369 |
| - private final List createdLobs = new LinkedList(); |
| 385 | + private final List<Object> temporaryLobs = new LinkedList<Object>(); |
370 | 386 |
|
371 | 387 | public void setBlobAsBytes(PreparedStatement ps, int paramIndex, final byte[] content)
|
372 | 388 | throws SQLException {
|
@@ -495,7 +511,7 @@ protected Object createLob(PreparedStatement ps, boolean clob, LobCallback callb
|
495 | 511 | Object lob = prepareLob(con, clob ? clobClass : blobClass);
|
496 | 512 | callback.populateLob(lob);
|
497 | 513 | lob.getClass().getMethod("close", (Class[]) null).invoke(lob, (Object[]) null);
|
498 |
| - this.createdLobs.add(lob); |
| 514 | + this.temporaryLobs.add(lob); |
499 | 515 | if (logger.isDebugEnabled()) {
|
500 | 516 | logger.debug("Created new Oracle " + (clob ? "CLOB" : "BLOB"));
|
501 | 517 | }
|
@@ -556,7 +572,7 @@ protected Object prepareLob(Connection con, Class lobClass) throws Exception {
|
556 | 572 | */
|
557 | 573 | public void close() {
|
558 | 574 | try {
|
559 |
| - for (Iterator it = this.createdLobs.iterator(); it.hasNext();) { |
| 575 | + for (Iterator it = this.temporaryLobs.iterator(); it.hasNext();) { |
560 | 576 | /*
|
561 | 577 | BLOB blob = (BLOB) it.next();
|
562 | 578 | blob.freeTemporary();
|
|
0 commit comments