db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1441088 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbc4/
Date Thu, 31 Jan 2013 17:49:45 GMT
Author: rhillegas
Date: Thu Jan 31 17:49:44 2013
New Revision: 1441088

URL: http://svn.apache.org/viewvc?rev=1441088&view=rev
Log:
DERBY-6000: Add JDBC 4.2 java.sql.PreparedStatement.executeLargeUpdate() to embedded and client
drivers.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EnginePreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/StatementTest.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java?rev=1441088&r1=1441087&r2=1441088&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalPreparedStatement.java
Thu Jan 31 17:49:44 2013
@@ -384,4 +384,16 @@ public class LogicalPreparedStatement
     public ResultSet executeQuery(String sql) throws SQLException {
         return getPhysPs().executeQuery(sql);
     }
+
+    ////////////////////////////////////////////////////////////////
+    //
+    //  ADDED BY JDBC 4.2
+    //
+    ////////////////////////////////////////////////////////////////
+
+    public  long    executeLargeUpdate() throws SQLException
+    {
+        return ((PreparedStatement) getPhysPs()).executeLargeUpdate();
+    }
+
 }

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=1441088&r1=1441087&r2=1441088&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 Thu
Jan 31 17:49:44 2013
@@ -2774,6 +2774,30 @@ public class PreparedStatement extends S
 
     // End of JDBC 4.0 methods
 
+    // Beginning of JDBC 4.2 methods
+
+    public long executeLargeUpdate() throws SQLException {
+        try
+        {
+            synchronized (connection_) {
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceEntry(this, "executeLargeUpdate");
+                }
+                long updateValue = executeUpdateX();
+                if (agent_.loggingEnabled()) {
+                    agent_.logWriter_.traceExit(this, "executeLargeUpdate", updateValue);
+                }
+                return updateValue;
+            }
+        }
+        catch ( SqlException se ) {
+            checkStatementValidity(se);
+            throw se.getSQLException();
+        }
+    }
+
+    // End of JDBC 4.2 methods
+
         /*
          * Method calls onStatementError occurred on the 
          * BrokeredConnectionControl class after checking the 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java?rev=1441088&r1=1441087&r2=1441088&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredPreparedStatement.java
Thu Jan 31 17:49:44 2013
@@ -500,6 +500,15 @@ public class BrokeredPreparedStatement e
         getPreparedStatement().setTimestamp( i, x, cal);
     }
     
+    // JDBC 4.1 methods exposed via the EnginePreparedStatement interface
+
+    public long executeLargeUpdate() throws SQLException
+    {
+        final EnginePreparedStatement engnps = (EnginePreparedStatement) getPreparedStatement();
 
+
+        return engnps.executeLargeUpdate();
+    }    
+    
     // JDBC 4.0 methods exposed via the EnginePreparedStatement interface
     
     public void setBinaryStream(int parameterIndex, 

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=1441088&r1=1441087&r2=1441088&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
Thu Jan 31 17:49:44 2013
@@ -47,4 +47,13 @@ public interface EnginePreparedStatement
      * @return version counter
      */
     public long getVersionCounter() throws SQLException;
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.2 IN JAVA 8
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public long executeLargeUpdate() throws SQLException;
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=1441088&r1=1441087&r2=1441088&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
Thu Jan 31 17:49:44 2013
@@ -307,12 +307,22 @@ public class EmbedPreparedStatement
 	 * @exception SQLException thrown on failure.
      */
         public final int executeUpdate() throws SQLException {
+            return (int) executeLargeUpdate();
+        }
+
+    /**
+     * Execute a SQL INSERT, UPDATE or DELETE statement. In addition,
+     * SQL statements that return nothing such as SQL DDL statements
+     * can be executed. For use with
+     * statements which may touch more than Integer.MAX_VALUE rows.
+     */
+        public final long executeLargeUpdate() throws SQLException {
             try {
                 executeStatement(activation, false, true);
             } catch(SQLException sqle) {
                 checkStatementValidity(sqle);
             }
-            return (int) updateCount;
+            return updateCount;
         }
 
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java?rev=1441088&r1=1441087&r2=1441088&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/PreparedStatementTest.java
Thu Jan 31 17:49:44 2013
@@ -1183,6 +1183,49 @@ public class PreparedStatementTest exten
         }
     }
 
