com.bigdata.btree
Class DefaultTupleSerializer<K,V>

java.lang.Object
  extended by com.bigdata.btree.DefaultTupleSerializer<K,V>
All Implemented Interfaces:
ITupleSerializer<K,V>, IKeyBuilderFactory, Externalizable, Serializable
Direct Known Subclasses:
BlobsTupleSerializer, CommitRecordIndex.CommitRecordIndexTupleSerializer, CommitTimeIndex.TupleSerializer, CounterSetBTree.CounterSetBTreeTupleSerializer, EventReceiver.EventBTree.EventBTreeTupleSerializer, FullTextIndexTupleSerializer, Id2TermTupleSerializer, JournalIndex.TupleSerializer, JustificationTupleSerializer, MetadataIndex.PartitionLocatorTupleSerializer, Name2Addr.Name2AddrTupleSerializer, NOPTupleSerializer, RDFFullTextIndexTupleSerializer, SPOTupleSerializer, Term2IdTupleSerializer, TPSTupleSerializer, TxId2CommitTimeIndex.TupleSerializer

public class DefaultTupleSerializer<K,V>
extends Object
implements ITupleSerializer<K,V>, Externalizable

Default implementation uses the KeyBuilder to format the object as a key and uses Java default serialization for the value. You only need to subclass this if you want to use custom (de-)serialization of the value, custom conversion of the application key to an unsigned byte[], or if you have a special type of application key such that you are able to decode the unsigned byte[] and materialize the corresponding application key.

Version:
$Id: DefaultTupleSerializer.java 4707 2011-06-14 15:48:36Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Constructor Summary
DefaultTupleSerializer()
          De-serialization ctor only.
DefaultTupleSerializer(IKeyBuilderFactory keyBuilderFactory)
           
DefaultTupleSerializer(IKeyBuilderFactory keyBuilderFactory, IRabaCoder leafKeysCoder, IRabaCoder leafValsCoder)
           
 
Method Summary
 V deserialize(ITuple tuple)
          De-serializes an object from the value stored in the tuple (ignores the key stored in the tuple).
 K deserializeKey(ITuple tuple)
          This is an unsupported operation.
static IKeyBuilderFactory getDefaultKeyBuilderFactory()
          Deprecated. by IndexMetadata.Options.KEY_BUILDER_FACTORY
static IRabaCoder getDefaultLeafKeysCoder()
          Deprecated. by IndexMetadata.Options.LEAF_KEYS_CODER
static IRabaCoder getDefaultValuesCoder()
          Deprecated. by IndexMetadata.Options.LEAF_VALUES_CODER
 IKeyBuilder getKeyBuilder()
          A thread-local IKeyBuilder instance.
 IRabaCoder getLeafKeysCoder()
          The object used to code (compress) an ordered array of keys such as found in a B+Tree ILeafData record or in a ResultSet.
 IRabaCoder getLeafValuesCoder()
          The object used to code (compress) an unordered array of values ordered array of keys such as found in a B+Tree ILeafData record or in a ResultSet.
static ITupleSerializer newInstance()
          Factory for a new instance using default values for the getKeyBuilder(), the getLeafKeysCoder(), and the getLeafValuesCoder().
 void readExternal(ObjectInput in)
           
 byte[] serializeKey(Object obj)
          Serialize a facet of an object's state that places the object into the total sort order for the index.
 byte[] serializeVal(V obj)
          Serializes the object as a byte[] using Java default serialization.
 void setLeafKeysCoder(IRabaCoder leafKeysCoder)
          Override the getLeafKeysCoder().
 void setLeafValuesCoder(IRabaCoder valuesCoder)
          Override the getLeafValuesCoder().
 String toString()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultTupleSerializer

public DefaultTupleSerializer()
De-serialization ctor only.


DefaultTupleSerializer

public DefaultTupleSerializer(IKeyBuilderFactory keyBuilderFactory)
Parameters:
keyBuilderFactory - The IKeyBuilderFactory, which will be automatically wrapped up by a ThreadLocalKeyBuilderFactory.

DefaultTupleSerializer

public DefaultTupleSerializer(IKeyBuilderFactory keyBuilderFactory,
                              IRabaCoder leafKeysCoder,
                              IRabaCoder leafValsCoder)
Method Detail

getDefaultKeyBuilderFactory

public static final IKeyBuilderFactory getDefaultKeyBuilderFactory()
Deprecated. by IndexMetadata.Options.KEY_BUILDER_FACTORY

The default for IKeyBuilderFactory.


getDefaultLeafKeysCoder

