本文整理匯總了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();
}
示例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();
}
示例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();
}
}
}
示例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);
}
示例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;
}
示例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();
}
}
}
}
示例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;
}