Java Code Examples for com.sleepycat.je.DatabaseEntry#setData()
The following examples show how to use
com.sleepycat.je.DatabaseEntry#setData() .
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 |
@Override public void objectToEntry(StorableMessageMetaData metaData, DatabaseEntry entry) { final int bodySize = 1 + metaData.getStorableSize(); byte[] underlying = new byte[4+bodySize]; underlying[4] = (byte) metaData.getType().ordinal(); try (QpidByteBuffer buf = QpidByteBuffer.wrap(underlying)) { buf.putInt(bodySize ^ 0x80000000); buf.position(5); try (QpidByteBuffer bufSlice = buf.slice()) { metaData.writeToBuffer(bufSlice); } } entry.setData(underlying); }
Example 2
Source File: JE_Table.java From tddl5 with Apache License 2.0 | 6 votes |
@Override public CloneableRecord get(ExecutionContext context, CloneableRecord key, IndexMeta indexMeta, String dbName) { DatabaseEntry keyEntry = new DatabaseEntry(); DatabaseEntry valueEntry = new DatabaseEntry(); keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key)); OperationStatus status = getDatabase(dbName).get(context.getTransaction() == null ? null : ((JE_Transaction) context.getTransaction()).txn, keyEntry, valueEntry, LockMode.DEFAULT); if (OperationStatus.SUCCESS != status) { return null; } if (valueEntry.getSize() != 0) { return indexCodecMap.get(indexMeta.getName()).getValue_codec().decode(valueEntry.getData()); } else { return null; } }
Example 3
Source File: JE_Table.java From tddl with Apache License 2.0 | 6 votes |
@Override public CloneableRecord get(ExecutionContext context, CloneableRecord key, IndexMeta indexMeta, String dbName) { DatabaseEntry keyEntry = new DatabaseEntry(); DatabaseEntry valueEntry = new DatabaseEntry(); keyEntry.setData(indexCodecMap.get(indexMeta.getName()).getKey_codec().encode(key)); OperationStatus status = getDatabase(dbName).get(context.getTransaction() == null ? null : ((JE_Transaction) context.getTransaction()).txn, keyEntry, valueEntry, LockMode.DEFAULT); if (OperationStatus.SUCCESS != status) { return null; } if (valueEntry.getSize() != 0) { return indexCodecMap.get(indexMeta.getName()).getValue_codec().decode(valueEntry.getData()); } else { return null; } }
Example 4
Source File: AbstractBDBMessageStore.java From qpid-broker-j with Apache License 2.0 | 5 votes |
/** * Stores a chunk of message data. * * @param tx The transaction for the operation. * @param messageId The message to store the data for. * @param contentBody The content of the data chunk. * * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist. */ private void addContent(final Transaction tx, long messageId, QpidByteBuffer contentBody) throws StoreException { DatabaseEntry key = new DatabaseEntry(); LongBinding.longToEntry(messageId, key); DatabaseEntry value = new DatabaseEntry(); byte[] data = new byte[contentBody.remaining()]; contentBody.copyTo(data); value.setData(data); try { OperationStatus status = getMessageContentDb().put(tx, key, value); if (status != OperationStatus.SUCCESS) { throw new StoreException("Error adding content for message id " + messageId + ": " + status); } getLogger().debug("Storing content for message {} in transaction {}", messageId, tx); } catch (RuntimeException e) { throw getEnvironmentFacade().handleDatabaseException("Error writing AMQMessage with id " + messageId + " to database: " + e.getMessage(), e); } }
Example 5
Source File: AbstractBDBMessageStore.java From qpid-broker-j with Apache License 2.0 | 5 votes |
/** * Places a message onto a specified queue, in a given transaction. * * @param tx The transaction for the operation. * @param queue The the queue to place the message on. * @param messageId The message to enqueue. * * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason. */ private void enqueueMessage(final Transaction tx, final TransactionLogResource queue, long messageId) throws StoreException { DatabaseEntry key = new DatabaseEntry(); QueueEntryKey queueEntryKey = new QueueEntryKey(queue.getId(), messageId); QueueEntryBinding.objectToEntry(queueEntryKey, key); DatabaseEntry value = new DatabaseEntry(); value.setData(ENQUEUE_RECORD_VALUE, 0, ENQUEUE_RECORD_VALUE.length); try { if (getLogger().isDebugEnabled()) { getLogger().debug("Enqueuing message {} on queue {} with id {} in transaction {}", messageId, queue.getName(), queue.getId(), tx); } getDeliveryDb().put(tx, key, value); } catch (RuntimeException e) { if (getLogger().isDebugEnabled()) { getLogger().debug("Failed to enqueue: {}", e.getMessage(), e); } throw getEnvironmentFacade().handleDatabaseException("Error writing enqueued message with id " + messageId + " for queue " + queue.getName() + " with id " + queue.getId() + " to database", e); } }
Example 6
Source File: QueueEntryBinding.java From qpid-broker-j with Apache License 2.0 | 5 votes |
public static void objectToEntry(QueueEntryKey entryKey, DatabaseEntry entry) { byte[] output = new byte[24]; UUID uuid = entryKey.getQueueId(); writeUnsignedLong(uuid.getMostSignificantBits() ^ 0x8000000000000000L, output, 0); writeUnsignedLong(uuid.getLeastSignificantBits() ^ 0x8000000000000000L, output, 8); writeUnsignedLong(entryKey.getMessageId() ^ 0x8000000000000000L, output, 16); entry.setData(output); }
Example 7
Source File: BerkeleyDBStore.java From hypergraphdb with Apache License 2.0 | 5 votes |
private DatabaseEntry objectToEntry(Object object) throws Exception { //byte[] bb = KryoSerializer.write(object); // #+# outcommented: What's KryoSerializer? byte[] bb = kryoserializer.serialize(object); // #+# ADDED DatabaseEntry entry = new DatabaseEntry(); entry.setData(bb); return entry; }
Example 8
Source File: TestKDTreeSplit.java From bboxdb with Apache License 2.0 | 4 votes |
/** * Handle the next bounding box * @param maxRegionSize * @param tuple */ private void insertNextBoundingBox(final Hyperrectangle boundingBox, final int maxRegionSize) { // Create first entry if(elements.isEmpty()) { dataDimension = boundingBox.getDimension(); final Hyperrectangle coveringBoundingBox = Hyperrectangle.createFullCoveringDimensionBoundingBox(dataDimension); final Database database = buildNewDatabase(); elements.put(coveringBoundingBox, database); boxDimension.put(coveringBoundingBox, 0); } // Bounding box db entry final DatabaseEntry key = new DatabaseEntry(); key.setData(Long.toString(System.nanoTime()).getBytes()); final DatabaseEntry value = new DatabaseEntry(); value.setData(boundingBox.toByteArray()); // Add element to all needed bounding boxes elements.entrySet() .stream() .filter(e -> e.getKey().intersects(boundingBox)) .forEach(e -> { elementCounter.computeIfAbsent(e.getKey(), l -> new AtomicLong(0)).incrementAndGet(); e.getValue().put(null, key, value); }); // Split and remove full boxes final List<Hyperrectangle> boxesToSplit = elementCounter.entrySet() .stream() .filter(e -> e.getValue().get() >= maxRegionSize) .map(e -> e.getKey()) .collect(Collectors.toList()); // Split region boxesToSplit.forEach(e -> splitRegion(e)); // Remove split regions elements.entrySet().removeIf(e -> boxesToSplit.contains(e.getKey())); elementCounter.entrySet().removeIf(e -> boxesToSplit.contains(e.getKey())); }
Example 9
Source File: PlainSecondaryKeyCreator.java From hypergraphdb with Apache License 2.0 | 4 votes |
public boolean createSecondaryKey(SecondaryDatabase secondary, DatabaseEntry key, DatabaseEntry data, DatabaseEntry result) throws DatabaseException { result.setData(data.getData()); return true; }
Example 10
Source File: IndexResultSet.java From hypergraphdb with Apache License 2.0 | 3 votes |
/** * * <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); }