class documentation

class TinyDBBinding(DBBinding):

View In Hierarchy

This class implements the TinyDB binding to the database. It is used by the Storage class.

Method addBatchNotification Add a batch notification to the database.
Method addOriginator Add an originator to the database.
Method backupDB Backup the database to a directory.
Method closeDB Close the database.
Method configure Callback method for the configuration phase of the plugin lifecycle.
Method countBatchNotifications Return the number of batch notifications for a resource and notification URI.
Method countResources Return the number of resources in the database.
Method deleteIdentifier Delete an identifier from the identifiers DB.
Method deleteRequests Remnove all stored requests from the database.
Method deleteResource Delete a resource from the database.
Method discoverResourcesByFilter Search for resources by a filter function. This goes through all resources in the database and applies the filter function to each resource. If the filter function returns True, the resource is added to the result list.
Method getActionRep Get an action representation by resource ID.
Method getAllActionReprs Return all action representations.
Method getBatchNotifications Return the batch notifications for a resource and notification URI.
Method getOriginator Get an originator and its information from the database.
Method getRequests Get requests for a resource ID, or all requests.
Method getSchedule Get a schedule from the database.
Method getSchedules Get all schedules from the database.
Method hasResource Check if a resource exists in the database.
Method init Callback method for the initialization phase of the plugin lifecycle.
Method insertRequest Add a request to the requests database.
Method insertResource Insert a resource into the database.
Method purgeDB Purge the database. Remove all data
Method purgeStatistics Purge the statistics DB.
Method removeActionRepr Remove an action representation.
Method removeBatchNotifications Remove the batch notifications for a resource and notification URI.
Method removeChildResource Remove a child resource from the childResources DB.
Method removeOldRequests Remove old requests from the database.
Method removeOriginator Remove an originator from the database.
Method removeSchedule Remove a schedule from the database.
Method removeSubscriptionRepr Remove a subscription representation from the database.
Method searchActionsReprsForSubject Search for action representations by subject.
Method searchByFragment Search and return all resources that match the given dictionary/document.
Method searchChildResourceIDsByParentRIAndType Search for child resources by parent resource ID and optional type.
Method searchIdentifiers Search for an resource ID OR for a structured name in the identifiers DB.
Method searchResources Search for resources by structured resource name, resource ID, CSE-ID, parent resource ID, resource type, or application entity ID.
Method searchSchedulesForParent Search for schedules in the database.
Method searchStatistics Search for statistics.
Method searchSubscriptionReprs Search for subscription representations by resource ID or parent resource ID.
Method start Callback method for the start phase of the plugin lifecycle.
Method updateActionRepr Update an action representation.
Method updateResource Update a resource in the database. Only the fields that are not None will be updated.
Method upsertActionRepr Update or insert an action representation.
Method upsertChildResource Add a child resource to the childResources DB.
Method upsertIdentifier Insert or update an identifier into the identifiers DB and a structured resource name into the structuredResourceNames DB.
Method upsertResource Update or insert a resource into the database.
Method upsertSchedule Add or update a schedule in the database.
Method upsertStatistics Update or insert statistics.
Method upsertSubscriptionRepr Update or insert a subscription representation into the database.
Method validate Callback method for the validation phase of the plugin lifecycle.
Class Variable __slots__ Define slots for instance variables.
Instance Variable actionsQuery The TinyDB query object for the actions table.
Instance Variable batchNotificationQuery The TinyDB query object for the batchNotifications table.
Instance Variable cacheSize Size of the cache for the TinyDB tables.
Instance Variable dbActions The TinyDB database for the actions table.
Instance Variable dbBatchNotifications The TinyDB database for the batchNotifications table.
Instance Variable dbIdentifiers The TinyDB database for the identifiers table.
Instance Variable dbOriginators The TinyDB database for the originators table.
Instance Variable dbRequests The TinyDB database for the requests table.
Instance Variable dbResources The TinyDB database for the resources table.
Instance Variable dbSchedules The TinyDB database for the schedules table.
Instance Variable dbStatistics The TinyDB database for the statistics table.
Instance Variable dbSubscriptions The TinyDB database for the subscriptions table.
Instance Variable fileActions Filename for the actions table.
Instance Variable fileBatchNotifications Filename for the batchNotifications table.
Instance Variable fileIdentifiers Filename for the identifiers table.
Instance Variable fileOriginators Filename for the originators table.
Instance Variable fileRequests Filename for the requests table.
Instance Variable fileResources Filename for the resources table.
Instance Variable fileSchedules Filename for the schedules table.
Instance Variable fileStatistics Filename for the statistics table.
Instance Variable fileSubscriptions Filename for the subscriptions table.
Instance Variable identifierQuery The TinyDB query object for the identifiers table.
Instance Variable lockActions Lock for the actions table.
Instance Variable lockBatchNotifications Lock for the batchNotifications table.
Instance Variable lockChildResources Lock for the childResources table.
Instance Variable lockIdentifiers Lock for the identifiers table.
Instance Variable lockOriginators Lock for the originators.
Instance Variable lockRequests Lock for the requests table.
Instance Variable lockResources Lock for the resources table.
Instance Variable lockSchedules Lock for the schedules table.
Instance Variable lockStatistics Lock for the statistics table.
Instance Variable lockStructuredIDs Lock for the structuredIDs table.
Instance Variable lockSubscriptions Lock for the subscriptions table.
Instance Variable originatorsQuery The TinyDB query object for the originators table.
Instance Variable path Path to the database directory.
Instance Variable postfix Postfix for the database file names.
Instance Variable requestsQuery The TinyDB query object for the requests table.
Instance Variable resourceQuery The TinyDB query object for the resources table.
Instance Variable schedulesQuery The TinyDB query object for the schedules table.
Instance Variable subscriptionQuery The TinyDB query object for the subscriptions table.
Instance Variable tabActions The TinyDB table for the actions table.
Instance Variable tabBatchNotifications The TinyDB table for the batchNotifications table.
Instance Variable tabChildResources The TinyDB table for the childResources table.
Instance Variable tabIdentifiers The TinyDB table for the identifiers table.
Instance Variable tabOriginators The TinyDB table for the originators table.
Instance Variable tabRequests The TinyDB table for the requests table.
Instance Variable tabResources The TinyDB table for the resources table.
Instance Variable tabSchedules The TinyDB table for the schedules table.
Instance Variable tabStatistics The TinyDB table for the statistics table.
Instance Variable tabStructuredIDs The TinyDB table for the structuredIDs table.
Instance Variable tabSubscriptions The TinyDB table for the subscriptions table.
Instance Variable writeDelay Delay for writing to the database.
def addBatchNotification(self, batchRecord: JSON) -> bool:

