db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1442195 - in /db/derby/code/trunk: ./ java/client/ java/client/org/apache/derby/client/am/ java/client/org/apache/derby/client/net/ java/client/org/apache/derby/jdbc/ java/engine/org/apache/derby/impl/jdbc/ java/testing/org/apache/derbyTes...
Date Mon, 04 Feb 2013 17:39:46 GMT
Author: rhillegas
Date: Mon Feb  4 17:39:46 2013
New Revision: 1442195

URL: http://svn.apache.org/viewvc?rev=1442195&view=rev
Log:
DERBY-6000: Add support for JDBC 4.2 changes to BatchUpdateException.

Added:
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
  (with props)
    db/derby/code/trunk/tools/jar/dnc.1.8.properties   (with props)
Removed:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java
Modified:
    db/derby/code/trunk/build.xml
    db/derby/code/trunk/java/client/build.xml
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
    db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java

Modified: db/derby/code/trunk/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/build.xml?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/build.xml (original)
+++ db/derby/code/trunk/build.xml Mon Feb  4 17:39:46 2013
@@ -165,6 +165,9 @@
     <available property="compilerAtCorrectLevel" classname="java.util.Queue"/>
 
     <fail unless="compilerAtCorrectLevel" message="Compiler level must be Java 5 or later."/>
+
+    <antcall target="checkVMLevel"/>
+    
   </target>
 
   <!-- checkVMLevel:
@@ -176,6 +179,7 @@
     <!-- The java.lang.ManagementFactory class was new in J2SE 5.0 -->
     <available classname="java.lang.management.ManagementFactory" property="vmLevelIsAtLeast1.5"/>
     <available classname="java.sql.Wrapper" property="vmLevelIsAtLeast1.6" value="true"/>
+    <available classname="java.sql.SQLType" property="vmLevelIsAtLeast1.8" value="true"/>
   </target>
 
 <!-- ==================================================================== -->
@@ -1714,7 +1718,7 @@
 
 <!-- - - - - - - - - - - - - - derbyclient.jar target - - - - - - - - -->
 
- <target name="derbyclientjar" depends="setsanityname,initjars">
+ <target name="derbyclientjar" depends="checkVMLevel,setsanityname,initjars">
 
     <echo level="info" message="Beginning derbyclient.jar ${sanity.name} build"/>
 
@@ -1725,6 +1729,7 @@
 
     <copy file="${basedir}/tools/jar/dnc.properties"
           tofile="${derby.jar.dir}/lists/dnc.properties"/>
+    <antcall target="derbyclientjar.1.8"/>
 
     <java classname="org.apache.derbyBuild.classlister" fork="yes">
       <jvmarg value="-Doutputfile=${derby.jar.dir}/lists/dnc.list"/>
@@ -1788,6 +1793,14 @@
     </jar>
   </target>
 
+
+  <!-- Add extra classes to jar file if building for Java 8 -->
+  <target name="derbyclientjar.1.8" if="vmLevelIsAtLeast1.8">
+    <concat destfile="${derby.jar.dir}/lists/dnc.properties" append="true">
+      <fileset file="${basedir}/tools/jar/dnc.1.8.properties" />
+    </concat>
+  </target>
+
 <!-- - - - - - - - - - - - - - derbyrun.jar target  - - - - - - - - - -->
    
   <target name="derbyrunjar" depends="setsanityname,initjars">

Modified: db/derby/code/trunk/java/client/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/build.xml?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/build.xml (original)
+++ db/derby/code/trunk/java/client/build.xml Mon Feb  4 17:39:46 2013
@@ -61,7 +61,7 @@
       proceed="${proceed}"
       verbose="${verbose}"
       srcdir="${derby.client.src.dir}"
-      excludes="**/*40.java" 
+      excludes="**/*40.java,**/*42.java" 
       destdir="${out.dir}">
       <classpath>
           <pathelement path="${java15compile.classpath}"/>
@@ -91,8 +91,34 @@
    </javac>
 </target> 
 
+<target name="compile_jdbc42" if="vmLevelIsAtLeast1.8">
+    <javac
+      source="${compilerLevel16}"
+      target="${compilerLevel16}"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.client.src.dir}"
+      includes="**/*42.java" 
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java18compile.classpath}"/>
+      </classpath>
+      <compilerarg value="-Xlint"/>
+   </javac>
+</target> 
   
 <!-- default target  -->
