Search in sources :

Example 16 with TransactionParameterBuffer

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

the class FBConnection method setTransactionParameters.

@Deprecated
public void setTransactionParameters(int isolationLevel, int[] parameters) throws SQLException {
    synchronized (getSynchronizationObject()) {
        checkValidity();
        TransactionParameterBuffer tpbParams = createTransactionParameterBuffer();
        for (int parameter : parameters) {
            tpbParams.addArgument(parameter);
        }
        setTransactionParameters(isolationLevel, tpbParams);
    }
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer)

Example 17 with TransactionParameterBuffer

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

the class FBConnectionProperties method getMapper.

public FBTpbMapper getMapper() throws FBResourceException {
    if (mapper != null) {
        return mapper;
    }
    if (tpbMapping == null) {
        mapper = FBTpbMapper.getDefaultMapper();
    } else {
        mapper = new FBTpbMapper(tpbMapping, getClass().getClassLoader());
    }
    mapper.setDefaultTransactionIsolation(defaultTransactionIsolation);
    for (Map.Entry<Integer, TransactionParameterBuffer> entry : customMapping.entrySet()) {
        Integer isolation = entry.getKey();
        TransactionParameterBuffer tpb = entry.getValue();
        mapper.setMapping(isolation, tpb);
    }
    return mapper;
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with TransactionParameterBuffer

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

the class FBTpbMapper method processMapping.

/**
 * Process comma-separated list of keywords and convert them into TPB
 * values.
 *
 * @param mapping
 *         comma-separated list of keywords.
 * @return set containing values corresponding to the specified keywords.
 * @throws FBResourceException
 *         if mapping contains keyword that is not
 *         a TPB parameter.
 */
public static TransactionParameterBuffer processMapping(String mapping) throws FBResourceException {
    // TODO instance creation should be delegated to FbDatabase
    TransactionParameterBuffer result = new TransactionParameterBufferImpl();
    StringTokenizer st = new StringTokenizer(mapping, ",");
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        Integer argValue = null;
        if (token.contains("=")) {
            String[] parts = token.split("=");
            try {
                argValue = Integer.valueOf(parts[1]);
            } catch (NumberFormatException ex) {
                throw new FBResourceException(parts[1] + " is not valid integer value");
            }
            token = parts[0];
        }
        Integer value = ParameterBufferHelper.getTpbParam(token);
        if (value == null) {
            throw new FBResourceException("Keyword " + token + " unknown. Please check your mapping.");
        }
        if (argValue == null) {
            result.addArgument(value);
        } else {
            result.addArgument(value, argValue);
        }
    }
    return result;
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) TransactionParameterBufferImpl(org.firebirdsql.gds.impl.TransactionParameterBufferImpl) FBResourceException(org.firebirdsql.jca.FBResourceException)

Example 19 with TransactionParameterBuffer

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

the class TestJnaDatabase 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 20 with TransactionParameterBuffer

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

the class TestFBDriver method testTransactionConfigThroughConnectionString.

@Test
public void testTransactionConfigThroughConnectionString() throws Exception {
    Properties props = getDefaultPropertiesForConnection();
    // Note that for proper testing this needs to be different from the mapping in isc_tpb_mapping.properties
    String jdbcUrl = getUrl() + "?TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_no_rec_version,isc_tpb_write,isc_tpb_nowait";
    connection = DriverManager.getConnection(jdbcUrl, props);
    FirebirdConnection fbConnection = connection.unwrap(FirebirdConnection.class);
    TransactionParameterBuffer tpb = fbConnection.getTransactionParameters(Connection.TRANSACTION_READ_COMMITTED);
    assertEquals(4, tpb.size());
    assertTrue("expected isc_tpb_read_committed", tpb.hasArgument(ISCConstants.isc_tpb_read_committed));
    assertTrue("expected isc_tpb_no_rec_version", tpb.hasArgument(ISCConstants.isc_tpb_no_rec_version));
    assertTrue("expected isc_tpb_write", tpb.hasArgument(ISCConstants.isc_tpb_write));
    assertTrue("expected isc_tpb_nowait", tpb.hasArgument(ISCConstants.isc_tpb_nowait));
}
Also used : TransactionParameterBuffer(org.firebirdsql.gds.TransactionParameterBuffer) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) Test(org.junit.Test)

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