Add a batch notification to the database.

Parameters
batchRecord:JSONThe batch notification to add.
Returns
boolTrue if the batch notification was added, False otherwise.
def addOriginator(self, originatorStructure: JSON, originator: str) -> bool:

Add an originator to the database.

Parameters
originatorStructure:JSONThe originator structure to add.
originator:strThe originator to add.
Returns
boolBoolean value to indicate success or failure.
def backupDB(self, dir: str) -> bool:

Backup the database to a directory.

Parameters
dir:strThe directory to backup to.
Returns
boolBoolean value to indicate success or failure.
def closeDB(self):

Close the database.

def configure(self, config: Configuration):

Callback method for the configuration phase of the plugin lifecycle.

Parameters
config:ConfigurationThe configuration object containing the configuration settings for the plugin.
def countBatchNotifications(self, ri: str, nu: str) -> int:

Return the number of batch notifications for a resource and notification URI.

Parameters
ri:strThe resource ID of the resource.
nu:strThe notification URI.
Returns
intThe number of batch notifications for the resource and notification URI.
def countResources(self) -> int:

Return the number of resources in the database.

Returns
intThe number of resources in the database.
def deleteIdentifier(self, ri: str, srn: str):

Delete an identifier from the identifiers DB.

Parameters
ri:strThe resource ID of the resource.
srn:strThe structured resource name of the resource.
def deleteRequests(self, ri: str | None = None):

Remnove all stored requests from the database.

Parameters
ri:str | NoneOptional resouce ID. Only requests for this resource ID will be deleted.
def deleteResource(self, ri: str):

Delete a resource from the database.

Parameters
ri:strThe resource ID of the resource.
def discoverResourcesByFilter(self, func: Callable[[JSON], bool]) -> list[JSON]:

