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


Java Environment.getThreadTransaction方法代码示例

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


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

示例1: 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

示例2: getReadableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Get a locker for a read or cursor operation.
 */
private static Locker getReadableLocker(Environment env,
                                        Locker locker,
                                        boolean readCommittedIsolation)
    throws DatabaseException {

    EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env);

    if (locker == null) {
        Transaction xaTxn = env.getThreadTransaction();
        if (xaTxn != null) {
            return DbInternal.getLocker(xaTxn);
        }
    }

    if (locker == null) {
        /* Non-transactional user operations use ThreadLocker. */
        locker = ThreadLocker.createThreadLocker(envImpl);
    } else {

        /*
         * Use the given locker.  For read-committed, wrap the given
         * transactional locker in a special locker for that isolation
         * level.
         */
        if (readCommittedIsolation) {
            locker = ReadCommittedLocker.
                createReadCommittedLocker(envImpl, locker);
        }
    }
    return locker;
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:35,代码来源:LockerFactory.java

示例3: 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

示例4: getThreadTransaction

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public static Transaction getThreadTransaction(Environment env)
throws DatabaseException {

       return env.getThreadTransaction();
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:6,代码来源:DbCompat.java

示例5: getWritableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Get a locker for a writable operation, also specifying whether to retain
    * non-transactional locks when a new locker must be created.
    *
    * @param retainNonTxnLocks is true for DbTree operations, so that the
    * handle lock may be transferred out of the locker when the operation is
    * complete.
    */
   public static Locker getWritableLocker(Environment env,
                                          Transaction userTxn,
                                          boolean dbIsTransactional,
                                          boolean retainNonTxnLocks,
                                          TransactionConfig autoCommitConfig)
       throws DatabaseException {

       EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
       boolean envIsTransactional = envImpl.isTransactional();

if (userTxn == null) {
    Transaction xaLocker = env.getThreadTransaction();
    if (xaLocker != null) {
	return DbInternal.getLocker(xaLocker);
    }
}

       if (dbIsTransactional && userTxn == null) {

           if (autoCommitConfig == null) {
               autoCommitConfig = DbInternal.getDefaultTxnConfig(env);
           }
           return new AutoTxn(envImpl, autoCommitConfig);

       } else if (userTxn == null) {

           if (retainNonTxnLocks) {
               return new BasicLocker(envImpl);
           } else {
               return new ThreadLocker(envImpl);
           }

       } else {

           /*
            * The user provided a transaction, the environment and the
            * database had better be opened transactionally.
            */
           if (!envIsTransactional) {
               throw new DatabaseException
	    ("A Transaction cannot be used because the"+
	     " environment was opened" +
	     " non-transactionally");
           }
           if (!dbIsTransactional) {
               throw new DatabaseException
	    ("A Transaction cannot be used because the" +
	     " database was opened" +
	     " non-transactionally");
           }

           /*
            * Use the locker for the given transaction.  For read-comitted,
            * wrap the given transactional locker in a special locker for that
            * isolation level.  But if retainNonTxnLocks we cannot use
            * read-committed, since retainNonTxnLocks is used for handle locks
            * that must be retained across operations.
            */
           Locker locker = DbInternal.getLocker(userTxn);
           if (locker.isReadCommittedIsolation() && !retainNonTxnLocks) {
               return new ReadCommittedLocker(envImpl, locker);
           } else {
               return locker;
           }
       }
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:75,代码来源:LockerFactory.java

示例6: getReadableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Get a locker for a read or cursor operation.
    * See getWritableLocker for an explanation of retainNonTxnLocks.
    */
   private static Locker getReadableLocker(Environment env,
                                           Locker locker,
                                           boolean retainNonTxnLocks,
                                           boolean readCommittedIsolation)
       throws DatabaseException {

       EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);

if (locker == null) {
    Transaction xaTxn = env.getThreadTransaction();
    if (xaTxn != null) {
	return DbInternal.getLocker(xaTxn);
    }
}

       if (locker == null) {

           /*
            * A non-transactional locker is requested.  If we're retaining
            * non-transactional locks across operations, use a BasicLocker
            * since the locker may be used across threads; this is used when
            * acquiring handle locks internally (open, close, remove, etc).
            * Otherwise, use a ThreadLocker to avoid self-deadlocks within the
            * same thread; this used for ordinary user operations.
            */
           if (retainNonTxnLocks) {
               locker = new BasicLocker(envImpl);
           } else {
               locker = new ThreadLocker(envImpl);
           }
       } else {

           /*
            * Use the given locker.  For read-committed, wrap the given
            * transactional locker in a special locker for that isolation
            * level.  But if retainNonTxnLocks we cannot use read-committed,
            * since retainNonTxnLocks is used for handle locks that must be
            * retained across operations.
            */
           if (readCommittedIsolation && !retainNonTxnLocks) {
               locker = new ReadCommittedLocker(envImpl, locker);
           }
       }
       return locker;
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:50,代码来源:LockerFactory.java

示例7: getWritableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Get a locker for a writable operation, also specifying whether to retain
    * non-transactional locks when a new locker must be created.
    *
    * @param retainNonTxnLocks is true for DbTree operations, so that the
    * handle lock may be transferred out of the locker when the operation is
    * complete.
    */
   public static Locker getWritableLocker(Environment env,
                                          Transaction userTxn,
                                          boolean dbIsTransactional,
                                          boolean retainNonTxnLocks,
                                          TransactionConfig autoCommitConfig)
       throws DatabaseException {

       EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
       boolean envIsTransactional = envImpl.isTransactional();

if (userTxn == null) {
    Transaction xaLocker = env.getThreadTransaction();
    if (xaLocker != null) {
	return DbInternal.getLocker(xaLocker);
    }
}

       if (dbIsTransactional && userTxn == null) {

           if (autoCommitConfig == null) {
               autoCommitConfig = DbInternal.getDefaultTxnConfig(env);
           }
           return new AutoTxn(envImpl, autoCommitConfig);

       } else if (userTxn == null) {

           if (retainNonTxnLocks) {
               return new BasicLocker(envImpl);
           } else {
               return new ThreadLocker(envImpl);
           }

       } else {

           /* 
            * The user provided a transaction, the environment and the
            * database had better be opened transactionally.
            */
           if (!envIsTransactional) {
               throw new DatabaseException
	    ("A Transaction cannot be used because the"+
	     " environment was opened" +
	     " non-transactionally");
           }
           if (!dbIsTransactional) {
               throw new DatabaseException
	    ("A Transaction cannot be used because the" +
	     " database was opened" +
	     " non-transactionally");
           }

           /*
            * Use the locker for the given transaction.  For read-comitted,
            * wrap the given transactional locker in a special locker for that
            * isolation level.  But if retainNonTxnLocks we cannot use
            * read-committed, since retainNonTxnLocks is used for handle locks
            * that must be retained across operations.
            */
           Locker locker = DbInternal.getLocker(userTxn);
           if (locker.isReadCommittedIsolation() && !retainNonTxnLocks) {
               return new ReadCommittedLocker(envImpl, locker);
           } else {
               return locker;
           }
       }
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:75,代码来源:LockerFactory.java

示例8: getReadableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
    * Get a locker for a read or cursor operation.
    * See getWritableLocker for an explanation of retainNonTxnLocks.
    */
   private static Locker getReadableLocker(Environment env,
                                           Locker locker,
                                           boolean retainNonTxnLocks,
                                           boolean readCommittedIsolation) 
       throws DatabaseException {

       EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);

if (locker == null) {
    Transaction xaTxn = env.getThreadTransaction();
    if (xaTxn != null) {
	return DbInternal.getLocker(xaTxn);
    }
}

       if (locker == null) {

           /*
            * A non-transactional locker is requested.  If we're retaining
            * non-transactional locks across operations, use a BasicLocker
            * since the locker may be used across threads; this is used when
            * acquiring handle locks internally (open, close, remove, etc).
            * Otherwise, use a ThreadLocker to avoid self-deadlocks within the
            * same thread; this used for ordinary user operations.
            */
           if (retainNonTxnLocks) {
               locker = new BasicLocker(envImpl);
           } else {
               locker = new ThreadLocker(envImpl);
           }
       } else {

           /*
            * Use the given locker.  For read-committed, wrap the given
            * transactional locker in a special locker for that isolation
            * level.  But if retainNonTxnLocks we cannot use read-committed,
            * since retainNonTxnLocks is used for handle locks that must be
            * retained across operations.
            */
           if (readCommittedIsolation && !retainNonTxnLocks) {
               locker = new ReadCommittedLocker(envImpl, locker);
           }
       }
       return locker;
   }
 
开发者ID:nologic,项目名称:nabs,代码行数:50,代码来源:LockerFactory.java

示例9: getThreadTransaction

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
public static Transaction getThreadTransaction(Environment env)
    throws DatabaseException {

    return env.getThreadTransaction();
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:6,代码来源:DbCompat.java

示例10: getWritableLocker

import com.sleepycat.je.Environment; //导入方法依赖的package包/类
/**
 * Get a locker for a write operation.
 *
 * @param autoTxnIsReplicated is true if this transaction is
 * executed on a rep group master, and needs to be broadcast.
 * Currently, all application-created transactions are of the type
 * com.sleepycat.je.txn.Txn, and are replicated if the parent
 * environment is replicated. Auto Txns are trickier because they may
 * be created for a local write operation, such as log cleaning.
 *
 * @throws IllegalArgumentException via db/cursor read/write methods.
 */
public static Locker getWritableLocker(Environment env,
                                       Transaction userTxn,
                                       boolean isInternalDb,
                                       boolean dbIsTransactional,
                                       boolean autoTxnIsReplicated,
                                       TransactionConfig autoCommitConfig)
    throws DatabaseException {

    EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env);
    boolean envIsTransactional = envImpl.isTransactional();

    if (userTxn == null) {
        Transaction xaLocker = env.getThreadTransaction();
        if (xaLocker != null) {
            return DbInternal.getLocker(xaLocker);
        }
    }

    if (dbIsTransactional && userTxn == null) {

        if (autoCommitConfig == null) {
            autoCommitConfig = DbInternal.getDefaultTxnConfig(env);
        }

        return Txn.createAutoTxn(envImpl,
                                 autoCommitConfig,
                                 (autoTxnIsReplicated ?
                                  ReplicationContext.MASTER :
                                  ReplicationContext.NO_REPLICATE));

    } else if (userTxn == null) {
        /* Non-transactional user operations use ThreadLocker. */
        return ThreadLocker.createThreadLocker(envImpl);
    } else {

        /*
         * The user provided a transaction, the environment and the
         * database had better be opened transactionally.
         */
        if (!isInternalDb && !envIsTransactional) {
            throw new IllegalArgumentException
                ("A Transaction cannot be used because the"+
                 " environment was opened non-transactionally");
        }
        if (!dbIsTransactional) {
            throw new IllegalArgumentException
                ("A Transaction cannot be used because the" +
                 " database was opened non-transactionally");
        }

        /*
         * Use the locker for the given transaction.  For read-comitted,
         * wrap the given transactional locker in a special locker for that
         * isolation level.
         */
        Locker locker = DbInternal.getLocker(userTxn);
        if (locker.isReadCommittedIsolation()) {
            return ReadCommittedLocker.
                createReadCommittedLocker(envImpl, locker);
        }
        
        return locker;
    }
}
 
开发者ID:prat0318,项目名称:dbms,代码行数:77,代码来源:LockerFactory.java


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