当前位置: 首页>>代码示例>>Java>>正文


Java Environment.beginTransaction方法代码示例

本文整理汇总了Java中com.sleepycat.je.Environment.beginTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.beginTransaction方法的具体用法?Java Environment.beginTransaction怎么用?Java Environment.beginTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sleepycat.je.Environment的用法示例。


在下文中一共展示了Environment.beginTransaction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initEnv

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
private void initEnv()
    throws DatabaseException {

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "4");
    envConfig.setTransactional(true);
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);

    String databaseName = "testDb";
    Transaction txn = env.beginTransaction(null, null);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    db = env.openDatabase(txn, databaseName, dbConfig);
    txn.commit();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:18,代码来源:SplitTest.java

示例2: initEnv

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
private void initEnv()
    throws DatabaseException {

    EnvironmentConfig envConfig = TestUtils.initEnvConfig();
    envConfig.setConfigParam(EnvironmentParams.NODE_MAX.getName(), "4");
    envConfig.setTransactional(true);
    envConfig.setAllowCreate(true);
    env = new Environment(envHome, envConfig);

    String databaseName = "testDb";
    Transaction txn = env.beginTransaction(null, null);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    dbConfig.setSortedDuplicates(true);
    db = env.openDatabase(txn, databaseName, dbConfig);
    txn.commit();
}
 
开发者ID:nologic,项目名称:nabs,代码行数:19,代码来源:GetParentNodeTest.java

