use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.
the class FBConnectionTest method testLockTable.
@Test
public void testLockTable() throws Exception {
try (Connection connection = getConnectionViaDriverManager()) {
executeCreateTable(connection, "CREATE TABLE test_lock(col1 INTEGER)");
}
try (FirebirdConnection connection = getConnectionViaDriverManager();
Statement stmt = connection.createStatement()) {
TransactionParameterBuffer tpb = connection.getTransactionParameters(Connection.TRANSACTION_READ_COMMITTED);
if (tpb.hasArgument(TransactionParameterBuffer.WAIT)) {
tpb.removeArgument(TransactionParameterBuffer.WAIT);
tpb.addArgument(TransactionParameterBuffer.NOWAIT);
}
connection.setTransactionParameters(Connection.TRANSACTION_READ_COMMITTED, tpb);
connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
connection.setAutoCommit(false);
try (FirebirdConnection anotherConnection = getConnectionViaDriverManager()) {
anotherConnection.setAutoCommit(false);
TransactionParameterBuffer anotherTpb = anotherConnection.createTransactionParameterBuffer();
anotherTpb.addArgument(TransactionParameterBuffer.CONSISTENCY);
anotherTpb.addArgument(TransactionParameterBuffer.WRITE);
anotherTpb.addArgument(TransactionParameterBuffer.NOWAIT);
anotherTpb.addArgument(TransactionParameterBuffer.LOCK_WRITE, "TEST_LOCK");
anotherTpb.addArgument(TransactionParameterBuffer.PROTECTED);
anotherConnection.setTransactionParameters(anotherTpb);
try (Statement anotherStmt = anotherConnection.createStatement()) {
anotherStmt.execute("INSERT INTO test_lock VALUES(1)");
}
expectedException.expect(errorCodeEquals(ISCConstants.isc_lock_conflict));
expectedException.reportMissingExceptionWithMessage("Should throw an error because of lock conflict.");
stmt.execute("INSERT INTO test_lock VALUES(2)");
}
} catch (SQLException ex) {
ex.printStackTrace();
throw ex;
}
}
use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.
the class TestFBMaintenanceManager method createLimboTransaction.
private void createLimboTransaction(int count) throws Exception {
try (FBConnection conn = (FBConnection) getConnectionViaDriverManager()) {
final FbDatabase fbDatabase = conn.getFbDatabase();
for (int i = 0; i < count; i++) {
TransactionParameterBuffer tpBuf = conn.createTransactionParameterBuffer();
FbTransaction transaction = fbDatabase.startTransaction(tpBuf);
transaction.prepare(null);
}
}
}
use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.
the class TestFBTpbMapper method testSetMapping_READ_UNCOMMITTED_throwsIllegalArgumentException.
@Test
public void testSetMapping_READ_UNCOMMITTED_throwsIllegalArgumentException() throws Exception {
FBTpbMapper mapper = new FBTpbMapper();
TransactionParameterBuffer newTpb = FBTpbMapper.processMapping("isc_tpb_read_committed,isc_tpb_no_rec_version,isc_tpb_write,isc_tpb_wait");
expectedException.expect(IllegalArgumentException.class);
mapper.setMapping(Connection.TRANSACTION_READ_UNCOMMITTED, newTpb);
}
use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.
the class TestV10Database method getTransaction.
private FbTransaction getTransaction(FbDatabase db) throws SQLException {
TransactionParameterBuffer tpb = new TransactionParameterBufferImpl();
tpb.addArgument(ISCConstants.isc_tpb_read_committed);
tpb.addArgument(ISCConstants.isc_tpb_rec_version);
tpb.addArgument(ISCConstants.isc_tpb_write);
tpb.addArgument(ISCConstants.isc_tpb_wait);
return db.startTransaction(tpb);
}
use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.
the class BaseTestBlob method getTransaction.
protected final FbTransaction getTransaction(FbDatabase db) throws SQLException {
TransactionParameterBuffer tpb = new TransactionParameterBufferImpl();
tpb.addArgument(ISCConstants.isc_tpb_read_committed);
tpb.addArgument(ISCConstants.isc_tpb_rec_version);
tpb.addArgument(ISCConstants.isc_tpb_write);
tpb.addArgument(ISCConstants.isc_tpb_wait);
return db.startTransaction(tpb);
}
Aggregations