Subject Re: TPB Settings required? [was Re: [Firebird-Java] Setting Isolation Level with Hibernate]
Author Roman Rokytskyy
> I DO need full table lock, and have changed to use the Firebird connection
> 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?

Please check the test cases - they have a lot of usage patterns. For example

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