com.sleepycat.bind.tuple.TupleOutput Java Examples

The following examples show how to use com.sleepycat.bind.tuple.TupleOutput. 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: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private static void writeRecords(Transaction.EnqueueRecord[] records, TupleOutput output)
{
    if(records == null)
    {
        output.writeInt(0);
    }
    else
    {
        output.writeInt(records.length);
        for(Transaction.EnqueueRecord record : records)
        {
            UUID id = record.getResource().getId();
            output.writeLong(id.getMostSignificantBits());
            output.writeLong(id.getLeastSignificantBits());
            output.writeLong(record.getMessage().getMessageNumber());
        }
    }
}
 
Example #2
Source File: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private static void writeRecords(Transaction.DequeueRecord[] records, TupleOutput output)
{
    if(records == null)
    {
        output.writeInt(0);
    }
    else
    {
        output.writeInt(records.length);
        for(Transaction.DequeueRecord record : records)
        {
            UUID id = record.getEnqueueRecord().getQueueId();
            output.writeLong(id.getMostSignificantBits());
            output.writeLong(id.getLeastSignificantBits());
            output.writeLong(record.getEnqueueRecord().getMessageNumber());
        }
    }
}
 
Example #3
Source File: XidBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void objectToEntry(Xid xid, TupleOutput output)
{
    output.writeLong(xid.getFormat());
    output.writeInt(xid.getGlobalId() == null ? 0 : xid.getGlobalId().length);
    if(xid.getGlobalId() != null)
    {
        output.write(xid.getGlobalId());
    }
    output.writeInt(xid.getBranchId() == null ? 0 : xid.getBranchId().length);
    if(xid.getBranchId() != null)
    {
        output.write(xid.getBranchId());
    }

}
 
Example #4
Source File: ConfiguredObjectBinding.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Override
public void objectToEntry(ConfiguredObjectRecord object, TupleOutput tupleOutput)
{
    try
    {
        StringWriter writer = new StringWriter();
        final ObjectMapper objectMapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
        objectMapper.writeValue(writer, object.getAttributes());
        tupleOutput.writeString(object.getType());
        tupleOutput.writeString(writer.toString());
    }
    catch (IOException e)
    {
        throw new StoreException(e);
    }
}
 
Example #5
Source File: AbstractSearchStructure.java    From multimedia-indexing with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to set the geolocation of a previously indexed vector. If the geolocation is
 * already set, this method replaces it.
 * 
 * @param iid
 *            The internal id of the vector
 * @param latitude
 * @param longitude
 * @return true if geolocation is successfully set, false otherwise
 */
public boolean setGeolocation(int iid, double latitude, double longitude) {
	if (iid < 0 || iid > loadCounter) {
		System.out.println("Internal id " + iid + " is out of range!");
		return false;
	}
	DatabaseEntry key = new DatabaseEntry();
	DatabaseEntry data = new DatabaseEntry();

	IntegerBinding.intToEntry(iid, key);
	TupleOutput output = new TupleOutput();
	output.writeDouble(latitude);
	output.writeDouble(longitude);
	TupleBinding.outputToEntry(output, data);

	if (iidToGeolocationDB.put(null, key, data) == OperationStatus.SUCCESS) {
		return true;
	} else {
		return false;
	}
}
 
Example #6
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void writeRecords(OldRecordImpl[] records, TupleOutput output)
{
    if (records == null)
    {
        output.writeInt(0);
    }
    else
    {
        output.writeInt(records.length);
        for (OldRecordImpl record : records)
        {
            output.writeString(record.getQueueName());
            output.writeLong(record.getMessageNumber());
        }
    }
}
 
Example #7
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void writeRecords(NewRecordImpl[] records, TupleOutput output)
{
    if (records == null)
    {
        output.writeInt(0);
    }
    else
    {
        output.writeInt(records.length);
        for (NewRecordImpl record : records)
        {
            UUID id = record.getId();
            output.writeLong(id.getMostSignificantBits());
            output.writeLong(id.getLeastSignificantBits());
            output.writeLong(record.getMessageNumber());
        }
    }
}
 
Example #8
Source File: AMQShortStringEncoding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public  static void writeShortString(AMQShortString shortString, TupleOutput tupleOutput)
{

    if (shortString == null)
    {
        tupleOutput.writeShort(-1);
    }
    else
    {
        tupleOutput.writeShort(shortString.length());
        tupleOutput.writeFast(shortString.getBytes(), 0, shortString.length());
    }
}
 
Example #9
Source File: LinkKeyEntryBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(final LinkKey linkKey, final TupleOutput output)
{
    output.writeString(linkKey.getRemoteContainerId());
    output.writeString(linkKey.getLinkName());
    output.writeBoolean(linkKey.getRole().getValue());
}
 
