com.amazon.carbonado.synthetic
Class SyntheticStorableReferenceBuilder<S extends Storable>

java.lang.Object
  extended by com.amazon.carbonado.synthetic.SyntheticStorableReferenceBuilder<S>
All Implemented Interfaces:
SyntheticBuilder

public class SyntheticStorableReferenceBuilder<S extends Storable>
extends Object
implements SyntheticBuilder

A SyntheticStorableReference defines new kinds of Storables from an existing master storable. This is used in situations when additional information about a storable needs to be tracked -- eg, for an index, or for caching. The storable may optionally have completely new, synthetic properties added.

All primary key properties of the master storable will also be provided by the derived storable. Three special methods will be provided:

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.amazon.carbonado.synthetic.SyntheticBuilder
SyntheticBuilder.ClassNameProvider
 
Constructor Summary
SyntheticStorableReferenceBuilder(Class<S> storableClass, boolean isUnique)
           
SyntheticStorableReferenceBuilder(Class<S> storableClass, String baseName, boolean isUnique)
           
 
Method Summary
 SyntheticKey addAlternateKey()
          Add an alternate key to be built.
 SyntheticIndex addIndex()
          Add an index to the set managed by this builder.
 SyntheticProperty addKeyProperty(String name, Direction direction)
          Add a property to the primary key which is a member of the Storable type being referenced by this one.
 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.
 void copyFromMaster(Storable indexEntry, S master)
          Deprecated. call getReferenceAccess
 void copyToMasterPrimaryKey(Storable indexEntry, S master)
          Deprecated. call getReferenceAccess
 Comparator<? extends Storable> getComparator()
          Deprecated. call getReferenceAccess
 Object getName()
           
 SyntheticStorableReferenceAccess getReferenceAccess()
          Build and return access to the generated storable reference class.
 Class<? extends Storable> getStorableClass()
           
 List<SyntheticProperty> getUserProps()
           
 boolean hasProperty(String name)
          Check to see if a particular property has already been added to the list of properties to generate
 boolean isConsistent(Storable indexEntry, S master)
          Deprecated. call getReferenceAccess
 boolean isUnique()
          True if the generated derived class should be considered unique.
 boolean isVersioned()
          Returns true if a property with the version attribute has been addded
 ClassFileBuilder prepare()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyntheticStorableReferenceBuilder

public SyntheticStorableReferenceBuilder(Class<S> storableClass,
                                         boolean isUnique)
Parameters:
storableClass - class of the storable that will be referenced by this synthetic. The name for the synthetic storable will be based on this class's name, decorated with the properties which participate in the primary key for the synthetic storable.

SyntheticStorableReferenceBuilder

public SyntheticStorableReferenceBuilder(Class<S> storableClass,
                                         String baseName,
                                         boolean isUnique)
Parameters:
storableClass - class of the storable that will be referenced by this synthetic
baseName - of the generated synthetic. Note that for some repositories this name will be visible across the entire repository, so it is good practice to include namespace information to guarantee uniqueness.
isUnique - true if the properties that are explicitly identified as primary key properites are sufficient to uniquely identify the index object.
Method Detail

prepare

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

getReferenceAccess

public SyntheticStorableReferenceAccess getReferenceAccess()
Build and return access to the generated storable reference class.

Since:
1.2.1

getStorableClass

public Class<? extends Storable> getStorableClass()
                                           throws IllegalStateException
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.
Throws:
IllegalStateException - if build has not yet been called.

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

addKeyProperty

public SyntheticProperty addKeyProperty(String name,
                                        Direction direction)
Add a property to the primary key which is a member of the Storable type being referenced by this one.

Parameters:
name -

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
See Also:
SyntheticStorableBuilder.addProperty(java.lang.String, java.lang.Class)

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
See Also:
SyntheticStorableBuilder.addProperty(com.amazon.carbonado.synthetic.SyntheticProperty)

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

getUserProps

public List<SyntheticProperty> getUserProps()
Returns:
Returns the indexProps.

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

getName

public Object getName()

isUnique

public boolean isUnique()
True if the generated derived class should be considered unique. If non-unique, all properties are added to the primary key so there will be no conflicts between various derived classes derived from the same base storable.


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

copyToMasterPrimaryKey

@Deprecated
public void copyToMasterPrimaryKey(Storable indexEntry,
                                              S master)
                            throws FetchException
Deprecated. call getReferenceAccess

Sets all the primary key properties of the given master, using the applicable properties of the given index entry.

Parameters:
indexEntry - source of property values
master - master whose primary key properties will be set
Throws:
FetchException

copyFromMaster

@Deprecated
public void copyFromMaster(Storable indexEntry,
                                      S master)
                    throws FetchException
Deprecated. call getReferenceAccess

Sets all the properties of the given index entry, using the applicable properties of the given master.

Parameters:
indexEntry - index entry whose properties will be set
master - source of property values
Throws:
FetchException

isConsistent

@Deprecated
public boolean isConsistent(Storable indexEntry,
                                       S master)
                     throws FetchException
Deprecated. call getReferenceAccess

Returns true if the properties of the given index entry match those contained in the master, excluding any version property. This will always return true after a call to copyFromMaster.

Parameters:
indexEntry - index entry whose properties will be tested
master - source of property values
Throws:
FetchException

getComparator

@Deprecated
public Comparator<? extends Storable> getComparator()
Deprecated. call getReferenceAccess

Returns a comparator for ordering index entries.



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