db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1439883 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ client/org/apache/derby/client/net/ drda/org/apache/derby/impl/drda/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/i...
Date Tue, 29 Jan 2013 13:14:40 GMT
Author: rhillegas
Date: Tue Jan 29 13:14:39 2013
New Revision: 1439883

URL: http://svn.apache.org/viewvc?rev=1439883&view=rev
Log:
DERBY-6000: Add the JDBC 4.2 large update methods to the client implementation of Statement.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Agent.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.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/Sqlca.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
    db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowUtil.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/jdbc4/XA40Test.java

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=1439883&r1=1439882&r2=1439883&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 Tue Jan 29 13:14:39 2013
@@ -252,7 +252,7 @@ public abstract class Agent {
         checkForExceptions();
     }
 
-    public final void endBatchedReadChain(int[] updateCounts, SqlException accumulatedExceptions) throws BatchUpdateException {
+    public final void endBatchedReadChain(long[] updateCounts, SqlException accumulatedExceptions) throws BatchUpdateException {
         disableBatchedExceptionTracking();
         for (int i = 0; i < batchedExceptionGenerated_.length; i++) {
             if (batchedExceptionGenerated_[i]) {
@@ -267,7 +267,7 @@ public abstract class Agent {
             }
         }
         if (accumulatedExceptions != null) {
-            throw new BatchUpdateException(logWriter_,
+            throw BatchUpdateException.newBatchUpdateException(logWriter_,
                 new ClientMessageId(SQLState.BATCH_NON_ATOMIC_FAILURE),
                 null, updateCounts, accumulatedExceptions);
         }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/BatchUpdateException.java Tue Jan 29 13:14:39 2013
@@ -35,6 +35,30 @@ public class BatchUpdateException extend
     private static final MessageUtil msgutil_ =
         SqlException.getMessageUtil();
 
+    //
+    // Factory methods to handle new constructor added by JDBC 4.2
+    //
+    public  static  BatchUpdateException    newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, Object[] args, long[] updateCounts, SqlException cause )
+    {
+        return new BatchUpdateException( logWriter, msgid, args, Utils.squashLongs( updateCounts ), cause );
+    }
+    public static   BatchUpdateException newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, Object[] args, long[] updateCounts )
+    {
+        return new BatchUpdateException( logWriter, msgid, args, Utils.squashLongs( updateCounts ) );
+    }
+    public static   BatchUpdateException newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, long[] updateCounts )
+    {
+        return new BatchUpdateException( logWriter, msgid, Utils.squashLongs( updateCounts ) );
+    }
+    public static   BatchUpdateException newBatchUpdateException
+        ( LogWriter logWriter, ClientMessageId msgid, Object arg1, long[] updateCounts)
+    {
+        return new BatchUpdateException( logWriter, msgid, arg1, Utils.squashLongs( updateCounts ) );
+    }
+
     public BatchUpdateException(LogWriter logWriter, ClientMessageId msgid,
         Object[] args, int[] updateCounts, SqlException cause)
     {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java Tue Jan 29 13:14:39 2013
@@ -276,4 +276,32 @@ abstract class LogicalStatementEntity
     {
         return ((org.apache.derby.client.am.Statement) getPhysStmt()).isCloseOnCompletion();
     }
+
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.2 IN JAVA 8
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  long executeLargeUpdate( String sql ) throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).executeLargeUpdate( sql );
+    }
+    public  long executeLargeUpdate( String sql, int autoGeneratedKeys) throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).executeLargeUpdate( sql, autoGeneratedKeys );
+    }
+    public  long executeLargeUpdate( String sql, int[] columnIndexes ) throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).executeLargeUpdate( sql, columnIndexes );
+    }
+    public  long executeLargeUpdate( String sql, String[] columnNames ) throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).executeLargeUpdate( sql, columnNames );
+    }
+    public  long getLargeUpdateCount() throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).getLargeUpdateCount();
+    }
+
 }

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=1439883&r1=1439882&r2=1439883&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 Tue Jan 29 13:14:39 2013
@@ -399,7 +399,7 @@ public class PreparedStatement extends S
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "executeUpdate");
                 }
-                int updateValue = executeUpdateX();
+                int updateValue = (int) executeUpdateX();
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
                 }
@@ -412,7 +412,7 @@ public class PreparedStatement extends S
         }
     }
 
-    private int executeUpdateX() throws SqlException {
+    private long executeUpdateX() throws SqlException {
         flowExecute(executeUpdateMethod__);
         return updateCount_;
     }
@@ -1654,13 +1654,13 @@ public class PreparedStatement extends S
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "executeBatch");
                 }
-                int[] updateCounts = null;
+                long[] updateCounts = null;
                 updateCounts = executeBatchX(false);
 
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeBatch", updateCounts);
                 }
-                return updateCounts;
+                return Utils.squashLongs( updateCounts );
             }
         }
         catch ( SqlException se )
@@ -2191,7 +2191,7 @@ public class PreparedStatement extends S
             }
     }
 
