本文整理汇总了Java中com.sleepycat.je.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于com.sleepycat.je包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connection
import com.sleepycat.je.Transaction; //导入依赖的package包/类
/**
* Returns a {@link BerkeleyDB} instance with given parameter
*/
public BerkeleyDB connection(String databaseName, DatabaseConfig databaseConfig, Transaction transaction) {
_dbName = databaseName; _database = this.getEnv().openDatabase(transaction,
checkNotNull(databaseName), databaseConfig = firstNonNull(databaseConfig, defaultDatabaseConfig()));
if (log.isDebugEnabled()) {
log.debug("Database initialized with name: " + databaseName);
log.debug("DatabaseConfig initialized: " + databaseConfig.toString());
log.debug("Transaction initialized: " + (null != transaction ? transaction.toString() : null));
}
storedClassCatalog = new StoredClassCatalog(delegate());
if (log.isDebugEnabled()) {
log.debug("StoredClassCatalog initialized with database: " + delegate().getDatabaseName());
}
return this;
}
示例2: setEntryInStore
import com.sleepycat.je.Transaction; //导入依赖的package包/类
@Override
protected void setEntryInStore(Integer id, ConceptVectorRecord value) {
try {
Transaction transaction = environment.beginTransaction(null, null);
DatabaseEntry theDBKey = new DatabaseEntry();
integerBinding.objectToEntry(id, theDBKey);
DatabaseEntry theDBValue = new DatabaseEntry();
recordDatabaseBinding.objectToEntry(value.getConceptVector(), theDBValue);
groundhog.put(transaction, theDBKey, theDBValue);
transaction.commit();
} catch (DatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: JoinForwardCursor
import com.sleepycat.je.Transaction; //导入依赖的package包/类
JoinForwardCursor(Transaction txn, CursorConfig config, boolean doKeys)
throws DatabaseException {
this.doKeys = doKeys;
try {
cursors = new Cursor[conditions.size()];
for (int i = 0; i < cursors.length; i += 1) {
Condition cond = conditions.get(i);
Cursor cursor = cond.openCursor(txn, config);
if (cursor == null) {
/* Leave joinCursor null. */
doClose(null);
return;
}
cursors[i] = cursor;
}
joinCursor = primary.getDatabase().join(cursors, null);
} catch (DatabaseException e) {
/* doClose will throw e. */
doClose(e);
}
}
示例4: insert
import com.sleepycat.je.Transaction; //导入依赖的package包/类
private void insert(byte keyVal, int keySize,
byte dataVal, int dataSize,
boolean commit)
throws DatabaseException {
Transaction txn = null;
if (!commit) {
txn = env.beginTransaction(null, null);
}
assertEquals(OperationStatus.SUCCESS,
db.put(null, getEntry(keyVal, keySize),
getEntry(dataVal, dataSize)));
if (!commit) {
txn.abort();
}
}
示例5: cursor
import com.sleepycat.je.Transaction; //导入依赖的package包/类
private <V> EntityCursor<V> cursor(Transaction txn,
PK fromKey,
boolean fromInclusive,
PK toKey,
boolean toInclusive,
ValueAdapter<V> adapter,
CursorConfig config)
throws DatabaseException {
DatabaseEntry fromEntry = null;
if (fromKey != null) {
fromEntry = new DatabaseEntry();
pkeyBinding.objectToEntry(fromKey, fromEntry);
}
DatabaseEntry toEntry = null;
if (toKey != null) {
toEntry = new DatabaseEntry();
pkeyBinding.objectToEntry(toKey, toEntry);
}
KeyRange pkeyRange = emptyPKeyRange.subRange
(fromEntry, fromInclusive, toEntry, toInclusive);
return cursor(txn, pkeyRange, adapter, config);
}
示例6: testGetSearchBoth_Success_Dup
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void testGetSearchBoth_Success_Dup()
throws DatabaseException, InterruptedException {
openEnv(true);
/* Insert dups. */
insert(1, 1);
insert(1, 3);
/* getSearchBoth returns key {1,3}. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
/* Insertions are never blocked. */
try {
insert(1, 2);
} catch (DeadlockException e) {
fail();
}
cursor.close();
readerTxn.commitNoSync();
closeEnv();
}
示例7: get
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public E get(Transaction txn, PK key, LockMode lockMode)
throws DatabaseException {
DatabaseEntry pkeyEntry = new DatabaseEntry();
DatabaseEntry dataEntry = new DatabaseEntry();
pkeyBinding.objectToEntry(key, pkeyEntry);
OperationStatus status =
db.getSearchBoth(txn, keyEntry, pkeyEntry, dataEntry, lockMode);
if (status == OperationStatus.SUCCESS) {
return (E) entityBinding.entryToObject(pkeyEntry, dataEntry);
} else {
return null;
}
}
示例8: testSR9992
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void testSR9992()
throws DatabaseException {
initEnvTransactional(true);
Transaction txn = exampleEnv.beginTransaction(null, null);
Cursor c = exampleDb.openCursor(txn, null);
for (int i = 1; i < simpleKeys.length; i++) {
c.put(simpleKeys[0], simpleData[i]);
}
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
c.getCurrent(key, data, LockMode.DEFAULT);
c.delete();
/* Expect "Can't replace a duplicate with different data." */
assertEquals(OperationStatus.NOTFOUND,
c.putCurrent(new DatabaseEntry("aaaa".getBytes())));
c.close();
txn.commit();
}
示例9: testInsertDeleteAbort
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void testInsertDeleteAbort()
throws DatabaseException {
openEnv();
/* Insert and update key 0. */
Transaction txn = env.beginTransaction(null, null);
long file0 = doPut(0, txn);
long file1 = doDelete(0, txn);
txn.abort();
performRecoveryOperation();
expectObsolete(file0, true);
expectObsolete(file1, true);
closeEnv(true);
}
示例10: insert
import com.sleepycat.je.Transaction; //导入依赖的package包/类
/**
* Inserts the given key and data in a new transaction and commits it.
*/
private void insert(int keyVal, int dataVal)
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
IntegerBinding.intToEntry(keyVal, key);
IntegerBinding.intToEntry(dataVal, data);
OperationStatus status;
Transaction writerTxn = env.beginTransaction(null, txnConfig);
try {
if (dups) {
status = db.putNoDupData(writerTxn, key, data);
} else {
status = db.putNoOverwrite(writerTxn, key, data);
}
} catch (DeadlockException e) {
writerTxn.abort();
throw e;
}
assertEquals(OperationStatus.SUCCESS, status);
writerTxn.commitNoSync();
}
示例11: testSearchKeySkipDeletedDup
import com.sleepycat.je.Transaction; //导入依赖的package包/类
/**
* Tests that searchKey returns SUCCESS when it must skip over a deleted
* duplicate. This did not work at one point and was causing warnings
* (Cursor Not Initialized) in duplicate.conf testing.
*/
public void testSearchKeySkipDeletedDup()
throws DatabaseException, InterruptedException {
openEnv(true);
/* Insert {1,1} and {1,2}. */
insert(1, 1);
insert(1, 2);
/* Delete {1,1}. */
Transaction txn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(txn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 1));
OperationStatus status = cursor.delete();
assertEquals(OperationStatus.SUCCESS, status);
/* Search for key 1 -- should not return NOTFOUND. */
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 1, 2));
cursor.close();
txn.commitNoSync();
closeEnv();
}
示例12: testUpdateUpdateAbort
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void testUpdateUpdateAbort()
throws DatabaseException {
openEnv();
/* Insert key 0 and checkpoint. */
long file0 = doPut(0, true);
env.checkpoint(forceConfig);
/* Update key 0 twice and abort. */
Transaction txn = env.beginTransaction(null, null);
long file1 = doPut(0, txn);
long file2 = doPut(0, txn);
txn.abort();
performRecoveryOperation();
expectObsolete(file0, false);
expectObsolete(file1, true);
expectObsolete(file2, true);
closeEnv(true);
}
示例13: writeProcessorMetadata
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void writeProcessorMetadata(Environment env,
Transaction txn,
String processorName,
ProcessorMetadata metadata) {
/* Serialize ProcessorMetadata. */
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(metadata);
} catch (IOException e) {
throw EnvironmentFailureException.unexpectedException(e);
}
DatabaseEntry data = new DatabaseEntry(baos.toByteArray());
/* Write the serialized object to database. */
writeData(env, txn, processorName, null, data,
DataType.PROCESSOR_METADATA, null);
}
示例14: testBasic2PC
import com.sleepycat.je.Transaction; //导入依赖的package包/类
/**
* Basic Two Phase Commit calls.
*/
public void testBasic2PC()
throws Throwable {
try {
Transaction txn = env.beginTransaction(null, null);
XidImpl xid = new XidImpl(1, "TwoPCTest1".getBytes(), null);
env.setXATransaction(xid, txn);
StringDbt key = new StringDbt("key");
StringDbt data = new StringDbt("data");
db.put(txn, key, data);
env.prepare(xid);
env.commit(xid, false);
} catch (Exception E) {
System.out.println("caught " + E);
}
}
示例15: discardChanges
import com.sleepycat.je.Transaction; //导入依赖的package包/类
public void discardChanges(Transaction txn) {
synchronized (envImpl.getSyncCleanerBarrier()) {
/* Free the memory held by this ChangeTxn. */
clear();
/*
* Set the LogChangeSet.lastSyncEnd to the commit point of this
* ChangeTxn.
*/
changeSet.setLastSyncEnd(commitPoint);
/*
* Reset the LogChangeSet.nextSyncStart and write the
* LogChangeSet into SyncDB.
*/
resetChangeSetNextSyncStart();
writeSyncDB(txn);
}
}