public class UpdatableSchemaImpl extends SchemaImpl implements UpdatableSchema
UpdatableSchema.
Note about cyclical definitions of schemas. Suppose schema a is the parent of schema b and b of a. It is in principle not possible to create such a cycle without hacking the database. If for some reason such a cycle occurs, it will be detected by the resolve method. The code constructing an updatable schema from its database representation should detect cycles, perform some minimal surgery in a way which allows detection of the cycle (like nullifying the parent creating the cycle: a -> b -> a -> null).
| Constructor and Description |
|---|
UpdatableSchemaImpl(String name,
UpdatableSchema base,
Collection<AttributeDefinition<?>> attributeDefs,
Collection<SeriesDefinition> seriesDefinitions,
Surrogate surrogate)
Construct an
UpdatableSchema. |
| Modifier and Type | Method and Description |
|---|---|
AttributeDefinition<?> |
addAttribute(int attrNr)
Add a new attribute to the schema.
|
AttributeDefinition<?> |
addAttribute(int seriesNr,
int attrNr)
Add a new attribute to a series.
|
SeriesDefinition |
addSeries(int seriesNr)
Add a new series to the schema.
|
void |
applyUpdates()
Apply pending updates.
|
protected Schema |
consolidate(String name,
Surrogate surrogate,
List<Surrogate> dependencyList)
Apply all changes and return the schema as a standard read-only schema.
|
void |
deleteAttribute(int attrNr)
Delete an attribute from the schema.
|
void |
deleteAttribute(int seriesNr,
int attrNr)
Delete an attribute from a series.
|
void |
deleteSeries(int seriesNr)
Delete a series from the schema.
|
void |
destroy()
Destroy the schema.
|
UpdatableSchema |
edit()
Return an
UpdatableSchema corresponding to this schema. |
protected AttributeDefinitionImpl<?> |
editAttributeDefinition(int attrNr)
Start editing an attribute definition.
|
protected AttributeDefinitionImpl<?> |
editSeriesAttributeDefinition(int seriesNr,
int attrNr,
boolean mustExist)
Start editing a series attribute definition.
|
void |
eraseAttribute(int attrNr)
Set an attribute as erasing.
|
void |
eraseAttribute(int seriesNr,
int attrNr)
Set a series attribute as erasing.
|
void |
eraseSeries(int seriesNr)
Set a series as erasing.
|
UpdatableSchema |
getBase()
Return the base schema if any.
|
String |
getName()
Return the name of the schema or series definition.
|
UpdatableSchema |
getPreviousBase()
Return the base schema before it was modified with
setBase(UpdatableSchema). |
void |
merge(UpdatableSchema schema)
Merge a schema into this schema.
|
Schema |
resolve()
Resolve into a schema.
|
void |
setAttributeDefault(int seriesNr,
int attrNr,
Object defaultValue)
Set the default value of a series attribute.
|
<T> void |
setAttributeDefault(int attrNr,
T defaultValue)
Set the default value of an attribute.
|
void |
setAttributeProperty(int seriesNr,
int attrNr,
Property<?> property)
Set the property of a series attribute.
|
<T> void |
setAttributeProperty(int attrNr,
Property<T> property)
Set the property of an attribute.
|
void |
setBase(UpdatableSchema base)
Set the base of the schema.
|
void |
setName(String name)
Set the name of the schema.
|
void |
setSeriesDescription(int seriesNr,
String description)
Set the description of the series.
|
void |
setSeriesName(int seriesNr,
String name)
Set the name of a series.
|
void |
setSeriesSparsity(int seriesNr,
boolean sparse)
Set the sparsity of the series.
|
void |
setSeriesTimeDomain(int seriesNr,
ch.agent.t2.time.TimeDomain timeDomain)
Set the time domain of the series.
|
void |
setSeriesType(int seriesNr,
String type)
Set the value type of the series using the name of the value type.
|
void |
setSeriesType(int seriesNr,
ValueType<?> type)
Set the value type of the series.
|
protected SeriesDefinitionImpl |
startEditingSeriesSchema(int seriesNr)
Start editing a series definition.
|
int |
traverse(boolean resolve,
UpdatableSchemaVisitor visitor)
Traverse all edited attribute and series definitions.
|
protected void |
update()
Refresh state.
|
protected int |
visit(UpdatableSchemaVisitor visitor,
SeriesDefinition seriesDef,
Map<Integer,AttributeDefinition<?>> editedADs,
Map<Integer,AttributeDefinition<?>> origADs) |
dependsOnSchema, getAttributeDefinition, getAttributeDefinition, getAttributeDefinitions, getAttributeDefinitionsObject, getDependencyList, getSeriesDefinition, getSeriesDefinition, getSeriesDefinitions, getSeriesDefinitionsObject, isComplete, toStringequals, getDatabase, getId, getSurrogate, hashCode, inConstruction, isValidclone, finalize, getClass, notify, notifyAll, wait, wait, waitdependsOnSchema, getSeriesDefinition, getSeriesDefinition, getSeriesDefinitions, isCompletegetAttributeDefinition, getAttributeDefinition, getAttributeDefinitionsgetDatabase, getId, getSurrogate, inConstruction, isValidpublic UpdatableSchemaImpl(String name, UpdatableSchema base, Collection<AttributeDefinition<?>> attributeDefs, Collection<SeriesDefinition> seriesDefinitions, Surrogate surrogate) throws T2DBException
UpdatableSchema.name - a stringbase - a base schemaattributeDefs - a collection of attribute definitionsseriesDefinitions - a collection of series definitionssurrogate - a surrogateT2DBException - if there is a duplicate attribute or series namepublic void applyUpdates()
throws T2DBException
UpdatableDatabase.commit() and
Database.rollback() is the client's responsibility.applyUpdates in interface UpdatableT2DBExceptionprotected void update()
throws T2DBException
SchemaImplupdate in class SchemaImplT2DBExceptionpublic UpdatableSchema edit()
SchemaUpdatableSchema corresponding to this schema.
Successfully getting an Updatable object does not imply
that any update can be successfully applied.edit in interface Schemaedit in class SchemaImplpublic void destroy()
throws T2DBException
UpdatableSchemadestroy in interface UpdatableSchemaT2DBExceptionpublic String getName()
IncompleteSchemagetName in interface IncompleteSchemagetName in class SchemaImplpublic void setName(String name) throws T2DBException
UpdatableSchemasetName in interface UpdatableSchemaname - a stringT2DBExceptionpublic UpdatableSchema getBase()
UpdatableSchemagetBase in interface UpdatableSchemapublic UpdatableSchema getPreviousBase()
setBase(UpdatableSchema).
Return the same result as getBase() if the base schema was not modified.public void setBase(UpdatableSchema base) throws T2DBException
UpdatableSchemaDBObject.inConstruction()).setBase in interface UpdatableSchemabase - an updatable schema or nullT2DBExceptionpublic SeriesDefinition addSeries(int seriesNr) throws T2DBException
UpdatableSchemaaddSeries in interface UpdatableSchemaseriesNr - a positive number not already usedT2DBExceptionpublic void deleteSeries(int seriesNr)
throws T2DBException
UpdatableSchemadeleteSeries in interface UpdatableSchemaseriesNr - the number of an existing seriesT2DBExceptionpublic void eraseSeries(int seriesNr)
throws T2DBException
UpdatableSchemaeraseSeries in interface UpdatableSchemaseriesNr - the number of an existing seriesT2DBExceptionpublic void setSeriesDescription(int seriesNr,
String description)
throws T2DBException
UpdatableSchemasetSeriesDescription in interface UpdatableSchemaseriesNr - the number of an existing seriesdescription - a stringT2DBExceptionpublic void setSeriesName(int seriesNr,
String name)
throws T2DBException
UpdatableSchemasetSeriesName in interface UpdatableSchemaseriesNr - the number of an existing seriesname - a stringT2DBExceptionpublic void setSeriesType(int seriesNr,
ValueType<?> type)
throws T2DBException
UpdatableSchemasetSeriesType in interface UpdatableSchemaseriesNr - the number of an existing seriestype - a value typeT2DBExceptionpublic void setSeriesType(int seriesNr,
String type)
throws T2DBException
UpdatableSchemasetSeriesType in interface UpdatableSchemaseriesNr - the number of an existing seriestype - the name of a value type defined in the databaseT2DBExceptionpublic void setSeriesTimeDomain(int seriesNr,
ch.agent.t2.time.TimeDomain timeDomain)
throws T2DBException
UpdatableSchemasetSeriesTimeDomain in interface UpdatableSchemaseriesNr - the number of an existing seriestimeDomain - a time domainT2DBExceptionpublic void setSeriesSparsity(int seriesNr,
boolean sparse)
throws T2DBException
UpdatableSchemasetSeriesSparsity in interface UpdatableSchemaseriesNr - the number of an existing seriessparse - true to force the series to use sparse time series, else falseT2DBExceptionpublic AttributeDefinition<?> addAttribute(int attrNr) throws T2DBException
UpdatableSchemaaddAttribute in interface UpdatableSchemaattrNr - a positive number not already usedT2DBExceptionpublic void deleteAttribute(int attrNr)
throws T2DBException
UpdatableSchemadeleteAttribute in interface UpdatableSchemaattrNr - the number of an existing attributeT2DBExceptionpublic void eraseAttribute(int attrNr)
throws T2DBException
UpdatableSchemaeraseAttribute in interface UpdatableSchemaattrNr - the number of an existing attributeT2DBExceptionpublic <T> void setAttributeProperty(int attrNr,
Property<T> property)
throws T2DBException
UpdatableSchemasetAttributeProperty in interface UpdatableSchemaattrNr - the number of an existing attributeproperty - a propertyT2DBExceptionpublic <T> void setAttributeDefault(int attrNr,
T defaultValue)
throws T2DBException
UpdatableSchemasetAttributeDefault in interface UpdatableSchemaattrNr - the number of an existing attributedefaultValue - a valueT2DBExceptionpublic AttributeDefinition<?> addAttribute(int seriesNr, int attrNr) throws T2DBException
UpdatableSchemaaddAttribute in interface UpdatableSchemaseriesNr - the number of an existing seriesattrNr - a positive number not yet in use within the seriesT2DBExceptionpublic void deleteAttribute(int seriesNr,
int attrNr)
throws T2DBException
UpdatableSchemadeleteAttribute in interface UpdatableSchemaseriesNr - the number of an existing seriesattrNr - the number of an existing attribute within the seriesT2DBExceptionpublic void eraseAttribute(int seriesNr,
int attrNr)
throws T2DBException
UpdatableSchemaeraseAttribute in interface UpdatableSchemaseriesNr - the number of an existing seriesattrNr - the number of an existing attribute within the seriesT2DBExceptionpublic void setAttributeProperty(int seriesNr,
int attrNr,
Property<?> property)
throws T2DBException
UpdatableSchemasetAttributeProperty in interface UpdatableSchemaseriesNr - the number of an existing seriesattrNr - the number of an existing attribute within the seriesproperty - a propertyT2DBExceptionpublic void setAttributeDefault(int seriesNr,
int attrNr,
Object defaultValue)
throws T2DBException
UpdatableSchemasetAttributeDefault in interface UpdatableSchemaseriesNr - the number of an existing seriesattrNr - the number of an existing attribute within the seriesdefaultValue - a valueT2DBExceptionprotected SeriesDefinitionImpl startEditingSeriesSchema(int seriesNr) throws T2DBException
seriesNr - a series numberT2DBExceptionprotected AttributeDefinitionImpl<?> editAttributeDefinition(int attrNr) throws T2DBException
attrNr - an attribute numberT2DBExceptionprotected AttributeDefinitionImpl<?> editSeriesAttributeDefinition(int seriesNr, int attrNr, boolean mustExist) throws T2DBException
seriesNr - a series numberattrNr - an attribute numbermustExist - if true throw an exception instead of returning nullT2DBExceptionpublic void merge(UpdatableSchema schema) throws T2DBException
schema - a schemaT2DBExceptionprotected Schema consolidate(String name, Surrogate surrogate, List<Surrogate> dependencyList) throws T2DBException
T2DBExceptionpublic Schema resolve() throws T2DBException
UpdatableSchemaSchema.isComplete().resolve in interface UpdatableSchemaT2DBExceptionpublic int traverse(boolean resolve,
UpdatableSchemaVisitor visitor)
throws T2DBException
resolve flag on. When
writing updates to the database , use the method with the
resolve flag off.resolve - if true, resolve original and updated schema before traversingvisitor - a schema update visitorT2DBExceptionprotected int visit(UpdatableSchemaVisitor visitor, SeriesDefinition seriesDef, Map<Integer,AttributeDefinition<?>> editedADs, Map<Integer,AttributeDefinition<?>> origADs) throws T2DBException
T2DBExceptionCopyright © 2017. All rights reserved.