com.bigdata.btree
Class AbstractTuple<E>

java.lang.Object
  extended by com.bigdata.btree.AbstractTuple<E>
All Implemented Interfaces:
ITuple<E>
Direct Known Subclasses:
Tuple

public abstract class AbstractTuple<E>
extends Object
implements ITuple<E>

Abstract base class with much of the functionality of ITuple.

Version:
$Id: AbstractTuple.java 4950 2011-07-19 20:53:37Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  int flags
           
protected  boolean needKeys
           
protected  boolean needVals
           
 
Constructor Summary
AbstractTuple(int flags)
           
 
Method Summary
protected  void clear()
          Clears the buffered data copied into the AbstractTuple from the source btree.
 void copy(int index, ILeafData leaf)
          Copy data and metadata for the index entry from the Leaf into the Tuple and increment the counter of the #of visited entries.
 void copyTuple(byte[] key, byte[] val)
          Assumes that the tuple is not deleted and that timestamp information is not available.
 void copyTuple(byte[] key, byte[] val, boolean deleted, long timestamp)
          Sets all fields on the tuple and increments the tuple visited counter.
 void copyTuple(ITuple t)
          Sets all fields and increments the tuple visited counter.
 int flags()
          The IRangeQuery flags
static String flagString(int flags)
          Externalizes the flags as a list of symbolic constants.
 byte[] getKey()
          Returns a copy of the current key.
 ByteArrayBuffer getKeyBuffer()
          The buffer into which the keys are being copied.
 boolean getKeysRequested()
          True iff IRangeQuery.KEYS was specified.
 DataInputBuffer getKeyStream()
          Return a stream from which the key may be read.
 E getObject()
          De-serializes the object from the key and/or value.
 byte[] getValue()
          The value in the index under the key.
 ByteArrayBuffer getValueBuffer()
          The buffer into which the values are being copied.
 boolean getValuesRequested()
          True iff IRangeQuery.VALS was specified.
 DataInputBuffer getValueStream()
          Return a stream from which the value may be read.
 long getVersionTimestamp()
          Return the timestamp associated with the index entry -or- 0L IFF the index does not support transactional isolation.
 long getVisitCount()
          The #of entries that have been visited so far and ZERO (0) until the first entry has been visited.
 boolean isDeletedVersion()
          Return true iff the index entry was marked as deleted.
 boolean isNull()
          true iff the value stored under the index entry is null.
 IBlock readBlock(long addr)
          Return an object that may be used to perform a streaming read of a large record from the IRawStore that provided this tuple.
 String toString()
          Note: A de-serialization problem thrown out of toString() MAY indicate that the ITupleSerializer was not overriden and a raw byte[] was stored as the tuple's value.
static String toString(ITuple tuple)
          Utility method returns a String representation of an ITuple.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.bigdata.btree.ITuple
getSourceIndex, getTupleSerializer
 

Field Detail

flags

protected final int flags

needKeys

protected final boolean needKeys

needVals

protected final boolean needVals
Constructor Detail

AbstractTuple

public AbstractTuple(int flags)
Method Detail

flags

public final int flags()
Description copied from interface: ITuple
The IRangeQuery flags
 
 if ((flags & IRangeQuery.KEYS) != 0) {
 
     // keys requested.
 
 }
 
 
Note: the IRangeQuery.DELETED flag state is a property of the iterator NOT the tuple. Whether or not a tuple is deleted is detected using ITuple.isDeletedVersion().

Specified by:
flags in interface ITuple<E>

getKeysRequested

public final boolean getKeysRequested()
Description copied from interface: ITuple
True iff IRangeQuery.KEYS was specified.

Specified by:
getKeysRequested in interface ITuple<E>

getValuesRequested

public final boolean getValuesRequested()
Description copied from interface: ITuple
True iff IRangeQuery.VALS was specified.

Specified by:
getValuesRequested in interface ITuple<E>

getKeyBuffer

public final ByteArrayBuffer getKeyBuffer()
Description copied from interface: ITuple
The buffer into which the keys are being copied.

Specified by:
getKeyBuffer in interface ITuple<E>
Returns:
The buffer.

getKeyStream

public final DataInputBuffer getKeyStream()
Return a stream from which the key may be read.

Specified by:
getKeyStream in interface ITuple<E>
Throws:
UnsupportedOperationException - if the keys were not requested.

getValueStream

public final DataInputBuffer getValueStream()
Return a stream from which the value may be read.

Specified by:
getValueStream in interface ITuple<E>
Throws:
UnsupportedOperationException - if the values were not requested.

getVisitCount

public long getVisitCount()
The #of entries that have been visited so far and ZERO (0) until the first entry has been visited.

Specified by:
getVisitCount in interface ITuple<E>

getKey

public final byte[] getKey()
Description copied from interface: ITuple
Returns a copy of the current key.

