本文整理汇总了Java中com.sleepycat.je.Transaction.commit方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.commit方法的具体用法?Java Transaction.commit怎么用?Java Transaction.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sleepycat.je.Transaction
的用法示例。
在下文中一共展示了Transaction.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: rmwModify
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void rmwModify()
throws DatabaseException {
Transaction txn = env.beginTransaction(null, null);
IntegerBinding.intToEntry(0, key);
assertEquals(OperationStatus.SUCCESS,
db.get(txn, key, data, LockMode.RMW));
IntegerBinding.intToEntry(1, key);
assertEquals(OperationStatus.SUCCESS,
db.get(txn, key, data, LockMode.RMW));
IntegerBinding.intToEntry(200, data);
assertEquals(OperationStatus.SUCCESS,
db.put(txn, key, data));
txn.commit();
}
示例3: testReuseKnownDeletedSlot
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testReuseKnownDeletedSlot()
throws DatabaseException {
openEnv();
/* Insert key 0 and abort to create a knownDeleted slot. */
Transaction txn = env.beginTransaction(null, null);
long file0 = doPut(0, txn);
txn.abort();
/* Insert key 0 to reuse the knownDeleted slot. */
txn = env.beginTransaction(null, null);
long file1 = doPut(0, txn);
txn.commit();
performRecoveryOperation();
/* Verify that file0 is still obsolete. */
expectObsolete(file0, true);
expectObsolete(file1, false);
closeEnv(true);
}
示例4: testUpdateUpdate
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testUpdateUpdate()
throws DatabaseException {
openEnv();
/* Insert key 0 and checkpoint. */
long file0 = doPut(0, true);
env.checkpoint(forceConfig);
/* Update key 0 twice. */
Transaction txn = env.beginTransaction(null, null);
long file1 = doPut(0, txn);
long file2 = doPut(0, txn);
txn.commit();
performRecoveryOperation();
expectObsolete(file0, true);
expectObsolete(file1, true);
expectObsolete(file2, false);
closeEnv(true);
}
示例5: clearGroundhog
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void clearGroundhog() {
try {
closeDatabase();
Transaction transaction = environment.beginTransaction(null, null);
environment.truncateDatabase(transaction, databaseName, false);
transaction.commit();
openDB();
conceptIndex.clearIndex();
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例6: doBasic
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Insert data, delete data into several dbs.
*/
public void doBasic(boolean runCheckpointerDaemon)
throws Throwable {
createEnvAndDbs(1 << 20, runCheckpointerDaemon, NUM_DBS);
int numRecs = NUM_RECS;
try {
// Set up an repository of expected data
Hashtable expectedData = new Hashtable();
// insert all the data
Transaction txn = env.beginTransaction(null, null);
insertData(txn, 0, numRecs - 1, expectedData, 1, true, NUM_DBS);
txn.commit();
// delete all the even records
txn = env.beginTransaction(null, null);
deleteData(txn, expectedData, false, true, NUM_DBS);
txn.commit();
// modify all the records
txn = env.beginTransaction(null, null);
modifyData(txn, NUM_RECS/2, expectedData, 1, true, NUM_DBS);
txn.commit();
closeEnv();
recoverAndVerify(expectedData, NUM_DBS);
} catch (Throwable t) {
// print stacktrace before trying to clean up files
t.printStackTrace();
throw t;
}
}
示例7: testTxnClose
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test db creation and deletion.
*/
public void testTxnClose()
throws DatabaseException {
createDbs();
Transaction txn = env.beginTransaction(null, null);
createCursors(txn);
try {
txn.commit();
fail("Commit should fail");
} catch (DatabaseException e) {
}
closeCursors();
closeAll();
}
示例8: testInsertDeleteDup
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testInsertDeleteDup()
throws DatabaseException {
dups = true;
openEnv();
/* Insert two key 0 dups and checkpoint. */
Transaction txn = env.beginTransaction(null, null);
long file0 = doPut(0, 0, txn); // 1st LN
long file2 = doPut(0, 1, txn); // 2nd LN
long file1 = file2 - 1; // DupCountLN
txn.commit();
env.checkpoint(forceConfig);
/* Insert and delete {0, 2}. */
txn = env.beginTransaction(null, null);
long file3 = doPut(0, 2, txn); // 3rd LN
long file4 = file3 + 1; // DupCountLN
long file5 = doDelete(0, 2, txn); // 4rd LN
long file6 = file5 + 1; // DupCountLN
txn.commit();
performRecoveryOperation();
expectObsolete(file0, false);
expectObsolete(file1, true);
expectObsolete(file2, false);
expectObsolete(file3, true);
expectObsolete(file4, true);
expectObsolete(file5, true);
expectObsolete(file6, false);
closeEnv(true);
}
示例9: updateData
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Updates the specified keys.
*/
private void updateData(int firstKey, int keyCount)
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
for (int i = 0; i < keyCount; i += 1) {
int nextKey = firstKey + i;
OperationStatus status;
if (dups) {
key.setData(MAIN_KEY_FOR_DUPS);
data.setData(TestUtils.getTestArray(nextKey));
status = cursor.getSearchBoth(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(MAIN_KEY_FOR_DUPS.length, key.getSize());
assertEquals(nextKey, TestUtils.getTestVal(data.getData()));
} else {
key.setData(TestUtils.getTestArray(nextKey));
status = cursor.getSearchKey(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(nextKey, TestUtils.getTestVal(key.getData()));
assertEquals(DATA_SIZE, data.getSize());
}
status = cursor.putCurrent(data);
assertEquals(OperationStatus.SUCCESS, status);
}
cursor.close();
txn.commit();
}
示例10: truncateClass
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public synchronized void truncateClass(Transaction txn, Class entityClass)
throws DatabaseException {
checkOpen();
checkWriteAllowed();
/* Close primary and secondary databases. */
closeClass(entityClass);
String clsName = entityClass.getName();
EntityMetadata entityMeta = checkEntityClass(clsName);
boolean autoCommit = false;
if (storeConfig.getTransactional() &&
txn == null &&
DbCompat.getThreadTransaction(env) == null) {
txn = env.beginTransaction(null, autoCommitTxnConfig);
autoCommit = true;
}
/*
* Truncate the primary first and let any exceptions propogate
* upwards. Then remove each secondary, only throwing the first
* exception.
*/
boolean success = false;
try {
boolean primaryExists =
truncateIfExists(txn, storePrefix + clsName);
if (primaryExists) {
DatabaseException firstException = null;
for (SecondaryKeyMetadata keyMeta :
entityMeta.getSecondaryKeys().values()) {
/* Ignore secondaries that do not exist. */
removeIfExists
(txn,
storePrefix +
makeSecName(clsName, keyMeta.getKeyName()));
}
if (firstException != null) {
throw firstException;
}
}
success = true;
} finally {
if (autoCommit) {
if (success) {
txn.commit();
} else {
txn.abort();
}
}
}
}
示例11: testSR13034
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testSR13034()
throws DatabaseException {
open();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
Transaction txn;
/*
* Insert {A, C}, then delete it. No dup tree has been created, so
* this logs a deleted LN with no data.
*/
txn = env.beginTransaction(null, null);
StringBinding.stringToEntry("A", key);
StringBinding.stringToEntry("C", data);
status = db.putNoOverwrite(txn, key, data);
assertEquals(OperationStatus.SUCCESS, status);
status = db.delete(txn, key);
assertEquals(OperationStatus.SUCCESS, status);
txn.commit();
/*
* Insert {A, A}, {A, B}, which creates a dup tree. Then abort to set
* KnownDeleted on these entries.
*/
txn = env.beginTransaction(null, null);
StringBinding.stringToEntry("A", key);
StringBinding.stringToEntry("A", data);
status = db.putNoDupData(txn, key, data);
StringBinding.stringToEntry("A", key);
StringBinding.stringToEntry("B", data);
status = db.putNoDupData(txn, key, data);
assertEquals(OperationStatus.SUCCESS, status);
txn.abort();
/*
* Close without a checkpoint and recover. Before the bug fix, the
* recovery would throw DatabaseException "attempt to fetch a deleted
* entry".
*/
db.close();
DbInternal.envGetEnvironmentImpl(env).close(false);
open();
close();
}
示例12: testGetPrevNoDup_NotFound_Dup
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testGetPrevNoDup_NotFound_Dup()
throws DatabaseException, InterruptedException {
openEnv(true);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert dups. */
insert(2, 1);
insert(2, 2);
/* getPrevNoDup returns NOTFOUND. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrevNoDup(key, data, null);
assertEquals(OperationStatus.NOTFOUND, status);
/* Insert {1,1} in a writer thread. */
startInsert(1, 1);
/*
* If serializable, getPrevNoDup should return NOTFOUND again;
* otherwise getPrevNoDup should see {1,1}.
*/
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrevNoDup(key, data, null);
if (txnSerializable) {
assertEquals(OperationStatus.NOTFOUND, status);
} else {
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getPrevNoDup returns {1,1}. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrevNoDup(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
cursor.close();
readerTxn.commit();
closeEnv();
}
示例13: testBasicDb
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test use through db.
*/
public void testBasicDb()
throws Throwable {
try {
TransactionStats stats =
env.getTransactionStats(TestUtils.FAST_STATS);
assertEquals(0, stats.getNAborts());
int initialCommits = 1; // 1 commits for adding UP database
assertEquals(initialCommits, stats.getNCommits());
int numKeys = 7;
createDbs();
// Insert data with autocommit
dbInsertData(0, numKeys, null);
verifyData(numKeys, 0);
// Insert data with a txn
Transaction txn = env.beginTransaction(null, null);
dbInsertData(numKeys, numKeys*2, txn);
txn.commit();
verifyData(numKeys*2, 0);
stats = env.getTransactionStats(TestUtils.FAST_STATS);
assertEquals(0, stats.getNAborts());
assertEquals((initialCommits + 1 + // 1 explicit commit above
(1 * NUM_DBS) + // 1 per create/open
(numKeys*NUM_DBS)), // 1 per record, using autotxn
stats.getNCommits());
// delete data with a txn, abort
txn = env.beginTransaction(null, null);
dbDeleteData(numKeys, numKeys * 2, txn);
verifyData(numKeys, 0); // verify w/dirty read
txn.abort();
closeAll();
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}
示例14: testGetPrevDup_Success_Dup
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testGetPrevDup_Success_Dup()
throws DatabaseException, InterruptedException {
openEnv(true);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert dups. */
insert(1, 1);
insert(1, 3);
/* getPrevDup returns {1,1}. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrevDup(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
/* Insertions before current position are never blocked. */
try {
insert(1, 0);
} catch (DeadlockException e) {
fail();
}
/* Insert {1,2} in a writer thread. */
startInsert(1, 2);
/*
* If serializable, getPrevDup should return {1,1} again; otherwise
* getPrevDup should see {1,2}.
*/
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrevDup(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
if (txnSerializable) {
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
} else {
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(2, IntegerBinding.entryToInt(data));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getPrevDup returns {1,2}. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrevDup(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(2, IntegerBinding.entryToInt(data));
cursor.close();
readerTxn.commit();
closeEnv();
}
示例15: testGetSearchKeyRange_NotFound
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testGetSearchKeyRange_NotFound()
throws DatabaseException, InterruptedException {
openEnv(false);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert key 1. */
insert(1);
/* getSearchKeyRange for key 2 returns NOTFOUND. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
IntegerBinding.intToEntry(2, key);
status = cursor.getSearchKeyRange(key, data, null);
assertEquals(OperationStatus.NOTFOUND, status);
/* Insert key 3 in a writer thread. */
startInsert(3);
/*
* If serializable, getSearchKeyRange should return NOTFOUND again;
* otherwise getSearchKeyRange should see key 3.
*/
IntegerBinding.intToEntry(2, key);
status = cursor.getSearchKeyRange(key, data, null);
if (txnSerializable) {
assertEquals(OperationStatus.NOTFOUND, status);
} else {
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(3, IntegerBinding.entryToInt(key));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getSearchKeyRange returns key 3. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
IntegerBinding.intToEntry(2, key);
status = cursor.getSearchKeyRange(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(3, IntegerBinding.entryToInt(key));
cursor.close();
readerTxn.commit();
closeEnv();
}