Subject | Re: TPB Settings required? [was Re: [Firebird-Java] Setting Isolation Level with Hibernate] |
---|---|
Author | Roman Rokytskyy |
Post date | 2006-01-17T23:03:08Z |
> I DO need full table lock, and have changed to use the Firebird connectionPlease check the test cases - they have a lot of usage patterns. For example
> pool.
>
> I've also looked at the TPB settings required, but am confused as they
> don't seem to match up with SNAPSHOT TABLE STABILITY as per Firebird book.
>
> Could you enlighten me as which attributes I need to set to accomplish
> full table lock, with no read access from another tx?
public void testLockTable() throws Exception {
FirebirdConnection connection =
(FirebirdConnection)getConnectionViaDriverManager();
try {
Statement stmt = connection.createStatement();
try {
stmt.execute("CREATE TABLE test_lock(col1 INTEGER)");
} catch(SQLException ex) {
// ignore
}
} finally {
connection.close();
}
connection = (FirebirdConnection)getConnectionViaDriverManager();
try {
Statement stmt = connection.createStatement();
try {
TransactionParameterBuffer tpb =
connection.getTransactionParameters(Connection.TRANSACTION_READ_COMMITTED);
tpb.removeArgument(TransactionParameterBuffer.WAIT);
tpb.addArgument(TransactionParameterBuffer.NOWAIT);
connection.setTransactionParameters(Connection.TRANSACTION_READ_COMMITTED,
tpb);
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
connection.setAutoCommit(false);
FirebirdConnection anotherConnection =
(FirebirdConnection)getConnectionViaDriverManager();
anotherConnection.setAutoCommit(false);
try {
TransactionParameterBuffer anotherTpb =
anotherConnection.createTransactionParameterBuffer();
anotherTpb.addArgument(TransactionParameterBuffer.CONSISTENCY);
anotherTpb.addArgument(TransactionParameterBuffer.WRITE);
anotherTpb.addArgument(TransactionParameterBuffer.NOWAIT);
anotherTpb.addArgument(TransactionParameterBuffer.PROTECTED);
anotherTpb.addArgument(TransactionParameterBuffer.LOCK_WRITE,
"TEST_LOCK");
anotherConnection.setTransactionParameters(anotherTpb);
Statement anotherStmt =
anotherConnection.createStatement();
try {
anotherStmt.execute("INSERT INTO test_lock
VALUES(1)");
} finally {
anotherStmt.close();
}
try {
stmt.execute("INSERT INTO test_lock VALUES(2)");
fail("Should throw an error because of lock
conflict.");
} catch(SQLException ex) {
assertEquals(ISCConstants.isc_lock_conflict,
ex.getErrorCode());
}
} finally {
anotherConnection.close();
}
} finally {
stmt.close();
}
} finally {
connection.close();
}
}
Roman