Note: This can cause a heap allocation depending on how the keys are buffered. See ITuple.getKeyBuffer() to avoid that allocation.

Specified by:
getKey in interface ITuple<E>

isNull

public final boolean isNull()
Description copied from interface: ITuple
true iff the value stored under the index entry is null.

Specified by:
isNull in interface ITuple<E>

getValue

public final byte[] getValue()
Description copied from interface: ITuple
The value in the index under the key.

Note: This causes a heap allocation. See ITuple.getValueBuffer() to avoid that allocation.

Specified by:
getValue in interface ITuple<E>
Returns:
The value in the index under the key -or- null if version metadata is being maintained and the the index entry is marked as deleted.

getValueBuffer

public final ByteArrayBuffer getValueBuffer()
Description copied from interface: ITuple
The buffer into which the values are being copied.

Note: If the index supports delete markers then you MUST test ITuple.isDeletedVersion() in order to determine whether or not the value buffer contains data for the current index entry.

Specified by:
getValueBuffer in interface ITuple<E>
Returns:
The buffer.

getObject

public final E getObject()
Description copied from interface: ITuple
De-serializes the object from the key and/or value.

Specified by:
getObject in interface ITuple<E>
Returns:
The de-serialized object.
See Also:
ITupleSerializer.deserialize(ITuple)

getVersionTimestamp

public final long getVersionTimestamp()
Description copied from interface: ITuple
Return the timestamp associated with the index entry -or- 0L IFF the index does not support transactional isolation.

Specified by:
getVersionTimestamp in interface ITuple<E>

isDeletedVersion

public final boolean isDeletedVersion()
Description copied from interface: ITuple
Return true iff the index entry was marked as deleted.

Note: If the index does not support deletion markers then this method MUST return false.

Note: the IRangeQuery.DELETED flag state is a property of the iterator NOT the tuple. Whether or not a tuple is deleted is detected using ITuple.isDeletedVersion().

Specified by:
isDeletedVersion in interface ITuple<E>

readBlock

public IBlock readBlock(long addr)
Description copied from interface: ITuple
Return an object that may be used to perform a streaming read of a large record from the IRawStore that provided this tuple.

Specified by:
readBlock in interface ITuple<E>
Parameters:
addr - The address of the record.
Returns:
The object that may be used to read that record.
TODO:
Implement. In order to work the tuple needs to know the source store from which the index entry was read. In the context of a fused view this is the element of that view that supplied the tuple binding (blocks may be stored on journals or index segments). In the context of a scale-out index, the state must include enough information to locate the data service for the index view and then the source index within that view.

Consider the notion of leases for the read back from a data service. If you do not read on the block soon enough the lease is gone and you will get an error if you try to read on the block. The lease can be used to limit the time that an index partition is locked to a data service.


copy

public void copy(int index,
                 ILeafData leaf)
Copy data and metadata for the index entry from the Leaf into the Tuple and increment the counter of the #of visited entries.

Parameters:
index - The index entry.
leaf - The leaf. If a raw record must be materialized, it will be read from the backing store for the Leaf.
TODO:
The various copy methods should also set the [sourceIndex] property and ITuple.getSourceIndex() should be implemented by this class (or maybe add a setSourceIndex() to be more flexible).

copyTuple

public void copyTuple(byte[] key,
                      byte[] val)
Assumes that the tuple is not deleted and that timestamp information is not available.

Parameters:
key -
val -

copyTuple

public void copyTuple(byte[] key,
                      byte[] val,
                      boolean deleted,
                      long timestamp)
Sets all fields on the tuple and increments the tuple visited counter.

Parameters:
key -
val -
deleted -
timestamp -

copyTuple

public void copyTuple(ITuple t)
Sets all fields and increments the tuple visited counter.

Parameters:
t - Some tuple.

clear

protected void clear()
Clears the buffered data copied into the AbstractTuple from the source btree.


toString

public String toString()
Note: A de-serialization problem thrown out of toString() MAY indicate that the ITupleSerializer was not overriden and a raw byte[] was stored as the tuple's value. In this case, getObject() will attempt to use Java standard de-serialization on the byte[] value, which will, of course, fail. The fix for this problem is to specify the NOPTupleSerializer for the index. This problem may still show up in some of the test suites when the trace level is turned up since many of the tests were written before the ITupleSerializer abstraction was addeded.

Overrides:
toString in class Object

toString

public static String toString(ITuple tuple)
Utility method returns a String representation of an ITuple.

Parameters:
tuple - The ITuple.
Returns:
The String representation of that ITuple.

flagString

public static String flagString(int flags)
Externalizes the flags as a list of symbolic constants.

Parameters:
flags - The IRangeQuery flags.
Returns:
The list of symbolic constants.


Copyright © 2006-2011 SYSTAP, LLC. All Rights Reserved.