Search in sources :

Example 21 with TransactionParameterBuffer

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;
    }
}
Also used : FBManagedConnection(org.firebirdsql.jca.FBManagedConnection) TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) Test(org.junit.Test)

Example 22 with TransactionParameterBuffer

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);
        }
    }
}
Also used : FBConnection(org.firebirdsql.jdbc.FBConnection) TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) FbDatabase(org.firebirdsql.gds.ng.FbDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction)

Example 23 with TransactionParameterBuffer

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);
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) Test(org.junit.Test)

Example 24 with TransactionParameterBuffer

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);
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) TransactionParameterBufferImpl(org.firebirdsql.gds.impl.TransactionParameterBufferImpl)

Example 25 with TransactionParameterBuffer

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);
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) TransactionParameterBufferImpl(org.firebirdsql.gds.impl.TransactionParameterBufferImpl)

Aggregations

TransactionParameterBuffer (org.firebirdsql.gds.TransactionParameterBuffer)25 Test (org.junit.Test)12 TransactionParameterBufferImpl (org.firebirdsql.gds.impl.TransactionParameterBufferImpl)8 Properties (java.util.Properties)3 HashMap (java.util.HashMap)2 FBTestProperties (org.firebirdsql.common.FBTestProperties)2 FBResourceException (org.firebirdsql.jca.FBResourceException)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FbDatabase (org.firebirdsql.gds.ng.FbDatabase)1 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)1 FBManagedConnection (org.firebirdsql.jca.FBManagedConnection)1 FBConnection (org.firebirdsql.jdbc.FBConnection)1