Search for resources by a filter function. This goes through all resources in the database and applies the filter function to each resource. If the filter function returns True, the resource is added to the result list.

Parameters
func:Callable[[JSON], bool]The filter function to use.
Returns
list[JSON]A list of found resource documents, or an empty list.
def getActionRep(self, ri: str) -> JSON | None:

Get an action representation by resource ID.

Parameters
ri:strThe resource ID of the action representation.
Returns
JSON | NoneThe action representation, or None if not found.
def getAllActionReprs(self) -> list[JSON]:

Return all action representations.

Returns
list[JSON]A list of action representations, or None if not found.
def getBatchNotifications(self, ri: str, nu: str) -> list[JSON]:

Return the batch notifications for a resource and notification URI.

Parameters
ri:strThe resource ID of the resource.
nu:strThe notification URI.
Returns
list[JSON]A list of batch notifications for the resource and notification URI.
def getOriginator(self, originator: str) -> tuple[str, OriginatorType] | None:

Get an originator and its information from the database.

Parameters
originator:strThe originator to search for.
Returns
tuple[str, OriginatorType] | NoneTuple containing the originator and its type, or None if not found.
def getRequests(self, ri: str | None = None) -> list[JSON]:

Get requests for a resource ID, or all requests.

Parameters
ri:str | NoneThe target resource's resource ID. If None or empty, then all requests are returned
Returns
list[JSON]List of Documents. May be empty.
def getSchedule(self, ri: str) -> JSON | None:

Get a schedule from the database.

Parameters
ri:strThe resource ID of the schedule.
Returns
JSON | NoneThe schedule, or None if not found.
def getSchedules(self) -> list[JSON]:

Get all schedules from the database.

Returns
list[JSON]List of Documents. May be empty.
def hasResource(self, ri: str | None = None, srn: str | None = None, ty: int | None = None) -> bool:

Check if a resource exists in the database.

Only one of the parameters may be used at a time. The order of precedence is: structured resource name, resource ID, resource type.

Parameters
ri:str | NoneA resource ID.
srn:str | NoneA structured resource name.
ty:int | NoneA resource type.
Returns
boolTrue if the resource exists, False otherwise.
def init(self):

Callback method for the initialization phase of the plugin lifecycle.

def insertRequest(self, req: JSON, ts: float) -> bool:

Add a request to the requests database.

Parameters
req:JSONThe request to store.
ts:floatThe timestamp of the request.
Returns
boolBoolean value to indicate success or failure.
def insertResource(self, resource: JSON, ri: str):

Insert a resource into the database.

Parameters
resource:JSONThe resource to insert.
ri:strThe resource ID of the resource.
def purgeDB(self):

Purge the database. Remove all data

def purgeStatistics(self):

Purge the statistics DB.

def removeActionRepr(self, ri: str) -> bool:

Remove an action representation.

Parameters
ri:strThe action's resource ID.
Returns
boolTrue if the action representation was removed, False otherwise.
def removeBatchNotifications(self, ri: str, nu: str) -> bool:

Remove the batch notifications for a resource and notification URI.

Parameters
ri:strThe resource ID of the resource.
nu:strThe notification URI.
Returns
boolTrue if the batch notifications were removed, False otherwise.
def removeChildResource(self, ri: str, pi: str):

Remove a child resource from the childResources DB.

Parameters
ri:strThe resource ID of the resource.
pi:strThe resource ID of the parent resource.
def removeOldRequests(self, maxRequests: int):

Remove old requests from the database.

Parameters
maxRequests:intThe maximum number of requests to keep.
def removeOriginator(self, originator: str) -> bool:

Remove an originator from the database.

Parameters
originator:strThe originator to remove.
Returns
boolBoolean value to indicate success or failure.
def removeSchedule(self, ri: str) -> bool:

Remove a schedule from the database.

Parameters
ri:strThe resource ID of the schedule to remove.
Returns
boolTrue if the schedule was removed, False otherwise.
def removeSubscriptionRepr(self, ri: str) -> bool:

Remove a subscription representation from the database.

Parameters
ri:strThe resource ID of the original SUB resource.
Returns
boolTrue if the subscription representation was removed, False otherwise.
def searchActionsReprsForSubject(self, subjectRi: str) -> Sequence[JSON]:

