public abstract class AbstractDBObjectBuilder<T extends AbstractBuildableObject> extends java.lang.Object implements DBObjectBuilder<T>
Modifier and Type | Class and Description |
---|---|
static interface |
AbstractDBObjectBuilder.PropertyBuilder
Annotation to mark methods that build components (properties) of a given
object within this builder.
|
BASE_COMPONENT_KEY
Modifier | Constructor and Description |
---|---|
protected |
AbstractDBObjectBuilder(AbstractDBObjectProvider pro,
java.lang.String type) |
Modifier and Type | Method and Description |
---|---|
void |
buildObject(T object)
Requests that the specified object be completed.
|
void |
buildObjectComponent(T object,
java.lang.String key)
Uses canBuildComponents() to work out whether this builder can build just
the given (key) subcomponent.
|
protected boolean |
canBuildComponents()
Returns false by default.
|
boolean |
canBuildEditableObject()
Tests whether this builder does a complete build of the given object,
or whether it is only used to create stub objects.
|
void |
cancelCurrentBuild(T object)
The default implementation sets an internal flagged that can be checked
using
#isCurrentBuildCancelled() . |
protected void |
checkInterruptOrCancel(T object)
Checks whether the current thread has been interrupted, or whether the
current build has been explictly cancelled.
|
T |
createObject(java.lang.String name,
Schema schema,
DBObjectID id)
Requests the creation of a new SchemaObject of the type built by this
DBObjectBuilder instance. |
protected void |
ensureComponent(T obj,
java.lang.String key)
Ensures that the given component has been built.
|
protected void |
fillInObject(T object)
Fills in the entire object definition - i.e.
|
protected boolean |
fillInObjectComponent(T object,
java.lang.String key)
Builds the whole object by default.
|
protected boolean |
fillInObjectComponentImpl(T object,
java.lang.String prop)
Actually fills in the given component on an object.
|
protected SystemObject |
findObjectInProviderCache(DBObjectID id)
Finds an existing object in the provider's object cache by id.
|
protected SystemObject |
findObjectInProviderCache(java.lang.String type,
Schema schema,
java.lang.String name)
Finds an existing object in the provider's object cache by name.
|
protected java.lang.String[] |
getBuiltProperties(java.lang.String key)
Gets the list of properties that will be built by the given component
key.
|
java.util.Collection<java.lang.String> |
getDerivedProperties(java.lang.String property)
Gets the properties that are derived from the given property.
|
protected java.lang.String |
getDerivedPropertySource(java.lang.String property)
Gets the source property name for a derived property.
|
protected java.util.logging.Logger |
getLogger() |
protected java.lang.String |
getObjectType() |
protected AbstractDBObjectProvider |
getProvider() |
protected Schema |
getSchema(java.lang.String name)
Gets the schema with the given name from the underlying provider.
|
protected boolean |
isBuildableProperty(java.lang.String key)
If this returns false, it means that the given property should not trigger
any kind of build on the object.
|
protected boolean |
isBuiltOnFailure(T object,
java.lang.String[] props,
DBException dbe)
Tests whether the given properties should be considered "built" by the
object even though the build threw an exception.
|
protected boolean |
isCurrentBuildCancelled(T object)
Tests whether
#cancelCurrentBuild() has been called during the
current build. |
protected void |
markAsBuilt(T obj) |
protected void |
markAsBuilt(T object,
java.lang.String... props)
Marks the given properties as "built" on the buildable object.
|
protected boolean |
needsBuilding(T obj,
java.lang.String key)
Returns true if the given subcomponent of the object hasn't been explicitly
built yet.
|
boolean |
needsBuilding(T obj,
java.lang.String key,
boolean checkBuilder)
Checks whether the given component key on the given object needs building
and optionally includes a check as to whether the object has been
completely built already.
|
protected <D extends DBObject> |
newObject(java.lang.Class<? extends D> clz,
DBObject parent,
java.lang.String name)
Creates a new object of the given class using the provider's object
factory.
|
protected <D extends DBObject> |
newObject(java.lang.Class<? extends D> clz,
java.lang.String name)
Creates a new object of the given class using the provider's object
factory.
|
protected void |
registerObject(T object)
Shared between buildObject and buildObjects to perform any post-build tasks
that are needed (e.g.
|
protected void |
replaceReferenceIDs(T object,
java.util.Map<DBObjectID,DBObjectID> idMap)
Directly replaces DBObejctID property values on the given object
without building further properties on the object.
|
protected void |
setBuilder(T obj)
(Re)sets this builder as the DBObjectBuilder for the given object.
|
void |
updateTimestamp(T object)
Sets the timestamp of the given object if the underyling
DBObjectProvider supports timestamping.
|
protected void |
updateTimestamp(T object,
boolean force) |
protected AbstractDBObjectBuilder(AbstractDBObjectProvider pro, java.lang.String type)
protected final java.lang.String getObjectType()
protected final AbstractDBObjectProvider getProvider()
protected java.util.logging.Logger getLogger()
public boolean canBuildEditableObject()
DBObjectBuilder
canBuildEditableObject
in interface DBObjectBuilder<T extends AbstractBuildableObject>
public void cancelCurrentBuild(T object)
#isCurrentBuildCancelled()
. If your builder
implementation is designed to throw CancelledException internally you
can periodically call #checkInterruptOrCancel()
to achieve
this check.cancelCurrentBuild
in interface DBObjectBuilder<T extends AbstractBuildableObject>
object
- the object whose build should be cancelled.protected boolean isCurrentBuildCancelled(T object)
#cancelCurrentBuild()
has been called during the
current build.protected void checkInterruptOrCancel(T object) throws CancelledException
CancelledException
- to abort the current build.protected final Schema getSchema(java.lang.String name) throws DBException
DBException
protected final SystemObject findObjectInProviderCache(java.lang.String type, Schema schema, java.lang.String name)
type
- the type of object to findschema
- the owning schema (if the object is a SchemaObject)name
- the name of the object to findprotected final SystemObject findObjectInProviderCache(DBObjectID id)
id
- the id of the object to findprotected final <D extends DBObject> D newObject(java.lang.Class<? extends D> clz, java.lang.String name)
clz
- the class of object to create.name
- the name to give the new object (can be null)protected final <D extends DBObject> D newObject(java.lang.Class<? extends D> clz, DBObject parent, java.lang.String name)
clz
- the class of object to create.parent
- the parent of the new object (can be a Schema for
SchemaObjects).name
- the name to give the new object (can be null)public T createObject(java.lang.String name, Schema schema, DBObjectID id)
DBObjectBuilder
DBObjectBuilder
instance.createObject
in interface DBObjectBuilder<T extends AbstractBuildableObject>
name
- The name of the new objectschema
- The schema containing the new objectid
- the DBObjectID for the new objectpublic final void buildObject(T object) throws DBException
DBObjectBuilder
buildObject
in interface DBObjectBuilder<T extends AbstractBuildableObject>
object
- The object needing buildingDBException
- if an error occurs trying to build the objectprotected void fillInObject(T object) throws DBException
object
- the object to fill inDBException
protected void registerObject(T object) throws DBException
DBException
public final void updateTimestamp(T object) throws DBException
DBException
protected final void updateTimestamp(T object, boolean force) throws DBException
DBException
protected final boolean needsBuilding(T obj, java.lang.String key)
Calling this
is the same as needsBuilding( obj, key false )
.
public final boolean needsBuilding(T obj, java.lang.String key, boolean checkBuilder)
protected final void markAsBuilt(T obj)
protected final void setBuilder(T obj)
obj
- the object to set "this" as the build for.protected final void ensureComponent(T obj, java.lang.String key) throws DBException
DBException
public final void buildObjectComponent(T object, java.lang.String key) throws DBException
buildObjectComponent
in interface DBObjectBuilder<T extends AbstractBuildableObject>
object
- the object that needs buildingkey
- the component to build - in the majority of cases this will
be a property name.DBException
- if an error occurs trying to build the objectprotected final boolean fillInObjectComponent(T object, java.lang.String key) throws DBException
object
- the object to buildkey
- the property/component to build on the objectDBException
protected boolean isBuiltOnFailure(T object, java.lang.String[] props, DBException dbe)
object
- the object being builtprops
- the properties being builtdbe
- the exception that the property building threwprotected final void markAsBuilt(T object, java.lang.String... props)
object
- the buildable objectprops
- the properties that should be marked as built.protected boolean fillInObjectComponentImpl(T object, java.lang.String prop) throws DBException
object
- the object to buildkey
- the component (i.e. property name) to buildCancelledException
- if the build is cancelled, or interrupted.DBException
- if the build failsprotected boolean canBuildComponents()
AbstractDBObjectBuilder.PropertyBuilder
annotation.protected boolean isBuildableProperty(java.lang.String key)
key
- the property key for component buildingprotected java.lang.String[] getBuiltProperties(java.lang.String key)
key
- the component key we're buildingpublic java.util.Collection<java.lang.String> getDerivedProperties(java.lang.String property)
property
- the property to queryprotected java.lang.String getDerivedPropertySource(java.lang.String property)
property
- the derived propertyprotected void replaceReferenceIDs(T object, java.util.Map<DBObjectID,DBObjectID> idMap)
object
- the object to replace ids onidMap
- the map of ids to replace