com.amazon.carbonado.synthetic
Class SyntheticStorableBuilder

java.lang.Object
  extended by com.amazon.carbonado.synthetic.SyntheticStorableBuilder
All Implemented Interfaces:
SyntheticBuilder

public class SyntheticStorableBuilder
extends Object
implements SyntheticBuilder

Allows the definition of very simple synthetic storables. Only a primary key index can be defined; at least one property must be a primary key property. A property can be nullable and can be specified as the version property. This class acts both as builder factory and as builder.

Author:
Don Schneider, Brian S O'Neill, David Rosenstrauch

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.amazon.carbonado.synthetic.SyntheticBuilder
SyntheticBuilder.ClassNameProvider
 
Constructor Summary
SyntheticStorableBuilder(String name, ClassLoader loader)
           
 
Method Summary
 SyntheticKey addAlternateKey()
          Add an alternate key to be built.
 SyntheticIndex addIndex()
          Add an index to the set managed by this builder.
 SyntheticKey addPrimaryKey()
          Add a primary key to be built.
 SyntheticProperty addProperty(String name, Class type)
          Add a property to the set managed by this builder.
 SyntheticProperty addProperty(SyntheticProperty prop)
          Add an externally defined synthetic property to the list
 Class<? extends Storable> build()
          Convenience method to generate the class.
protected  boolean definePropertyBeanMethods(ClassFile cf, SyntheticProperty property)
          Add the get & set methods for this property
 SyntheticBuilder.ClassNameProvider getClassNameProvider()
           
protected  String getName()
          Frequently used by the SyntheticBuilder.ClassNameProvider as a basis for the generated classname
protected  List<SyntheticProperty> getPropertyList()
          Frequently used by the SyntheticBuilder.ClassNameProvider as a basis for the generated classname
 Class<? extends Storable> getStorableClass()
           
 boolean hasProperty(String name)
          Check to see if a particular property has already been added to the list of properties to generate
 boolean isVersioned()
          Returns true if a property with the version attribute has been addded
 ClassFileBuilder prepare()
           
 void setClassNameProvider(SyntheticBuilder.ClassNameProvider classNameProvider)
           
 void setEvolvable(boolean evolvable)
          By default, generated storable implements the Unevolvable marker interface, which can affect how it is encoded.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyntheticStorableBuilder

public SyntheticStorableBuilder(String name,
                                ClassLoader loader)
Parameters:
name - base name for the generated class. This is usually a fully qualified name, a la "com.amazon.carbonado.storables.happy.synthetic.storable"
loader - ClassLoader to use for the generated class
Method Detail

prepare

public ClassFileBuilder prepare()
                         throws SupportException
Specified by:
prepare in interface SyntheticBuilder
Returns:
ClassFileBuilder ready for further decoration or building
Throws:
SupportException

getStorableClass

public Class<? extends Storable> getStorableClass()
Specified by:
getStorableClass in interface SyntheticBuilder
Returns:
the generated class file for this builder. Note that proper operation requires that SyntheticBuilder.prepare() already have been called prior to calling this method.

build

public Class<? extends Storable> build()
                                throws SupportException
Description copied from interface: SyntheticBuilder
Convenience method to generate the class. Build will always call SyntheticBuilder.prepare() and return the result of generating the class from that classfile. If the caller does not wish to regenerate the class from scratch, use SyntheticBuilder.getStorableClass() instead.

Specified by:
build in interface SyntheticBuilder
Throws:
SupportException

addProperty

public SyntheticProperty addProperty(String name,
                                     Class type)
Description copied from interface: SyntheticBuilder
Add a property to the set managed by this builder.

Specified by:
addProperty in interface SyntheticBuilder
Parameters:
name - of the property
type - of the property
Returns:
property specification which can be further refined

addProperty

public SyntheticProperty addProperty(SyntheticProperty prop)
Description copied from interface: SyntheticBuilder
Add an externally defined synthetic property to the list

Specified by:
addProperty in interface SyntheticBuilder
Parameters:
prop - to add
Returns:
original synthetic property as a convenience

hasProperty

public boolean hasProperty(String name)
Description copied from interface: SyntheticBuilder
Check to see if a particular property has already been added to the list of properties to generate

Specified by:
hasProperty in interface SyntheticBuilder

addPrimaryKey

public SyntheticKey addPrimaryKey()
Description copied from interface: SyntheticBuilder
Add a primary key to be built.

Specified by:
addPrimaryKey in interface SyntheticBuilder
Returns:
key to be decorated with property values defining the primary key

addAlternateKey

public SyntheticKey addAlternateKey()
Description copied from interface: SyntheticBuilder
Add an alternate key to be built.

Specified by:
addAlternateKey in interface SyntheticBuilder
Returns:
key to be decorated with property values defining the alternate key

addIndex

public SyntheticIndex addIndex()
Description copied from interface: SyntheticBuilder
Add an index to the set managed by this builder. All indexes added this way will be in addition to the primary and alternate key indexes.

Specified by:
addIndex in interface SyntheticBuilder
Returns:
index to be decorated with property values defining the index

isVersioned

public boolean isVersioned()
Description copied from interface: SyntheticBuilder
Returns true if a property with the version attribute has been addded

Specified by:
isVersioned in interface SyntheticBuilder

getClassNameProvider

public SyntheticBuilder.ClassNameProvider getClassNameProvider()
Returns:
Returns the classNameProvider.

setClassNameProvider

public void setClassNameProvider(SyntheticBuilder.ClassNameProvider classNameProvider)
Parameters:
classNameProvider - The classNameProvider to set.

setEvolvable

public void setEvolvable(boolean evolvable)
By default, generated storable implements the Unevolvable marker interface, which can affect how it is encoded. It usually does not make sense to support storable evolution new versions can be (and often will be) given different names.

Pass in true to change from the default behavior, and not implement Unevolvable. When doing so, a ClassNameProvider should also be provided to ensure consistent naming which does not include property names.


definePropertyBeanMethods

protected boolean definePropertyBeanMethods(ClassFile cf,
                                            SyntheticProperty property)
Add the get & set methods for this property

Returns:
true if version property was added

getName

protected String getName()
Frequently used by the SyntheticBuilder.ClassNameProvider as a basis for the generated classname

Returns:
builder name

getPropertyList

protected List<SyntheticProperty> getPropertyList()
Frequently used by the SyntheticBuilder.ClassNameProvider as a basis for the generated classname

Returns:
properties for this storable

toString

public String toString()
Overrides:
toString in class Object


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