Example #10
Source File: ByteBufferBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(QpidByteBuffer data, final TupleOutput output)
{
    try (QpidByteBuffer dup = data.duplicate())
    {
        byte[] copyBuf = COPY_BUFFER.get();
        while (dup.hasRemaining())
        {
            int length = Math.min(COPY_BUFFER_SIZE, dup.remaining());
            dup.get(copyBuf, 0, length);
            output.write(copyBuf, 0, length);
        }
    }
}
 
Example #11
Source File: StringMapBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(final Map<String, String> stringStringMap, final TupleOutput tupleOutput)
{
    tupleOutput.writeInt(stringStringMap.size());
    for(Map.Entry<String,String> entry : stringStringMap.entrySet())
    {
        tupleOutput.writeString(entry.getKey());
        tupleOutput.writeString(entry.getValue());
    }
}
 
Example #12
Source File: MapBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(final Map<String, Object> map, final TupleOutput output)
{
    try
    {
        StringWriter writer = new StringWriter();
        final ObjectMapper objectMapper = ConfiguredObjectJacksonModule.newObjectMapper(true);
        objectMapper.writeValue(writer, map);
        output.writeString(writer.toString());
    }
    catch (IOException e)
    {
        throw new StoreException(e);
    }
}
 
Example #13
Source File: OrphanConfigurationRecordPurger.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private TupleOutput uuidToKey(final UUID uuid)
{
    DatabaseEntry key = new DatabaseEntry();
    TupleOutput output = new TupleOutput();
    output.writeLong(uuid.getMostSignificantBits());
    output.writeLong(uuid.getLeastSignificantBits());
    return output;
}
 
Example #14
Source File: FieldTableEncoding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public  static void writeFieldTable(FieldTable fieldTable, TupleOutput tupleOutput)
{

    if (fieldTable == null)
    {
        tupleOutput.writeLong(0);
    }
    else
    {
        tupleOutput.writeLong(fieldTable.getEncodedSize());
        tupleOutput.writeFast(fieldTable.getDataAsBytes());
    }
}
 
Example #15
Source File: PreparedTransactionBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static void objectToEntry(final PreparedTransaction preparedTransaction, final DatabaseEntry value)
{
    TupleOutput tupleOutput = new TupleOutput();
    writeRecords(preparedTransaction.getEnqueues(), tupleOutput);
    writeRecords(preparedTransaction.getDequeues(), tupleOutput);
    TupleBinding.outputToEntry(tupleOutput, value);
}
 
Example #16
Source File: ConfiguredObjectBindingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testObjectToEntryAndEntryToObject()
{
    TupleOutput tupleOutput = new TupleOutput();

    _configuredObjectBinding.objectToEntry(_object, tupleOutput);

    byte[] entryAsBytes = tupleOutput.getBufferBytes();
    TupleInput tupleInput = new TupleInput(entryAsBytes);

    ConfiguredObjectRecord storedObject = _configuredObjectBinding.entryToObject(tupleInput);
    assertEquals("Unexpected attributes", DUMMY_ATTRIBUTES_MAP, storedObject.getAttributes());
    assertEquals("Unexpected type", DUMMY_TYPE_STRING, storedObject.getType());
}
 
