DefaultLobHandler uses explicit Blob/Clob access for reading when "wrapAsLob"=true
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@620 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
793bf07941
commit
41c04863f1
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -115,27 +115,57 @@ public class DefaultLobHandler extends AbstractLobHandler {
|
||||||
|
|
||||||
public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException {
|
public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
logger.debug("Returning BLOB as bytes");
|
logger.debug("Returning BLOB as bytes");
|
||||||
return rs.getBytes(columnIndex);
|
if (this.wrapAsLob) {
|
||||||
|
Blob blob = rs.getBlob(columnIndex);
|
||||||
|
return blob.getBytes(1, (int) blob.length());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rs.getBytes(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
|
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
logger.debug("Returning BLOB as binary stream");
|
logger.debug("Returning BLOB as binary stream");
|
||||||
return rs.getBinaryStream(columnIndex);
|
if (this.wrapAsLob) {
|
||||||
|
Blob blob = rs.getBlob(columnIndex);
|
||||||
|
return blob.getBinaryStream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rs.getBinaryStream(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
|
public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
logger.debug("Returning CLOB as string");
|
logger.debug("Returning CLOB as string");
|
||||||
return rs.getString(columnIndex);
|
if (this.wrapAsLob) {
|
||||||
|
Clob clob = rs.getClob(columnIndex);
|
||||||
|
return clob.getSubString(1, (int) clob.length());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rs.getString(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException {
|
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
logger.debug("Returning CLOB as ASCII stream");
|
logger.debug("Returning CLOB as ASCII stream");
|
||||||
return rs.getAsciiStream(columnIndex);
|
if (this.wrapAsLob) {
|
||||||
|
Clob clob = rs.getClob(columnIndex);
|
||||||
|
return clob.getAsciiStream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rs.getAsciiStream(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
|
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException {
|
||||||
logger.debug("Returning CLOB as character stream");
|
logger.debug("Returning CLOB as character stream");
|
||||||
return rs.getCharacterStream(columnIndex);
|
if (this.wrapAsLob) {
|
||||||
|
Clob clob = rs.getClob(columnIndex);
|
||||||
|
return clob.getCharacterStream();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return rs.getCharacterStream(columnIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LobCreator getLobCreator() {
|
public LobCreator getLobCreator() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,21 +31,22 @@ import java.sql.SQLException;
|
||||||
* <p>Provides accessor methods for BLOBs and CLOBs, and acts as factory for
|
* <p>Provides accessor methods for BLOBs and CLOBs, and acts as factory for
|
||||||
* LobCreator instances, to be used as sessions for creating BLOBs or CLOBs.
|
* LobCreator instances, to be used as sessions for creating BLOBs or CLOBs.
|
||||||
* LobCreators are typically instantiated for each statement execution or for
|
* LobCreators are typically instantiated for each statement execution or for
|
||||||
* each transaction. They are not thread-safe because they might track
|
* each transaction; they are not thread-safe because they might track
|
||||||
* allocated database resources to be able to free them after execution.
|
* allocated database resources in order to free them after execution.
|
||||||
*
|
*
|
||||||
* <p>Most databases/drivers should be able to work with {@link DefaultLobHandler},
|
* <p>Most databases/drivers should be able to work with {@link DefaultLobHandler},
|
||||||
* which by default delegates to JDBC's direct accessor methods, avoiding
|
* which by default delegates to JDBC's direct accessor methods, avoiding the
|
||||||
* <code>java.sql.Blob</code> and <code>java.sql.Clob</code> completely.
|
* <code>java.sql.Blob</code> and <code>java.sql.Clob</code> API completely.
|
||||||
* {@link DefaultLobHandler} can also be configured to populate LOBs using
|
* {@link DefaultLobHandler} can also be configured to access LOBs using
|
||||||
* <code>PreparedStatement.setBlob/setClob</code> (e.g. for PostgreSQL).
|
* <code>PreparedStatement.setBlob/setClob</code> (e.g. for PostgreSQL), through
|
||||||
|
* setting the {@link DefaultLobHandler#setWrapAsLob "wrapAsLob"} property.
|
||||||
*
|
*
|
||||||
* <p>Unfortunately, Oracle 9i just accepts Blob/Clob instances created via its own
|
* <p>Unfortunately, Oracle 9i just accepts Blob/Clob instances created via its own
|
||||||
* proprietary BLOB/CLOB API, and additionally doesn't accept large streams for
|
* proprietary BLOB/CLOB API, and additionally doesn't accept large streams for
|
||||||
* PreparedStatement's corresponding setter methods. Therefore, you need to use
|
* PreparedStatement's corresponding setter methods. Therefore, you need to use
|
||||||
* {@link OracleLobHandler} there, which uses Oracle's BLOB/CLOB API for both all access.
|
* {@link OracleLobHandler} there, which uses Oracle's BLOB/CLOB API for both types
|
||||||
* The Oracle 10g JDBC driver should basically work with {@link DefaultLobHandler}
|
* of access. The Oracle 10g JDBC driver should basically work with
|
||||||
* as well, with some limitations in terms of LOB sizes.
|
* {@link DefaultLobHandler} as well, with some limitations in terms of LOB sizes.
|
||||||
*
|
*
|
||||||
* <p>Of course, you need to declare different field types for each database.
|
* <p>Of course, you need to declare different field types for each database.
|
||||||
* In Oracle, any binary content needs to go into a BLOB, and all character content
|
* In Oracle, any binary content needs to go into a BLOB, and all character content
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue