You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2007/05/09 20:19:11 UTC
svn commit: r536613 -
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Author: kahatlen
Date: Wed May 9 11:19:11 2007
New Revision: 536613
URL: http://svn.apache.org/viewvc?view=rev&rev=536613
Log:
DERBY-2597: Language result sets should not reuse current isolation
level across executions
Added test case which tests changing of isolation level between
executions of UpdateResultSets.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java?view=diff&rev=536613&r1=536612&r2=536613
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/ResultSetsFromPreparedStatementTest.java Wed May 9 11:19:11 2007
@@ -407,6 +407,24 @@
dumpee.close();
}
+ /**
+ * Check whether a table is locked exclusively.
+ *
+ * @param table name of the table
+ * @return whether the table is locked exclusively
+ */
+ private boolean hasTableXLock(String table) throws SQLException {
+ PreparedStatement ps = prepareStatement(
+ "select count(*) from syscs_diag.lock_table where tablename=? " +
+ "and type='TABLE' and mode='X'");
+ ps.setString(1, table);
+ ResultSet rs = ps.executeQuery();
+ assertTrue(rs.next());
+ int count = rs.getInt(1);
+ rs.close();
+ ps.close();
+ return count != 0;
+ }
// ---------------------------------------------------------------
// Framework methods
@@ -1572,6 +1590,30 @@
}
tst.close();
sel.close();
+ }
+
+ /**
+ * Test that an UpdateResultSet is able to detect changes in isolation
+ * level between executions.
+ */
+ public void testUpdateResultSetWithIsolation() throws SQLException {
+ createTestTable("dept", DS, "dept_data");
+ commit();
+ PreparedStatement ps = prepareStatement("update dept set c0 = c0");
+ getConnection().setTransactionIsolation(
+ Connection.TRANSACTION_SERIALIZABLE);
+ assertEquals(3, ps.executeUpdate());
+ // when serializable, UpdateResultSet uses table-level locking
+ assertTrue(hasTableXLock("DEPT"));
+ commit();
+ // all locks released on commit
+ assertFalse(hasTableXLock("DEPT"));
+ getConnection().setTransactionIsolation(
+ Connection.TRANSACTION_READ_COMMITTED);
+ assertEquals(3, ps.executeUpdate());
+ // when read committed, UpdateResultSet uses row-level locking
+ assertFalse(hasTableXLock("DEPT"));
+ ps.close();
}
/**