Search for action representations by subject.

Parameters
subjectRi:strThe resource ID of the action representation's subject.
Returns
Sequence[JSON]A list of action representations, or an empty list if not found.
def searchByFragment(self, dct: dict) -> list[JSON]:

Search and return all resources that match the given dictionary/document.

Parameters
dct:dictThe dictionary/document to search for.
Returns
list[JSON]A list of found resources, or an empty list.
def searchChildResourceIDsByParentRIAndType(self, pi: str, ty: ResourceTypes | list[ResourceTypes] | None = None) -> list[str]:

Search for child resources by parent resource ID and optional type.

Parameters
pi:strThe parent resource ID.
ty:ResourceTypes | list[ResourceTypes] | NoneThe resource type of the child resources to search for, or a list of resource types.
Returns
list[str]A list of child resource IDs, or an empty list if not found.
def searchIdentifiers(self, ri: str | None = None, srn: str | None = None) -> list[JSON]:

Search for an resource ID OR for a structured name in the identifiers DB.

Either ri or srn shall be given. If both are given then srn is taken.

Parameters
ri:str | NoneResource ID to search for.
srn:str | NoneStructured path to search for.
Returns
list[JSON]A list of found identifier documents (see upsertIdentifier), or an empty list if not found.
def searchResources(self, ri: str | None = None, csi: str | None = None, srn: str | None = None, pi: str | None = None, ty: int | None = None, aei: str | None = None) -> list[JSON]:

Search for resources by structured resource name, resource ID, CSE-ID, parent resource ID, resource type, or application entity ID.

Only one of the parameters may be used at a time. The order of precedence is: structured resource name, resource ID, CSE-ID, structured resource name, parent resource ID, resource type, application entity ID.

Parameters
ri:str | NoneA resource ID.
csi:str | NoneA CSE ID.
srn:str | NoneA structured resource name.
pi:str | NoneA parent resource ID.
ty:int | NoneA resource type.
aei:str | NoneAn application entity ID.
Returns
list[JSON]A list of found resource documents, or an empty list.
def searchSchedulesForParent(self, pi: str) -> list[JSON]:

Search for schedules in the database.

Parameters
pi:strThe resource ID of the parent resource.
Returns
list[JSON]List of Documents. May be empty.
def searchStatistics(self) -> JSON:

Search for statistics.

Returns
JSONThe statistics, or None if not found.
def searchSubscriptionReprs(self, ri: str | None = None, pi: str | None = None) -> list[JSON] | None:

Search for subscription representations by resource ID or parent resource ID.

Only one of the parameters may be used at a time. The order of precedence is: resource ID, parent resource ID.

Parameters
ri:str | NoneA resource ID.
pi:str | NoneA parent resource ID.
Returns
list[JSON] | NoneA list of found subscription representations, or None.
def start(self):

Callback method for the start phase of the plugin lifecycle.

def updateActionRepr(self, actionRepr: JSON) -> bool:

Update an action representation.

Parameters
actionRepr:JSONThe action representation to update.
Returns
boolTrue if the action representation was updated, False otherwise.
def updateResource(self, resource: JSON, ri: str) -> JSON:

Update a resource in the database. Only the fields that are not None will be updated.

Parameters
resource:JSONThe resource to update.
ri:strThe resource ID of the resource.
Returns
JSONThe updated resource dirctionary.
def upsertActionRepr(self, actionRepr: JSON, ri: str) -> bool:

Update or insert an action representation.

Parameters
actionRepr:JSONThe action representation to update or insert.
ri:strThe resource ID of the action representation.
Returns
boolTrue if the action representation was updated or inserted, False otherwise.
def upsertChildResource(self, childResource: JSON, ri: str):

Add a child resource to the childResources DB.

Parameters
childResource:JSONThe resource to add as a child.
ri:strThe resource ID of the resource.
def upsertIdentifier(self, identifierMapping: JSON, structuredPathMapping: JSON, ri: str, srn: str):

Insert or update an identifier into the identifiers DB and a structured resource name into the structuredResourceNames DB.

