本文整理了Java中com.sleepycat.je.Cursor.getSearchKey()
方法的一些代码示例,展示了Cursor.getSearchKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cursor.getSearchKey()
方法的具体详情如下:
包路径:com.sleepycat.je.Cursor
类名称:Cursor
方法名:getSearchKey
[英]Moves the cursor to the given key of the database, and returns the datum associated with the given key. If the matching key has duplicate values, the first data item in the set of duplicates is returned.
Calling this method is equivalent to calling #get(DatabaseEntry,DatabaseEntry,Get,ReadOptions) with Get#SEARCH.
[中]将光标移动到数据库的给定键,并返回与给定键关联的数据。如果匹配项具有重复值,则返回重复项集中的第一个数据项。
调用此方法相当于使用get#SEARCH调用#get(DatabaseEntry、DatabaseEntry、get、ReadOptions)。
代码示例来源:origin: internetarchive/heritrix3
protected OperationStatus getNextNearestItem(DatabaseEntry headKey,
DatabaseEntry result) throws DatabaseException {
Cursor cursor = null;
OperationStatus status;
try {
cursor = this.pendingUrisDB.openCursor(null, null);
// get cap; headKey at this point should always point to
// a queue-beginning cap entry (zero-length value)
status = cursor.getSearchKey(headKey, result, null);
if (status != OperationStatus.SUCCESS) {
LOGGER.severe("bdb queue cap missing: "
+ status.toString() + " " + new String(headKey.getData()));
return status;
}
if (result.getData().length > 0) {
LOGGER.severe("bdb queue has nonzero size: "
+ result.getData().length);
return OperationStatus.KEYEXIST;
}
// get next item (real first item of queue)
status = cursor.getNext(headKey,result,null);
} finally {
if(cursor!=null) {
cursor.close();
}
}
return status;
}
代码示例来源:origin: internetarchive/heritrix3
try {
cursor = pendingUrisDB.openCursor(null,null);
result = cursor.getSearchKey(key, value, null);
代码示例来源:origin: yasserg/crawler4j
public boolean removeURL(WebURL webUrl) {
synchronized (mutex) {
DatabaseEntry key = getDatabaseEntryKey(webUrl);
DatabaseEntry value = new DatabaseEntry();
Transaction txn = beginTransaction();
try (Cursor cursor = openCursor(txn)) {
OperationStatus result = cursor.getSearchKey(key, value, null);
if (result == OperationStatus.SUCCESS) {
result = cursor.delete();
if (result == OperationStatus.SUCCESS) {
return true;
}
}
} finally {
commit(txn);
}
}
return false;
}
}
代码示例来源:origin: opensourceBIM/BIMserver
@Override
public List<byte[]> getDuplicates(String tableName, byte[] keyBytes, DatabaseSession databaseSession) throws BimserverDatabaseException {
DatabaseEntry key = new DatabaseEntry(keyBytes);
DatabaseEntry value = new DatabaseEntry();
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
Cursor cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
try {
OperationStatus operationStatus = cursor.getSearchKey(key, value, LockMode.DEFAULT);
List<byte[]> result = new ArrayList<byte[]>();
while (operationStatus == OperationStatus.SUCCESS) {
result.add(value.getData());
operationStatus = cursor.getNextDup(key, value, LockMode.DEFAULT);
}
return result;
} finally {
cursor.close();
}
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
代码示例来源:origin: com.sleepycat/je
/**
* Reads persistent fields from the sequence record. Returns false if the
* key is not present in the database.
*/
private boolean readData(Cursor cursor, LockMode lockMode)
throws DatabaseException {
/* Fetch the sequence record. */
DatabaseEntry data = new DatabaseEntry();
OperationStatus status = cursor.getSearchKey(key, data, lockMode);
if (status != OperationStatus.SUCCESS) {
return false;
}
ByteBuffer buf = ByteBuffer.wrap(data.getData());
/* Get the persistent fields from the record data. */
byte version = buf.get();
byte flags = buf.get();
boolean unpacked = (version < 1);
rangeMin = LogUtils.readLong(buf, unpacked);
rangeMax = LogUtils.readLong(buf, unpacked);
storedValue = LogUtils.readLong(buf, unpacked);
increment = (flags & FLAG_INCR) != 0;
wrapAllowed = (flags & FLAG_WRAP) != 0;
overflow = (flags & FLAG_OVER) != 0;
return true;
}
代码示例来源:origin: com.sleepycat/je
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;
}
}
}
代码示例来源:origin: org.archive.heritrix/heritrix-engine
protected OperationStatus getNextNearestItem(DatabaseEntry headKey,
DatabaseEntry result) throws DatabaseException {
Cursor cursor = null;
OperationStatus status;
try {
cursor = this.pendingUrisDB.openCursor(null, null);
// get cap; headKey at this point should always point to
// a queue-beginning cap entry (zero-length value)
status = cursor.getSearchKey(headKey, result, null);
if (status != OperationStatus.SUCCESS) {
LOGGER.severe("bdb queue cap missing: "
+ status.toString() + " " + new String(headKey.getData()));
return status;
}
if (result.getData().length > 0) {
LOGGER.severe("bdb queue has nonzero size: "
+ result.getData().length);
return OperationStatus.KEYEXIST;
}
// get next item (real first item of queue)
status = cursor.getNext(headKey,result,null);
} finally {
if(cursor!=null) {
cursor.close();
}
}
return status;
}
代码示例来源:origin: HuygensING/timbuctoo
public void replace(KeyT key, ValueT initialValue, Function<ValueT, ValueT> replacer) throws DatabaseWriteException {
synchronized (keyEntry) {
try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
keyBinder.objectToEntry(key, keyEntry);
OperationStatus searchResult = cursor.getSearchKey(keyEntry, valueEntry, LockMode.DEFAULT);
ValueT newValue = initialValue;
if (searchResult.equals(OperationStatus.SUCCESS)) {
newValue = replacer.apply(valueBinder.entryToObject(valueEntry));
}
valueBinder.objectToEntry(newValue, valueEntry);
cursor.putCurrent(valueEntry);
} catch (Exception e) {
throw new DatabaseWriteException(e);
}
}
}
代码示例来源:origin: net.sourceforge.ondex.core/berkeley
@Override
public int size() {
Cursor c = berkeley.openSecondaryCursor(proxyObject, null, clazz, cc);
DatabaseEntry theData = new DatabaseEntry();
// TODO: this is a very slow but robust way to get the size
int size = 0;
OperationStatus retVal = c.getSearchKey(theKey, theData,
LockMode.DEFAULT);
if (retVal == OperationStatus.SUCCESS && c.count() > 0) {
while (retVal == OperationStatus.SUCCESS) {
retVal = c.getNextDup(theKey, theData, LockMode.DEFAULT);
size++;
}
}
berkeley.releaseCursor(proxyObject);
return size;
}
代码示例来源:origin: net.sourceforge.ondex.core/berkeley
@Override
public int size() {
if (size == null) {
CursorConfig cc = new CursorConfig();
cc.setReadUncommitted(true);
Cursor c = berkeley.openDupCursor(proxyObject, null, clazz, cc);
if (c.getSearchKey(theKey, new DatabaseEntry(), LockMode.DEFAULT) != OperationStatus.SUCCESS) {
size = 0;
} else {
size = c.count();
}
berkeley.releaseCursor(c);
}
return size;
}
代码示例来源:origin: org.jboss.cache/jbosscache-core
status = cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
if (status == OperationStatus.SUCCESS)
代码示例来源:origin: org.jboss.cache/jbosscache-core
/**
* Internal version of remove(String,Object) that allows passing a
* transaction.
*/
private Object doRemove(Transaction txn, Fqn name, Object key)
throws Exception
{
Object oldVal = null;
DatabaseEntry keyEntry = makeKeyEntry(name);
DatabaseEntry foundData = new DatabaseEntry();
Cursor cursor = cacheDb.openCursor(txn, null);
try
{
OperationStatus status =
cursor.getSearchKey(keyEntry, foundData, LockMode.RMW);
if (status == OperationStatus.SUCCESS)
{
Map map = makeDataObject(foundData);
oldVal = map.remove(key);
cursor.putCurrent(makeDataEntry(map));
}
}
finally
{
cursor.close();
}
return oldVal;
}
代码示例来源:origin: com.sleepycat/je
private RepGroupImpl fetchGroupObject(final Txn txn,
final DatabaseImpl groupDbImpl,
final LockMode lockMode)
throws DatabaseException {
RepGroupDB.GroupBinding groupBinding = new RepGroupDB.GroupBinding();
DatabaseEntry groupEntry = new DatabaseEntry();
Cursor cursor = null;
try {
cursor = makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
final OperationStatus status =
cursor.getSearchKey(groupKeyEntry, groupEntry, lockMode);
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);
}
代码示例来源:origin: edu.uci.ics/crawler4j
public boolean removeURL(WebURL webUrl) {
synchronized (mutex) {
DatabaseEntry key = getDatabaseEntryKey(webUrl);
DatabaseEntry value = new DatabaseEntry();
Transaction txn = beginTransaction();
try (Cursor cursor = openCursor(txn)) {
OperationStatus result = cursor.getSearchKey(key, value, null);
if (result == OperationStatus.SUCCESS) {
result = cursor.delete();
if (result == OperationStatus.SUCCESS) {
return true;
}
}
} finally {
commit(txn);
}
}
return false;
}
}
代码示例来源:origin: addthis/hydra
/**
* internal/raw bdb delete
*/
@Override public byte[] delete(byte[] key) throws DatabaseException {
DatabaseEntry dk = new DatabaseEntry(key);
DatabaseEntry dv = new DatabaseEntry();
dv.setPartial(0, 0, true);
Cursor cursor = bdb.openCursor(null, CursorConfig.READ_UNCOMMITTED);
try {
if (cursor.getSearchKey(dk, dv, lockMode) == opSuccess && cursor.delete() == opSuccess && cursor.getPrev(dk, dv, lockMode) == opSuccess) {
return dk.getData();
}
} finally {
cursor.close();
}
return null;
}
代码示例来源:origin: addthis/hydra
/**
* internal/raw bdb delete
*/
@Override public byte[] delete(byte[] key) throws DatabaseException {
DatabaseEntry dk = new DatabaseEntry(key);
DatabaseEntry dv = new DatabaseEntry();
dv.setPartial(0, 0, true);
Cursor cursor = bdb.openCursor(null, cursorConfig);
try {
if (cursor.getSearchKey(dk, dv, lockMode) == opSuccess &&
cursor.delete() == opSuccess && cursor.getPrev(dk, dv, lockMode) == opSuccess) {
return dk.getData();
}
} finally {
cursor.close();
}
return null;
}
代码示例来源:origin: org.jboss.cache/jbosscache-core
/**
* Internal version of removeData(Fqn) that allows passing a transaction.
*/
private void doRemoveData(Transaction txn, Fqn name)
throws Exception
{
DatabaseEntry dataEntry = new DatabaseEntry();
dataEntry.setPartial(0, 0, true);
DatabaseEntry keyEntry = makeKeyEntry(name);
Cursor cursor = cacheDb.openCursor(txn, null);
try
{
OperationStatus status =
cursor.getSearchKey(keyEntry, dataEntry, LockMode.RMW);
if (status == OperationStatus.SUCCESS)
{
cursor.putCurrent(makeDataEntry(null));
}
}
finally
{
cursor.close();
}
}
代码示例来源:origin: HuygensING/timbuctoo
public boolean put(KeyT key, ValueT value) throws DatabaseWriteException {
synchronized (keyEntry) {
try {
keyBinder.objectToEntry(key, keyEntry);
if (databaseConfig.getSortedDuplicates()) {
valueBinder.objectToEntry(value, valueEntry);
OperationStatus operationStatus = database.putNoDupData(transaction, keyEntry, valueEntry);
// operation status is only SUCCESS if the data was not in the database before
return operationStatus.equals(OperationStatus.SUCCESS);
} else {
try (Cursor cursor = database.openCursor(transaction, CursorConfig.DEFAULT)) {
OperationStatus searchResult = cursor.getSearchKey(keyEntry, valueEntry, LockMode.DEFAULT);
if (searchResult == SUCCESS && Objects.equals(value, valueBinder.entryToObject(valueEntry))) {
return false;
} else {
valueBinder.objectToEntry(value, valueEntry);
database.put(transaction, keyEntry, valueEntry); // returns OperationStatus.SUCCESS or throws an exception
return true;
}
}
}
} catch (Exception e) {
throw new DatabaseWriteException(e);
}
}
}
代码示例来源:origin: com.sleepycat/je
/** Override phase 2 to delete the node entry if delete is true. */
@Override
void phase2Body() {
if (!delete) {
super.phase2Body();
return;
}
final DatabaseEntry nodeNameKey = new DatabaseEntry();
StringBinding.stringToEntry(removeNode.getName(), nodeNameKey);
final Cursor cursor =
makeCursor(groupDbImpl, txn, CursorConfig.DEFAULT);
try {
final OperationStatus status = cursor.getSearchKey(
nodeNameKey, new DatabaseEntry(), LockMode.RMW);
if (status != OperationStatus.SUCCESS) {
throw EnvironmentFailureException.unexpectedState(
"Node ID: " + removeNode.getNameIdPair() +
" not present in group db");
}
cursor.delete();
} finally {
cursor.close();
}
}
};
代码示例来源:origin: itisaid/Doris
private Value get(Key key, LockMode lockMode) {
Cursor cursor = null;
try {
cursor = db.openCursor(null, null);
ByteWrapper keyBytes = serializerFactory.encode(key);
DatabaseEntry keyEntry = new DatabaseEntry(keyBytes.getBytes(), keyBytes.getStartPos(), keyBytes.getLen());
DatabaseEntry valueEntry = new DatabaseEntry();
OperationStatus status = cursor.getSearchKey(keyEntry, valueEntry, lockMode);
while (status == OperationStatus.SUCCESS) {
return serializerFactory.decodeValue(valueEntry.getData());
// status = cursor.getNextDup(keyEntry, valueEntry, lockMode);
}
return null;
} catch (DatabaseException e) {
throw new BDBStorageException(e);
} finally {
closeCursor(cursor);
}
}
内容来源于网络,如有侵权,请联系作者删除!