public static final IRabaCoder getDefaultLeafKeysCoder()
Deprecated. by IndexMetadata.Options.LEAF_KEYS_CODER

The default for getLeafKeysCoder() (compression for the keys stored in a leaf).


getDefaultValuesCoder

public static final IRabaCoder getDefaultValuesCoder()
Deprecated. by IndexMetadata.Options.LEAF_VALUES_CODER

The default for getLeafValuesCoder() (compression for the values stored in a leaf).


getLeafKeysCoder

public final IRabaCoder getLeafKeysCoder()
Description copied from interface: ITupleSerializer
The object used to code (compress) an ordered array of keys such as found in a B+Tree ILeafData record or in a ResultSet.

Note: If you change this value in a manner that is not backward compatible once entries have been written on the index then you may be unable to any read data already written.

Specified by:
getLeafKeysCoder in interface ITupleSerializer<K,V>

getLeafValuesCoder

public final IRabaCoder getLeafValuesCoder()
Description copied from interface: ITupleSerializer
The object used to code (compress) an unordered array of values ordered array of keys such as found in a B+Tree ILeafData record or in a ResultSet.

Note: If you change this value in a manner that is not backward compatible once entries have been written on the index then you may be unable to any read data already written.

Specified by:
getLeafValuesCoder in interface ITupleSerializer<K,V>

setLeafKeysCoder

public final void setLeafKeysCoder(IRabaCoder leafKeysCoder)
Override the getLeafKeysCoder(). It is NOT safe to change this value once data have been stored in an IIndex using another value as existing data MAY become unreadable.

Parameters:
leafKeysCoder - The new value.

setLeafValuesCoder

public final void setLeafValuesCoder(IRabaCoder valuesCoder)
Override the getLeafValuesCoder(). It is NOT safe to change this value once data have been stored in an IIndex using another value as existing data MAY become unreadable.

Parameters:
valuesCoder - The new value.

newInstance

public static ITupleSerializer newInstance()
Factory for a new instance using default values for the getKeyBuilder(), the getLeafKeysCoder(), and the getLeafValuesCoder().


toString

public String toString()
Overrides:
toString in class Object

getKeyBuilder

public final IKeyBuilder getKeyBuilder()
A thread-local IKeyBuilder instance.

Note: By default, the getKeyBuilder() uses whatever default is in place on the host/JVM where the DefaultTupleSerializer instance was first created. That backing IKeyBuilderFactory object is serialized along with the DefaultTupleSerializer so that the specific configuration values are persisted, even when the DefaultTupleSerializer is de-serialized on a different host.

Specified by:
getKeyBuilder in interface ITupleSerializer<K,V>
Specified by:
getKeyBuilder in interface IKeyBuilderFactory

serializeKey

public byte[] serializeKey(Object obj)
Description copied from interface: ITupleSerializer
Serialize a facet of an object's state that places the object into the total sort order for the index. This method is automatically applied by IAutoboxBTree.insert(Object, Object) and friends to convert the key object into an unsigned variable length byte[].

Note: This handles the conversion between an object and the unsigned variable length byte[] representation of that object which determines its place within the total index order. Since this transform imposes the total order of the index, different techniques are applied here than are applied to the serialization of the index values.

Specified by:
serializeKey in interface ITupleSerializer<K,V>
Parameters:
obj - A object (MAY NOT be null).
Returns:
An unsigned byte[] which places the object into the total sort order for the index and never null ( null keys are not allowed into an index).

serializeVal

public byte[] serializeVal(V obj)
Serializes the object as a byte[] using Java default serialization.

Specified by:
serializeVal in interface ITupleSerializer<K,V>
Parameters:
obj - The object to be serialized (MAY be null).
Returns:
The serialized representation of the object as a byte[] -or- null if the reference is null.

deserialize

public V deserialize(ITuple tuple)
De-serializes an object from the value stored in the tuple (ignores the key stored in the tuple).

Specified by:
deserialize in interface ITupleSerializer<K,V>
Parameters:
tuple - The tuple.
Returns:
The de-serialized object.

deserializeKey

public K deserializeKey(ITuple tuple)
This is an unsupported operation. Additional information is required to either decode the internal unsigned byte[] keys or to extract the key from the de-serialized value (if it is being stored in that value). You can either write your own ITupleSerializer or you can specialize this one so that it can de-serialize your keys using whichever approach makes the most sense for your data.

Specified by:
deserializeKey in interface ITupleSerializer<K,V>
Throws:
UnsupportedOperationException - always.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException


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