db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1051890 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/PreparedStatement.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
Date Wed, 22 Dec 2010 13:34:15 GMT
Author: rhillegas
Date: Wed Dec 22 13:34:15 2010
New Revision: 1051890

URL: http://svn.apache.org/viewvc?rev=1051890&view=rev
Log:
DERBY-4869: JDBC 4.1 spec clarification that addBatch(String) should fail on prepared and
callable statements.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java

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=1051890&r1=1051889&r2=1051890&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 Wed
Dec 22 13:34:15 2010
@@ -329,6 +329,15 @@ public class PreparedStatement extends S
 
     //------------------- Prohibited overrides from Statement --------------------
 
+    public void addBatch(String sql) throws SQLException {
+        if (agent_.loggingEnabled()) {
+            agent_.logWriter_.traceEntry(this, "addBatch", sql);
+        }
+        throw new SqlException(agent_.logWriter_,
+            new ClientMessageId(SQLState.NOT_FOR_PREPARED_STATEMENT),
+            "addBatch(String)").getSQLException();
+    }
+
     public boolean execute(String sql) throws SQLException {
         if (agent_.loggingEnabled()) {
             agent_.logWriter_.traceEntry(this, "execute", sql);

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java?rev=1051890&r1=1051889&r2=1051890&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
Wed Dec 22 13:34:15 2010
@@ -21,7 +21,9 @@ limitations under the License.
 
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 
+import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.sql.SQLException;
@@ -40,6 +42,8 @@ import junit.framework.TestSuite;
  * to JUnit.
  */
 public class StatementJdbc20Test extends BaseJDBCTestCase {
+
+    private static  final   String  METHOD_NOT_ALLOWED = "XJ016";
     
     /**
      * Create a test with the given name.
@@ -256,4 +260,35 @@ public class StatementJdbc20Test extends
         stmt.close();
         commit();
     }
+
+    /**
+     * Test the following clarification made by JDBC 4.1: You should
+     * raise an exception when addBatch(String) is called on a PreparedStatement
+     * or a CallableStatement.
+     */
+    public void testAddBatchClarification_jdbc4_1() throws SQLException
+    {
+        PreparedStatement ps = prepareStatement( "select * from sys.systables" );
+        CallableStatement cs = prepareCall( "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)"
);
+
+        try {
+            ps.addBatch( "select * from sys.systables" );
+            fail( "Oops. ps.addBatch() worked." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+        
+        try {
+            cs.addBatch( "CALL SYSCS_UTIL.SYSCS_SET_RUNTIMESTATISTICS(1)" );
+            fail( "Oops. cs.addBatch() worked." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( METHOD_NOT_ALLOWED, se );
+        }
+    }
+
+
 }



Mime
View raw message