com.amazon.carbonado.raw
Class CustomStorableCodec<S extends Storable>

java.lang.Object
  extended by com.amazon.carbonado.raw.CustomStorableCodec<S>
All Implemented Interfaces:
StorableCodec<S>

public abstract class CustomStorableCodec<S extends Storable>
extends Object
implements StorableCodec<S>

Allows codecs to be defined for storables that have a custom encoding.

Author:
Brian S O'Neill
See Also:
CustomStorableCodecFactory

Nested Class Summary
static interface CustomStorableCodec.InstanceFactory
           
 
Constructor Summary
CustomStorableCodec(Class<S> type, boolean isMaster)
           
CustomStorableCodec(Class<S> type, boolean isMaster, RawSupport<S> support)
           
 
Method Summary
 StorableIndex<S> buildPkIndex(String... propertyNames)
          Convenient way to define the clustered primary key index descriptor.
abstract  void decodeData(S storable, byte[] bytes)
          Decode the data into properties of the storable.
abstract  void decodePrimaryKey(S storable, byte[] bytes)
          Decode the primary key into properties of the storable.
abstract  byte[] encodeData(S storable)
          Encode all properties of the storable excluding the primary key.
 byte[] encodePrimaryKey(Object[] values)
          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.
 Map<String,? extends StorableProperty<S>> getAllProperties()
          Convenient access to all the storable properties.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.amazon.carbonado.raw.StorableCodec
decode, encodePrimaryKey, encodePrimaryKey, encodePrimaryKeyPrefix, getPrimaryKeyIndex, getPrimaryKeyPrefixLength
 

Constructor Detail

CustomStorableCodec

public CustomStorableCodec(Class<S> type,
                           boolean isMaster)
                    throws SupportException
Parameters:
isMaster - when true, version properties and sequences are managed
Throws:
SupportException - if Storable is not supported

CustomStorableCodec

public CustomStorableCodec(Class<S> type,
                           boolean isMaster,
                           RawSupport<S> support)
                    throws SupportException
Parameters:
isMaster - when true, version properties and sequences are managed
Throws:
SupportException - if Storable is not supported
Since:
1.2
Method Detail

getStorableType

public Class<S> getStorableType()
Description copied from interface: StorableCodec
Returns the type of Storable produced by this codec.

Specified by:
getStorableType in interface StorableCodec<S extends Storable>

instantiate

public S instantiate()
Description copied from interface: StorableCodec
Instantiate a Storable with no key or value defined yet. The default RawSupport is supplied to the instance.

Specified by:
instantiate in interface StorableCodec<S extends Storable>
Since:
1.2

instantiate

public S instantiate(byte[] key,
                     byte[] value)
                               throws FetchException
Description copied from interface: StorableCodec
Instantiate a Storable with a specific key and value. The default RawSupport is supplied to the instance.

Specified by:
instantiate in interface StorableCodec<S extends Storable>
Throws:
FetchException
Since:
1.2

instantiate

public S instantiate(RawSupport<S> support)
Description copied from interface: StorableCodec
Instantiate a Storable with no key or value defined yet. Any RawSupport can be supplied to the instance.

Specified by:
instantiate in interface StorableCodec<S extends Storable>
Parameters:
support - binds generated storable with a storage layer

instantiate

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

Specified by:
instantiate in interface StorableCodec<S extends Storable>
Parameters:
support - binds generated storable with a storage layer
Throws:
FetchException

encodePrimaryKey

public byte[] encodePrimaryKey(S storable)
Description copied from interface: StorableCodec
Encode a key by extracting all the primary key properties from the given storable.

Specified by:
encodePrimaryKey in interface StorableCodec<S extends Storable>
Parameters:
storable - extract primary key properties from this instance
Returns:
raw search key

encodePrimaryKey

public byte[] encodePrimaryKey(Object[] values)
Description copied from interface: StorableCodec
Encode a key by extracting all the primary key properties from the given storable.

Specified by:
encodePrimaryKey in interface StorableCodec<S extends Storable>
Parameters:
values - values to build into a key. It must be long enough to accommodate all primary key properties.
Returns:
raw search key

getSupport

public RawSupport<S> getSupport()
Description copied from interface: StorableCodec
Returns the default RawSupport object that is supplied to Storable instances produced by this codec.

Specified by:
getSupport in interface StorableCodec<S extends Storable>
Since:
1.2

getAllProperties

public Map<String,? extends StorableProperty<S>> getAllProperties()
Convenient access to all the storable properties.


buildPkIndex

public StorableIndex<S> buildPkIndex(String... propertyNames)
Convenient way to define the clustered primary key index descriptor. Direction can be specified by prefixing the property name with a '+' or '-'. If unspecified, direction is assumed to be ascending.


decodePrimaryKey

public abstract void decodePrimaryKey(S storable,
                                      byte[] bytes)
                               throws CorruptEncodingException
Decode the primary key into properties of the storable.

Throws:
CorruptEncodingException

encodeData

public abstract byte[] encodeData(S storable)
Encode all properties of the storable excluding the primary key.


decodeData

public abstract void decodeData(S storable,
                                byte[] bytes)
                         throws CorruptEncodingException
Decode the data into properties of the storable.

Throws:
CorruptEncodingException


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