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, toString
equals, getDatabase, getId, getSurrogate, hashCode, inConstruction, isValid
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
dependsOnSchema, getSeriesDefinition, getSeriesDefinition, getSeriesDefinitions, isComplete
getAttributeDefinition, getAttributeDefinition, getAttributeDefinitions
getDatabase, getId, getSurrogate, inConstruction, isValid
public 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
Updatable
Database.commit()
and
Database.rollback()
is the client's responsibility.applyUpdates
in interface Updatable
T2DBException
protected void update() throws T2DBException
SchemaImpl
update
in class SchemaImpl
T2DBException
public UpdatableSchema edit()
Schema
UpdatableSchema
corresponding to this schema.
Successfully getting an Updatable
object does not imply
that any update can be successfully applied.edit
in interface Schema
edit
in class SchemaImpl
public void destroy() throws T2DBException
UpdatableSchema
destroy
in interface UpdatableSchema
T2DBException
public String getName()
IncompleteSchema
getName
in interface IncompleteSchema
getName
in class SchemaImpl
public void setName(String name) throws T2DBException
UpdatableSchema
setName
in interface UpdatableSchema
name
- a stringT2DBException
public UpdatableSchema getBase()
UpdatableSchema
getBase
in interface UpdatableSchema
public UpdatableSchema getPreviousBase()
setBase(UpdatableSchema)
.
Return the same result as getBase()
if the base schema was not modified.public void setBase(UpdatableSchema base) throws T2DBException
UpdatableSchema
DBObject.inConstruction()
).setBase
in interface UpdatableSchema
base
- an updatable schema or nullT2DBException
public SeriesDefinition addSeries(int seriesNr) throws T2DBException
UpdatableSchema
addSeries
in interface UpdatableSchema
seriesNr
- a positive number not already usedT2DBException
public void deleteSeries(int seriesNr) throws T2DBException
UpdatableSchema
deleteSeries
in interface UpdatableSchema
seriesNr
- the number of an existing seriesT2DBException
public void eraseSeries(int seriesNr) throws T2DBException
UpdatableSchema
eraseSeries
in interface UpdatableSchema
seriesNr
- the number of an existing seriesT2DBException
public void setSeriesDescription(int seriesNr, String description) throws T2DBException
UpdatableSchema
setSeriesDescription
in interface UpdatableSchema
seriesNr
- the number of an existing seriesdescription
- a stringT2DBException
public void setSeriesName(int seriesNr, String name) throws T2DBException
UpdatableSchema
setSeriesName
in interface UpdatableSchema
seriesNr
- the number of an existing seriesname
- a stringT2DBException
public void setSeriesType(int seriesNr, ValueType<?> type) throws T2DBException
UpdatableSchema
setSeriesType
in interface UpdatableSchema
seriesNr
- the number of an existing seriestype
- a value typeT2DBException
public void setSeriesType(int seriesNr, String type) throws T2DBException
UpdatableSchema
setSeriesType
in interface UpdatableSchema
seriesNr
- the number of an existing seriestype
- the name of a value type defined in the databaseT2DBException
public void setSeriesTimeDomain(int seriesNr, ch.agent.t2.time.TimeDomain timeDomain) throws T2DBException
UpdatableSchema
setSeriesTimeDomain
in interface UpdatableSchema
seriesNr
- the number of an existing seriestimeDomain
- a time domainT2DBException
public void setSeriesSparsity(int seriesNr, boolean sparse) throws T2DBException
UpdatableSchema
setSeriesSparsity
in interface UpdatableSchema
seriesNr
- the number of an existing seriessparse
- true to force the series to use sparse time series, else falseT2DBException
public AttributeDefinition<?> addAttribute(int attrNr) throws T2DBException
UpdatableSchema
addAttribute
in interface UpdatableSchema
attrNr
- a positive number not already usedT2DBException
public void deleteAttribute(int attrNr) throws T2DBException
UpdatableSchema
deleteAttribute
in interface UpdatableSchema
attrNr
- the number of an existing attributeT2DBException
public void eraseAttribute(int attrNr) throws T2DBException
UpdatableSchema
eraseAttribute
in interface UpdatableSchema
attrNr
- the number of an existing attributeT2DBException
public <T> void setAttributeProperty(int attrNr, Property<T> property) throws T2DBException
UpdatableSchema
setAttributeProperty
in interface UpdatableSchema
attrNr
- the number of an existing attributeproperty
- a propertyT2DBException
public <T> void setAttributeDefault(int attrNr, T defaultValue) throws T2DBException
UpdatableSchema
setAttributeDefault
in interface UpdatableSchema
attrNr
- the number of an existing attributedefaultValue
- a valueT2DBException
public AttributeDefinition<?> addAttribute(int seriesNr, int attrNr) throws T2DBException
UpdatableSchema
addAttribute
in interface UpdatableSchema
seriesNr
- the number of an existing seriesattrNr
- a positive number not yet in use within the seriesT2DBException
public void deleteAttribute(int seriesNr, int attrNr) throws T2DBException
UpdatableSchema
deleteAttribute
in interface UpdatableSchema
seriesNr
- the number of an existing seriesattrNr
- the number of an existing attribute within the seriesT2DBException
public void eraseAttribute(int seriesNr, int attrNr) throws T2DBException
UpdatableSchema
eraseAttribute
in interface UpdatableSchema
seriesNr
- the number of an existing seriesattrNr
- the number of an existing attribute within the seriesT2DBException
public void setAttributeProperty(int seriesNr, int attrNr, Property<?> property) throws T2DBException
UpdatableSchema
setAttributeProperty
in interface UpdatableSchema
seriesNr
- the number of an existing seriesattrNr
- the number of an existing attribute within the seriesproperty
- a propertyT2DBException
public void setAttributeDefault(int seriesNr, int attrNr, Object defaultValue) throws T2DBException
UpdatableSchema
setAttributeDefault
in interface UpdatableSchema
seriesNr
- the number of an existing seriesattrNr
- the number of an existing attribute within the seriesdefaultValue
- a valueT2DBException
protected SeriesDefinitionImpl startEditingSeriesSchema(int seriesNr) throws T2DBException
seriesNr
- a series numberT2DBException
protected AttributeDefinitionImpl<?> editAttributeDefinition(int attrNr) throws T2DBException
attrNr
- an attribute numberT2DBException
protected 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 nullT2DBException
public void merge(UpdatableSchema schema) throws T2DBException
schema
- a schemaT2DBException
protected Schema consolidate(String name, Surrogate surrogate, List<Surrogate> dependencyList) throws T2DBException
T2DBException
public Schema resolve() throws T2DBException
UpdatableSchema
Schema.isComplete()
.resolve
in interface UpdatableSchema
T2DBException
public 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 visitorT2DBException
protected int visit(UpdatableSchemaVisitor visitor, SeriesDefinition seriesDef, Map<Integer,AttributeDefinition<?>> editedADs, Map<Integer,AttributeDefinition<?>> origADs) throws T2DBException
T2DBException
Copyright © 2017. All rights reserved.