public final class StorableGenerator<S extends Storable>
extends java.lang.Object
Storable
types. This greatly simplifies the process of defining new kinds of Repositories
, since most of the mundane code generation is taken
care of.MasterStorableGenerator
,
DelegateStorableGenerator
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ADAPTER_FIELD_ELEMENT
Adapter field names are propertyName + "$adapter$" + number
|
static java.lang.String |
CHECK_PK_FOR_DELETE_METHOD_NAME
Name of protected method in generated storable which checks that
primary keys are initialized, throwing an exception otherwise.
|
static java.lang.String |
CHECK_PK_FOR_INSERT_METHOD_NAME
Name of protected method in generated storable which checks that
primary keys are initialized, throwing an exception otherwise.
|
static java.lang.String |
CHECK_PK_FOR_LOAD_METHOD_NAME
Name of protected method in generated storable which checks that
primary keys are initialized, throwing an exception otherwise.
|
static java.lang.String |
CHECK_PK_FOR_UPDATE_METHOD_NAME
Name of protected method in generated storable which checks that
primary keys are initialized, throwing an exception otherwise.
|
static java.lang.String |
CONSTRAINT_FIELD_ELEMENT
Constraint field names are propertyName + "$constraint$" + number
|
static java.lang.String |
DO_TRY_DELETE_METHOD_NAME
Name of protected abstract method in generated storable
|
static java.lang.String |
DO_TRY_INSERT_METHOD_NAME
Name of protected abstract method in generated storable
|
static java.lang.String |
DO_TRY_LOAD_METHOD_NAME
Name of protected abstract method in generated storable
|
static java.lang.String |
DO_TRY_UPDATE_METHOD_NAME
Name of protected abstract method in generated storable
|
static java.lang.String |
IS_ALT_KEY_INITIALIZED_PREFIX
Name prefix of protected method in generated storable that returns false
if a specific alternate key is uninitialized.
|
static java.lang.String |
IS_PARTITION_KEY_INITIALIZED_METHOD_NAME
Name of protected method in generated storable that returns false if any
partition keys are uninitialized.
|
static java.lang.String |
IS_PK_INITIALIZED_METHOD_NAME
Name of protected method in generated storable that returns false if any
primary keys are uninitialized.
|
static java.lang.String |
IS_REQUIRED_DATA_INITIALIZED_METHOD_NAME
Name of protected method in generated storable that returns false if any
non-nullable, non-pk properties are uninitialized.
|
static java.lang.String |
IS_VERSION_INITIALIZED_METHOD_NAME
Name of protected method in generated storable that returns false if
version property is uninitialized.
|
static java.lang.String |
LOAD_COMPLETED_METHOD_NAME
Name of protected method which must be called after load to identify all
properties as valid and to fire any load triggers.
|
static int |
PROPERTY_STATE_CLEAN
Property state indicating that property value reflects a clean value
|
static int |
PROPERTY_STATE_DIRTY
Property state indicating that property has been set, but not saved
|
static java.lang.String |
PROPERTY_STATE_FIELD_NAME
Prefix of protected field in generated storable that holds property
states.
|
static int |
PROPERTY_STATE_MASK
Property state mask is 3, to cover the two bits used by a property state
|
static int |
PROPERTY_STATE_UNINITIALIZED
Property state indicating that property has never been set, loaded, or saved
|
static java.lang.String |
SUPPORT_FIELD_NAME
Reference to TriggerSupport instance
|
Modifier and Type | Method and Description |
---|---|
static <S extends Storable> |
getAbstractClass(java.lang.Class<S> type)
Returns an abstract implementation of the given Storable type, which is
fully thread-safe.
|
public static final java.lang.String DO_TRY_LOAD_METHOD_NAME
public static final java.lang.String DO_TRY_INSERT_METHOD_NAME
public static final java.lang.String DO_TRY_UPDATE_METHOD_NAME
public static final java.lang.String DO_TRY_DELETE_METHOD_NAME
public static final java.lang.String CHECK_PK_FOR_INSERT_METHOD_NAME
public static final java.lang.String CHECK_PK_FOR_UPDATE_METHOD_NAME
public static final java.lang.String CHECK_PK_FOR_DELETE_METHOD_NAME
public static final java.lang.String CHECK_PK_FOR_LOAD_METHOD_NAME
public static final java.lang.String IS_PK_INITIALIZED_METHOD_NAME
public static final java.lang.String IS_PARTITION_KEY_INITIALIZED_METHOD_NAME
public static final java.lang.String IS_ALT_KEY_INITIALIZED_PREFIX
public static final java.lang.String IS_REQUIRED_DATA_INITIALIZED_METHOD_NAME
public static final java.lang.String IS_VERSION_INITIALIZED_METHOD_NAME
public static final java.lang.String LOAD_COMPLETED_METHOD_NAME
public static final java.lang.String PROPERTY_STATE_FIELD_NAME
public static final java.lang.String ADAPTER_FIELD_ELEMENT
public static final java.lang.String CONSTRAINT_FIELD_ELEMENT
public static final java.lang.String SUPPORT_FIELD_NAME
public static final int PROPERTY_STATE_UNINITIALIZED
public static final int PROPERTY_STATE_DIRTY
public static final int PROPERTY_STATE_CLEAN
public static final int PROPERTY_STATE_MASK
public static <S extends Storable> java.lang.Class<? extends S> getAbstractClass(java.lang.Class<S> type) throws java.lang.IllegalArgumentException
/** * @param support Access to triggers */ public <init>(TriggerSupport support);
Subclasses must implement the following abstract protected methods, whose exact names are defined by constants in this class:
// Load the object by examining the primary key. protected abstract boolean doTryLoad() throws FetchException; // Insert the object into the storage layer. protected abstract boolean doTryInsert() throws PersistException; // Update the object in the storage. protected abstract boolean doTryUpdate() throws PersistException; // Delete the object from the storage layer by the primary key. protected abstract boolean doTryDelete() throws PersistException;A set of protected hook methods are provided which ensure that all primary keys are initialized before performing a repository operation. Subclasses may override them, if they are capable of filling in unspecified primary keys. One such example is applying a sequence on insert.
// Throws exception if any primary keys are uninitialized. // Actual method name defined by CHECK_PK_FOR_INSERT_METHOD_NAME. protected void checkPkForInsert() throws IllegalStateException; // Throws exception if any primary keys are uninitialized. // Actual method name defined by CHECK_PK_FOR_UPDATE_METHOD_NAME. protected void checkPkForUpdate() throws IllegalStateException; // Throws exception if any primary keys are uninitialized. // Actual method name defined by CHECK_PK_FOR_DELETE_METHOD_NAME. protected void checkPkForDelete() throws IllegalStateException;Each property value is defined as a protected field whose name and type matches the property. Subclasses should access these fields directly during loading and storing. For loading, it bypasses constraint checks. For both, it provides better performance.
Subclasses also have access to a set of property state bits stored in protected int fields. Subclasses are not responsible for updating these values. The intention is that these states may be used by subclasses to support partial updates. They may otherwise be ignored.
As a convenience, protected methods are provided to test and alter the property state bits. Subclass constructors that fill all properties with loaded values must call loadCompleted to ensure all properties are identified as being valid and to fire any load triggers.
// Returns true if all primary key properties have been set. protected boolean isPkInitialized(); // Returns true if all partition key properties have been set. protected boolean isPartitionKeyInitialized(); // Returns true if all required data properties are set. // A required data property is a non-nullable, non-primary key. protected boolean isRequiredDataInitialized(); // Returns true if a version property has been set. // Note: This method is not generated if there is no version property. protected boolean isVersionInitialized(); // Must be called after load to identify all properties as valid // and to fire any load triggers. // Actual method name defined by LOAD_COMPLETED_METHOD_NAME. protected void loadCompleted() throws FetchException;Property state field names are defined by the concatenation of
PROPERTY_STATE_FIELD_NAME
and a zero-based decimal
number. To determine which field holds a particular property's state,
the field number is computed as the property number divided by 16. The
specific two-bit state position is the remainder of this division times 2.MalformedTypeException
- if Storable type is not well-formedjava.lang.IllegalArgumentException
- if type is nullCopyright © 2006-2013 Amazon Technologies, Inc.. All Rights Reserved.