com.amazon.carbonado.raw
Interface StorableCodec<S extends Storable>

All Known Implementing Classes:
CustomStorableCodec, GenericStorableCodec

public interface StorableCodec<S extends Storable>

Supports encoding and decoding of storables.

Author:
Brian S O'Neill
See Also:
StorableCodecFactory

Method Summary
 void decode(S dest, int generation, byte[] data)
          Used for decoding different generations of Storable.
 byte[] encodePrimaryKey(Object[] values)
          Encode a key by extracting all the primary key properties from the given storable.
 byte[] encodePrimaryKey(Object[] values, int rangeStart, int rangeEnd)
          Encode a key by extracting all the primary key properties from the given storable.
 byte[] encodePrimaryKey(S storable)
          Encode a key by extracting all the primary key properties from the given storable.
 byte[] encodePrimaryKey(S storable, int rangeStart, int rangeEnd)
          Encode a key by extracting all the primary key properties from the given storable.
 byte[] encodePrimaryKeyPrefix()
          Encode the primary key for when there are no values, but there may be a prefix.
 StorableIndex<S> getPrimaryKeyIndex()
          Returns the sequence and directions of properties that make up the primary key.
 int getPrimaryKeyPrefixLength()
          Returns the number of prefix bytes in the primary key, which may be zero.
 Class<S> getStorableType()
          Returns the type of Storable produced by this codec.
 RawSupport<S> getSupport()
          Returns the default RawSupport object that is supplied to Storable instances produced by this codec.
 S instantiate()
          Instantiate a Storable with no key or value defined yet.
 S instantiate(byte[] key, byte[] value)
          Instantiate a Storable with a specific key and value.
 S instantiate(RawSupport<S> support)
          Instantiate a Storable with no key or value defined yet.
 S instantiate(RawSupport<S> support, byte[] key, byte[] value)
          Instantiate a Storable with a specific key and value.
 

Method Detail

getStorableType

Class<S> getStorableType()
Returns the type of Storable produced by this codec.


instantiate

S instantiate()
Instantiate a Storable with no key or value defined yet. The default RawSupport is supplied to the instance.

Throws:
IllegalStateException - if no default support exists
Since:
1.2

instantiate

S instantiate(byte[] key,
              byte[] value)
                               throws FetchException
Instantiate a Storable with a specific key and value. The default RawSupport is supplied to the instance.

Throws:
IllegalStateException - if no default support exists
FetchException
Since:
1.2

instantiate

S instantiate(RawSupport<S> support)
Instantiate a Storable with no key or value defined yet. Any RawSupport can be supplied to the instance.

Parameters:
support - binds generated storable with a storage layer

instantiate

S instantiate(RawSupport<S> support,
              byte[] key,
              byte[] value)
                               throws FetchException
Instantiate a Storable with a specific key and value. Any RawSupport can be supplied to the instance.

Parameters:
support - binds generated storable with a storage layer
Throws:
FetchException

getPrimaryKeyIndex

StorableIndex<S> getPrimaryKeyIndex()
Returns the sequence and directions of properties that make up the primary key.


getPrimaryKeyPrefixLength

int getPrimaryKeyPrefixLength()
Returns the number of prefix bytes in the primary key, which may be zero.


encodePrimaryKey

byte[] encodePrimaryKey(S storable)
Encode a key by extracting all the primary key properties from the given storable.

Parameters:
storable - extract primary key properties from this instance
Returns:
raw search key

encodePrimaryKey

byte[] encodePrimaryKey(S storable,
                        int rangeStart,
                        int rangeEnd)
Encode a key by extracting all the primary key properties from the given storable.

Parameters:
storable - extract primary key properties from this instance
rangeStart - index of first property to use. Its value must be less than the count of primary key properties.
rangeEnd - index of last property to use, exlusive. Its value must be less than or equal to the count of primary key properties.
Returns:
raw search key

encodePrimaryKey

byte[] encodePrimaryKey(Object[] values)
Encode a key by extracting all the primary key properties from the given storable.

Parameters:
values - values to build into a key. It must be long enough to accommodate all primary key properties.
Returns:
raw search key

encodePrimaryKey

byte[] encodePrimaryKey(Object[] values,
                        int rangeStart,
                        int rangeEnd)
Encode a key by extracting all the primary key properties from the given storable.

Parameters:
values - values to build into a key. The length may be less than the amount of primary key properties used by this factory. It must not be less than the difference between rangeStart and rangeEnd.
rangeStart - index of first property to use. Its value must be less than the count of primary key properties.
rangeEnd - index of last property to use, exlusive. Its value must be less than or equal to the count of primary key properties.
Returns:
raw search key

encodePrimaryKeyPrefix

byte[] encodePrimaryKeyPrefix()
Encode the primary key for when there are no values, but there may be a prefix. Returned value may be null if no prefix is defined.


decode

void decode(S dest,
            int generation,
            byte[] data)
            throws CorruptEncodingException
Used for decoding different generations of Storable. If layout generations are not supported, simply throw a CorruptEncodingException.

Parameters:
dest - storable to receive decoded properties
generation - storable layout generation number
data - decoded into properties, some of which may be dropped if destination storable doesn't have it
Throws:
CorruptEncodingException - if generation is unknown or if data cannot be decoded
Since:
1.2.1

getSupport

RawSupport<S> getSupport()
Returns the default RawSupport object that is supplied to Storable instances produced by this codec.

Since:
1.2


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.