Java Code Examples for com.sleepycat.je.Cursor#getSearchKey()

The following examples show how to use com.sleepycat.je.Cursor#getSearchKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: DefaultIndexImpl.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: DefaultIndexImpl.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
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)
			{
			}
		}
	}
}
 
Example 4
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 5
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
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)
		{
		}
	}
}