From 129e6ae0696ad7bcf98376c0968ade79cd436948 Mon Sep 17 00:00:00 2001 From: Heath Thomann Date: Sat, 12 May 2012 18:41:15 +0000 Subject: [PATCH] OPENJPA-2067: Added code, gated by the new DBDictionary.useJDBC4SetBinaryStream prop, to use a JDBC 4.0 version of setBinaryStream. git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1337605 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/jdbc/sql/DBDictionary.java | 15 +++++++++++++ .../openjpa/jdbc/sql/localizer.properties | 4 ++++ .../lib/jdbc/LoggingConnectionDecorator.java | 8 ++++++- .../src/doc/manual/ref_guide_dbsetup.xml | 21 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 7c057d82d..1e225bb95 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -28,6 +28,7 @@ import java.io.OutputStream; import java.io.Reader; import java.io.StringReader; import java.io.Writer; +import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Array; @@ -288,6 +289,7 @@ public class DBDictionary public boolean useGetObjectForBlobs = false; public boolean useGetStringForClobs = false; public boolean useSetStringForClobs = false; + public boolean useJDBC4SetBinaryStream = false;//OPENJPA-2067 public int maxEmbeddedBlobSize = -1; public int maxEmbeddedClobSize = -1; public int inClauseLimit = -1; @@ -935,6 +937,19 @@ public class DBDictionary public void setBinaryStream(PreparedStatement stmnt, int idx, InputStream val, int length, Column col) throws SQLException { + + //OPENJPA-2067: If the user has set the 'useJDBC4SetBinaryStream' property + //then lets use the JDBC 4.0 version of the setBinaryStream method. + if (useJDBC4SetBinaryStream) { + if (isJDBC4){ + stmnt.setBinaryStream(idx, val); + return; + } + else { + log.warn(_loc.get("jdbc4-setbinarystream-unsupported")); + } + } + stmnt.setBinaryStream(idx, val, length); } diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties index 9566fef22..925e6c526 100644 --- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties +++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties @@ -223,3 +223,7 @@ sequencesql-override: Going to override the DB2 specific default for the \ invalid-locking-mode: Invalid locking mode for SolidDB: "{0}" oracle-set-clob-warning: Setting the supportsSetClob property on the OracleDictionary no longer has an \ effect. The functionality provided by the supportsSetClob property is now enabled, by default. +jdbc4-setbinarystream-unsupported: The JRE or JDBC level in use does not support the \ + JDBC 4.0 version of the "java.sql.PreparedStatement.setBinaryStream" method which is \ + necessary when the property "openjpa.jdbc.DBDictionary=useJDBC4SetBinaryStream" is \ + set to true. A prior version of this method will be used. diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java index 6e67466d1..d907e340e 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/LoggingConnectionDecorator.java @@ -1494,7 +1494,13 @@ public class LoggingConnectionDecorator implements ConnectionDecorator { setLogParameter(i1, "InputStream", is); super.setBinaryStream(i1, is, i2); } - + + public void setBinaryStream(int i1, InputStream is) + throws SQLException { + setLogParameter(i1, "InputStream", is); + super.setBinaryStream(i1, is); + } + public void clearParameters() throws SQLException { clearLogParameters(false); super.clearParameters(); diff --git a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml index 80e9695a3..18acb53ad 100644 --- a/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml +++ b/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml @@ -3408,6 +3408,27 @@ ResultSet.getString will be used to obtain clob data rather than ResultSet.getCharacterStream. + + + + + + JDBC + + + UseJDBC4SetBinaryStream + + +UseJDBC4SetBinaryStream: When true, an attempt will be made to obtain +a JDBC 4.0 version of PreparedStatement.setBinaryStream. +By default a setBinaryStream is used which takes the length of the +stream. OpenJPA uses a -1 for the length since OpenJPA doesn't know the length of the stream. +A few JDBC drivers check the length and throw an exception when the length is less than zero. +When this property is set to true, and an applicable JDK and JDBC 4.0 driver is available, a +version of setBinaryStream will be used which does not take a length. +The default value of this property is false. + +