Search in sources :

Example 11 with TransactionParameterBuffer

use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.

the class TestFBTpbMapper method testNewWithMappingFile.

@Test
public void testNewWithMappingFile() throws Exception {
    FBTpbMapper mapper = new FBTpbMapper(TEST_TPB_MAPPING, getClass().getClassLoader());
    TransactionParameterBuffer tpbValue = mapper.getMapping(Connection.TRANSACTION_READ_COMMITTED);
    assertTrue("READ_COMMITTED must be isc_tpb_read_committed+isc_tpb_no_rec_version+isc_tpb_write+isc_tpb_nowait", tpbValue.size() == 4 && tpbValue.hasArgument(ISCConstants.isc_tpb_read_committed) && tpbValue.hasArgument(ISCConstants.isc_tpb_no_rec_version) && tpbValue.hasArgument(ISCConstants.isc_tpb_write) && tpbValue.hasArgument(ISCConstants.isc_tpb_nowait));
    tpbValue = mapper.getMapping(Connection.TRANSACTION_REPEATABLE_READ);
    assertTrue("REPEATABLE_READ must be isc_tpb_consistency+isc_tpb_write+isc_tpb_wait", tpbValue.size() == 3 && tpbValue.hasArgument(ISCConstants.isc_tpb_consistency) && tpbValue.hasArgument(ISCConstants.isc_tpb_write) && tpbValue.hasArgument(ISCConstants.isc_tpb_wait));
    tpbValue = mapper.getMapping(Connection.TRANSACTION_SERIALIZABLE);
    assertTrue("SERIALIZABLE must be isc_tpb_concurrency+isc_tpb_write+isc_tpb_wait", tpbValue.size() == 3 && tpbValue.hasArgument(ISCConstants.isc_tpb_concurrency) && tpbValue.hasArgument(ISCConstants.isc_tpb_write) && tpbValue.hasArgument(ISCConstants.isc_tpb_wait));
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) Test(org.junit.Test)

Example 12 with TransactionParameterBuffer

use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.

the class TestFBTpbMapper method testNewWithIncompleteMap_unspecifiedUseDefaults.

@Test
public void testNewWithIncompleteMap_unspecifiedUseDefaults() throws Exception {
    final FBTpbMapper defaultMapper = FBTpbMapper.getDefaultMapper();
    final Map<String, String> map = new HashMap<>();
    map.put(FBTpbMapper.TRANSACTION_REPEATABLE_READ, "isc_tpb_concurrency,isc_tpb_write,isc_tpb_wait,isc_tpb_lock_timeout=5");
    FBTpbMapper mapper = new FBTpbMapper(map);
    // Check if matches specified
    TransactionParameterBuffer tpbValue = mapper.getMapping(Connection.TRANSACTION_REPEATABLE_READ);
    assertTrue("REPEATABLE_READ must be isc_tpb_concurrency+isc_tpb_write+isc_tpb_wait+isc_tpb_lock_timeout=5", tpbValue.size() == 4 && tpbValue.hasArgument(ISCConstants.isc_tpb_concurrency) && tpbValue.hasArgument(ISCConstants.isc_tpb_write) && tpbValue.hasArgument(ISCConstants.isc_tpb_wait) && tpbValue.hasArgument(ISCConstants.isc_tpb_lock_timeout) && tpbValue.getArgumentAsInt(ISCConstants.isc_tpb_lock_timeout) == 5);
    // Check other isolation levels match default:
    assertEquals(defaultMapper.getMapping(Connection.TRANSACTION_SERIALIZABLE), mapper.getMapping(Connection.TRANSACTION_SERIALIZABLE));
    assertEquals(defaultMapper.getMapping(Connection.TRANSACTION_SERIALIZABLE), mapper.getMapping(Connection.TRANSACTION_SERIALIZABLE));
}
Also used : HashMap(java.util.HashMap) TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) Test(org.junit.Test)

Example 13 with TransactionParameterBuffer

use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.

the class TestV10EventHandling 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 14 with TransactionParameterBuffer

use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.

the class TestJnaEvents 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 15 with TransactionParameterBuffer

use of org.firebirdsql.gds.TransactionParameterBuffer in project jaybird by FirebirdSQL.

the class FBTpbMapper method processMapping.

/**
 * Process specified string mapping. This method updates default mapping
 * with values specified in a <code>stringMapping</code>.
 *
 * @param stringMapping
 *         mapping to process.
 * @throws FBResourceException
 *         if mapping contains incorrect values.
 */
private void processMapping(Map<String, String> stringMapping) throws FBResourceException {
    for (Map.Entry<String, String> entry : stringMapping.entrySet()) {
        String jdbcTxIsolation = entry.getKey();
        Integer isolationLevel;
        try {
            isolationLevel = getTransactionIsolationLevel(jdbcTxIsolation);
        } catch (IllegalArgumentException ex) {
            throw new FBResourceException("Transaction isolation " + jdbcTxIsolation + " is not supported.");
        }
        TransactionParameterBuffer tpb = processMapping(entry.getValue());
        mapping.put(isolationLevel, tpb);
    }
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) FBResourceException(org.firebirdsql.jca.FBResourceException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

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