public abstract class DatabaseBackendImpl extends Object implements DatabaseBackend
DatabaseBackend
.BUILTIN_PROP_SPARSITY, BUILTIN_PROP_SYMBOL, BUILTIN_PROP_TIME_DOMAIN, BUILTIN_PROP_TYPE, DB_PARAM_Boolean_STRICT_NAME_SPACE, DB_PARAM_Boolean_STRICT_NAME_SPACE_DEFAULT, DB_PARAM_Class_ChronicleUpdatePolicyExtension, DB_PARAM_Class_PermissionChecker, DB_PARAM_Float_CACHE_LOAD_FACTOR, DB_PARAM_Float_CACHE_LOAD_FACTOR_DEFAULT, DB_PARAM_Int_CACHE_SIZE, DB_PARAM_Int_CACHE_SIZE_DEFAULT, MAGIC_NAME_NR, MAGIC_SPARSITY_NR, MAGIC_TIMEDOMAIN_NR, MAGIC_TYPE_NR, MAX_MAGIC_NR
Constructor and Description |
---|
DatabaseBackendImpl(String name,
ch.agent.t2.time.TimeDomainCatalog timeDomainCatalog)
Construct a
DatabaseBackend . |
Modifier and Type | Method and Description |
---|---|
void |
check(Permission permission,
DBObject dBObject)
Check if a permission is available on a database object.
|
boolean |
check(Permission permission,
DBObject dBObject,
boolean permissionRequired)
Check if a permission is available on a database object.
|
void |
check(Permission permission,
Surrogate surrogate)
Check if a permission is available on a database object.
|
boolean |
check(Permission permission,
Surrogate surrogate,
boolean permissionRequired)
Check if a permission is available on a database object.
|
protected void |
checkSurrogate(Surrogate surrogate,
DBObjectType required)
Check the validity of a surrogate for this database and a given database object type.
|
void |
clear()
Clear the internal state of the database.
|
void |
close()
Close the database.
|
void |
configure(DatabaseConfiguration configuration)
Configure the database.
|
<T> UpdatableProperty<T> |
createProperty(String name,
ValueType<T> valueType,
boolean indexed)
Create a property with the parameters specified.
|
UpdatableSchema |
createSchema(String name,
String nameOfBase)
Create a schema with the parameters specified.
|
<T> UpdatableValueType<T> |
createValueType(String name,
boolean restricted,
String scannerClassOrKeyword)
Create a value type with the parameters specified.
|
<T> boolean |
deleteValue(UpdatableSeries<T> series,
ch.agent.t2.time.TimeIndex t)
Delete a value from a series in the database.
|
boolean |
equals(Object obj) |
<T> ValueAccessMethods<T> |
getAccessMethods(ValueType<T> valueType)
Return the series access methods object for the given value type.
|
DatabaseCache |
getCache()
Return the database cache.
|
Chronicle |
getChronicle(String name,
boolean mustExist)
Return the chronicle with the given full name.
|
Chronicle |
getChronicle(Surrogate surrogate)
Return the chronicle identified by a surrogate.
|
ChronicleUpdatePolicy |
getChronicleUpdatePolicy()
Return the chronicle update policy object.
|
<T> ch.agent.t2.timeseries.Observation<T> |
getFirstObservation(Series<T> series,
ch.agent.t2.time.TimeIndex time)
Return the observation at a given time index or the first following
observation.
|
<T> ch.agent.t2.timeseries.Observation<T> |
getLastObservation(Series<T> series,
ch.agent.t2.time.TimeIndex time)
Return the observation at a given time index or the last preceding
observation.
|
MessageListener |
getMessageListener()
Return the message listener.
|
NamingPolicy |
getNamingPolicy()
Return the naming policy of the database.
|
protected PermissionChecker |
getPermissionChecker()
Return the permission checker.
|
Property<?> |
getProperty(String name,
boolean mustExist)
Return the property with the given name.
|
<T> ch.agent.t2.time.Range |
getRange(Series<T> series)
Return the range of the series.
|
Schema |
getSchema(Surrogate surrogate)
Return the schema identified by a surrogate.
|
Collection<Schema> |
getSchemas(String pattern)
Return schemas with names matching a pattern.
|
SchemaUpdatePolicy |
getSchemaUpdatePolicy()
Return the schema update policy.
|
<T> Series<T> |
getSeries(String name,
boolean mustExist)
Return the series with the given full name.
|
Property<?> |
getSparsityBuiltInProperty()
Return the built-in property for sparsity.
|
Property<?> |
getSymbolBuiltInProperty()
Return the built-in property for symbols.
|
Property<?> |
getTimeDomainBuiltInProperty()
Return the built-in property for time domains.
|
ch.agent.t2.time.TimeDomainCatalog |
getTimeDomainCatalog()
Return the time domain catalog.
|
Chronicle |
getTopChronicle()
Return the top chronicle.
|
Property<?> |
getTypeBuiltInProperty()
Return the built-in property for value types.
|
UpdatableSchema |
getUpdatableSchema(Schema schema)
Return the updatable schema corresponding to a schema.
|
Collection<UpdatableSchema> |
getUpdatableSchemas(String pattern)
Return updatable schemas with names matching a pattern.
|
<T> UpdatableSeries<T> |
getUpdatableSeries(String name,
boolean mustExist)
Return an updatable series.
|
UpdateEventPublisher |
getUpdateEventPublisher()
Return the event publisher for this database.
|
<T> long |
getValues(Series<T> series,
ch.agent.t2.time.Range range,
ch.agent.t2.timeseries.TimeAddressable<T> ts)
Load values into the time series in the range specified.
|
int |
hashCode() |
boolean |
isBuiltIn(AttributeDefinition<?> def)
Test whether an attribute definition is built-in.
|
protected boolean |
isChronicleUpdatePolicyExtensionAllowed() |
protected boolean |
isChronicleUpdatePolicyExtensionMandatory() |
boolean |
isStrictNameSpaceMode()
Test if strict name space mode has been configured.
|
Surrogate |
makeSurrogate(String string)
Return a
Surrogate corresponding to the input. |
void |
open()
Open the database.
|
protected void |
publish(UpdateEvent event)
Short cut method to publish a deferred event.
|
<T> void |
setAccessMethods(String valueTypeExternalRepresentation,
ValueAccessMethods<T> accessMethods)
Set the series access methods object for the given value type.
|
void |
setMessageListener(MessageListener listener)
Set the message listener used for logging messages.
|
void |
setStrictNameSpaceMode(boolean strictNameSpaceMode)
Set strict name space mode.
|
String |
toString() |
<T> boolean |
update(UpdatableSeries<T> series,
ch.agent.t2.time.Range range)
Reduce the range of a series in the database.
|
<T> long |
update(UpdatableSeries<T> series,
ch.agent.t2.timeseries.TimeAddressable<T> values)
Update a series in the database with values from a time series.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
create, create, create, create, create, deleteAttributeValue, deleteChronicle, deleteProperty, deleteSchema, deleteSeries, deleteValueType, findChronicle, findChronicle, findChronicle, getAttributeValue, getChronicle, getChronicleOrNull, getChroniclesByAttributeValue, getChroniclesByParent, getProperty, getSchemaSurrogates, getSeries, getUpdatableSchema, makeDBObjectId, update, update, update, update, update
commit, getProperties, getProperty, getSeries, getValueType, getValueType, getValueTypes, rollback
public DatabaseBackendImpl(String name, ch.agent.t2.time.TimeDomainCatalog timeDomainCatalog)
DatabaseBackend
.name
- the name of the databasetimeDomainCatalog
- the catalog to use for scanning time domainspublic ch.agent.t2.time.TimeDomainCatalog getTimeDomainCatalog()
Database
getTimeDomainCatalog
in interface Database
public void open() throws T2DBException
Database
Database.configure(ch.agent.crnickl.api.DatabaseConfiguration)
. What the method does depends on the implementation.
On some implementations it is not necessary to invoke the method before
using the database. Depending on the implementation it is possible to
continue using the database after a fatal error by invoking
Database.close()
then Database.open()
.open
in interface Database
T2DBException
public void close() throws T2DBException
Database
Database.close()
then
Database.open()
.close
in interface Database
T2DBException
public void clear() throws T2DBException
Database
clear
in interface Database
T2DBException
public <T> ValueAccessMethods<T> getAccessMethods(ValueType<T> valueType)
DatabaseBackend
getAccessMethods
in interface DatabaseBackend
valueType
- a value typepublic <T> void setAccessMethods(String valueTypeExternalRepresentation, ValueAccessMethods<T> accessMethods)
DatabaseBackend
Value types are identified using ValueType.getExternalRepresentation()
.
setAccessMethods
in interface DatabaseBackend
valueTypeExternalRepresentation
- a string used as external representation of value typeaccessMethods
- an access methods objectpublic boolean isStrictNameSpaceMode()
DatabaseBackend
isStrictNameSpaceMode
in interface DatabaseBackend
public void setStrictNameSpaceMode(boolean strictNameSpaceMode)
DatabaseBackend
setStrictNameSpaceMode
in interface DatabaseBackend
strictNameSpaceMode
- if true set strict name space modepublic Surrogate makeSurrogate(String string) throws T2DBException
Database
Surrogate
corresponding to the input. The input is
typically a string returned by Surrogate.toString()
. An exception
is thrown if there is a syntax error or if the database of the surrogate
is unknown.makeSurrogate
in interface Database
string
- a string representation of a surrogateT2DBException
protected void checkSurrogate(Surrogate surrogate, DBObjectType required) throws T2DBException
surrogate
- a surrogaterequired
- a database object typeT2DBException
protected boolean isChronicleUpdatePolicyExtensionMandatory()
protected boolean isChronicleUpdatePolicyExtensionAllowed()
public void configure(DatabaseConfiguration configuration) throws T2DBException
Database
configure
in interface Database
configuration
- a database configurationT2DBException
public boolean isBuiltIn(AttributeDefinition<?> def)
DatabaseBackend
isBuiltIn
in interface DatabaseBackend
def
- an attribute definitionpublic DatabaseCache getCache()
DatabaseBackend
getCache
in interface DatabaseBackend
public NamingPolicy getNamingPolicy()
Database
getNamingPolicy
in interface Database
public ChronicleUpdatePolicy getChronicleUpdatePolicy()
DatabaseBackend
getChronicleUpdatePolicy
in interface DatabaseBackend
public SchemaUpdatePolicy getSchemaUpdatePolicy()
DatabaseBackend
getSchemaUpdatePolicy
in interface DatabaseBackend
public UpdateEventPublisher getUpdateEventPublisher()
Database
getUpdateEventPublisher
in interface Database
protected void publish(UpdateEvent event)
event
- an update eventpublic void setMessageListener(MessageListener listener)
Database
setMessageListener
in interface Database
listener
- a message listener or nullpublic MessageListener getMessageListener()
Database
Level.OFF
.getMessageListener
in interface Database
protected PermissionChecker getPermissionChecker()
public boolean check(Permission permission, DBObject dBObject, boolean permissionRequired) throws T2DBException
PermissionChecker
permissionRequired
throw an exception or return false on
failure.check
in interface PermissionChecker
permission
- a permissiondBObject
- a database objectpermissionRequired
- if true throw an exception on failure else return falseT2DBException
public void check(Permission permission, DBObject dBObject) throws T2DBException
PermissionChecker
check
in interface PermissionChecker
permission
- a permissiondBObject
- a database objectT2DBException
public boolean check(Permission permission, Surrogate surrogate, boolean permissionRequired) throws T2DBException
PermissionChecker
permissionRequired
throw an exception or return false on
failure.check
in interface PermissionChecker
permission
- a permissionsurrogate
- a surrogate identifying a database objectpermissionRequired
- if true throw an exception on failure else return falseT2DBException
public void check(Permission permission, Surrogate surrogate) throws T2DBException
PermissionChecker
check
in interface PermissionChecker
permission
- a permissionsurrogate
- if true throw an exception on failure else return falseT2DBException
public Chronicle getTopChronicle()
Database
getTopChronicle
in interface Database
public Chronicle getChronicle(String name, boolean mustExist) throws T2DBException
mustExist
parameter determines behavior when nothing is
found: exception or null result.
When an chronicle exists for the name, throw an exception if reading it is not permitted.
getChronicle
in interface Database
name
- a full namemustExist
- if true throw an exception instead of returning nullT2DBException
public <T> UpdatableSeries<T> getUpdatableSeries(String name, boolean mustExist) throws T2DBException
Database
mustExist
parameter. If set, the series is created on the
fly, unless something is wrong, in which case an exception is thrown. If
not set the method returns null (unless something is wrong). Something is
wrong when the chronicle does not exist or is not accessible, or when the
series is not defined in the schema.
After a new series has been created, the client must execute
Updatable.applyUpdates()
on the series's chronicle or
on the series itself.
getUpdatableSeries
in interface Database
T
- the data type of the underlying time seriesname
- a full namemustExist
- if true throw an exception instead of returning nullT2DBException
public <T> Series<T> getSeries(String name, boolean mustExist) throws T2DBException
Database
mustExist
parameter.getSeries
in interface Database
T
- the data type of the underlying time seriesname
- a full namemustExist
- if true throw an exception instead of returning nullT2DBException
public Chronicle getChronicle(Surrogate surrogate) throws T2DBException
Database
getChronicle
in interface Database
surrogate
- a surrogateT2DBException
public <T> ch.agent.t2.time.Range getRange(Series<T> series) throws T2DBException
DatabaseBackend
getRange
in interface DatabaseBackend
series
- a seriesT2DBException
public <T> long getValues(Series<T> series, ch.agent.t2.time.Range range, ch.agent.t2.timeseries.TimeAddressable<T> ts) throws T2DBException
DatabaseBackend
getValues
in interface DatabaseBackend
series
- a seriesrange
- a range or nullts
- a time seriesT2DBException
public <T> ch.agent.t2.timeseries.Observation<T> getFirstObservation(Series<T> series, ch.agent.t2.time.TimeIndex time) throws T2DBException
DatabaseBackend
getFirstObservation
in interface DatabaseBackend
time
- a time indexT2DBException
public <T> ch.agent.t2.timeseries.Observation<T> getLastObservation(Series<T> series, ch.agent.t2.time.TimeIndex time) throws T2DBException
DatabaseBackend
getLastObservation
in interface DatabaseBackend
time
- a time indexT2DBException
public <T> boolean update(UpdatableSeries<T> series, ch.agent.t2.time.Range range) throws T2DBException
DatabaseBackend
update
in interface DatabaseBackend
series
- a seriesrange
- a rangeT2DBException
public <T> boolean deleteValue(UpdatableSeries<T> series, ch.agent.t2.time.TimeIndex t) throws T2DBException
DatabaseBackend
deleteValue
in interface DatabaseBackend
series
- a seriest
- a time indexT2DBException
public <T> long update(UpdatableSeries<T> series, ch.agent.t2.timeseries.TimeAddressable<T> values) throws T2DBException
DatabaseBackend
update
in interface DatabaseBackend
series
- a seriesvalues
- a time series of valuesT2DBException
public Schema getSchema(Surrogate surrogate) throws T2DBException
This method consolidates the chain of schemas by following links to the parent schema until there is no parent. The result is also known as "runtime schema".
Historical note. In a previous version of this system, chronicle level attributes were merged into series attributes. This is not done any more.
getSchema
in interface Database
surrogate
- a surrogateT2DBException
public Property<?> getProperty(String name, boolean mustExist) throws T2DBException
Database
mustExist
.getProperty
in interface Database
name
- the name of the propertymustExist
- if true throw an exception instead of returning nullT2DBException
public Property<?> getSymbolBuiltInProperty() throws T2DBException
Database
getSymbolBuiltInProperty
in interface Database
T2DBException
public Property<?> getTimeDomainBuiltInProperty() throws T2DBException
Database
getTimeDomainBuiltInProperty
in interface Database
T2DBException
public Property<?> getTypeBuiltInProperty() throws T2DBException
Database
getTypeBuiltInProperty
in interface Database
T2DBException
public Property<?> getSparsityBuiltInProperty() throws T2DBException
Database
getSparsityBuiltInProperty
in interface Database
T2DBException
public Collection<Schema> getSchemas(String pattern) throws T2DBException
Database
getSchemas
in interface Database
pattern
- a name patternT2DBException
public Collection<UpdatableSchema> getUpdatableSchemas(String pattern) throws T2DBException
Database
getUpdatableSchemas
in interface Database
pattern
- a name patternT2DBException
public UpdatableSchema getUpdatableSchema(Schema schema) throws T2DBException
DatabaseBackend
getUpdatableSchema
in interface DatabaseBackend
schema
- a schemaT2DBException
public <T> UpdatableValueType<T> createValueType(String name, boolean restricted, String scannerClassOrKeyword) throws T2DBException
Database
ValueType.StandardValueType
or the name of a class implementing
ValueScanner
. The client must execute
Updatable.applyUpdates()
on the result.createValueType
in interface Database
name
- the name of the value typerestricted
- true if the value type has a list of allowed valuesscannerClassOrKeyword
- a keyword or the name of a scanner classT2DBException
public <T> UpdatableProperty<T> createProperty(String name, ValueType<T> valueType, boolean indexed) throws T2DBException
Database
Updatable.applyUpdates()
on the result.createProperty
in interface Database
name
- the name of the propertyvalueType
- the value type of the attribute valuesindexed
- true if the property is suitable as a search criterionT2DBException
public UpdatableSchema createSchema(String name, String nameOfBase) throws T2DBException
Database
Updatable.applyUpdates()
on the result.createSchema
in interface Database
name
- the name of the schemanameOfBase
- the name of the base schema or null if there is no base schemaT2DBException
Copyright © 2017. All rights reserved.