Example #17
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadNullValues()
{
    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(null, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertNull("Expected null but got " + result, result);
}
 
Example #18
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadShortStringWithLengthOver127()
{
    AMQShortString value = createString('a', 128);

    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(value, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertEquals("Expected " + value + " but got " + result, value, result);
}
 
Example #19
Source File: AMQShortStringEncodingTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testWriteReadShortStringWithLengthLess127()
{
    AMQShortString value = AMQShortString.createAMQShortString("test");

    // write into tuple output
    TupleOutput tupleOutput = new TupleOutput();
    AMQShortStringEncoding.writeShortString(value, tupleOutput);
    byte[] data = tupleOutput.getBufferBytes();

    // read from tuple input
    TupleInput tupleInput = new TupleInput(data);
    AMQShortString result = AMQShortStringEncoding.readShortString(tupleInput);
    assertEquals("Expected " + value + " but got " + result, value, result);
}
 
Example #20
Source File: LinkBinding.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public void objectToEntry(HGPersistentHandle[] link, TupleOutput output) {
	//HGPersistentHandle[] link = (HGPersistentHandle[])x;
	byte[] buffer = new byte[link.length * handleSize];
	for (int i = 0; i < link.length; i++) {
		HGPersistentHandle handle = (HGPersistentHandle)link[i];
		System.arraycopy(handle.toByteArray(), 0, buffer, i * handleSize, handleSize);
	}
	output.writeFast(buffer);
}
 
Example #21
Source File: LinkBinding.java    From hypergraphdb with Apache License 2.0 5 votes vote down vote up
public void objectToEntry(HGPersistentHandle[] link, TupleOutput output)
{
    byte [] buffer = new byte[link.length * handleSize];
    for (int i = 0; i < link.length; i++)
    {
        HGPersistentHandle handle = (HGPersistentHandle)link[i];
        System.arraycopy(handle.toByteArray(), 0, 
                         buffer, i*handleSize, 
                         handleSize);            
    }
    output.writeFast(buffer);
}
 
Example #22
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the persistent index with the given (byte) code.
 * 
 * @param code
 *            The code
 */
private void appendPersistentIndex(int listId, byte[] code) {
	// write id, listId and code
	TupleOutput output = new TupleOutput();
	output.writeInt(listId);
	for (int i = 0; i < numSubVectors; i++) {
		output.writeByte(code[i]);
	}
	DatabaseEntry data = new DatabaseEntry();
	TupleBinding.outputToEntry(output, data);
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	iidToIvfpqDB.put(null, key, data);
}
 
Example #23
Source File: IVFPQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the persistent index with the given (short) code.
 * 
 * @param code
 *            The code
 */
private void appendPersistentIndex(int listId, short[] code) {
	// write id, listId and code
	TupleOutput output = new TupleOutput();
	output.writeInt(listId);
	for (int i = 0; i < numSubVectors; i++) {
		output.writeShort(code[i]);
	}
	DatabaseEntry data = new DatabaseEntry();
	TupleBinding.outputToEntry(output, data);
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	iidToIvfpqDB.put(null, key, data);
}
 
Example #24
Source File: PQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the persistent index with the given (byte) code.
 * 
 * @param code
 *            The code
 */
private void appendPersistentIndex(byte[] code) {
	// write id and code
	TupleOutput output = new TupleOutput();
	for (int i = 0; i < numSubVectors; i++) {
		output.writeByte(code[i]);
	}
	DatabaseEntry data = new DatabaseEntry();
	TupleBinding.outputToEntry(output, data);
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	iidToPqDB.put(null, key, data);
}
 
Example #25
Source File: PQ.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the persistent index with the given (short) code.
 * 
 * @param code
 *            The code
 */
private void appendPersistentIndex(short[] code) {
	// write id and code
	TupleOutput output = new TupleOutput();
	for (int i = 0; i < numSubVectors; i++) {
		output.writeShort(code[i]);
	}
	DatabaseEntry data = new DatabaseEntry();
	TupleBinding.outputToEntry(output, data);
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	iidToPqDB.put(null, key, data);
}
 
Example #26
Source File: Linear.java    From multimedia-indexing with Apache License 2.0 5 votes vote down vote up
/**
 * Appends the persistent index with the given vector.
 * 
 * @param vector
 *            The vector
 */
private void appendPersistentIndex(double[] vector) {
	TupleOutput output = new TupleOutput();
	for (int i = 0; i < vectorLength; i++) {
		output.writeDouble(vector[i]);
	}
	DatabaseEntry data = new DatabaseEntry();
	TupleBinding.outputToEntry(output, data);
	DatabaseEntry key = new DatabaseEntry();
	IntegerBinding.intToEntry(loadCounter, key);
	iidToVectorDB.put(null, key, data);
}
 
Example #27
Source File: UpgradeFrom4To5.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(BindingRecord binding, TupleOutput tupleOutput)
{
    AMQShortStringEncoding.writeShortString(binding.getExchangeName(), tupleOutput);
    AMQShortStringEncoding.writeShortString(binding.getQueueName(), tupleOutput);
    AMQShortStringEncoding.writeShortString(binding.getRoutingKey(), tupleOutput);

    FieldTableEncoding.writeFieldTable(binding.getArguments(), tupleOutput);
}
 
Example #28
Source File: LinkValueEntryBinding.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(final LinkValue linkValue, final TupleOutput output)
{
    output.writeByte(linkValue.getVersion());
    write(linkValue.getSource(), output);
    write(linkValue.getTarget(), output);
}
 
Example #29
Source File: UpgradeFrom7To8.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
void storeVirtualHostHierarchyRecord(Database hierarchyDb, Transaction txn, UUID id, UUID virtualHostId)
{
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    UUIDTupleBinding.getInstance().objectToEntry(virtualHostId, value);
    TupleOutput tupleOutput = new TupleOutput();
    tupleOutput.writeLong(id.getMostSignificantBits());
    tupleOutput.writeLong(id.getLeastSignificantBits());
    tupleOutput.writeString("VirtualHost");
    TupleBinding.outputToEntry(tupleOutput, key);
    hierarchyDb.put(txn, key, value);
}
 
Example #30
Source File: UpgradeFrom5To6.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
public void objectToEntry(OldQueueRecord queue, TupleOutput tupleOutput)
{
    AMQShortStringEncoding.writeShortString(queue.getNameShortString(), tupleOutput);
    AMQShortStringEncoding.writeShortString(queue.getOwner(), tupleOutput);
    FieldTableEncoding.writeFieldTable(queue.getArguments(), tupleOutput);
    tupleOutput.writeBoolean(queue.isExclusive());
}