-    public int[] executeBatchX(boolean supportsQueryBatchRequest) 
+    public long[] executeBatchX(boolean supportsQueryBatchRequest) 
         throws SqlException, SQLException, BatchUpdateException {
         synchronized (connection_) {
             checkForClosedStatement(); // Per jdbc spec (see Statement.close() javadoc)
@@ -2201,11 +2201,11 @@ public class PreparedStatement extends S
     }
 
 
-    private int[] executeBatchRequestX(boolean supportsQueryBatchRequest)
+    private long[] executeBatchRequestX(boolean supportsQueryBatchRequest)
             throws SqlException, BatchUpdateException {
         SqlException chainBreaker = null;
         int batchSize = batch_.size();
-        int[] updateCounts = new int[batchSize];
+        long[] updateCounts = new long[batchSize];
         int numInputColumns;
         try {
             numInputColumns = parameterMetaData_ == null ? 0 : parameterMetaData_.getColumnCount();
@@ -2223,7 +2223,7 @@ 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 new BatchUpdateException(agent_.logWriter_, 
+            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.TOO_MANY_COMMANDS_FOR_BATCH), 
                 65534, updateCounts);
 
@@ -2235,11 +2235,11 @@ public class PreparedStatement extends S
         }
 
         if (!supportsQueryBatchRequest && sqlMode_ == isQuery__) {
-            throw new BatchUpdateException(agent_.logWriter_, 
+            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.CANNOT_BATCH_QUERIES), updateCounts);
         }
         if (supportsQueryBatchRequest && sqlMode_ != isQuery__) {
-            throw new BatchUpdateException(agent_.logWriter_, 
+            throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
                 new ClientMessageId(SQLState.QUERY_BATCH_ON_NON_QUERY_STATEMENT), 
                 updateCounts);
         }
@@ -2288,7 +2288,7 @@ public class PreparedStatement extends S
                         chainAutoCommit || (i != batchSize - 1));  // more statements to chain
             } else if (outputRegistered_) // make sure no output parameters are registered
             {
-                throw new BatchUpdateException(agent_.logWriter_, 
+                throw BatchUpdateException.newBatchUpdateException(agent_.logWriter_, 
                     new ClientMessageId(SQLState.OUTPUT_PARAMS_NOT_ALLOWED),
                     updateCounts);
             } else {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Sqlca.java Tue Jan 29 13:14:39 2013
@@ -27,6 +27,13 @@ import org.apache.derby.shared.common.er
 import org.apache.derby.shared.common.reference.SQLState;
 
 public abstract class Sqlca {
+
+    // Indexes into sqlErrd_
+    public  static  final   int HIGH_ORDER_ROW_COUNT = 0;
+    public  static  final   int LOW_ORDER_ROW_COUNT = 1;
+    public  static  final   int LOW_ORDER_UPDATE_COUNT = 2;
+    public  static  final   int HIGH_ORDER_UPDATE_COUNT = 3;
+    public  static  final   int SQL_ERR_LENGTH = 6;
     transient protected Connection connection_;
     SqlException exceptionThrownOnStoredProcInvocation_;
     boolean messageTextRetrievedContainsTokensOnly_ = true;
@@ -215,7 +222,7 @@ public abstract class Sqlca {
             return sqlErrd_;
         }
 
-        sqlErrd_ = new int[6]; // create an int array.
+        sqlErrd_ = new int[ SQL_ERR_LENGTH ]; // create an int array.
         return sqlErrd_;
     }
 
@@ -469,15 +476,18 @@ public abstract class Sqlca {
         return new String(bytes, offset, length, Typdef.UTF8ENCODING);
     }
 
-    public int getUpdateCount() {
+    public long getUpdateCount() {
         if (sqlErrd_ == null) {
-            return 0;
+            return 0L;
         }
-        return sqlErrd_[2];
+        long    result = sqlErrd_[ LOW_ORDER_UPDATE_COUNT ];
+        result &= 0xFFFFFFFFL;
+        result |= ((long) sqlErrd_[ HIGH_ORDER_UPDATE_COUNT ] << 32);
+        return result;
     }
 
     public long getRowCount() throws org.apache.derby.client.am.DisconnectException {
-        return ((long) sqlErrd_[0] << 32) + sqlErrd_[1];
+        return ((long) sqlErrd_[ HIGH_ORDER_ROW_COUNT ] << 32) + sqlErrd_[ LOW_ORDER_ROW_COUNT ];
     }
 
     public void setContainsSqlcax(boolean containsSqlcax) {

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=1439883&r1=1439882&r2=1439883&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 Tue Jan 29 13:14:39 2013
@@ -41,7 +41,7 @@ public class Statement implements java.s
     ResultSet resultSet_;
 
     // Use -1, if there is no update count returned, ie. when result set is returned. 0 is a valid update count for DDL.
-    int updateCount_ = -1;
+    long updateCount_ = -1L;
     int returnValueFromProcedure_;
 
     // Enumeration of the flavors of statement execute call used.
@@ -232,7 +232,7 @@ public class Statement implements java.s
         warnings_ = null;
         //section_ = null;
         resultSet_ = null;
-        updateCount_ = -1;
+        updateCount_ = -1L;
         returnValueFromProcedure_ = 0;
         openOnClient_ = true;
         openOnServer_ = false;
@@ -482,7 +482,7 @@ public class Statement implements java.s
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "executeUpdate", sql);
                 }
-                int updateValue = executeUpdateX(sql);
+                int updateValue = (int) executeUpdateX(sql);
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
                 }
@@ -495,7 +495,28 @@ public class Statement implements java.s
         }
     }
 
