Search in sources :

Example 1 with TransactionConfig

use of com.sleepycat.je.TransactionConfig in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method putRecord.

private void putRecord(final ReplicatedEnvironmentFacade master, final Database db, final int keyValue, final String dataValue) {
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    TransactionConfig transactionConfig = new TransactionConfig();
    transactionConfig.setDurability(master.getRealMessageStoreDurability());
    Transaction txn = master.beginTransaction(transactionConfig);
    IntegerBinding.intToEntry(keyValue, key);
    StringBinding.stringToEntry(dataValue, data);
    db.put(txn, key, data);
    txn.commit();
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TransactionConfig(com.sleepycat.je.TransactionConfig)

Example 2 with TransactionConfig

use of com.sleepycat.je.TransactionConfig in project GeoGig by boundlessgeo.

the class JEObjectDatabase method newTransaction.

@Nullable
private Transaction newTransaction() {
    final boolean transactional = objectDb.getConfig().getTransactional();
    if (transactional) {
        TransactionConfig txConfig = new TransactionConfig();
        txConfig.setReadUncommitted(true);
        Optional<String> durability = configDB.get(OBJECT_DURABILITY_CONFIG_KEY);
        if (!durability.isPresent()) {
            durability = configDB.getGlobal(OBJECT_DURABILITY_CONFIG_KEY);
        }
        if ("safe".equals(durability.orNull())) {
            txConfig.setDurability(Durability.COMMIT_SYNC);
        } else {
            txConfig.setDurability(Durability.COMMIT_WRITE_NO_SYNC);
        }
        Transaction transaction = env.beginTransaction(null, txConfig);
        return transaction;
    }
    return null;
}
Also used : Transaction(com.sleepycat.je.Transaction) TransactionConfig(com.sleepycat.je.TransactionConfig) Nullable(javax.annotation.Nullable)

Example 3 with TransactionConfig

use of com.sleepycat.je.TransactionConfig in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testBeginTransaction.

@Test
public void testBeginTransaction() throws Exception {
    ReplicatedEnvironmentFacade facade = createMaster();
    Transaction txn = null;
    try {
        TransactionConfig transactionConfig = new TransactionConfig();
        transactionConfig.setDurability(facade.getRealMessageStoreDurability());
        txn = facade.beginTransaction(transactionConfig);
        assertNotNull("Transaction is not created", txn);
        txn.commit();
        txn = null;
    } finally {
        if (txn != null) {
            txn.abort();
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) TransactionConfig(com.sleepycat.je.TransactionConfig) Test(org.junit.Test)

Example 4 with TransactionConfig

use of com.sleepycat.je.TransactionConfig in project janusgraph by JanusGraph.

the class BerkeleyJEStoreManager method beginTransaction.

@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
    try {
        Transaction tx = null;
        Configuration effectiveCfg = new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());
        if (transactional) {
            TransactionConfig txnConfig = new TransactionConfig();
            ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL), IsolationLevel.class).configure(txnConfig);
            tx = environment.beginTransaction(null, txnConfig);
        } else {
            if (txCfg instanceof TransactionConfiguration) {
                if (!((TransactionConfiguration) txCfg).isSingleThreaded()) {
                    // Non-transactional cursors can't shared between threads, more info ThreadLocker.checkState
                    throw new PermanentBackendException("BerkeleyJE does not support non-transactional for multi threaded tx");
                }
            }
        }
        BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE), LockMode.class), ConfigOption.getEnumValue(effectiveCfg.get(CACHE_MODE), CacheMode.class), txCfg);
        if (log.isTraceEnabled()) {
            log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
        }
        return btx;
    } catch (DatabaseException e) {
        throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
    }
}
Also used : TransactionConfiguration(org.janusgraph.graphdb.transaction.TransactionConfiguration) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Transaction(com.sleepycat.je.Transaction) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) TransactionConfiguration(org.janusgraph.graphdb.transaction.TransactionConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) CacheMode(com.sleepycat.je.CacheMode) TransactionConfig(com.sleepycat.je.TransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) LockMode(com.sleepycat.je.LockMode) DatabaseException(com.sleepycat.je.DatabaseException)

Example 5 with TransactionConfig

use of com.sleepycat.je.TransactionConfig in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method putRecord.

private void putRecord(final ReplicatedEnvironmentFacade master, final Database db, final int key, final String value, final boolean commitNosync) {
    final DatabaseEntry keyEntry = new DatabaseEntry();
    IntegerBinding.intToEntry(key, keyEntry);
    final DatabaseEntry dataEntry = new DatabaseEntry();
    StringBinding.stringToEntry(value, dataEntry);
    final TransactionConfig transactionConfig = new TransactionConfig();
    transactionConfig.setDurability(master.getRealMessageStoreDurability());
    final Transaction txn = master.beginTransaction(transactionConfig);
    db.put(txn, keyEntry, dataEntry);
    if (commitNosync) {
        master.commitNoSync(txn);
    } else {
        master.commit(txn);
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseEntry(com.sleepycat.je.DatabaseEntry) TransactionConfig(com.sleepycat.je.TransactionConfig)

Aggregations

Transaction (com.sleepycat.je.Transaction)5 TransactionConfig (com.sleepycat.je.TransactionConfig)5 DatabaseEntry (com.sleepycat.je.DatabaseEntry)2 CacheMode (com.sleepycat.je.CacheMode)1 DatabaseException (com.sleepycat.je.DatabaseException)1 LockMode (com.sleepycat.je.LockMode)1 Nullable (javax.annotation.Nullable)1 ReplicatedEnvironmentFacade (org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade)1 BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1 Configuration (org.janusgraph.diskstorage.configuration.Configuration)1 MergedConfiguration (org.janusgraph.diskstorage.configuration.MergedConfiguration)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)1 TransactionConfiguration (org.janusgraph.graphdb.transaction.TransactionConfiguration)1 Test (org.junit.Test)1