openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hthom...@apache.org
Subject svn commit: r1337557 - in /openjpa/branches/2.0.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/ openjpa-project/src/doc/manual/
Date Sat, 12 May 2012 14:54:39 GMT
Author: hthomann
Date: Sat May 12 14:54:39 2012
New Revision: 1337557

URL: http://svn.apache.org/viewvc?rev=1337557&view=rev
Log:
OPENJPA-2067: Added code, gated by the new DBDictionary.useJDBC4SetBinaryStream prop, to use
a JDBC 4.0 version of setBinaryStream.

Modified:
    openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
    openjpa/branches/2.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml

Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1337557&r1=1337556&r2=1337557&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Sat May 12 14:54:39 2012
@@ -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;
@@ -51,7 +52,6 @@ import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
-import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -66,10 +66,10 @@ import javax.sql.DataSource;
 import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.identifier.ColumnDefIdentifierRule;
-import org.apache.openjpa.jdbc.identifier.Normalizer;
 import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.identifier.DBIdentifierRule;
 import org.apache.openjpa.jdbc.identifier.DBIdentifierUtil;
+import org.apache.openjpa.jdbc.identifier.Normalizer;
 import org.apache.openjpa.jdbc.identifier.DBIdentifier.DBIdentifierType;
 import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
 import org.apache.openjpa.jdbc.kernel.JDBCStore;
@@ -88,7 +88,6 @@ import org.apache.openjpa.jdbc.schema.In
 import org.apache.openjpa.jdbc.schema.NameSet;
 import org.apache.openjpa.jdbc.schema.PrimaryKey;
 import org.apache.openjpa.jdbc.schema.Schema;
-import org.apache.openjpa.jdbc.schema.SchemaGroup;
 import org.apache.openjpa.jdbc.schema.Sequence;
 import org.apache.openjpa.jdbc.schema.Table;
 import org.apache.openjpa.jdbc.schema.Unique;
@@ -103,6 +102,7 @@ import org.apache.openjpa.lib.identifier
 import org.apache.openjpa.lib.identifier.IdentifierRule;
 import org.apache.openjpa.lib.identifier.IdentifierUtil;
 import org.apache.openjpa.lib.jdbc.ConnectionDecorator;
+import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
 import org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
@@ -288,6 +288,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;
@@ -396,6 +397,11 @@ public class DBDictionary
     // 0  = no batch
     // any positive number = batch limit
     public int batchLimit = NO_BATCH;
+
+    /**
+     * Set when we reflectively find a JDBC 4.0 version of the 'setBinaryStream' method.
+     */
+    Method _setBinaryStream = null;
     
     public final Map<Integer,Set<String>> sqlStateCodes = 
         new HashMap<Integer, Set<String>>();
@@ -927,6 +933,39 @@ 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 an attempt will be made, using reflections, to obtain the necessary
+    	//setBinaryStream method.
+		if (useJDBC4SetBinaryStream) {
+			try {
+				if (_setBinaryStream == null) {
+					_setBinaryStream = PreparedStatement.class.getMethod(
+							"setBinaryStream", int.class, InputStream.class);
+				}
+
+				//If here, the necessary 'setBinaryStream' method exists so call it now.
+	            PreparedStatement inner = stmnt;
+	            PreparedStatement outer = stmnt;
+	            if (stmnt instanceof DelegatingPreparedStatement) {
+	                inner = (PreparedStatement) ((DelegatingPreparedStatement)stmnt).getInnermostDelegate();
+	                outer = (PreparedStatement) ((DelegatingPreparedStatement)stmnt).getDelegate();
+	            }
+	            
+	            _setBinaryStream.invoke(inner, new Object[] { idx, val } );
+	            // Direct invocation of setClob on the Oracle driver bypasses OpenJPA's built-in
+	            // parameter logging via decorators.  Log the parameter directly.
+	            LoggingConnectionDecorator.logStatementParameter(outer, idx, "setBinaryStream",
val);
+				return;
+			} catch (Throwable t) {
+				//If we didn't find the proper setBinaryStream method, lets set 
+				//'useJDBC4SetBinaryStream' to false to avoid lots of message
+				//warnings.
+				useJDBC4SetBinaryStream=false;
+				log.warn(_loc.get("jdbc4-setbinarystream-unsupported"), t);
+			}
+		}
+
         stmnt.setBinaryStream(idx, val, length);
     }
 

Modified: openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties?rev=1337557&r1=1337556&r2=1337557&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
(original)
+++ openjpa/branches/2.0.x/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/localizer.properties
Sat May 12 14:54:39 2012
@@ -223,4 +223,8 @@ oracle-set-clob-failed: Invocation of me
     large object (CLOB) or XML values did not complete successfully.  An \
     alternate method is used to store the data;  however, if the data is larger \
     than 4000 bytes, data, an error might occur.
+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=true"
is \
+    set.  A prior version of this method will be used.    
 

Modified: openjpa/branches/2.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
URL: http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=1337557&r1=1337556&r2=1337557&view=diff
==============================================================================
--- openjpa/branches/2.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml (original)
+++ openjpa/branches/2.0.x/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Sat May 12
14:54:39 2012
@@ -3301,6 +3301,27 @@ ResultSet.getString</methodname> will be
 <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>



Mime
View raw message