Java Code Examples for com.sleepycat.je.DatabaseEntry#getData()

The following examples show how to use com.sleepycat.je.DatabaseEntry#getData() . 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: MessageMetaDataBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public StorableMessageMetaData entryToObject(DatabaseEntry entry)
{
    try(DataInputStream stream = new DataInputStream(new ByteArrayInputStream(entry.getData(),
                                                                              entry.getOffset(),
                                                                              entry.getSize())))
    {
        final int bodySize = stream.readInt() ^ 0x80000000;
        final int metaDataType = stream.readByte() & 0xff;
        MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(metaDataType);

        try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream))
        {
            return type.createMetaData(buf);
        }
    }
    catch (IOException | RuntimeException e)
    {
        throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
    }
}
 
Example 2
Source File: BerkeleyDB.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
@VisibleForTesting
public void readData(int limit)
{
    Cursor cursor = scaffoldDatabase.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    int i = 0;
    while(cursor.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS)
    {
        if(i >= limit)
            break;
        String keyString = new String(key.getData());
        System.out.println("hash: " + keyString);
        i++;
    }
    cursor.close();
}
 
Example 3
Source File: BJEStorageImplementation.java    From hypergraphdb with Apache License 2.0 6 votes vote down vote up
public byte[] getData(HGPersistentHandle handle)
{
	try
	{
		DatabaseEntry key = new DatabaseEntry(handle.toByteArray());
		DatabaseEntry value = new DatabaseEntry();
		if (primitive_db.get(txn().getBJETransaction(), key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)
			return value.getData();
		else
			return null;
	}
	catch (Exception ex)
	{
		throw new HGException("Failed to retrieve link with handle " + handle, ex);
	}
}
 
Example 4
Source File: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
QpidByteBuffer getAllContent(long messageId) throws StoreException
{
    DatabaseEntry contentKeyEntry = new DatabaseEntry();
    LongBinding.longToEntry(messageId, contentKeyEntry);
    DatabaseEntry value = new DatabaseEntry();

    getLogger().debug("Message Id: {} Getting content body", messageId);

    try
    {
        OperationStatus status = getMessageContentDb().get(null, contentKeyEntry, value, LockMode.READ_UNCOMMITTED);

        if (status == OperationStatus.SUCCESS)
        {
            byte[] data = value.getData();
            int offset = value.getOffset();
            int length = value.getSize();
            QpidByteBuffer buf = QpidByteBuffer.allocateDirect(length);
            buf.put(data, offset, length);
            buf.flip();
            return buf;
        }
        else
        {
            throw new StoreException("Unable to find message with id " + messageId);
        }

    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException("Error getting AMQMessage with id "
                                                             + messageId
                                                             + " to database: "
                                                             + e.getMessage(), e);
    }
}
 
Example 5
Source File: QueueEntryBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static QueueEntryKey entryToObject(final CachingUUIDFactory uuidFactory, DatabaseEntry entry)
{
    byte[] data = entry.getData();
    int offset = entry.getOffset();

    UUID queueId = uuidFactory.createUuidFromBits(readUnsignedLong(data, offset) ^ 0x8000000000000000L, readUnsignedLong(data, offset + 8) ^ 0x8000000000000000L);
    long messageId = readUnsignedLong(data,offset+16)^ 0x8000000000000000L;

    return new QueueEntryKey(queueId, messageId);
}
 
Example 6
Source File: BerkeleyDBHandle.java    From SPADE with GNU General Public License v3.0 5 votes vote down vote up
@Override
public byte[] get(byte[] key) throws Exception{
	DatabaseEntry keyEntry = new DatabaseEntry(key);
	DatabaseEntry valueEntry = new DatabaseEntry();
	OperationStatus status = database.get(null, keyEntry, valueEntry, LockMode.DEFAULT);
	switch(status){
		case SUCCESS: return valueEntry.getData();
		case NOTFOUND: return null;
		default: throw new Exception("Non-success status returned from BerkeleyDB: '"+status+"'");
	}
}
 
Example 7
Source File: BJETxLock.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public BJETxLock(HyperGraph graph, DatabaseEntry objectId) {
	this.graph = graph;
	this.objectId = new DatabaseEntry();
	byte[] tmp = new byte[objectId.getData().length];
	System.arraycopy(objectId.getData(), 0, tmp, 0, tmp.length);
	this.objectId = new DatabaseEntry(tmp);
}
 
Example 8
Source File: BerkeleyKeyValueStore.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public byte[] get(String tableName, byte[] keyBytes, DatabaseSession databaseSession) throws BimserverDatabaseException {
	DatabaseEntry key = new DatabaseEntry(keyBytes);
	DatabaseEntry value = new DatabaseEntry();
	try {
		TableWrapper tableWrapper = getTableWrapper(tableName);
		OperationStatus operationStatus = tableWrapper.getDatabase().get(getTransaction(databaseSession, tableWrapper), key, value, getLockMode(tableWrapper));
		if (operationStatus == OperationStatus.SUCCESS) {
			return value.getData();
		}
	} catch (DatabaseException e) {
		LOGGER.error("", e);
	}
	return null;
}
 
Example 9
Source File: FlumePersistentManager.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private SimpleEvent createEvent(final DatabaseEntry data) {
    final SimpleEvent event = new SimpleEvent();
    try {
        byte[] eventData = data.getData();
        if (secretKey != null) {
            final Cipher cipher = Cipher.getInstance("AES");
            cipher.init(Cipher.DECRYPT_MODE, secretKey);
            eventData = cipher.doFinal(eventData);
        }
        final ByteArrayInputStream bais = new ByteArrayInputStream(eventData);
        final DataInputStream dais = new DataInputStream(bais);
        int length = dais.readInt();
        final byte[] bytes = new byte[length];
        dais.read(bytes, 0, length);
        event.setBody(bytes);
        length = dais.readInt();
        final Map<String, String> map = new HashMap<>(length);
        for (int i = 0; i < length; ++i) {
            final String headerKey = dais.readUTF();
            final String value = dais.readUTF();
            map.put(headerKey, value);
        }
        event.setHeaders(map);
        return event;
    } catch (final Exception ex) {
        LOGGER.error("Error retrieving event", ex);
        return null;
    }
}
 
Example 10
Source File: BerkeleyDBUtils.java    From WebCollector with GNU General Public License v3.0 4 votes vote down vote up
public static CrawlDatum createCrawlDatum(DatabaseEntry key,DatabaseEntry value) throws Exception{
    String datumKey=new String(key.getData(),"utf-8");
    String valueStr=new String(value.getData(),"utf-8");
    JsonArray datumJsonArray = GsonUtils.parse(valueStr).getAsJsonArray();
    return CrawlDatum.fromJsonArray(datumKey, datumJsonArray);
}
 
Example 11
Source File: BerkeleyRecord.java    From BIMserver with GNU Affero General Public License v3.0 4 votes vote down vote up
public BerkeleyRecord(DatabaseEntry key, DatabaseEntry value) {
	this.key = key.getData();
	this.value = value.getData();
}
 
Example 12
Source File: IndexResultSet.java    From hypergraphdb with Apache License 2.0 3 votes vote down vote up
/**
 * 
 * <p>
 * Copy <code>data</code> into the <code>entry</code>. Adjust <code>entry</code>'s byte buffer if needed.
 * </p>
 * 
 * @param entry
 * @param data
 */
protected void assignData(DatabaseEntry entry, byte[] data) {
	byte[] dest = entry.getData();
	if (dest == null || dest.length != data.length) {
		dest = new byte[data.length];
		entry.setData(dest);
	}
	System.arraycopy(data, 0, dest, 0, data.length);
}