-  <target name="client" depends="compile, compile_jdbc4"/>
+  <target name="client" depends="checkVMLevel, compile, compile_jdbc4, compile_jdbc42"/>
+
+  <target name="checkVMLevel">
+    <available classname="java.sql.SQLType" property="vmLevelIsAtLeast1.8" value="true"/>
+  </target>
+
 </project>
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java Mon Feb  4 17:39:46
2013
@@ -21,6 +21,7 @@
 
 package org.apache.derby.client.am;
 
+import org.apache.derby.jdbc.ClientDriver;
 import org.apache.derby.shared.common.reference.SQLState;
 
 public abstract class Agent {
@@ -252,7 +253,8 @@ public abstract class Agent {
         checkForExceptions();
     }
 
-    public final void endBatchedReadChain(long[] updateCounts, SqlException accumulatedExceptions)
throws BatchUpdateException {
+    public final void endBatchedReadChain(long[] updateCounts, SqlException accumulatedExceptions)
+        throws java.sql.BatchUpdateException {
         disableBatchedExceptionTracking();
         for (int i = 0; i < batchedExceptionGenerated_.length; i++) {
             if (batchedExceptionGenerated_[i]) {
@@ -267,7 +269,7 @@ public abstract class Agent {
             }
         }
         if (accumulatedExceptions != null) {
-            throw BatchUpdateException.newBatchUpdateException(logWriter_,
+            throw ClientDriver.getFactory().newBatchUpdateException(logWriter_,
                 new ClientMessageId(SQLState.BATCH_NON_ATOMIC_FAILURE),
                 null, updateCounts, accumulatedExceptions);
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClientJDBCObjectFactory.java
Mon Feb  4 17:39:46 2013
@@ -382,4 +382,10 @@ public interface ClientJDBCObjectFactory
      *
      */
     ParameterMetaData newParameterMetaData(ColumnMetaData columnMetaData);
+    
+    /**
+     * Creates a BatchUpdateException depending on the JVM level.
+     */
+    public  java.sql.BatchUpdateException    newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, Object[] args, long[] updateCounts,
SqlException cause );
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Configuration.java Mon Feb
 4 17:39:46 2013
@@ -222,6 +222,20 @@ public class Configuration {
         }
     }
 
+    /**
+     * Check to see if the jvm version is such that JDBC 4.2 is supported
+     */
+    
+    public static boolean supportsJDBC42() {
+        // use reflection to identify whether we support JDBC42
+        try {
+            Class.forName("java.sql.SQLType");
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
 
 
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Mon
Feb  4 17:39:46 2013
@@ -1647,7 +1647,7 @@ public class PreparedStatement extends S
 
     // Batch requires that input types are exact, we perform no input cross conversion for
Batch.
     // If so, this is an external semantic, and should go into the release notes
-    public int[] executeBatch() throws SQLException, BatchUpdateException {
+    public int[] executeBatch() throws SQLException {
         try
         {
             synchronized (connection_) {
@@ -2192,7 +2192,7 @@ public class PreparedStatement extends S
     }
 
     public long[] executeBatchX(boolean supportsQueryBatchRequest) 
-        throws SqlException, SQLException, BatchUpdateException {
+        throws SqlException, SQLException {
         synchronized (connection_) {
             checkForClosedStatement(); // Per jdbc spec (see Statement.close() javadoc)
             clearWarningsX(); // Per jdbc spec 0.7, also see getWarnings() javadoc
@@ -2202,7 +2202,7 @@ public class PreparedStatement extends S
 
 
     private long[] executeBatchRequestX(boolean supportsQueryBatchRequest)
-            throws SqlException, BatchUpdateException {
+            throws SqlException, java.sql.BatchUpdateException {
         SqlException chainBreaker = null;
         int batchSize = batch_.size();
         long[] updateCounts = new long[batchSize];
@@ -2223,9 +2223,9 @@ public class PreparedStatement extends S
         // and the values 0 and 0xffff are reserved as special values. So
         // that imposes an upper limit on the batch size we can support:
         if (batchSize > 65534)
-            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
+            throw ClientDriver.getFactory().newBatchUpdateException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.TOO_MANY_COMMANDS_FOR_BATCH), 
-                65534, updateCounts);
+                new Object[] { new Integer( 65534 ) }, updateCounts, null );
 
         // Initialize all the updateCounts to indicate failure
         // This is done to account for "chain-breaking" errors where we cannot
@@ -2235,13 +2235,13 @@ public class PreparedStatement extends S
         }
 
         if (!supportsQueryBatchRequest && sqlMode_ == isQuery__) {
-            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
-                new ClientMessageId(SQLState.CANNOT_BATCH_QUERIES), updateCounts);
+            throw ClientDriver.getFactory().newBatchUpdateException(agent_.logWriter_, 
+            new ClientMessageId(SQLState.CANNOT_BATCH_QUERIES), (Object [])null, updateCounts,
null);
         }
         if (supportsQueryBatchRequest && sqlMode_ != isQuery__) {
-            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
+            throw ClientDriver.getFactory().newBatchUpdateException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.QUERY_BATCH_ON_NON_QUERY_STATEMENT), 
-                updateCounts);
+                (Object [])null, updateCounts, null);
         }
 
         resultSetList_ = null;
@@ -2288,9 +2288,9 @@ public class PreparedStatement extends S
                         chainAutoCommit || (i != batchSize - 1));  // more statements to
chain
             } else if (outputRegistered_) // make sure no output parameters are registered
             {
-                throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
+                throw ClientDriver.getFactory().newBatchUpdateException(agent_.logWriter_,

                     new ClientMessageId(SQLState.OUTPUT_PARAMS_NOT_ALLOWED),
-                    updateCounts);
+                    (Object [])null, updateCounts, null );
             } else {
                 writeExecuteCall(false, // no output expected for batched CALLs
                         null, // no procedure name supplied for prepared CALLs

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Mon Feb  4 17:39:46
2013
@@ -1175,7 +1175,7 @@ public class Statement implements java.s
         }
     }
 
-    public int[] executeBatch() throws SQLException, BatchUpdateException {
+    public int[] executeBatch() throws SQLException {
         try
         {
             synchronized (connection_) {
@@ -1196,7 +1196,7 @@ public class Statement implements java.s
     }
 
     // Added by JDBC 4.2
-    public long[] executeLargeBatch() throws SQLException, BatchUpdateException {
+    public long[] executeLargeBatch() throws SQLException {
         try
         {
             synchronized (connection_) {
@@ -1216,7 +1216,7 @@ public class Statement implements java.s
         }
     }
 
-    private long[] executeBatchX() throws SqlException, BatchUpdateException {
+    private long[] executeBatchX() throws SqlException, java.sql.BatchUpdateException {
         checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
         clearWarningsX(); // Per jdbc spec 0.7, and getWarnings() javadoc
         resultSetList_ = null;
@@ -2349,7 +2349,7 @@ public class Statement implements java.s
         }
     }
 
-    void flowExecuteBatch(long[] updateCounts) throws SqlException, BatchUpdateException
{
+    void flowExecuteBatch(long[] updateCounts) throws SqlException, java.sql.BatchUpdateException
{
         SqlException chainBreaker = null;
         boolean isCallCataloguedBestGuess = true;
         agent_.beginBatchedWriteChain(this);

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl.java
Mon Feb  4 17:39:46 2013
@@ -27,6 +27,7 @@ import org.apache.derby.client.ClientXAC
 import org.apache.derby.client.am.CachingLogicalConnection;
 import org.apache.derby.client.am.CallableStatement;
 import org.apache.derby.client.am.ClientJDBCObjectFactory;
+import org.apache.derby.client.am.ClientMessageId;
 import org.apache.derby.client.am.LogicalConnection;
 import org.apache.derby.client.am.ParameterMetaData;
 import org.apache.derby.client.am.PreparedStatement;
@@ -43,6 +44,9 @@ import org.apache.derby.client.am.stmtca
 import org.apache.derby.jdbc.ClientBaseDataSourceRoot;
 import org.apache.derby.client.am.ColumnMetaData;
 import org.apache.derby.client.am.StatementCacheInteractor;
+import org.apache.derby.client.am.Utils;
+import org.apache.derby.shared.common.i18n.MessageUtil;
+import org.apache.derby.shared.common.error.ExceptionUtil;
 
 /**
  * Implements the the ClientJDBCObjectFactory interface and returns the classes
@@ -52,6 +56,15 @@ import org.apache.derby.client.am.Statem
  */
 
 public class ClientJDBCObjectFactoryImpl implements ClientJDBCObjectFactory{
+    /** 
+     *  The message utility instance we use to find messages
+     *  It's primed with the name of the client message bundle so that
+     *  it knows to look there if the message isn't found in the
+     *  shared message bundle.
+     */
+    private static final MessageUtil msgutil_ =
+        SqlException.getMessageUtil();
+
     /**
      * Returns an instance of org.apache.derby.client.ClientPooledConnection 
      */
@@ -420,4 +433,36 @@ public class ClientJDBCObjectFactoryImpl
     public ParameterMetaData newParameterMetaData(ColumnMetaData columnMetaData) {
         return new ParameterMetaData(columnMetaData);
     }
+
+    /**
+     * Creates a BatchUpdateException depending on the JVM level.
+     */
+    public  java.sql.BatchUpdateException    newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, Object[] args, long[] updateCounts,
SqlException cause )
+    {
+        java.sql.BatchUpdateException   bue = newBatchUpdateException
+            (
+             msgutil_.getCompleteMessage( msgid.msgid, args),
+             ExceptionUtil.getSQLStateFromIdentifier(msgid.msgid),
+             ExceptionUtil.getSeverityFromIdentifier(msgid.msgid),
+             updateCounts
+             );
+    
+        if (logWriter != null) {
+            logWriter.traceDiagnosable( bue );
+        }
+
+        if (cause != null) {
+            bue.initCause(cause);
+            bue.setNextException(cause.getSQLException());
+        }
+    
+        return bue;
+    }
+    /** This method is overriden on JVM 8 */
+    protected   java.sql.BatchUpdateException   newBatchUpdateException
+        ( String message, String sqlState, int errorCode, long[] updateCounts )
+    {
+        return new java.sql.BatchUpdateException( message, sqlState, errorCode, Utils.squashLongs(
updateCounts ) );
+    }
 }

Added: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java?rev=1442195&view=auto
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
(added)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
Mon Feb  4 17:39:46 2013
@@ -0,0 +1,39 @@
+/*
+ 
+   Derby - Class org.apache.derby.client.net.ClientJDBCObjectFactoryImpl42
+ 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+
+package org.apache.derby.client.net;
+
+/**
+ * Implements the ClientJDBCObjectFactory interface and returns the JDBC 4.2
+ * specific classes.
+ */
+public class ClientJDBCObjectFactoryImpl42 extends ClientJDBCObjectFactoryImpl40
+{
+    /** This method is overriden on JVM 8 to take advantage of long update counts */
+    protected   java.sql.BatchUpdateException   newBatchUpdateException
+        ( String message, String sqlState, int errorCode, long[] updateCounts )
+    {
+        return new java.sql.BatchUpdateException( message, sqlState, errorCode, updateCounts,
null );
+    }
+}
+
+    
+

Propchange: db/derby/code/trunk/java/client/org/apache/derby/client/net/ClientJDBCObjectFactoryImpl42.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientDriver.java Mon Feb  4 17:39:46
2013
@@ -399,7 +399,9 @@ public class ClientDriver implements jav
     public static ClientJDBCObjectFactory getFactory() {
         if(factoryObject!=null)
             return factoryObject;
-        if (Configuration.supportsJDBC40()) {
+        if (Configuration.supportsJDBC42()) {
+            factoryObject = createJDBC42FactoryImpl();
+        } else if (Configuration.supportsJDBC40()) {
             factoryObject = createJDBC40FactoryImpl();
         } else {
             factoryObject = createDefaultFactoryImpl();
@@ -440,6 +442,34 @@ public class ClientDriver implements jav
             return createDefaultFactoryImpl();
         }
     }
+
+    /**
+     *Returns an instance of the ClientJDBCObjectFactoryImpl42 class
+     *If a ClassNotFoundException occurs then it returns an
+     *instance of the most refined ClientJDBCObjectFactoryImpl possible
+     *
+     *If a future version of JDBC comes then
+     *a similar method would be added say createJDBCXXFactoryImpl
+     *in which if  the class is not found then it would
+     *return the lower version thus having a sort of cascading effect
+     *until it gets a valid instance
+     */
+    
+    private static ClientJDBCObjectFactory createJDBC42FactoryImpl() {
+        final String factoryName =
+                "org.apache.derby.client.net.ClientJDBCObjectFactoryImpl42";
+        try {
+            return (ClientJDBCObjectFactory)
+            Class.forName(factoryName).newInstance();
+        } catch (ClassNotFoundException cnfe) {
+            return createJDBC40FactoryImpl();
+        } catch (InstantiationException ie) {
+            return createJDBC40FactoryImpl();
+        } catch (IllegalAccessException iae) {
+            return createJDBC40FactoryImpl();
+        }
+    }
+
 }
 
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/Util.java Mon Feb  4 17:39:46
2013
@@ -24,6 +24,7 @@ package org.apache.derby.impl.jdbc;
 import org.apache.derby.iapi.error.ErrorStringBuilder;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.i18n.MessageService;
+import org.apache.derby.iapi.services.info.JVMInfo;
 
 import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.iapi.services.sanity.SanityManager;
@@ -39,6 +40,8 @@ import org.apache.derby.iapi.reference.S
 import org.apache.derby.iapi.reference.MessageId;
 import org.apache.derby.iapi.reference.JDBC40Translation;
 
+import java.lang.reflect.Constructor;
+import java.sql.BatchUpdateException;
 import java.sql.SQLException;
 import java.sql.Types;
 import java.io.IOException;
@@ -114,18 +117,21 @@ public abstract class Util  {
     			(message != null) && (message.equals("Connection refused : java.lang.OutOfMemoryError")))
			
     		return;
 
+        logError( "\nERROR " +  se.getSQLState() + ": "  + se.getMessage() + "\n", se );
+    }
+    private static  void    logError( String errorMessage, Throwable t )
+    {
     	HeaderPrintWriter errorStream = Monitor.getStream();
     	if (errorStream == null) {
-    		se.printStackTrace();
+    		t.printStackTrace();
     		return;
     	}
     	ErrorStringBuilder	errorStringBuilder = new ErrorStringBuilder(errorStream.getHeader());
-    	errorStringBuilder.append("\nERROR " +  se.getSQLState() + ": "  + se.getMessage() +
"\n");
-    	errorStringBuilder.stackTrace(se);
+    	errorStringBuilder.append( errorMessage );
+    	errorStringBuilder.stackTrace( t );
     	errorStream.print(errorStringBuilder.get().toString());
     	errorStream.flush();
     	errorStringBuilder.reset();
-
     }
 
 	
@@ -338,7 +344,27 @@ public abstract class Util  {
     static  SQLException    newBatchUpdateException
         ( String message, String sqlState, int errorCode, long[] updateCounts )
     {
-        return new java.sql.BatchUpdateException
+        if ( JVMInfo.JDK_ID >= JVMInfo.J2SE_18 )
+        {
+            try {
+                Constructor constructor = BatchUpdateException.class.getConstructor
+                    (
+                     new Class[] { String.class, String.class, Integer.TYPE, updateCounts.getClass(),
Throwable.class }
+                     );
+
+                return (BatchUpdateException) constructor.newInstance
+                    ( new Object[] { message, sqlState, new Integer( errorCode ), updateCounts,
(Throwable) null } );
+            }
+            catch (Exception e)
+            {
+                // unanticipated problem. log it and return the Java 7 version of the exception
+                logError( "\nERROR " +  e.getMessage() + "\n", e );
+            }
+        }
+
+        // use this constructor if we're not on Java 8 or if an error occurred
+        // while using the Java 8 constructor
+        return new BatchUpdateException
             ( message, sqlState, errorCode, squashLongs( updateCounts ) );
     }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java
Mon Feb  4 17:39:46 2013
@@ -24,8 +24,9 @@ import org.apache.derby.vti.VTITemplate;
 import org.apache.derby.impl.jdbc.EmbedResultSet;
 import org.apache.derby.impl.sql.execute.RowUtil;
 
-import org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41Statement;
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.BatchUpdateTest;
 import org.apache.derbyTesting.functionTests.tests.jdbcapi.SetQueryTimeoutTest;
+import org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41Statement;
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.TestConfiguration;
@@ -386,6 +387,8 @@ public class StatementTest
         largeBatchTest( sw, 0L);
 
         largeMaxRowsTest( sw,  ((long) Integer.MAX_VALUE) + 1L );
+
+        largeBatchUpdateExceptionTest( sw, ((long) Integer.MAX_VALUE) + 1L );
     }
     private static  void    largeUpdateTest( StatementWrapper sw, long rowCountBase )
         throws Exception
@@ -490,6 +493,45 @@ public class StatementTest
         assertEquals( expectedRowCount, rowCount );
         assertEquals( maxRows, sw.getLargeMaxRows() );
     }
+    private static  void    largeBatchUpdateExceptionTest( StatementWrapper sw, long rowCountBase
)
+        throws Exception
+    {
+        println( "Large batch update exception test with rowCountBase = " + rowCountBase
);
+        
+        sw.getWrappedStatement().clearBatch();
+        sw.getWrappedStatement().execute( "create table intTable( col1 int generated always
as identity, col2 int )" );
+
+        // poke the rowCountBase into the engine. all returned row counts will be
+        // increased by this amount
+        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );
+
+        //
+        // Create a batch of statements. The last one will die on an overflow condition.
+        //
+        sw.getWrappedStatement().addBatch( "insert into intTable( col2 ) values ( 1 )" );
+        sw.getWrappedStatement().addBatch( "insert into intTable( col2 ) values ( 1 )" );
+        sw.getWrappedStatement().addBatch( "update intTable set col2 = 2147483647 + 1" );
+
+        if ( usingEmbedded() )
+        {
+            BatchUpdateTest.assertBatchExecuteError
+                (
+                 "22003", sw.getWrappedStatement(),
+                 new long[] { rowCountBase + 1L, rowCountBase + 1L }
+                 );
+        }
+        else if ( usingDerbyNetClient() )
+        {
+            BatchUpdateTest.assertBatchExecuteError
+                (
+                 "XJ208", sw.getWrappedStatement(),
+                 new long[] { rowCountBase + 1L, rowCountBase + 1L, -3 }
+                 );
+        }
+        
+        sw.getWrappedStatement().clearBatch();
+        setRowCountBase( sw.getWrappedStatement(), false, 0L );
+    }
         
     public static  void    setRowCountBase
         ( Statement stmt, boolean onClient, long rowCountBase )

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/BatchUpdateTest.java
Mon Feb  4 17:39:46 2013
@@ -24,6 +24,7 @@ package org.apache.derbyTesting.function
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.reflect.Method;
 import java.sql.BatchUpdateException;
 import java.sql.CallableStatement;
 import java.sql.Connection;
@@ -203,9 +204,35 @@ public class BatchUpdateTest extends Bas
     } 
     
     /* 
+     * helper method to check each count in the return array of a BatchUpdateException
+     */
+    public  static   void assertBatchUpdateCounts
+        ( long[] expectedBatchResult, BatchUpdateException bue )
+    {
+        assertBatchUpdateCounts( squashLongs( expectedBatchResult ), bue.getUpdateCounts()
);
+        
+        if ( isJava8() )
+        {
+            BatchUpdateExceptionWrapper wrapper = new BatchUpdateExceptionWrapper( bue );
+
+            assertEquals( expectedBatchResult, wrapper.getLargeUpdateCounts() );
+        }
+    }
+   
+    /** Squash an array of longs into an array of ints */
+    public static  int[]   squashLongs( long[] longs )
+    {
+        int count = (longs == null) ? 0 : longs.length;
+        int[]   ints = new int[ count ];
+        for ( int i = 0; i < count; i++ ) { ints[ i ] = (int) longs[ i ]; }
+
+        return ints;
+    }
+    
+    /* 
      * helper method to check each count in the return array of batchExecute
      */
-    private void assertBatchUpdateCounts( 
+    private static void assertBatchUpdateCounts( 
         int[] expectedBatchResult, int[] executeBatchResult )
     {
         assertEquals("length of array should be identical", 
@@ -233,20 +260,18 @@ public class BatchUpdateTest extends Bas
      *                             be executed.
      * @param expectedUpdateCount The expectedUpdateCount array.
      */
-    protected void assertBatchExecuteError( 
+    public static void assertBatchExecuteError( 
         String expectedError,
         Statement stmt,
-        int[] expectedUpdateCount) 
+        long[] expectedUpdateCount) 
     throws SQLException 
-    {
-        int[] updateCount;    
-        try {
-            updateCount = stmt.executeBatch();
+    { 
+       try {
+            stmt.executeBatch();
             fail("Expected batchExecute to fail");
         } catch (BatchUpdateException bue) {
             assertSQLState(expectedError, bue);
-            updateCount = bue.getUpdateCounts();
-            assertBatchUpdateCounts(expectedUpdateCount, updateCount);
+            assertBatchUpdateCounts(expectedUpdateCount, bue);
         } 
     }
     
@@ -520,9 +545,9 @@ public class BatchUpdateTest extends Bas
         stmt.addBatch("insert into t1 values(1)");
         if (usingEmbedded())
             /* Ensure the exception is the ResultSetReturnNotAllowed */
-            assertBatchExecuteError("X0Y79", stmt, new int[] {});
+            assertBatchExecuteError("X0Y79", stmt, new long[] {});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {-3, 1});
+            assertBatchExecuteError("XJ208", stmt, new long[] {-3, 1});
         
         assertTableRowCount("T1",
                 usingEmbedded() ? 0 : 1);
@@ -535,9 +560,9 @@ public class BatchUpdateTest extends Bas
         stmt.addBatch("insert into t1 values(1)");
         if (usingEmbedded())
             /* Ensure the exception is the ResultSetReturnNotAllowed */
-            assertBatchExecuteError("X0Y79", stmt, new int[] {1});
+            assertBatchExecuteError("X0Y79", stmt, new long[] {1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {1,-3,1});
+            assertBatchExecuteError("XJ208", stmt, new long[] {1,-3,1});
             
         assertTableRowCount("T1",
                 usingEmbedded() ? 1 : 3);
@@ -550,9 +575,9 @@ public class BatchUpdateTest extends Bas
         stmt.addBatch("SELECT * FROM SYS.SYSCOLUMNS");
         if (usingEmbedded())
             /* Ensure the exception is the ResultSetReturnNotAllowed */
-            assertBatchExecuteError("X0Y79", stmt, new int[] {1,1});
+            assertBatchExecuteError("X0Y79", stmt, new long[] {1,1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {1,1,-3});
+            assertBatchExecuteError("XJ208", stmt, new long[] {1,1,-3});
 
         assertTableRowCount("T1",
                 usingEmbedded() ? 3 : 5);
@@ -583,7 +608,7 @@ public class BatchUpdateTest extends Bas
         else if (usingDerbyNetClient())
         {
             stmt.addBatch("insert into t1 values(1)"); 
-            assertBatchExecuteError("XJ208",stmt, new int[] {-3,1});           
+            assertBatchExecuteError("XJ208",stmt, new long[] {-3,1});           
             // pull level with embedded situation
             rollback();
         }
@@ -633,7 +658,7 @@ public class BatchUpdateTest extends Bas
             stmt.addBatch("SELECT * FROM SYS.SYSCOLUMNS");
             if (usingDerbyNetClient())
             {
-                assertBatchExecuteError("XJ208", stmt, new int[] {1,1,-3});
+                assertBatchExecuteError("XJ208", stmt, new long[] {1,1,-3});
             }
             else if (usingEmbedded())
             {
@@ -677,9 +702,9 @@ public class BatchUpdateTest extends Bas
         /* Check to be sure the exception is the one we expect */
         /* Overflow is first stmt in the batch, so expect no update count */
         if (usingEmbedded())
-            assertBatchExecuteError("22003", stmt, new int[] {});
+            assertBatchExecuteError("22003", stmt, new long[] {});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {-3,1});
+            assertBatchExecuteError("XJ208", stmt, new long[] {-3,1});
 
         assertTableRowCount("T1",
                 usingEmbedded() ? 1 : 2);
@@ -693,9 +718,9 @@ public class BatchUpdateTest extends Bas
         /* Check to be sure the exception is the one we expect */
         /* Update is second statement in the batch, expect 1 update count */
         if (usingEmbedded())
-            assertBatchExecuteError("22003", stmt, new int[] {1});
+            assertBatchExecuteError("22003", stmt, new long[] {1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {1,-3,1});
+            assertBatchExecuteError("XJ208", stmt, new long[] {1,-3,1});
 
         assertTableRowCount("T1",
                 usingEmbedded() ? 2 : 4);
@@ -709,9 +734,9 @@ public class BatchUpdateTest extends Bas
         /* Check to be sure the exception is the one we expect */
         /* Update is last statement in the batch, expect 2 update counts */
         if (usingEmbedded())
-            assertBatchExecuteError("22003", stmt, new int[] {1,1});
+            assertBatchExecuteError("22003", stmt, new long[] {1,1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", stmt, new int[] {1,1,-3});
+            assertBatchExecuteError("XJ208", stmt, new long[] {1,1,-3});
 
         assertTableRowCount("T1",
                 usingEmbedded() ? 4 : 6);
@@ -1261,9 +1286,9 @@ public class BatchUpdateTest extends Bas
             /* Ensure the exception is the ResultSetReturnNotAllowed */
             /* "Select is first statement in the batch, 
              * so there should not be any update counts */
-            assertBatchExecuteError("X0Y79", pStmt, new int[] {});
+            assertBatchExecuteError("X0Y79", pStmt, new long[] {});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ117", pStmt, new int[] {-3});
+            assertBatchExecuteError("XJ117", pStmt, new long[] {-3});
         pStmt.close();
 
         assertTableRowCount("T1", 0);
@@ -1373,9 +1398,9 @@ public class BatchUpdateTest extends Bas
             /* Check to be sure the exception is the one we expect */
             /* Overflow is first statement in the batch, 
              * so there should not be any update count */
-            assertBatchExecuteError("22003", pStmt, new int[] {});
+            assertBatchExecuteError("22003", pStmt, new long[] {});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", pStmt, new int[] {-3});
+            assertBatchExecuteError("XJ208", pStmt, new long[] {-3});
         pStmt.close();
 
         assertTableRowCount("T1", 1);
@@ -1393,9 +1418,9 @@ public class BatchUpdateTest extends Bas
             /* Check to be sure the exception is the one we expect */
             /* Overflow is second statement in the batch, 
              * so there should be only 1 update count */
-            assertBatchExecuteError("22003", pStmt, new int[] {1});
+            assertBatchExecuteError("22003", pStmt, new long[] {1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", pStmt, new int[] {1,-3,1});
+            assertBatchExecuteError("XJ208", pStmt, new long[] {1,-3,1});
         pStmt.close();
 
         assertTableRowCount("T1", 1);
@@ -1414,9 +1439,9 @@ public class BatchUpdateTest extends Bas
             /* Check to be sure the exception is the one we expect */
             /* Overflow is last statement in the batch, 
              * so there should be 2 update counts */
-            assertBatchExecuteError("22003", pStmt, new int[] {1,1});
+            assertBatchExecuteError("22003", pStmt, new long[] {1,1});
         else if (usingDerbyNetClient())
-            assertBatchExecuteError("XJ208", pStmt, new int[] {1,1,-3});
+            assertBatchExecuteError("XJ208", pStmt, new long[] {1,1,-3});
 
         assertTableRowCount("T1", 1);
         
@@ -1547,8 +1572,8 @@ public class BatchUpdateTest extends Bas
         // Embedded stops processing the batch on the first failure, and only
         // the update count from the successful statement is returned. The
         // client driver continues after the failure, so it'll also drop C.
-        int[] expectedCounts = usingEmbedded() ?
-            new int[]{0} : new int[]{0, Statement.EXECUTE_FAILED, 0};
+        long[] expectedCounts = usingEmbedded() ?
+            new long[]{0} : new long[]{0, Statement.EXECUTE_FAILED, 0};
 
         assertBatchExecuteError("X0Y25", s, expectedCounts);
 
@@ -1566,4 +1591,53 @@ public class BatchUpdateTest extends Bas
             assertStatementError("42X05", s, "select * from c");
         }
     }
+    ////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED JDBC 4.2 WRAPPER AROUND A BatchUpdateException
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * This wrapper is used to expose JDBC 4.2 methods which can run on
+     * VM rev levels lower than Java 8.
+     * </p>
+     */
+    public  static  class   BatchUpdateExceptionWrapper
+    {
+        private BatchUpdateException    _wrappedException;
+
+        public BatchUpdateExceptionWrapper( BatchUpdateException wrappedException )
+        {
+            _wrappedException = wrappedException;
+        }
+
+        public  BatchUpdateException   getWrappedException() { return _wrappedException;
}
+
+        // New methods added by JDBC 4.2
+        public  long[] getLargeUpdateCounts()
+        {
+            return ((long[]) invoke
+                (
+                 "getLargeUpdateCounts",
+                 new Class[] {},
+                 new Object[] {}
+                 ));
+        }
+
+        // Reflection minion
+        protected Object  invoke( String methodName, Class[] argTypes, Object[] argValues
)
+        {
+            try {
+                Method  method = _wrappedException.getClass().getMethod( methodName, argTypes
);
+
+                return method.invoke( _wrappedException, argValues );
+            }
+            catch (Exception nsme) { printException( nsme ); }
+
+            return null;
+        }
+        private void    printException( Throwable t ) { BaseJDBCTestCase.println( t.getMessage()
); }
+    }
+    
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1442195&r1=1442194&r2=1442195&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Mon Feb
 4 17:39:46 2013
@@ -808,6 +808,10 @@ public abstract class BaseTestCase
         return getSystemProperty("java.version").startsWith("1.7");
     }
 
+    public static final boolean isJava8() {
+        return getSystemProperty("java.version").startsWith("1.8");
+    }
+
     public static final boolean runsWithEmma() {
         return getSystemProperty("java.class.path").indexOf("emma.jar") != -1;
     }

Added: db/derby/code/trunk/tools/jar/dnc.1.8.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/dnc.1.8.properties?rev=1442195&view=auto
==============================================================================
--- db/derby/code/trunk/tools/jar/dnc.1.8.properties (added)
+++ db/derby/code/trunk/tools/jar/dnc.1.8.properties Mon Feb  4 17:39:46 2013
@@ -0,0 +1,2 @@
+# extra client classes if we're building for Java 8
+derby.module.client.42cjof=org.apache.derby.client.net.ClientJDBCObjectFactoryImpl42

Propchange: db/derby/code/trunk/tools/jar/dnc.1.8.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message