本文整理了Java中com.sleepycat.je.Transaction
类的一些代码示例,展示了Transaction
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction
类的具体详情如下:
包路径:com.sleepycat.je.Transaction
类名称:Transaction
[英]The Transaction object is the handle for a transaction. Methods off the transaction handle are used to configure, abort and commit the transaction. Transaction handles are provided to other Berkeley DB methods in order to transactionally protect those operations.
A single Transaction may be used to protect operations for any number of Databases in a given environment. However, a single Transaction may not be used for operations in more than one distinct environment.
Transaction handles are free-threaded; transactions handles may be used concurrently by multiple threads. Once the Transaction#abort or Transaction#commit method is called, the handle may not be accessed again, regardless of the success or failure of the method, with one exception: the abort method may be called any number of times to simplify error handling.
To obtain a transaction with default attributes:
Transaction txn = myEnvironment.beginTransaction(null, null);
To customize the attributes of a transaction:
TransactionConfig config = new TransactionConfig();
config.setReadUncommitted(true);
Transaction txn = myEnvironment.beginTransaction(null, config);
[中]事务对象是事务的句柄。事务句柄之外的方法用于配置、中止和提交事务。事务句柄提供给其他Berkeley DB方法,以便以事务方式保护这些操作。
单个事务可用于保护给定环境中任意数量数据库的操作。但是,单个事务不能用于多个不同环境中的操作。
事务句柄是自由线程的;多个线程可以同时使用事务句柄。一旦调用了Transaction#abort或Transaction#commit方法,不管该方法成功与否,都可能无法再次访问句柄,只有一个例外:可以多次调用abort方法以简化错误处理。
要获取具有默认属性的事务,请执行以下操作:
Transaction txn = myEnvironment.beginTransaction(null, null);
要自定义事务的属性,请执行以下操作:
TransactionConfig config = new TransactionConfig();
config.setReadUncommitted(true);
Transaction txn = myEnvironment.beginTransaction(null, config);
代码示例来源:origin: yasserg/crawler4j
public void setValue(String name, long value) {
synchronized (mutex) {
try {
counterValues.put(name, value);
if (statisticsDB != null) {
Transaction txn = env.beginTransaction(null, null);
statisticsDB.put(txn, new DatabaseEntry(name.getBytes()),
new DatabaseEntry(Util.long2ByteArray(value)));
txn.commit();
}
} catch (RuntimeException e) {
if (config.isHaltOnError()) {
throw e;
} else {
logger.error("Exception setting value", e);
}
}
}
}
代码示例来源:origin: voldemort/voldemort
private void attemptAbort(Transaction transaction) {
try {
if(transaction != null)
transaction.abort();
} catch(DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error("Abort failed!", e);
}
}
代码示例来源:origin: opensourceBIM/BIMserver
@Override
public long getId() {
return transaction.getId();
}
}
代码示例来源:origin: GeoWebCache/geowebcache
public Void call() throws Exception {
final Transaction transaction =
entityStore.getEnvironment().beginTransaction(null, null);
try {
createLayer(layerName, transaction);
transaction.commit();
} catch (RuntimeException e) {
transaction.abort();
}
return null;
}
});
代码示例来源:origin: dCache/nfs4j
env = new Environment(dir, envConfig);
clientRecoveryDatabase = env.openDatabase(null, CLIENT_DB, dbConfig);
clientDatabase = env.openDatabase(null, CLIENT_DB_RECOVER, dbConfig);
tx.commit();
代码示例来源:origin: yasserg/crawler4j
dbConfig.setTransactional(true);
dbConfig.setDeferredWrite(false);
statisticsDB = env.openDatabase(null, DATABASE_NAME, dbConfig);
Transaction tnx = env.beginTransaction(null, null);
Cursor cursor = statisticsDB.openCursor(tnx, null);
result = cursor.getFirst(key, value, null);
tnx.commit();
代码示例来源:origin: dCache/nfs4j
/**
* Remove all record for client's that did not showed up during grace
* period. Drop recovery database.
*/
@Override
public synchronized void reclaimComplete() {
if (clientRecoveryDatabase == null) {
return;
}
Transaction tx = env.beginTransaction(null, null);
try {
try (Cursor cursor = clientRecoveryDatabase.openCursor(tx, config)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
while (cursor.getNext(key, data, null) == OperationStatus.SUCCESS) {
Instant clientCreationTime = Instant.ofEpochMilli(LongBinding.entryToLong(data));
LOGGER.info("Dropping expired recovery record: [{}], {}", new String(key.getData(), UTF_8), clientCreationTime);
}
}
clientDatabase.close();
clientRecoveryDatabase.close();
clientRecoveryDatabase = null;
env.removeDatabase(tx, CLIENT_DB);
env.renameDatabase(tx, CLIENT_DB_RECOVER, CLIENT_DB);
clientDatabase = env.openDatabase(tx, CLIENT_DB, dbConfig);
} finally {
tx.commit();
}
}
代码示例来源:origin: co.paralleluniverse/galaxy
public void truncate() {
LOG.info("Truncating database, home: {}", env.getHome());
Transaction txn = env.beginTransaction(null, TransactionConfig.DEFAULT);
try {
env.truncateDatabase(txn, "ownerDirecotry", false);
env.truncateDatabase(txn, "ownerIndex", false);
txn.commit();
env.truncateDatabase(null, "mainStore", false);
env.truncateDatabase(null, "allocationDirectory", false);
} catch (Exception e) {
LOG.error("Exception while truncating database. Aborting.", e);
txn.abort();
throw Throwables.propagate(e);
}
}
代码示例来源:origin: yasserg/crawler4j
protected static void commit(Transaction tnx) {
if (tnx != null) {
tnx.commit();
}
}
代码示例来源:origin: org.jsimpledb/jsimpledb-kv-bdb
@Override
public synchronized void commit() {
if (this.closed)
throw new StaleTransactionException(this);
this.close();
try {
if (this.readOnly)
this.tx.abort();
else
this.tx.commit();
} catch (DatabaseException e) {
throw this.wrapException(e);
}
}
代码示例来源:origin: org.jboss.cache/jbosscache-core
while (true)
Transaction txn = env.beginTransaction(null, null);
try
txn.abort();
if (e instanceof DeadlockException && retries > 0)
代码示例来源:origin: HuygensING/timbuctoo
public void commit() {
if (transaction != null) {
transaction.commit();
}
try {
boolean success = this.put(isCleanHandler.getKey(), isCleanHandler.getValue());
if (!success) {
LOG.error("Could not add 'isClean' property");
}
} catch (DatabaseWriteException e) {
LOG.error("Could not add 'isClean' property for database '" + database.getDatabaseName() + "'", e);
}
database.sync();
dbEnvironment.sync(); // needed for better recoverability
}
代码示例来源:origin: org.deephacks/graphene-core
public void commit() {
closeCursors();
if (tx.isValid()) {
tx.commit();
}
}
代码示例来源:origin: com.sleepycat/je
try {
errors.append("aborting " + txn);
txn.abort();
} catch (RuntimeException e) {
if (!environmentImpl.isValid()) {
errors.append(txn.getId());
errors.append(" encountered exception: ");
errors.append(e).append("\n");
代码示例来源:origin: stackoverflow.com
Log.e(MY_ACTIVITY, "Product is null for transId: "+trans.getId());
continue;
Log.e(MY_ACTIVITY, "User is null for transId: "+trans.getId();
continue;
item.setProduct(trans.getProduct().getName());
item.setCost(trans.getCost());
item.setName(trans.getUser().getName());
item.setDate(trans.getCreated_at());
item.setId(trans.getId());
transaction.add(item);
代码示例来源:origin: com.sleepycat/je
/**
* Configures the timeout value for the transaction lifetime, with the
* timeout value specified in microseconds. This method is equivalent to:
*
* <pre>setTxnTimeout(long, TimeUnit.MICROSECONDS);</pre>
*
* @deprecated as of 4.0, replaced by {@link #setTxnTimeout(long,
* TimeUnit)}.
*/
public void setTxnTimeout(long timeOut)
throws IllegalArgumentException, DatabaseException {
setTxnTimeout(timeOut, TimeUnit.MICROSECONDS);
}
代码示例来源:origin: com.amazon.carbonado/carbonado-sleepycat-je
void setLockTimeout(long timeout) throws DatabaseException {
if (timeout <= 0) {
timeout = timeout < 0 ? 0 : 1;
}
mTxn.setLockTimeout(timeout);
}
代码示例来源:origin: GeoWebCache/geowebcache
public Void call() throws Exception {
Transaction transaction = entityStore.getEnvironment().beginTransaction(null, null);
try {
call(transaction);
transaction.commit();
} catch (RuntimeException e) {
transaction.abort();
throw e;
}
return null;
}
代码示例来源:origin: edu.uci.ics/crawler4j
dbConfig.setTransactional(true);
dbConfig.setDeferredWrite(false);
statisticsDB = env.openDatabase(null, DATABASE_NAME, dbConfig);
Transaction tnx = env.beginTransaction(null, null);
Cursor cursor = statisticsDB.openCursor(tnx, null);
result = cursor.getFirst(key, value, null);
tnx.commit();
代码示例来源:origin: voldemort/voldemort
private void attemptCommit(Transaction transaction) {
try {
if(transaction != null)
transaction.commit();
} catch(DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error("Transaction commit failed!", e);
attemptAbort(transaction);
throw new PersistenceFailureException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!