+    /**
+     * 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
+    {
+        println( "Running large update test for JDBC 4.2" );
+        
+        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();
+
+        Statement   stmt = conn.createStatement();
+        PreparedStatementWrapper  psw = new PreparedStatementWrapper
+            ( conn.prepareStatement( "insert into bigintTable( col2 ) values ( 1 ), ( 2 ),
( 3 ), ( 4 ), ( 5 )" ) );
+
+        largeUpdateTest( stmt, psw, ((long) Integer.MAX_VALUE) + 1L );
+        
+        StatementTest.setRowCountBase( stmt, false, 0L );
+    }
+    private static  void    largeUpdateTest
+        ( Statement stmt, PreparedStatementWrapper psw, long rowCountBase )
+        throws Exception
+    {
+        StatementTest.setRowCountBase( stmt, false, rowCountBase );
+
+        assertEquals( rowCountBase + 5L, psw.executeLargeUpdate() );
+    }
+
     /************************************************************************
      *                 A U X I L I A R Y  M E T H O D S                     *
      ************************************************************************/
@@ -1289,4 +1332,39 @@ public class PreparedStatementTest exten
         assertEquals("Incorrect internal SQL state", expectedInternal,
                      dioe.getSQLState());
     }
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    // NESTED JDBC 4.2 WRAPPER AROUND A PreparedStatement
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <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   PreparedStatementWrapper    extends StatementTest.StatementWrapper
+    {
+        private PreparedStatement   _wrappedPreparedStatement;
+
+        public  PreparedStatementWrapper( PreparedStatement wrappedPreparedStatement )
+        {
+            super( wrappedPreparedStatement );
+        }
+
+        PreparedStatement   getWrappedPreparedStatement() { return (PreparedStatement) getWrappedStatement();
}
+
+        public  long executeLargeUpdate() throws SQLException
+        {
+            return ((Long) invoke
+                (
+                 "executeLargeUpdate",
+                 new Class[] {},
+                 new Object[] {}
+                 )).longValue();
+        }
+    }
+    
 }

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=1441088&r1=1441087&r2=1441088&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
Thu Jan 31 17:49:44 2013
@@ -392,7 +392,7 @@ public class StatementTest
     {
         // poke the rowCountBase into the engine. all returned row counts will be
         // increased by this amount
-        setRowCountBase( sw, false, rowCountBase );
+        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );
 
         largeUpdateTest( sw, rowCountBase, 1L );
         largeUpdateTest( sw, rowCountBase, 3L );
@@ -447,7 +447,7 @@ public class StatementTest
         // poke the rowCountBase into the engine. all returned row counts will be
         // increased by this amount
         sw.getWrappedStatement().clearBatch();
-        setRowCountBase( sw, false, rowCountBase );
+        setRowCountBase( sw.getWrappedStatement(), false, rowCountBase );
 
         long[]  expectedResult = new long[] { rowCountBase + 1L, rowCountBase + 1L, rowCountBase
+ 2L };
 
@@ -476,7 +476,7 @@ public class StatementTest
         truncate( sw );
         sw.getWrappedStatement().execute( "insert into bigintTable( col2 ) values ( 1 ),
( 2 ), ( 3 ), ( 4 ), ( 5 )" );
         
-        setRowCountBase( sw, usingDerbyNetClient(), maxRows - expectedRowCount );
+        setRowCountBase( sw.getWrappedStatement(), usingDerbyNetClient(), maxRows - expectedRowCount
);
 
         sw.setLargeMaxRows( maxRows );
         
@@ -485,14 +485,14 @@ public class StatementTest
         while( rs.next() ) { rowCount++; }
         rs.close();
 
-        setRowCountBase( sw, usingDerbyNetClient(), 0L );
+        setRowCountBase( sw.getWrappedStatement(), usingDerbyNetClient(), 0L );
         
         assertEquals( expectedRowCount, rowCount );
         assertEquals( maxRows, sw.getLargeMaxRows() );
     }
         
-    private static  void    setRowCountBase
-        ( StatementTest.StatementWrapper sw, boolean onClient, long rowCountBase )
+    public static  void    setRowCountBase
+        ( Statement stmt, boolean onClient, long rowCountBase )
         throws Exception
     {
         if ( onClient )
@@ -501,7 +501,7 @@ public class StatementTest
         }
         else
         {
-            sw.getWrappedStatement().execute( "call setRowCountBase( " + rowCountBase + "
)" );
+            stmt.execute( "call setRowCountBase( " + rowCountBase + " )" );
         }
     }
     private static  void    truncate( StatementTest.StatementWrapper sw )
@@ -543,7 +543,7 @@ public class StatementTest
      * VM rev levels lower than Java 8.
      * </p>
      */
-    public  static  final   class   StatementWrapper
+    public  static  class   StatementWrapper
     {
         private Statement   _wrappedStatement;
 
@@ -630,7 +630,7 @@ public class StatementTest
 
 
         // Reflection minion
-        private Object  invoke( String methodName, Class[] argTypes, Object[] argValues )
+        protected Object  invoke( String methodName, Class[] argTypes, Object[] argValues
)
             throws SQLException
         {
             try {



Mime
View raw message