本文整理匯總了Java中com.sleepycat.je.Cursor.getPrev方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getPrev方法的具體用法?Java Cursor.getPrev怎麽用?Java Cursor.getPrev使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Cursor
的用法示例。
在下文中一共展示了Cursor.getPrev方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: examineGTEBucket
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Find a bucket that is GTE the target, and sees if that bucket is
* the owner. If it is not the owner look at the previous bucket.
* @return null if no GTE bucket was found.
*/
private VLSNBucket examineGTEBucket(VLSN target, Cursor cursor) {
/* getSearchKeyRange will return a bucket >= target if one exists */
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
LongBinding.longToEntry(target.getSequence(), key);
OperationStatus status =
cursor.getSearchKeyRange(key, data, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
VLSNBucket bucket = VLSNBucket.readFromDatabase(data);
if (bucket.owns(target)) {
return bucket;
}
/*
* The bucket we found is > than our target. Look at the
* previous one.
*/
status = cursor.getPrev(key, data, LockMode.DEFAULT);
if (isValidBucket(status, key)) {
VLSNBucket prevBucket = VLSNBucket.readFromDatabase(data);
if (prevBucket.owns(target)) {
return prevBucket;
}
}
/*
* There is no bucket that owns this target, return the greater
* one.
*/
return bucket;
}
/* No bucket at a key >= the target. */
return null;
}
示例2: positionBeforeOrEqual
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private boolean positionBeforeOrEqual(Cursor cursor,
VLSN vlsn,
DatabaseEntry key,
DatabaseEntry data)
throws DatabaseException {
LongBinding.longToEntry(vlsn.getSequence(), key);
VLSNBucket bucket = null;
/* getSearchKeyRange will give us a bucket >= Y. */
OperationStatus status =
cursor.getSearchKeyRange(key, data, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
bucket = VLSNBucket.readFromDatabase(data);
if (bucket.owns(vlsn)) {
return true;
}
/* The bucket we found is > than our VLSN. Get the previous one. */
status = cursor.getPrev(key, data, LockMode.DEFAULT);
if (isValidBucket(status, key)) {
return true;
}
/* Hey, nothing else in the database. */
return false;
}
/*
* There was no bucket >= Y. Let's find the last bucket in this
* database then. It should be a bucket that's < Y.
*/
status = cursor.getLast(key, data, LockMode.DEFAULT);
if (isValidBucket(status, key)) {
return true;
}
return false;
}
示例3: testGetPrev_Success
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetPrev_Success()
throws DatabaseException, InterruptedException {
openEnv(false);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert key 1 and 3. */
insert(1);
insert(3);
/* getPrev returns key 1. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 3));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
/* Insertions before current position are never blocked. */
try {
insert(0);
} catch (DeadlockException e) {
fail();
}
/* Insert key 2 in a writer thread. */
startInsert(2);
/*
* If serializable, getPrev should return key 1 again; otherwise
* getPrev should see key 2.
*/
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 3));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
if (txnSerializable) {
assertEquals(1, IntegerBinding.entryToInt(key));
} else {
assertEquals(2, IntegerBinding.entryToInt(key));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getPrev returns key 2. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 3));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(2, IntegerBinding.entryToInt(key));
cursor.close();
readerTxn.commit();
closeEnv();
}
示例4: testGetPrev_Success_Dup
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetPrev_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);
/* getPrev returns {1,1}. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrev(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, getPrev should return {1,1} again; otherwise
* getPrev should see {1,2}.
*/
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrev(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();
/* getPrev returns {1,2}. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 1, 3));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
assertEquals(2, IntegerBinding.entryToInt(data));
cursor.close();
readerTxn.commit();
closeEnv();
}
示例5: testGetPrev_NotFound
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetPrev_NotFound()
throws DatabaseException, InterruptedException {
openEnv(false);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert key 2. */
insert(2);
/* getPrev returns NOTFOUND. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 2));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.NOTFOUND, status);
/* Insert key 1 in a writer thread. */
startInsert(1);
/*
* If serializable, getPrev should return NOTFOUND again; otherwise
* getPrev should see key 1.
*/
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 2));
status = cursor.getPrev(key, data, null);
if (txnSerializable) {
assertEquals(OperationStatus.NOTFOUND, status);
} else {
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getPrev returns key 1. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchKey(cursor, 2));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, IntegerBinding.entryToInt(key));
cursor.close();
readerTxn.commit();
closeEnv();
}
示例6: testGetPrev_NotFound_Dup
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void testGetPrev_NotFound_Dup()
throws DatabaseException, InterruptedException {
openEnv(true);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
/* Insert dups. */
insert(2, 2);
insert(2, 3);
/* getPrev returns NOTFOUND. */
Transaction readerTxn = env.beginTransaction(null, txnConfig);
Cursor cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.NOTFOUND, status);
/* Insert {2,1} in a writer thread. */
startInsert(2, 1);
/*
* If serializable, getPrev should return NOTFOUND again; otherwise
* getPrev should see {2,1}.
*/
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrev(key, data, null);
if (txnSerializable) {
assertEquals(OperationStatus.NOTFOUND, status);
} else {
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(2, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
}
/* Close reader to allow writer to finish. */
cursor.close();
readerTxn.commitNoSync();
waitForInsert();
/* getPrev returns {2,1}. */
readerTxn = env.beginTransaction(null, txnConfig);
cursor = db.openCursor(readerTxn, null);
assertEquals(OperationStatus.SUCCESS, searchBoth(cursor, 2, 2));
status = cursor.getPrev(key, data, null);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(2, IntegerBinding.entryToInt(key));
assertEquals(1, IntegerBinding.entryToInt(data));
cursor.close();
readerTxn.commit();
closeEnv();
}