-    private int executeUpdateX(String sql) throws SqlException {
+    // Added by JDBC 4.2
+    public long executeLargeUpdate(String sql) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql);
+                }
+                long updateValue = executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    private long executeUpdateX(String sql) throws SqlException {
         flowExecute(executeUpdateMethod__, sql);
         return updateCount_;
     }
@@ -937,7 +958,7 @@ public class Statement implements java.s
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "getUpdateCount", updateCount_);
                 }
-                return updateCount_;
+                return (int) updateCount_;
             }
         }
         catch ( SqlException se )
@@ -946,6 +967,27 @@ public class Statement implements java.s
         }
     }
 
+    // Added by JDBC 4.2
+    public long getLargeUpdateCount() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "getUpdateCount");
+                }
+                checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "getUpdateCount", updateCount_);
+                }
+                return updateCount_;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+    
     public boolean getMoreResults() throws SQLException {
         try
         {
@@ -1120,11 +1162,11 @@ public class Statement implements java.s
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceEntry(this, "executeBatch");
                 }
-                int[] updateCounts = executeBatchX();
+                long[] updateCounts = executeBatchX();
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeBatch", updateCounts);
                 }
-                return updateCounts;
+                return Utils.squashLongs( updateCounts );
             }
         }
         catch ( SqlException se )
@@ -1133,14 +1175,14 @@ public class Statement implements java.s
         }
     }
 
-    private int[] executeBatchX() throws SqlException, BatchUpdateException {
+    private long[] executeBatchX() throws SqlException, BatchUpdateException {
         checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
         clearWarningsX(); // Per jdbc spec 0.7, and getWarnings() javadoc
         resultSetList_ = null;
         // Initialize all the updateCounts to indicate failure
         // This is done to account for "chain-breaking" errors where we cannot
         // read any more replies
-        int[] updateCounts = new int[batch_.size()];
+        long[] updateCounts = new long[batch_.size()];
         Arrays.fill(updateCounts, -3);
         flowExecuteBatch(updateCounts);
         return updateCounts;
@@ -1186,7 +1228,7 @@ public class Statement implements java.s
     private boolean getMoreResultsX(int current) throws SqlException {
         checkForClosedStatement(); // Per jdbc spec (see java.sql.Statement.close() javadoc)
         boolean resultIsResultSet;
-        updateCount_ = -1;
+        updateCount_ = -1L;
         if (resultSetList_ == null) {
             if (resultSet_ != null) {
                 if (current != KEEP_CURRENT_RESULT) {
@@ -1247,7 +1289,29 @@ public class Statement implements java.s
                     agent_.logWriter_.traceEntry(this, "executeUpdate", sql, autoGeneratedKeys);
                 }
                 autoGeneratedKeys_ = autoGeneratedKeys;
-                int updateValue = executeUpdateX(sql);
+                int updateValue = (int) executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    // Added by JDBC 4.2
+    public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, autoGeneratedKeys);
+                }
+                autoGeneratedKeys_ = autoGeneratedKeys;
+                long updateValue = executeUpdateX(sql);
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
                 }
@@ -1270,7 +1334,31 @@ public class Statement implements java.s
                 if (columnIndexes != null && columnIndexes.length > 0)
                     autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
                 generatedKeysColumnIndexes_ = columnIndexes;
-                int updateValue = executeUpdateX(sql);
+                int updateValue = (int) executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    // Added by JDBC 4.2
+    public long executeLargeUpdate(String sql, int columnIndexes[]) throws SQLException {
+        try
+        {
+            synchronized (connection_) {  
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnIndexes);
+                }
+                if (columnIndexes != null && columnIndexes.length > 0)
+                    autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
+                generatedKeysColumnIndexes_ = columnIndexes;
+                long updateValue = executeUpdateX(sql);
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
                 }
@@ -1293,7 +1381,31 @@ public class Statement implements java.s
                 if (columnNames != null && columnNames.length > 0)
                     autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
                 generatedKeysColumnNames_ = columnNames;
-                int updateValue = executeUpdateX(sql);
+                int updateValue = (int) executeUpdateX(sql);
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se )
+        {
+            throw se.getSQLException();
+        }
+    }
+
+    // Added by JDBC 4.2
+    public long executeLargeUpdate(String sql, String columnNames[]) throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeUpdate", sql, columnNames);
+                }
+                if (columnNames != null && columnNames.length > 0)
+                    autoGeneratedKeys_ = Statement.RETURN_GENERATED_KEYS;
+                generatedKeysColumnNames_ = columnNames;
+                long updateValue = executeUpdateX(sql);
                 if (agent_.loggingEnabled()) {
                     agent_.logWriter_.traceExit(this, "executeUpdate", updateValue);
                 }
@@ -1612,7 +1724,7 @@ public class Statement implements java.s
             // sometime for call statement, protocol will return updateCount_, we will always set that to 0
             // sqlMode_ is not set for statements, only for prepared statements
             if (sqlMode_ == isCall__) {
-                updateCount_ = -1;
+                updateCount_ = -1L;
                 returnValueFromProcedure_ = sqlca.getSqlErrd()[0];  ////what is this for??
             }
             // Sqlcode 466 indicates a call statement has issued and result sets returned.