Parameters
identifierMapping:JSONThe identifier mapping to insert.
structuredPathMapping:JSONThe structured path mapping to insert.
ri:strThe resource ID of the resource.
srn:strThe structured resource name of the resource.
def upsertResource(self, resource: JSON, ri: str):

Update or insert a resource into the database.

Parameters
resource:JSONThe resource to upate or insert.
ri:strThe resource ID of the resource.
def upsertSchedule(self, schedule: JSON, ri: str) -> bool:

Add or update a schedule in the database.

Parameters
schedule:JSONThe schedule to store.
ri:strThe resource ID of the schedule.
Returns
boolTrue if the schedule was added or updated, False otherwise.
def upsertStatistics(self, stats: JSON) -> bool:

Update or insert statistics.

Parameters
stats:JSONThe statistics to update or insert.
Returns
boolTrue if the statistics were updated or inserted, False otherwise.
def upsertSubscriptionRepr(self, subscription: JSON, ri: str) -> bool:

Update or insert a subscription representation into the database.

Parameters
subscription:JSONThe subscription representation to update or insert.
ri:strThe resource ID of the original SUB resource.
Returns
boolTrue if the subscription representation was updated or inserted, False otherwise.
def validate(self, config: Configuration):

Callback method for the validation phase of the plugin lifecycle.

Parameters
config:ConfigurationThe configuration object containing the configuration settings for the plugin.
__slots__: tuple[str, ...] =

Define slots for instance variables.

actionsQuery =

The TinyDB query object for the actions table.

batchNotificationQuery =

The TinyDB query object for the batchNotifications table.

cacheSize =

Size of the cache for the TinyDB tables.

dbActions =

The TinyDB database for the actions table.

dbBatchNotifications =

The TinyDB database for the batchNotifications table.

dbIdentifiers =

The TinyDB database for the identifiers table.

dbOriginators =

The TinyDB database for the originators table.

dbRequests =

The TinyDB database for the requests table.

dbResources =

The TinyDB database for the resources table.

dbSchedules =

The TinyDB database for the schedules table.

dbStatistics =

The TinyDB database for the statistics table.

dbSubscriptions =

The TinyDB database for the subscriptions table.

fileActions =

Filename for the actions table.

fileBatchNotifications =

Filename for the batchNotifications table.

fileIdentifiers =

Filename for the identifiers table.

fileOriginators =

Filename for the originators table.

fileRequests =

Filename for the requests table.

fileResources =

Filename for the resources table.

fileSchedules =

Filename for the schedules table.

fileStatistics =

Filename for the statistics table.

fileSubscriptions =

Filename for the subscriptions table.

identifierQuery =

The TinyDB query object for the identifiers table.

lockActions =

Lock for the actions table.

lockBatchNotifications =

Lock for the batchNotifications table.

lockChildResources =

Lock for the childResources table.

lockIdentifiers =

Lock for the identifiers table.

lockOriginators =

Lock for the originators.

lockRequests =

Lock for the requests table.

lockResources =

Lock for the resources table.

lockSchedules =

Lock for the schedules table.

lockStatistics =

Lock for the statistics table.

lockStructuredIDs =

Lock for the structuredIDs table.

lockSubscriptions =

Lock for the subscriptions table.

originatorsQuery =

The TinyDB query object for the originators table.

path =

Path to the database directory.

postfix =

Postfix for the database file names.

requestsQuery =

The TinyDB query object for the requests table.

resourceQuery =

The TinyDB query object for the resources table.

schedulesQuery =

The TinyDB query object for the schedules table.

subscriptionQuery =

The TinyDB query object for the subscriptions table.

tabActions =

The TinyDB table for the actions table.

tabBatchNotifications =

The TinyDB table for the batchNotifications table.

tabChildResources =

The TinyDB table for the childResources table.

tabIdentifiers =

The TinyDB table for the identifiers table.

tabOriginators =

The TinyDB table for the originators table.

tabRequests =

The TinyDB table for the requests table.

tabResources =

The TinyDB table for the resources table.

tabSchedules =

The TinyDB table for the schedules table.

tabStatistics =

The TinyDB table for the statistics table.

tabStructuredIDs =

The TinyDB table for the structuredIDs table.

tabSubscriptions =

The TinyDB table for the subscriptions table.

writeDelay =

Delay for writing to the database.