示例3: initChangeSet

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
private void initChangeSet(Environment env) {
    Transaction txn = env.beginTransaction(null, null);
    boolean success = false;

    try {
        DatabaseEntry changeSetData = new DatabaseEntry();

        processor.readChangeSetData(txn, dataSetName, changeSetData);

        /* 
         * If there is no ChangeSet information for this SyncDataSet in 
         * SyncDB, create a new one, otherwise deserialize the 
         * DatabaseEntry.
         */
        changeSet = (changeSetData.getData() == null) ?
            new LogChangeSet() : binding.entryToObject(changeSetData);
        success = true;
    } finally {
       if (success) {
          txn.commit();
       } else {
          txn.abort();
       }
    } 
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:26,代码来源:LogChangeReader.java

示例4: delete

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public boolean delete(Transaction txn, PK key)
       throws DatabaseException {

       DatabaseEntry pkeyEntry = new DatabaseEntry();
       DatabaseEntry dataEntry = BasicIndex.NO_RETURN_ENTRY;
       pkeyBinding.objectToEntry(key, pkeyEntry);

       boolean autoCommit = false;
Environment env = db.getEnvironment();
       if (transactional &&
    txn == null &&
    env.getThreadTransaction() == null) {
           txn = env.beginTransaction(null, null);
           autoCommit = true;
       }

       boolean failed = true;
       OperationStatus status;
       SecondaryCursor cursor = db.openSecondaryCursor(txn, null);
       try {
           status = cursor.getSearchBoth
               (keyEntry, pkeyEntry, dataEntry, LockMode.RMW);
           if (status == OperationStatus.SUCCESS) {
               status = cursor.delete();
           }
           failed = false;
       } finally {
           cursor.close();
           if (autoCommit) {
               if (failed) {
                   txn.abort();
               } else {
                   txn.commit();
               }
           }
       }

       return (status == OperationStatus.SUCCESS);
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:40,代码来源:SubIndex.java

示例5: getGroup

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * An internal API used to obtain group information by opening a stand
 * alone environment handle and reading the RepGroupDB. Used for debugging
 * and utilities.
 *
 * @param envDir the directory containing the environment log files
 *
 * @return the group as currently defined by the environment
 */
public static RepGroupImpl getGroup(final File envDir) {

    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setReadOnly(true);
    envConfig.setTransactional(true);
    envConfig.setAllowCreate(false);
    Environment env = new Environment(envDir, envConfig);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setReadOnly(true);
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(false);
    Transaction txn = env.beginTransaction(null, null);
    Database db = env.openDatabase(txn, DbType.REP_GROUP.getInternalName(),
                                   dbConfig);

    DatabaseEntry groupEntry = new DatabaseEntry();
    OperationStatus status =
        db.get(txn, groupKeyEntry, groupEntry, LockMode.READ_COMMITTED);
    if (status != OperationStatus.SUCCESS) {
        throw new IllegalStateException
            ("Group entry not found " + status);
    }
    GroupBinding groupBinding = new GroupBinding();
    RepGroupImpl group = groupBinding.entryToObject(groupEntry);

    group = fetchGroup(group.getName(),
                       DbInternal.getDatabaseImpl(db),
                       DbInternal.getTxn(txn));
    txn.commit();
    db.close();
    env.close();
    return group;
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:43,代码来源:RepGroupDB.java

示例6: put

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Inserts an entity and returns null, or updates it if the primary key
    * already exists and returns the existing entity.
    *
    * <p>If a {@link PrimaryKey#sequence} is used and the primary key field of
    * the given entity is null or zero, this method will assign the next value
    * from the sequence to the primary key field of the given entity.</p>
    *
    * @param txn the transaction used to protect this operation, null to use
    * auto-commit, or null if the store is non-transactional.
    *
    * @param entity the entity to be inserted or updated.
    *
    * @return the existing entity that was updated, or null if the entity was
    * inserted.
    */
   public E put(Transaction txn, E entity)
       throws DatabaseException {

       DatabaseEntry keyEntry = new DatabaseEntry();
       DatabaseEntry dataEntry = new DatabaseEntry();
       assignKey(entity, keyEntry);

       boolean autoCommit = false;
Environment env = db.getEnvironment();
       if (transactional &&
    txn == null &&
    env.getThreadTransaction() == null) {
           txn = env.beginTransaction(null, null);
           autoCommit = true;
       }

       boolean failed = true;
       Cursor cursor = db.openCursor(txn, null);
       try {
           while (true) {
               OperationStatus status =
                   cursor.getSearchKey(keyEntry, dataEntry, LockMode.RMW);
               if (status == OperationStatus.SUCCESS) {
                   E existing =
                       (E) entityBinding.entryToObject(keyEntry, dataEntry);
                   entityBinding.objectToData(entity, dataEntry);
                   cursor.put(keyEntry, dataEntry);
                   failed = false;
                   return existing;
               } else {
                   entityBinding.objectToData(entity, dataEntry);
                   status = cursor.putNoOverwrite(keyEntry, dataEntry);
                   if (status != OperationStatus.KEYEXIST) {
                       failed = false;
                       return null;
                   }
               }
           }
       } finally {
           cursor.close();
           if (autoCommit) {
               if (failed) {
                   txn.abort();
               } else {
                   txn.commit();
               }
           }
       }
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:66,代码来源:PrimaryIndex.java

示例7: beginTransaction

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Begins a new transaction for this environment and associates it with
 * the current thread.  If a transaction is already active for this
 * environment and thread, a nested transaction will be created.
 *
 * @param config the transaction configuration used for calling
 * {@link Environment#beginTransaction}, or null to use the default
 * configuration.
 *
 * @return the new transaction.
 *
 * <!-- begin JE only -->
 * @throws com.sleepycat.je.rep.InsufficientReplicasException if the Master
 * in a replicated environment could not contact a quorum of replicas as
 * determined by the {@link com.sleepycat.je.Durability.ReplicaAckPolicy}.
 *
 * @throws com.sleepycat.je.rep.ReplicaConsistencyException if a replica
 * in a replicated environment cannot become consistent within the timeout
 * period.
 *
 * @throws EnvironmentFailureException if an unexpected, internal or
 * environment-wide failure occurs.
 * <!-- end JE only -->
 *
 * @throws DatabaseException if the transaction cannot be started, in which
 * case any existing transaction is not affected.
 *
 * @throws IllegalStateException if a transaction is already active and
 * nested transactions are not supported by the environment.
 */
public final Transaction beginTransaction(TransactionConfig config)
    throws DatabaseException {

    Environment env = getEnvironment();
    Trans trans = (Trans) localTrans.get();
    if (trans != null) {
        if (trans.txn != null) {
            if (!DbCompat.NESTED_TRANSACTIONS) {
                throw new IllegalStateException
                    ("Nested transactions are not supported");
            }
            Transaction parentTxn = trans.txn;
            trans = new Trans(trans, config);
            trans.txn = env.beginTransaction(parentTxn, config);
            localTrans.set(trans);
        } else {
            trans.txn = env.beginTransaction(null, config);
            trans.config = config;
        }
    } else {
        trans = new Trans(null, config);
        trans.txn = env.beginTransaction(null, config);
        localTrans.set(trans);
    }
    return trans.txn;
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:57,代码来源:CurrentTransaction.java


注:本文中的com.sleepycat.je.Environment.beginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。