@@ -1628,7 +1740,7 @@ public class Statement implements java.s
     }
 
 
-    public void setUpdateCount(int updateCount) {
+    public void setUpdateCount(long updateCount) {
         updateCount_ = updateCount;
     }
 
@@ -1991,9 +2103,9 @@ public class Statement implements java.s
         parseSqlAndSetSqlModes(sql);
         checkAutoGeneratedKeysParameters();
         if (sqlMode_ == isUpdate__) {
-            updateCount_ = 0;
+            updateCount_ = 0L;
         } else {
-            updateCount_ = -1;
+            updateCount_ = -1L;
         }
 
         checkForAppropriateSqlMode(executeType, sqlMode_);
@@ -2191,12 +2303,12 @@ public class Statement implements java.s
 
         // The JDBC spec says that executeUpdate() should return 0
         // when no row count is returned.
-        if (executeType == executeUpdateMethod__ && updateCount_ < 0) {
-            updateCount_ = 0;
+        if (executeType == executeUpdateMethod__ && updateCount_ < 0L) {
+            updateCount_ = 0L;
         }
     }
 
-    void flowExecuteBatch(int[] updateCounts) throws SqlException, BatchUpdateException {
+    void flowExecuteBatch(long[] updateCounts) throws SqlException, BatchUpdateException {
         SqlException chainBreaker = null;
         boolean isCallCataloguedBestGuess = true;
         agent_.beginBatchedWriteChain(this);
@@ -2245,7 +2357,7 @@ public class Statement implements java.s
                     invalidSQLCaughtByClient = e;
                 }
                 if (invalidSQLCaughtByClient == null) {
-                    updateCount_ = -1;
+                    updateCount_ = -1L;
                     if (sqlMode_ != isCall__) {
                         readExecuteImmediateForBatch(sql);
                     } else {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Utils.java Tue Jan 29 13:14:39 2013
@@ -258,7 +258,7 @@ public final class Utils {
         return sqlca.getSqlCode();
     }
 
-    static public int getUpdateCountFromSqlcard(Sqlca sqlca) {
+    static public long getUpdateCountFromSqlcard(Sqlca sqlca) {
         if (sqlca == null) {
             return 0;
         } else {
@@ -266,6 +266,16 @@ public final class Utils {
         }
     }
 
+    /** 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;
+    }
+
     // latestException is assumed to be non-null, accumulatedExceptions can be null
     public static SQLException accumulateSQLException(SQLException latestException,
                                                       SQLException accumulatedExceptions) {

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetConnectionReply.java Tue Jan 29 13:14:39 2013
@@ -2678,7 +2678,7 @@ public class NetConnectionReply extends 
             skipFastBytes(18);
         }
         //   SQLERRD1 to SQLERRD6; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
-        int[] sqlerrd = new int[6];
+        int[] sqlerrd = new int[ NetSqlca.SQL_ERR_LENGTH ];
         readFastIntArray(sqlerrd);
 
         //   SQLWARN0 to SQLWARNA; PROTOCOL TYPE FCS; ENVLID 0x30; Length Override 1

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/net/NetCursor.java Tue Jan 29 13:14:39 2013
@@ -662,7 +662,7 @@ public class NetCursor extends org.apach
 
 
         //   SQLERRD1 to SQLERRD6; PROTOCOL TYPE I4; ENVLID 0x02; Length Override 4
-        int[] sqlerrd = new int[6];
+        int[] sqlerrd = new int[ NetSqlca.SQL_ERR_LENGTH ];
         for (int i = 0; i < sqlerrd.length; i++) {
             sqlerrd[i] = readFdocaInt();
         }

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Tue Jan 29 13:14:39 2013
@@ -53,6 +53,7 @@ import org.apache.derby.iapi.error.Excep
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.jdbc.AuthenticationService;
 import org.apache.derby.iapi.jdbc.EngineLOB;
+import org.apache.derby.iapi.jdbc.EngineStatement;
 import org.apache.derby.iapi.jdbc.EnginePreparedStatement;
 import org.apache.derby.iapi.jdbc.EngineResultSet;
 import org.apache.derby.iapi.reference.Attribute;
@@ -186,7 +187,7 @@ class DRDAConnThread extends Thread {
     private static final byte[] eod00000 = { '0', '0', '0', '0', '0' };
     private static final byte[] eod02000 = { '0', '2', '0', '0', '0' };
     private static final byte[] nullSQLState = { ' ', ' ', ' ', ' ', ' ' };
-    private static final byte[] errD4_D6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // 12x0 
+    private static final byte[] errD5_D6 = { 0, 0, 0, 0, 0, 0, 0, 0 }; // 8x0 
     private static final byte[] warn0_warnA = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' };  // 11x ' '
 
     private final static String AUTHENTICATION_PROVIDER_BUILTIN_CLASS =
@@ -755,7 +756,7 @@ class DRDAConnThread extends Thread {
                     break;
                 case CodePoint.EXCSQLIMM:
                     try {
-                        int updateCount = parseEXCSQLIMM();
+                        long updateCount = parseEXCSQLIMM();
                         // RESOLVE: checking updateCount is not sufficient
                         // since it will be 0 for creates, we need to know when
                         // any logged changes are made to the database
@@ -4387,7 +4388,7 @@ class DRDAConnThread extends Thread {
         // are ready to send resultset info.
         stmt.finishParams();
             
-        PreparedStatement ps = stmt.getPreparedStatement();
+        EnginePreparedStatement ps = stmt.getPreparedStatement();
         int rsNum = 0;
         do {
         if (hasResultSet)
@@ -4417,7 +4418,7 @@ class DRDAConnThread extends Thread {
         }
         else  if (! sendSQLDTARD)
         {
-            int updateCount = ps.getUpdateCount();
+            long updateCount = ps.getLargeUpdateCount();
 
             // The protocol wants us to send RDBUPDRM here, but we don't do
             // that because it used to cause protocol errors. DERBY-5847 has
@@ -4640,7 +4641,7 @@ class DRDAConnThread extends Thread {
     private void parseSQLDTA_work(DRDAStatement stmt) throws DRDAProtocolException,SQLException
     {
         String strVal;
-        PreparedStatement ps = stmt.getPreparedStatement();
+        EnginePreparedStatement ps = stmt.getPreparedStatement();
         int codePoint;
         ParameterMetaData pmeta = null;
 
@@ -4728,7 +4729,7 @@ class DRDAConnThread extends Thread {
                             }
                             rtnParam = true;
                         }
-                        ps = cs;
+                        ps = (EnginePreparedStatement) cs;
                         stmt.ps = ps;
                     }
 
@@ -5348,7 +5349,7 @@ class DRDAConnThread extends Thread {
      * @throws DRDAProtocolException
      * @throws SQLException
      */
-    private int parseEXCSQLIMM() throws DRDAProtocolException,SQLException
+    private long parseEXCSQLIMM() throws DRDAProtocolException,SQLException
     {
         int codePoint;
         reader.markCollection();
@@ -5383,13 +5384,13 @@ class DRDAConnThread extends Thread {
         // initialize statement for reuse
         drdaStmt.initialize();
         String sqlStmt = parseEXECSQLIMMobjects();
-        Statement statement = drdaStmt.getStatement();
+        EngineStatement statement = drdaStmt.getStatement();
         statement.clearWarnings();
         if (pendingStatementTimeout >= 0) {
             statement.setQueryTimeout(pendingStatementTimeout);
             pendingStatementTimeout = -1;
         }
-        int updCount = statement.executeUpdate(sqlStmt);
+        long updCount = statement.executeLargeUpdate(sqlStmt);
         return updCount;
     }
 
@@ -6057,13 +6058,13 @@ class DRDAConnThread extends Thread {
         reader.skipBytes();
     }
 
-    private void writeSQLCARDs(SQLException e, int updateCount)
+    private void writeSQLCARDs(SQLException e, long updateCount)
                                     throws DRDAProtocolException
     {
         writeSQLCARDs(e, updateCount, false);
     }
 
-    private void writeSQLCARDs(SQLException e, int updateCount, boolean sendSQLERRRM)
+    private void writeSQLCARDs(SQLException e, long updateCount, boolean sendSQLERRRM)
                                     throws DRDAProtocolException
     {
 
@@ -6145,7 +6146,7 @@ class DRDAConnThread extends Thread {
     }
 
     private void writeSQLCARD(SQLException e,
-        int updateCount, long rowCount ) throws DRDAProtocolException
+        long updateCount, long rowCount ) throws DRDAProtocolException
     {
         writer.createDssObject();
         writer.startDdm(CodePoint.SQLCARD);
@@ -6285,7 +6286,7 @@ class DRDAConnThread extends Thread {
      * 
      * @exception DRDAProtocolException
      */
-    private void writeSQLCAGRP(SQLException e, int updateCount, long rowCount)
+    private void writeSQLCAGRP(SQLException e, long updateCount, long rowCount)
         throws DRDAProtocolException
     {
         int sqlcode = getSqlCode(e);
@@ -6360,7 +6361,7 @@ class DRDAConnThread extends Thread {
      */
 
     private void writeSQLCAGRP(byte[] sqlState, int sqlcode, 
-                               int updateCount, long rowCount) throws DRDAProtocolException
+                               long updateCount, long rowCount) throws DRDAProtocolException
     {
         if (rowCount < 0 && updateCount < 0) {
             writer.writeByte(CodePoint.NULLDATA);
@@ -6601,7 +6602,7 @@ class DRDAConnThread extends Thread {
      * 
      * @exception DRDAProtocolException
      */
-    private void writeSQLCAXGRP(int updateCount,  long rowCount, String sqlerrmc,
+    private void writeSQLCAXGRP(long updateCount,  long rowCount, String sqlerrmc,
                 SQLException nextException) throws DRDAProtocolException
     {
         writer.writeByte(0);        // SQLCAXGRP INDICATOR
@@ -6628,15 +6629,18 @@ class DRDAConnThread extends Thread {
      * @param updateCount
      * @param rowCount 
      */
-    private void writeSQLCAERRWARN(int updateCount, long rowCount) 
+    private void writeSQLCAERRWARN(long updateCount, long rowCount) 
     {
-        // SQL ERRD1 - ERRD2 - row Count
-        writer.writeInt((int)((rowCount>>>32))); 
+        // SQL ERRD1 = Sqlca.HIGH_ORDER_ROW_COUNT
+        writer.writeInt((int)((rowCount>>>32)));
+        // SQL ERRD2 = Sqlca.LOW_ORDER_ROW_COUNT
         writer.writeInt((int)(rowCount & 0x0000000ffffffffL));
-        // SQL ERRD3 - updateCount
-        writer.writeInt(updateCount);
-        // SQL ERRD4 - D6 (12 bytes)
-        writer.writeBytes(errD4_D6); // byte[] constant
+        // SQL ERRD3 = Sqlca.LOW_ORDER_UPDATE_COUNT
+        writer.writeInt( (int)(updateCount & 0x0000000ffffffffL) );
+        // SQL ERRD4 = Sqlca.HIGH_ORDER_UPDATE_COUNT
+        writer.writeInt( (int)(updateCount>>>32) );
+        // SQL ERRD5 - D6 (8 bytes)
+        writer.writeBytes(errD5_D6); // byte[] constant
         // WARN0-WARNA (11 bytes)
         writer.writeBytes(warn0_warnA); // byte[] constant
     }
@@ -9093,7 +9097,7 @@ class DRDAConnThread extends Thread {
      * @exception DRDAProtocolException
      */
     private void checkWarning(Connection conn, Statement stmt, ResultSet rs,
-                          int updateCount, boolean alwaysSend, boolean sendWarn)
+                          long updateCount, boolean alwaysSend, boolean sendWarn)
         throws DRDAProtocolException, SQLException
     {
         // instead of writing a chain of sql warning, we send the first one, this is

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java Tue Jan 29 13:14:39 2013
@@ -35,6 +35,7 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Hashtable;
+import org.apache.derby.iapi.jdbc.EngineStatement;
 import org.apache.derby.iapi.jdbc.EnginePreparedStatement;
 import org.apache.derby.iapi.jdbc.EngineResultSet;
 import org.apache.derby.iapi.reference.JDBC30Translation;
@@ -75,7 +76,7 @@ class DRDAStatement
     protected long rowCount;            // Number of rows we have processed
     protected byte [] rslsetflg;        // Result Set Flags
     protected int maxrslcnt;            // Maximum Result set count
-    protected PreparedStatement ps;     // Prepared statement
+    protected EnginePreparedStatement ps;     // Prepared statement
     protected ParameterMetaData stmtPmeta; // param metadata
     protected boolean isCall;
     protected String procName;          // callable statement's method name
@@ -86,7 +87,7 @@ class DRDAStatement
         
     protected static int NOT_OUTPUT_PARAM = -100000;
     protected boolean outputExpected;   // expect output from a callable statement
-    private Statement stmt;             // SQL statement
+    private EngineStatement stmt;             // SQL statement
 
 
     private DRDAResultSet currentDrdaRs;  // Current ResultSet
@@ -339,7 +340,7 @@ class DRDAStatement
     protected void setStatement(Connection conn)
         throws SQLException
     {
-        stmt = conn.createStatement();
+        stmt = (EngineStatement) conn.createStatement();
         //beetle 3849 -  see  prepareStatement for details
         if (cursorName != null)
             stmt.setCursorName(cursorName);
@@ -350,7 +351,7 @@ class DRDAStatement
      * @return statement
      * @exception SQLException
      */
-    protected Statement getStatement() 
+    protected EngineStatement getStatement() 
         throws SQLException
     {
         return stmt;
@@ -659,13 +660,13 @@ class DRDAStatement
         if (isCallableSQL(sqlStmt))
         {
             isCall = true;
-            ps = database.getConnection().prepareCall(
+            ps = (EnginePreparedStatement) database.getConnection().prepareCall(
                 sqlStmt, scrollType, concurType, withHoldCursor);
             setupCallableStatementParams((CallableStatement)ps);
         }
         else
         {
-            ps = database.getConnection().prepareStatement(
+            ps = (EnginePreparedStatement) database.getConnection().prepareStatement(
                 sqlStmt, scrollType, concurType, withHoldCursor);
         }
 
@@ -688,7 +689,7 @@ class DRDAStatement
      *
      * @return prepared statement
      */
-    protected PreparedStatement getPreparedStatement() throws SQLException
+    protected EnginePreparedStatement getPreparedStatement() throws SQLException
     {
         return ps;
     }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java Tue Jan 29 13:14:39 2013
@@ -640,5 +640,9 @@ public class BrokeredStatement implement
     {
         return ((EngineStatement) getStatement()).executeLargeUpdate( sql, columnNames );
     }
+    public  long getLargeUpdateCount() throws SQLException
+    {
+        return ((EngineStatement) getStatement()).getLargeUpdateCount();
+    }
 
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java Tue Jan 29 13:14:39 2013
@@ -32,7 +32,7 @@ import java.sql.PreparedStatement;
  * PreparedStatement and Brokered PreparedStatements.
  * (DERBY-1015)
  */
-public interface EnginePreparedStatement extends PreparedStatement {
+public interface EnginePreparedStatement extends PreparedStatement, EngineStatement {
     
     public void setBinaryStream(int parameterIndex, InputStream x)
         throws SQLException; 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java Tue Jan 29 13:14:39 2013
@@ -71,5 +71,6 @@ public interface EngineStatement extends
     public  long executeLargeUpdate( String sql, int autoGeneratedKeys) throws SQLException;
     public  long executeLargeUpdate( String sql, int[] columnIndexes ) throws SQLException;
     public  long executeLargeUpdate( String sql, String[] columnNames ) throws SQLException;
+    public  long getLargeUpdateCount() throws SQLException;
 
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Tue Jan 29 13:14:39 2013
@@ -801,6 +801,19 @@ public class EmbedStatement extends Conn
 	}
 
     /**
+     * JDBC 4.2
+     *
+     *  getLargeUpdateCount returns the current result as an update count;
+     *  if the result is a ResultSet or there are no more results -1
+     *  is returned.  It should only be called once per result. For use with
+     * statements which may touch more than Integer.MAX_VALUE rows.
+     */
+	public final long getLargeUpdateCount()	throws SQLException  {
+		checkStatus();
+		return updateCount;
+	}
+
+    /**
      * getMoreResults moves to a Statement's next result.  It returns true if
      * this result is a ResultSet.  getMoreResults also implicitly
      * closes any current ResultSet obtained with getResultSet.

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/DMLWriteResultSet.java Tue Jan 29 13:14:39 2013
@@ -112,7 +112,7 @@ abstract class DMLWriteResultSet extends
 		needToObjectifyStream = (this.constantAction.getTriggerInfo() != null);
 	}
 
-	public final long	modifiedRowCount() { return rowCount; }
+	public final long	modifiedRowCount() { return rowCount + RowUtil.rowCountBase; }
 
 
 	/**

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowUtil.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/RowUtil.java Tue Jan 29 13:14:39 2013
@@ -36,6 +36,8 @@ import org.apache.derby.iapi.sql.execute
   */
 public class RowUtil
 {
+    /** Row count base added for testing JDBC 4.2 */
+    public  static  long    rowCountBase = 0L;
 
  	/**
 	  Get an empty ExecRow.

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=1439883&r1=1439882&r2=1439883&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 Tue Jan 29 13:14:39 2013
@@ -20,6 +20,9 @@
 
 package org.apache.derbyTesting.functionTests.tests.jdbc4;
 
+import org.apache.derby.vti.VTITemplate;
+import org.apache.derby.impl.sql.execute.RowUtil;
+
 import org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41Statement;
 import org.apache.derbyTesting.functionTests.tests.jdbcapi.SetQueryTimeoutTest;
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
@@ -28,6 +31,8 @@ import org.apache.derbyTesting.junit.Tes
 
 import junit.framework.*;
 
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.sql.*;
 
 /**
@@ -348,6 +353,88 @@ public class StatementTest
     }
 
     /**
+     * Test the large update methods added by JDBC 4.2.
+     */
+    public void testLargeUpdate_jdbc4_2() throws Exception
+    {
+        Connection  conn = getConnection();
+
+        largeUpdate_jdbc4_2( conn );
+    }
+
+    public  static  void    largeUpdate_jdbc4_2( Connection conn )
+        throws Exception
+    {
+        conn.prepareStatement
+            (
+             "create procedure setRowCountBase( newBase bigint )\n" +
+             "language java parameter style java no sql\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.jdbc4.StatementTest.setRowCountBase'\n"
+             ).execute();
+        conn.prepareStatement
+            (
+             "create table bigintTable( col1 int generated always as identity, col2 bigint )"
+             ).execute();
+
+        StatementWrapper  sw = new StatementWrapper( conn.createStatement() );
+
+        largeUpdateTest( sw, (long) Integer.MAX_VALUE );
+        largeUpdateTest( sw, 0L);
+    }
+    private static  void    largeUpdateTest( StatementWrapper sw, long rowCountBase )
+        throws Exception
+    {
+        // poke the rowCountBase into the engine. all returned row counts will be
+        // increased by this amount
+        sw.getWrappedStatement().execute( "call setRowCountBase( " + rowCountBase + " )" );
+
+        largeUpdateTest( sw, rowCountBase, 1L );
+        largeUpdateTest( sw, rowCountBase, 3L );
+    }
+    private static  void    largeUpdateTest( StatementWrapper sw, long rowCountBase, long rowCount )
+        throws Exception
+    {
+        StringBuffer    buffer = new StringBuffer();
+        buffer.append( "insert into bigintTable( col2 ) values " );
+        for ( long i = 0L; i < rowCount; i++ )
+        {
+            if ( i > 0L ) { buffer.append( ", " ); }
+            buffer.append( "( " + i + " )" );
+        }
+        String  text = buffer.toString();
+
+        long    expectedResult = rowCountBase + rowCount;
+
+        vetUpdateSize( sw, (int) expectedResult,
+                       sw.getWrappedStatement().executeUpdate( text ), expectedResult );
+        vetUpdateSize( sw, (int) expectedResult,
+                       sw.getWrappedStatement().executeUpdate( text, Statement.RETURN_GENERATED_KEYS ), expectedResult );
+        vetUpdateSize( sw, (int) expectedResult,
+                       sw.getWrappedStatement().executeUpdate( text, new int[] { 1 } ), expectedResult );
+        vetUpdateSize( sw, (int) expectedResult,
+                       sw.getWrappedStatement().executeUpdate( text, new String[] { "COL1" } ), expectedResult );
+
+        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text ), expectedResult );
+        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, Statement.RETURN_GENERATED_KEYS ), expectedResult );
+        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, new int[] { 1 } ), expectedResult );
+        vetUpdateSize( sw, expectedResult, sw.executeLargeUpdate( text, new String[] { "COL1" } ), expectedResult );
+    }
+    private static  void    vetUpdateSize( StatementWrapper sw, int expected, int actual, long longAnswer )
+        throws Exception
+    {
+        assertEquals( expected, actual );
+        assertEquals( expected, sw.getWrappedStatement().getUpdateCount() );
+        assertEquals( longAnswer, sw.getLargeUpdateCount() );
+    }
+    private static  void    vetUpdateSize( StatementWrapper sw, long expected, long actual, long longAnswer )
+        throws Exception
+    {
+        assertEquals( expected, actual );
+        assertEquals( (int) expected, sw.getWrappedStatement().getUpdateCount() );
+        assertEquals( longAnswer, sw.getLargeUpdateCount() );
+    }
+    
+    /**
      * Create test suite for StatementTest.
      */
     public static Test suite() {
@@ -359,5 +446,106 @@ public class StatementTest
             new StatementTestSetup(new TestSuite(StatementTest.class))));
         return suite;
     }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED JDBC 4.2 WRAPPER AROUND A Statement
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <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  final   class   StatementWrapper
+    {
+        private Statement   _wrappedStatement;
+
+        public  StatementWrapper( Statement wrappedStatement )
+        {
+            _wrappedStatement = wrappedStatement;
+        }
+
+        public  Statement   getWrappedStatement() { return _wrappedStatement; }
+
+        // New methods added by JDBC 4.2
+        public  long executeLargeUpdate( String sql ) throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "executeLargeUpdate",
+                 new Class[] { String.class },
+                 new Object[] { sql }
+                 )).longValue();
+        }
+        public  long executeLargeUpdate( String sql, int autoGeneratedKeys) throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "executeLargeUpdate",
+                 new Class[] { String.class, Integer.TYPE },
+                 new Object[] { sql, new Integer( autoGeneratedKeys ) }
+                 )).longValue();
+        }
+        public  long executeLargeUpdate( String sql, int[] columnIndexes ) throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "executeLargeUpdate",
+                 new Class[] { String.class, columnIndexes.getClass() },
+                 new Object[] { sql, columnIndexes }
+                 )).longValue();
+        }
+        public  long executeLargeUpdate( String sql, String[] columnNames ) throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "executeLargeUpdate",
+                 new Class[] { String.class, columnNames.getClass() },
+                 new Object[] { sql, columnNames }
+                 )).longValue();
+        }
+        public  long getLargeUpdateCount() throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "getLargeUpdateCount",
+                 new Class[] {},
+                 new Object[] {}
+                 )).longValue();
+        }
+
+
+        // Reflection minion
+        private Object  invoke( String methodName, Class[] argTypes, Object[] argValues )
+            throws SQLException
+        {
+            try {
+                Method  method = _wrappedStatement.getClass().getMethod( methodName, argTypes );
+
+                return method.invoke( _wrappedStatement, argValues );
+            }
+            catch (NoSuchMethodException nsme) { throw wrap( nsme ); }
+            catch (SecurityException se) { throw wrap( se ); }
+            catch (IllegalAccessException iae) { throw wrap( iae ); }
+            catch (IllegalArgumentException iare) { throw wrap( iare ); }
+            catch (InvocationTargetException ite) { throw wrap( ite ); }
+        }
+        private SQLException    wrap( Throwable t ) { return new SQLException( t.getMessage(), t ); }
+    }
     
