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
This commit is contained in:
Heath Thomann 2012-05-12 18:41:15 +00:00
parent 61238ede48
commit 129e6ae069
4 changed files with 47 additions and 1 deletions

View File

@ -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);
}

View File

@ -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.

View File

@ -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();

View File

@ -3408,6 +3408,27 @@ ResultSet.getString</methodname> will be used to obtain clob data rather than
<methodname>ResultSet.getCharacterStream</methodname>.
</para>
</listitem>
<listitem id="DBDictionary.UseJDBC4SetBinaryStream">
<para>
<indexterm>
<primary>
JDBC
</primary>
<secondary>
UseJDBC4SetBinaryStream
</secondary>
</indexterm>
<literal>UseJDBC4SetBinaryStream</literal>: When true, an attempt will be made to obtain
a JDBC 4.0 version of <methodname>PreparedStatement.setBinaryStream</methodname>.
By default a <methodname>setBinaryStream</methodname> 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 <methodname>setBinaryStream</methodname> will be used which does not take a length.
The default value of this property is false.
</para>
</listitem>
<listitem id="DBDictionary.UseNativeSequenceCache">
<para>
<indexterm>