本文整理匯總了Java中com.sleepycat.je.Cursor.getSearchKey方法的典型用法代碼示例。如果您正苦於以下問題:Java Cursor.getSearchKey方法的具體用法?Java Cursor.getSearchKey怎麽用?Java Cursor.getSearchKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sleepycat.je.Cursor
的用法示例。
在下文中一共展示了Cursor.getSearchKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openCursor
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
Cursor openCursor(Transaction txn, CursorConfig config)
throws DatabaseException {
OperationStatus status;
Cursor cursor = db.openCursor(txn, config);
try {
DatabaseEntry data = BasicIndex.NO_RETURN_ENTRY;
status = cursor.getSearchKey(key, data, null);
} catch (DatabaseException e) {
try {
cursor.close();
} catch (DatabaseException ignored) {}
throw e;
}
if (status == OperationStatus.SUCCESS) {
return cursor;
} else {
cursor.close();
return null;
}
}
示例2: mergeDuplicateEntries
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public void mergeDuplicateEntries() {
try {
System.out.println("Starting to merge duplicate entries in the Database " + StringUtilities.now());
Cursor myCursor = conceptToConceptVectorIndexStore.openCursor(null, null);
DatabaseEntry searchKey = new DatabaseEntry();
DatabaseEntry foundData = new DatabaseEntry();
for (Integer key: indexedConceptsWithDuplicates) {
myIntegerBinding.objectToEntry(key, searchKey);
if (myCursor.getSearchKey(searchKey, foundData, null) == OperationStatus.SUCCESS) {
if (myCursor.count() > 1) {
ConceptToConceptVectorRecordIndexEntry entry = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
//OperationStatus status = myCursor.delete();
while (myCursor.getNextDup(searchKey, foundData, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
ConceptToConceptVectorRecordIndexEntry addition = (ConceptToConceptVectorRecordIndexEntry) myDataBinding.entryToObject(foundData);
entry.conceptVectorRecordIDs.addAll(addition.conceptVectorRecordIDs);
entry.sumOfValuesInRecords += addition.sumOfValuesInRecords;
myCursor.delete();
}
setEntryInStore(key, entry);
}
}
}
System.out.println("Done merging duplicate entries in the Database " + StringUtilities.now());
myCursor.close();
} catch (DatabaseException e) {
e.printStackTrace();
}
}
示例3: findFirst
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public ValueType findFirst(KeyType key)
{
checkOpen();
DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
DatabaseEntry value = new DatabaseEntry();
ValueType result = null;
Cursor cursor = null;
try
{
cursor = db.openCursor(txn().getBJETransaction(), cursorConfig);
OperationStatus status = cursor.getSearchKey(keyEntry, value, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS)
result = valueConverter.fromByteArray(value.getData(), value.getOffset(), value.getSize());
}
catch (Exception ex)
{
throw new HGException("Failed to lookup index '" + name + "': " + ex.toString(), ex);
}
finally
{
if (cursor != null)
{
try
{
cursor.close();
}
catch (Throwable t)
{
}
}
}
return result;
}
示例4: count
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public long count(KeyType key)
{
Cursor cursor = null;
try
{
cursor = db.openCursor(txn().getBJETransaction(), cursorConfig);
DatabaseEntry keyEntry = new DatabaseEntry(keyConverter.toByteArray(key));
DatabaseEntry value = new DatabaseEntry();
OperationStatus status = cursor.getSearchKey(keyEntry, value, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS)
return cursor.count();
else
return 0;
}
catch (DatabaseException ex)
{
throw new HGException(ex);
}
finally
{
if (cursor != null)
{
try
{
cursor.close();
}
catch (Throwable t)
{
}
}
}
}
示例5: getIncidenceResultSet
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public HGRandomAccessResult<HGPersistentHandle> getIncidenceResultSet(HGPersistentHandle handle)
{
if (handle == null)
throw new NullPointerException("HGStore.getIncidenceSet called with a null handle.");
Cursor cursor = null;
try
{
DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
DatabaseEntry value = new DatabaseEntry();
TransactionBJEImpl tx = txn();
cursor = incidence_db.openCursor(tx.getBJETransaction(), cursorConfig);
OperationStatus status = cursor.getSearchKey(key, value, LockMode.DEFAULT);
if (status == OperationStatus.NOTFOUND)
{
cursor.close();
return (HGRandomAccessResult<HGPersistentHandle>) HGSearchResult.EMPTY;
}
else
return new SingleKeyResultSet<HGPersistentHandle>(tx.attachCursor(cursor), key,
BAtoHandle.getInstance(handleFactory));
}
catch (Throwable ex)
{
if (cursor != null)
try
{
cursor.close();
}
catch (Throwable t)
{
}
throw new HGException("Failed to retrieve incidence set for handle " + handle + ": " + ex.toString(), ex);
}
}
示例6: getIncidenceSetCardinality
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
public long getIncidenceSetCardinality(HGPersistentHandle handle)
{
if (handle == null)
throw new NullPointerException("HGStore.getIncidenceSetCardinality called with a null handle.");
Cursor cursor = null;
try
{
DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
DatabaseEntry value = new DatabaseEntry();
cursor = incidence_db.openCursor(txn().getBJETransaction(), cursorConfig);
OperationStatus status = cursor.getSearchKey(key, value, LockMode.DEFAULT);
if (status == OperationStatus.NOTFOUND)
return 0;
else
return cursor.count();
}
catch (Exception ex)
{
throw new HGException("Failed to retrieve incidence set for handle " + handle + ": " + ex.toString(), ex);
}
finally
{
try
{
cursor.close();
}
catch (Throwable t)
{
}
}
}
示例7: searchKey
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Performs getSearchKey on the given key, expects given data value.
*/
private OperationStatus searchKey(Cursor cursor, int keyVal, int dataVal)
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
IntegerBinding.intToEntry(keyVal, key);
OperationStatus status = cursor.getSearchKey(key, data, null);
if (status == OperationStatus.SUCCESS) {
assertEquals(keyVal, IntegerBinding.entryToInt(key));
assertEquals(dataVal, IntegerBinding.entryToInt(data));
}
return status;
}
示例8: deleteData
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Deletes the specified keys.
*/
private void deleteData(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);
} else {
key.setData(TestUtils.getTestArray(nextKey));
status = cursor.getSearchKey(key, data, null);
}
assertEquals(OperationStatus.SUCCESS, status);
status = cursor.delete();
assertEquals(OperationStatus.SUCCESS, status);
existingKeys.remove(new Integer(nextKey));
}
cursor.close();
txn.commit();
}
示例9: fetchGroupObject
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private RepGroupImpl fetchGroupObject(Txn txn,
DatabaseImpl groupDbImpl)
throws DatabaseException {
RepGroupDB.GroupBinding groupBinding = new RepGroupDB.GroupBinding();
DatabaseEntry groupEntry = new DatabaseEntry();
Cursor cursor = null;
try {
cursor = makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
OperationStatus status = cursor.getSearchKey(groupKeyEntry,
groupEntry,
LockMode.RMW);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState
("Group entry key: " + GROUP_KEY +
" missing from group database");
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return groupBinding.entryToObject(groupEntry);
}
示例10: updateData
import com.sleepycat.je.Cursor; //導入方法依賴的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();
}
示例11: verifyData
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Verifies that the data written by writeData can be read.
*/
private void verifyData()
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
for (Iterator i = existingKeys.iterator(); i.hasNext();) {
int nextKey = ((Integer) i.next()).intValue();
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());
}
}
cursor.close();
txn.commit();
}
示例12: runNoOverwriteWithDuplicates
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* The old putNoOverwrite() inserted a duplicate after a search returned
* NOTFOUND, when duplicates were configured. This test tries to create
* the situation where the second thread inserting with a given key inserts
* a duplicate, which should never happen since we're using
* putNoOverwrite().
*/
public void runNoOverwriteWithDuplicates()
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
while (nextKey < MAX_KEY) {
/*
* Attempt to insert a duplicate for the same key as was just
* inserted by the other thread. Each thread uses a different data
* value (modulo 2) so to avoid a duplicate-duplicate, which would
* not be inserted.
*/
int val = nextKey++;
int keyVal = val / 2;
int dataVal = val % 2;
key.setData(TestUtils.getTestArray(keyVal));
data.setData(TestUtils.getTestArray(dataVal));
while (true) {
Transaction txn = txnBegin();
boolean commit = true;
try {
db.putNoOverwrite(txn, key, data);
} catch (DeadlockException DE) {
commit = false;
}
if (commit) {
txnCommit(txn);
break;
} else {
txnAbort(txn);
}
}
Cursor cursor = db.openCursor(null, null);
try {
OperationStatus status = cursor.getSearchKey(key, data,
LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals(1, cursor.count());
} finally {
cursor.close();
}
}
}
示例13: evolveIndex
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
private void evolveIndex(Format format,
EvolveEvent event,
EvolveListener listener)
throws DatabaseException {
Class entityClass = format.getType();
String entityClassName = format.getClassName();
EntityMetadata meta = model.getEntityMetadata(entityClassName);
String keyClassName = meta.getPrimaryKey().getClassName();
keyClassName = SimpleCatalog.keyClassName(keyClassName);
DatabaseConfig dbConfig = getPrimaryConfig(meta);
PrimaryIndex<Object,Object> index = getPrimaryIndex
(Object.class, keyClassName, entityClass, entityClassName);
Database db = index.getDatabase();
EntityBinding binding = index.getEntityBinding();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
Cursor readCursor = db.openCursor(null, CursorConfig.READ_UNCOMMITTED);
try {
while (readCursor.getNext(key, data, null) ==
OperationStatus.SUCCESS) {
if (evolveNeeded(key, data, binding)) {
Transaction txn = null;
if (dbConfig.getTransactional()) {
boolean success = false;
txn = env.beginTransaction(null, null);
}
boolean written = false;
Cursor writeCursor = null;
try {
writeCursor = db.openCursor(txn, null);
if (writeCursor.getSearchKey
(key, data, LockMode.RMW) ==
OperationStatus.SUCCESS) {
if (evolveNeeded(key, data, binding)) {
writeCursor.putCurrent(data);
written = true;
}
if (listener != null) {
EvolveInternal.updateEvent
(event, entityClassName, 1,
written ? 1 : 0);
if (!listener.evolveProgress(event)) {
break;
}
}
}
} finally {
if (writeCursor != null) {
writeCursor.close();
}
if (txn != null) {
if (written) {
txn.commit();
} else {
txn.abort();
}
}
}
}
}
} finally {
readCursor.close();
}
}
示例14: testRetry
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
/**
* Test retries after cleaning fails because an LN was write-locked.
*/
public void testRetry()
throws DatabaseException {
openEnv(highUtilizationConfig);
writeData();
verifyData();
/*
* The first file is full of LNs. Delete all but the last record to
* cause it to be selected next for cleaning.
*/
int firstKey = ((Integer) firstKeysInFiles.get(1)).intValue();
int nextKey = ((Integer) firstKeysInFiles.get(2)).intValue();
int count = nextKey - firstKey - 1;
deleteData(firstKey, count);
verifyData();
/* Write-lock the last record to cause cleaning to fail. */
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
OperationStatus status;
if (dups) {
key.setData(MAIN_KEY_FOR_DUPS);
data.setData(TestUtils.getTestArray(nextKey - 1));
status = cursor.getSearchBoth(key, data, LockMode.RMW);
} else {
key.setData(TestUtils.getTestArray(nextKey - 1));
status = cursor.getSearchKey(key, data, LockMode.RMW);
}
assertEquals(OperationStatus.SUCCESS, status);
status = cursor.delete();
assertEquals(OperationStatus.SUCCESS, status);
/* Cleaning should fail. */
forceCleanOne();
verifyDeletedFiles(null);
forceCleanOne();
verifyDeletedFiles(null);
/* Release the write-lock. */
cursor.close();
txn.abort();
verifyData();
/* Cleaning should succeed, with all files deleted. */
forceCleanOne();
verifyDeletedFiles(new int[] {0, 1, 2});
verifyData();
closeEnv();
}
示例15: VLSNTracker
import com.sleepycat.je.Cursor; //導入方法依賴的package包/類
VLSNTracker(EnvironmentImpl envImpl,
DatabaseImpl mappingDbImpl,
int stride,
int maxMappings,
int maxDistance,
StatGroup statistics)
throws DatabaseException {
this.stride = stride;
this.maxMappings = maxMappings;
this.maxDistance = maxDistance;
this.envImpl = envImpl;
nBucketsCreated =
new LongStat(statistics, VLSNIndexStatDefinition.N_BUCKETS_CREATED);
bucketCache = new TreeMap<Long, VLSNBucket>();
/* Read the current range information. */
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
LongBinding.longToEntry(VLSNRange.RANGE_KEY, key);
Cursor cursor = null;
Locker locker = null;
try {
locker = BasicLocker.createBasicLocker(envImpl);
cursor = DbInternal.makeCursor(mappingDbImpl,
locker,
CursorConfig.DEFAULT);
DbInternal.getCursorImpl(cursor).setAllowEviction(false);
OperationStatus status = cursor.getSearchKey(key, data,
LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
/* initialize the range from the database. */
VLSNRangeBinding rangeBinding = new VLSNRangeBinding();
range = rangeBinding.entryToObject(data);
lastOnDiskVLSN = range.getLast();
} else if (status == OperationStatus.NOTFOUND) {
/* No mappings exist before. */
range = VLSNRange.EMPTY;
} else {
throw EnvironmentFailureException.unexpectedState
("VLSNTracker init: status=" + status);
}
} finally {
if (cursor != null) {
cursor.close();
}
if (locker != null) {
locker.operationEnd(true);
}
}
}