+    ////////////////////////////////////////////////////////////////////////
+    //
+    // PROCEDURE FOR BUMPING THE RETURNED ROW COUNT, FOR TESTING JDBC 4.2.
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /** Set the base which is used for returned row counts */
+    public  static  void    setRowCountBase( long newBase )
+    {
+        RowUtil.rowCountBase = newBase;
+    }
+
 } // End class StatementTest

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/XA40Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/XA40Test.java?rev=1439883&r1=1439882&r2=1439883&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/XA40Test.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/XA40Test.java Tue Jan 29 13:14:39 2013
@@ -1,6 +1,6 @@
 /*
  *
- * Derby - Class XA40Test
+ * Derby - Class org.apache.derbyTesting.functionTests.tests.jdbc4.XA40Test
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -177,6 +177,15 @@ public class XA40Test extends BaseJDBCTe
         assertTrue("CallableStatement must be poolable", cs.isPoolable());
     }
 
+    /**
+     * <p>
+     * Test the JDBC 4.2 statement additions to brokered and logical statements.
+     * </p>
+     */
+    public void testLargeUpdate_jdbc4_2() throws Exception
+    {
+        StatementTest.largeUpdate_jdbc4_2( con );
+    }
 
     /**
      * Create test suite for XA40Test.



Mime
View raw message