public class DBTagStore extends AbstractTagStore
Modifier and Type | Class and Description |
---|---|
protected class |
DBTagStore.DBWriteResult
This wrapper is used to actually write results to the database.
|
protected class |
DBTagStore.PollRunner |
protected class |
DBTagStore.SQLTWriteOperation |
static class |
DBTagStore.TagWriteTask |
protected class |
DBTagStore.WriteJob |
AbstractTagStore.LegacyAlertInfo
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
BASE_VALUE_READ_QUERY |
protected static int |
CLEANUP_CYCLE |
protected static int |
LEASE_EXTENSION_PERIOD |
protected static int |
LEASE_UPDATE_WRITE_CYCLE |
protected static int |
MAX_PARAMETERS |
protected boolean |
tablesVerified |
protected static int |
WRITE_CYCLE_WAIT_TIME |
protected static int |
WRITE_TIMEOUT |
log
Constructor and Description |
---|
DBTagStore(GatewayContext context,
java.lang.String managerName,
java.lang.String dataSource,
int pollRate,
int pollOverlap,
boolean isDriving,
java.lang.String driverName) |
Modifier and Type | Method and Description |
---|---|
void |
addLeaseChangeListener(LeaseEventListener listener) |
protected void |
addPropertySetToBatch(int tagId,
BatchStatement stmt,
java.lang.String subPath,
PropertySet props) |
protected void |
addPropertyToBatch(int tagId,
BatchStatement propStmt,
java.lang.String name,
java.lang.Object value,
DataTypeClass dtype) |
protected void |
addPropertyToBatch(int tagId,
BatchStatement stmt,
java.lang.String name,
java.lang.Object value,
DataTypeClass dtype,
DataType type,
java.lang.String subPath,
boolean isCustom) |
void |
addScanClasses(java.util.Collection<ScanClass> scanclasses)
Same as with tags, but for scanclasses.
|
void |
addTags(TagPath parentFolder,
java.util.List<? extends Tag> tags)
Saves the specified tag definitions to the store.
|
protected int |
addTagsV2(TagPath parentFolder,
java.util.List<? extends Tag> tags) |
protected void |
bulkInsertTagMeta(BatchStatement stmt,
int tagId,
java.util.Iterator<PropertyValue> itr) |
protected void |
cacheValuesToWrite(java.util.List<TagPropertyValue> values)
NOTE: Only call after already having sychronized on valuesToWrite *
|
protected void |
checkVersion() |
protected void |
cleanupTables()
Cleans up tables that might have "abandoned" rows.
|
protected void |
configPoll() |
protected void |
deletePropertiesForUpdate(EntityId id,
PropertySet ps,
java.lang.String overridePath,
BatchStatement stmt) |
protected void |
deletePropertyForUpdate(EntityId owner,
Property<?> prop,
java.lang.String overridePath,
BatchStatement stmt) |
void |
deleteScanClasses(java.util.Collection<EntityId> scanclassIds) |
protected void |
deleteTagPropertiesForUpdate(java.util.Collection<EntityId> ids,
TagDiff diff) |
protected void |
deleteTagPropertiesForUpdate(EntityId id,
TagDiff diff,
BatchStatement stmt) |
void |
deleteTags(java.util.Collection<EntityId> tagIds)
Deletes the given tags from the store.
|
protected void |
deleteTagsBatch(SRConnection conn,
java.util.List<EntityId> tagIds,
TaskProgressUpdater updater) |
protected int |
findSCID(java.lang.String scName) |
protected java.sql.PreparedStatement |
getAlarmStateStatement(SRConnection conn) |
protected int |
getBatchSize()
Returns the size that should be used for batching.
|
protected SRConnection |
getConnection()
Returns a new connection.
|
java.sql.Timestamp |
getCurrentUpdateDate() |
protected Datasource |
getDatasource() |
java.lang.String |
getDataSource() |
TagDefinition |
getDefinition(EntityId id) |
java.util.List<TagDefinition> |
getDefinitions(java.util.List<EntityId> ids) |
java.lang.String |
getDriverName() |
ExternalScanclassUpdateListener |
getExternalScanclassListener() |
protected java.util.Map<java.lang.String,java.lang.Integer> |
getIdsForNewTags(SRConnection conn) |
protected java.sql.Timestamp |
getLastUpdateDate(boolean overlapAdjusted) |
protected java.sql.PreparedStatement |
getMetaInsertStatement(SRConnection conn) |
protected java.sql.PreparedStatement |
getPermissionStatment(SRConnection conn) |
TagValue |
getProperty(EntityId id,
TagProp prop) |
protected java.lang.String |
getQuery(java.lang.String key,
java.lang.String rawQuery)
Gets a quoted query from the cache, inserting it if not already there.
|
protected java.util.List<DBTableSchema> |
getRequiredTables() |
protected java.lang.String |
getSCName(EntityId id) |
protected java.util.Iterator<PropertyValue> |
getTagPropValues(Tag tag) |
protected java.lang.String |
getTagValueReadQuery() |
DBValueUpdateListener |
getValueListener() |
DBWriteHandler |
getWriteHandler() |
protected void |
insertComplexTag(java.lang.Integer ownerId,
ComplexTag tag) |
protected void |
insertInWriteTable(DBTagStore.WriteJob job) |
protected void |
insertTagAlarmConfig(SRConnection conn,
java.lang.Long tagId,
java.util.List<AlarmDefinition> config,
java.lang.String overridePath) |
protected void |
insertTagAlarmProperties(SRConnection conn,
java.util.Map<java.lang.Long,AlarmDefinition> defs) |
protected void |
insertTagEventScripts(SRConnection conn,
java.lang.Long tagId,
TagEventScripts scripts,
java.lang.String overridePath) |
protected java.util.Map<java.lang.Integer,GeneralTagConfig<Tag,java.lang.String>> |
insertTags(java.util.List<GeneralTagConfig<Tag,java.lang.String>> tags,
java.lang.Integer ownerId) |
protected void |
internalConfigPoll()
This is where the work is done.
|
protected void |
internalDeleteTag(java.util.List<EntityId> tagIds,
TaskProgressUpdater updater) |
protected void |
internalStoreTagValues(java.util.List<TagPropertyValue> tagVals)
Stores the values.
|
protected boolean |
isConfigPaused() |
protected boolean |
isDatasourceAvailable() |
protected void |
loadAlarmStates(java.util.Map<java.lang.Integer,TagDefinition> tagDefs,
boolean cfgLoad,
java.lang.Object param) |
protected TagDefinition |
loadDefinition(EntityId id) |
protected void |
loadEventScripts(java.util.Map<java.lang.Integer,TagDefinition> tagDefs,
boolean cfgLoad,
java.lang.Object param) |
protected java.util.List<LeaseInfo> |
loadLeaseChanges() |
protected void |
loadMetaProperties(java.util.Map<java.lang.Integer,TagDefinition> tagDefs) |
protected TagValue |
loadMetaPropFromResultset(Dataset set,
int rowId,
TagProp prop) |
protected void |
loadPermissions(java.util.Map<java.lang.Integer,TagDefinition> tagDefs,
boolean cfgLoad,
java.lang.Object param) |
protected void |
loadScanClasses(java.util.List<TagStoreObject<ScanClass>> modifiedSCIs,
java.util.List<EntityId> deletedSCIs)
Returns a map of scan classes loaded from the database.
|
protected void |
loadTags(java.util.List<TagStoreObject<TagConfig>> modifiedTags,
java.util.List<EntityId> deletedTags) |
protected void |
loadTags(java.util.List<TagStoreObject<TagConfig>> modifiedTags,
java.util.List<EntityId> deletedTags,
boolean cfgLoad,
java.lang.Object param)
Loads the tags from the db.
|
protected void |
loadTagsFromResultset(Dataset resultSet,
java.util.List<TagStoreObject<TagConfig>> modifiedTags,
java.util.List<EntityId> deletedTags,
java.util.Map<java.lang.Integer,TagDefinition> tagMap,
java.util.Map<java.lang.Integer,ComplexTagStoreObject> ownerLookup)
This function does slightly different things based on the parameters.
|
protected java.util.List<DBTagValue> |
loadTagValueChanges()
This function reads the value changes for "external tags" (the definition of which depends on
what mode we're
in).
|
protected java.util.List<DBWriteRequest> |
loadWriteQueueRequests()
Scans the write queue for write commands.
|
protected void |
modifyComplexTag(EntityId tagId,
ComplexTagDiff diff) |
void |
modifyScanClass(EntityId scanclassId,
ScanClass newDefinition) |
void |
modifyTagPaths(java.util.List<EntityId> ids,
java.util.List<TagPath> newPaths)
Writes new tag paths to the store.
|
protected void |
modifyTags(java.util.Collection<EntityId> tagIds,
TagDiff diff,
TaskProgressUpdater updater) |
void |
modifyTags(TagDiff diff,
java.util.Collection<EntityId> tagIds)
Applies the tagdiff to the given tags.
|
protected void |
notifyLeasesModified(java.util.Collection<LeaseInfo> leases) |
protected void |
processScanClassLeases()
**************************
START - Scanclass leasing
***************************
|
java.util.Map<java.lang.String,DriverInformation> |
readDriverInformation() |
protected void |
readExternalWriteResults()
This function looks for results of write tasks that we've entered.
|
void |
reloadTags(java.util.Set<EntityId> ids) |
void |
removeLeaseChangeListener(LeaseEventListener listener) |
protected void |
reportError(ErrorLifecycle lifeCycle,
ErrorSeverity severity,
java.lang.String message) |
protected void |
runTableVerification() |
protected void |
saveWriteResults(java.util.List<DBTagStore.DBWriteResult> results) |
protected void |
setConfigPaused(boolean value) |
void |
setConfigPoll(int value) |
void |
setCurrentUpdateDate(java.sql.Timestamp value) |
void |
setDataSource(java.lang.String value) |
void |
setDriverInformation(java.lang.String ipAddress,
int port) |
void |
setExternalScanclassListener(ExternalScanclassUpdateListener listener) |
protected void |
setLastUpdateDate(java.sql.Timestamp value) |
void |
setPollOverlap(int value) |
void |
setValueListener(DBValueUpdateListener valueListener) |
void |
setWriteHandler(DBWriteHandler writeHandler) |
void |
shutdown()
Shuts down the tag store, finalizing any writes and preventing further operations.
|
void |
startup()
Start up the tag store, checks the tables and starts polling.
|
protected void |
storeAlarmConfiguration(SRConnection conn,
java.lang.Long tagId,
AlarmConfiguration config,
java.lang.String overridePath,
boolean tryUpdate) |
protected void |
storeTagEventScripts(SRConnection conn,
java.lang.Long tagId,
TagEventScripts scripts,
boolean tryUpdate) |
void |
storeTagValues(java.util.Collection<TagPropertyValue> tagVals)
Writes the given values to the store.
|
protected void |
updateDriverTable()
This function updates the driver information in the database, inserting it if necessary.
|
protected void |
updateExternalScanclasses()
Reads the full scanclassinstance table and returns the rows as SCI objects.
|
void |
updateLeasedScanclassSet(java.util.Collection<EntityId> scanClasseIds) |
void |
updateScanClassExecStatistics(ExecutableScanClass scanClass,
boolean nextExecOnly)
Update the scanclass instance table with statistics about the executing scan class.
|
protected void |
updateTagCache(java.util.List<TagStoreObject<TagConfig>> modifiedTags,
java.util.List<EntityId> deletedTags) |
protected void |
upgradeAlerts() |
protected void |
verifyTables(boolean createIfAbsent) |
void |
writeAgainstExternalProvider(java.util.List<DBTagStore.TagWriteTask> tasks)
**************************
START - Value write code
***************************
|
protected void |
writeCoreTag(BatchStatement stmt,
java.util.List<GeneralTagConfig<Tag,java.lang.String>> tags,
java.lang.Integer ownerId) |
protected void |
writePermissions(BatchStatement stmt,
int tagid,
TagPermissionsModel permissions) |
protected void |
writePermissions(SRConnection conn,
int tagid,
TagPermissionsModel permissions,
boolean deletePrevious) |
addConfigurationListener, buildPropertyValue, executeScalar, flattenTags, getDBId, getDeepTagCount, getGatewayContext, getIdForMemberPath, getIdsForMemberPaths, getLastError, getLogger, getManagerName, getTypeForValueProp, isErrored, notifyItemsAdded, notifyItemsRemoved, notifyPropertiesChanged, registerUDTs, removeConfigurationListener, removeFromUIDEidCache, setErrored, updateStatMetrics, updateUDTEidCache, updateUDTsForLoadedTags
protected static final int LEASE_UPDATE_WRITE_CYCLE
protected static final int LEASE_EXTENSION_PERIOD
protected static final int WRITE_TIMEOUT
protected static final int WRITE_CYCLE_WAIT_TIME
protected static final int CLEANUP_CYCLE
protected static final int MAX_PARAMETERS
protected boolean tablesVerified
protected static final java.lang.String BASE_VALUE_READ_QUERY
public DBTagStore(GatewayContext context, java.lang.String managerName, java.lang.String dataSource, int pollRate, int pollOverlap, boolean isDriving, java.lang.String driverName)
protected int getBatchSize()
public java.lang.String getDriverName()
public java.lang.String getDataSource()
public void setDataSource(java.lang.String value)
protected boolean isDatasourceAvailable()
protected boolean isConfigPaused()
protected void setConfigPaused(boolean value)
public DBWriteHandler getWriteHandler()
public void setWriteHandler(DBWriteHandler writeHandler)
public DBValueUpdateListener getValueListener()
public void setValueListener(DBValueUpdateListener valueListener)
public ExternalScanclassUpdateListener getExternalScanclassListener()
public void setExternalScanclassListener(ExternalScanclassUpdateListener listener)
public void setConfigPoll(int value)
public void setPollOverlap(int value)
protected java.sql.Timestamp getLastUpdateDate(boolean overlapAdjusted)
protected void setLastUpdateDate(java.sql.Timestamp value)
public java.sql.Timestamp getCurrentUpdateDate()
public void setCurrentUpdateDate(java.sql.Timestamp value)
public void addLeaseChangeListener(LeaseEventListener listener)
public void removeLeaseChangeListener(LeaseEventListener listener)
protected void notifyLeasesModified(java.util.Collection<LeaseInfo> leases)
public void startup() throws java.lang.Exception
java.lang.Exception
public void shutdown()
TagStore
protected SRConnection getConnection() throws java.sql.SQLException
java.sql.SQLException
protected Datasource getDatasource()
protected java.lang.String getQuery(java.lang.String key, java.lang.String rawQuery)
key
- rawQuery
- protected java.lang.String getSCName(EntityId id)
protected final void configPoll()
protected void internalConfigPoll() throws java.lang.Exception
conn
- java.lang.Exception
public TagDefinition getDefinition(EntityId id)
public java.util.List<TagDefinition> getDefinitions(java.util.List<EntityId> ids)
protected TagDefinition loadDefinition(EntityId id)
protected void updateTagCache(java.util.List<TagStoreObject<TagConfig>> modifiedTags, java.util.List<EntityId> deletedTags)
public void reloadTags(java.util.Set<EntityId> ids)
protected void loadTags(java.util.List<TagStoreObject<TagConfig>> modifiedTags, java.util.List<EntityId> deletedTags) throws java.sql.SQLException
java.sql.SQLException
protected void loadTags(java.util.List<TagStoreObject<TagConfig>> modifiedTags, java.util.List<EntityId> deletedTags, boolean cfgLoad, java.lang.Object param) throws java.sql.SQLException
modifiedTags
- deletedTags
- cfgLoad
- param
- java.sql.SQLException
protected void loadTagsFromResultset(Dataset resultSet, java.util.List<TagStoreObject<TagConfig>> modifiedTags, java.util.List<EntityId> deletedTags, java.util.Map<java.lang.Integer,TagDefinition> tagMap, java.util.Map<java.lang.Integer,ComplexTagStoreObject> ownerLookup)
resultSet
- deletedTags
- tagMap
- ownerLookup
- protected void loadMetaProperties(java.util.Map<java.lang.Integer,TagDefinition> tagDefs) throws java.lang.Exception
java.lang.Exception
protected TagValue loadMetaPropFromResultset(Dataset set, int rowId, TagProp prop)
protected void loadAlarmStates(java.util.Map<java.lang.Integer,TagDefinition> tagDefs, boolean cfgLoad, java.lang.Object param) throws java.lang.Exception
java.lang.Exception
protected void loadPermissions(java.util.Map<java.lang.Integer,TagDefinition> tagDefs, boolean cfgLoad, java.lang.Object param) throws java.lang.Exception
java.lang.Exception
protected void loadEventScripts(java.util.Map<java.lang.Integer,TagDefinition> tagDefs, boolean cfgLoad, java.lang.Object param) throws java.lang.Exception
java.lang.Exception
protected void loadScanClasses(java.util.List<TagStoreObject<ScanClass>> modifiedSCIs, java.util.List<EntityId> deletedSCIs) throws java.sql.SQLException
providerId
- java.sql.SQLException
protected java.util.List<DBWriteRequest> loadWriteQueueRequests() throws java.sql.SQLException
java.sql.SQLException
protected void saveWriteResults(java.util.List<DBTagStore.DBWriteResult> results) throws java.lang.Exception
java.lang.Exception
protected void reportError(ErrorLifecycle lifeCycle, ErrorSeverity severity, java.lang.String message)
protected java.lang.String getTagValueReadQuery()
protected java.util.List<DBTagValue> loadTagValueChanges()
public void storeTagValues(java.util.Collection<TagPropertyValue> tagVals)
TagStore
protected void internalStoreTagValues(java.util.List<TagPropertyValue> tagVals)
protected void cacheValuesToWrite(java.util.List<TagPropertyValue> values)
protected void updateExternalScanclasses()
public void addTags(TagPath parentFolder, java.util.List<? extends Tag> tags) throws java.lang.Exception
TagStore
java.lang.Exception
protected int addTagsV2(TagPath parentFolder, java.util.List<? extends Tag> tags) throws java.lang.Exception
java.lang.Exception
protected void insertComplexTag(java.lang.Integer ownerId, ComplexTag tag) throws java.lang.Exception
java.lang.Exception
protected java.util.Map<java.lang.Integer,GeneralTagConfig<Tag,java.lang.String>> insertTags(java.util.List<GeneralTagConfig<Tag,java.lang.String>> tags, java.lang.Integer ownerId) throws java.lang.Exception
java.lang.Exception
protected void writeCoreTag(BatchStatement stmt, java.util.List<GeneralTagConfig<Tag,java.lang.String>> tags, java.lang.Integer ownerId) throws java.sql.SQLException, TaskCancellationException
java.sql.SQLException
TaskCancellationException
protected java.util.Map<java.lang.String,java.lang.Integer> getIdsForNewTags(SRConnection conn) throws java.sql.SQLException
java.sql.SQLException
protected java.util.Iterator<PropertyValue> getTagPropValues(Tag tag)
public void modifyTags(TagDiff diff, java.util.Collection<EntityId> tagIds)
TagStore
protected void modifyTags(java.util.Collection<EntityId> tagIds, TagDiff diff, TaskProgressUpdater updater)
public void modifyTagPaths(java.util.List<EntityId> ids, java.util.List<TagPath> newPaths) throws java.lang.Exception
TagStore
java.lang.Exception
protected java.sql.PreparedStatement getMetaInsertStatement(SRConnection conn) throws java.sql.SQLException
java.sql.SQLException
protected void bulkInsertTagMeta(BatchStatement stmt, int tagId, java.util.Iterator<PropertyValue> itr) throws java.lang.Exception
java.lang.Exception
protected void addPropertyToBatch(int tagId, BatchStatement propStmt, java.lang.String name, java.lang.Object value, DataTypeClass dtype) throws java.lang.Exception
java.lang.Exception
protected void addPropertySetToBatch(int tagId, BatchStatement stmt, java.lang.String subPath, PropertySet props) throws java.lang.Exception
java.lang.Exception
protected void addPropertyToBatch(int tagId, BatchStatement stmt, java.lang.String name, java.lang.Object value, DataTypeClass dtype, DataType type, java.lang.String subPath, boolean isCustom) throws java.sql.SQLException
java.sql.SQLException
protected void deleteTagPropertiesForUpdate(java.util.Collection<EntityId> ids, TagDiff diff) throws java.sql.SQLException
java.sql.SQLException
protected void deleteTagPropertiesForUpdate(EntityId id, TagDiff diff, BatchStatement stmt) throws java.sql.SQLException
java.sql.SQLException
protected void deletePropertiesForUpdate(EntityId id, PropertySet ps, java.lang.String overridePath, BatchStatement stmt) throws java.sql.SQLException
java.sql.SQLException
protected void deletePropertyForUpdate(EntityId owner, Property<?> prop, java.lang.String overridePath, BatchStatement stmt) throws java.sql.SQLException
java.sql.SQLException
protected java.sql.PreparedStatement getAlarmStateStatement(SRConnection conn) throws java.sql.SQLException
java.sql.SQLException
protected void modifyComplexTag(EntityId tagId, ComplexTagDiff diff) throws java.lang.Exception
java.lang.Exception
protected void storeTagEventScripts(SRConnection conn, java.lang.Long tagId, TagEventScripts scripts, boolean tryUpdate) throws java.lang.Exception
java.lang.Exception
protected void storeAlarmConfiguration(SRConnection conn, java.lang.Long tagId, AlarmConfiguration config, java.lang.String overridePath, boolean tryUpdate) throws java.lang.Exception
java.lang.Exception
protected void insertTagEventScripts(SRConnection conn, java.lang.Long tagId, TagEventScripts scripts, java.lang.String overridePath)
protected void insertTagAlarmConfig(SRConnection conn, java.lang.Long tagId, java.util.List<AlarmDefinition> config, java.lang.String overridePath) throws java.sql.SQLException
java.sql.SQLException
protected void insertTagAlarmProperties(SRConnection conn, java.util.Map<java.lang.Long,AlarmDefinition> defs) throws java.sql.SQLException
java.sql.SQLException
protected java.sql.PreparedStatement getPermissionStatment(SRConnection conn) throws java.sql.SQLException
java.sql.SQLException
protected void writePermissions(SRConnection conn, int tagid, TagPermissionsModel permissions, boolean deletePrevious) throws java.sql.SQLException
java.sql.SQLException
protected void writePermissions(BatchStatement stmt, int tagid, TagPermissionsModel permissions) throws java.sql.SQLException
java.sql.SQLException
protected int findSCID(java.lang.String scName)
public void deleteTags(java.util.Collection<EntityId> tagIds) throws java.lang.Exception
TagStore
deleteTags
in interface TagStore
deleteTags
in class AbstractTagStore
java.lang.Exception
protected void internalDeleteTag(java.util.List<EntityId> tagIds, TaskProgressUpdater updater) throws java.lang.Exception
internalDeleteTag
in class AbstractTagStore
java.lang.Exception
protected void deleteTagsBatch(SRConnection conn, java.util.List<EntityId> tagIds, TaskProgressUpdater updater) throws java.lang.Exception
java.lang.Exception
public void addScanClasses(java.util.Collection<ScanClass> scanclasses) throws java.lang.Exception
TagStore
java.lang.Exception
public void modifyScanClass(EntityId scanclassId, ScanClass newDefinition) throws java.lang.Exception
java.lang.Exception
public void deleteScanClasses(java.util.Collection<EntityId> scanclassIds)
protected java.util.List<DBTableSchema> getRequiredTables()
protected void runTableVerification()
protected final void verifyTables(boolean createIfAbsent) throws java.lang.Exception
java.lang.Exception
protected void checkVersion()
public void setDriverInformation(java.lang.String ipAddress, int port)
protected void updateDriverTable()
public void updateScanClassExecStatistics(ExecutableScanClass scanClass, boolean nextExecOnly)
scanClass
- nextExecOnly
- protected java.util.List<LeaseInfo> loadLeaseChanges()
protected void processScanClassLeases()
public void updateLeasedScanclassSet(java.util.Collection<EntityId> scanClasseIds)
public java.util.Map<java.lang.String,DriverInformation> readDriverInformation()
protected void cleanupTables() throws java.lang.Exception
conn
- java.lang.Exception
protected void upgradeAlerts() throws java.lang.Exception
java.lang.Exception
public void writeAgainstExternalProvider(java.util.List<DBTagStore.TagWriteTask> tasks)
protected void insertInWriteTable(DBTagStore.WriteJob job)
protected void readExternalWriteResults()
conn
-