From d7cb7dc88ddd1126b4997f8fed4a46035599ea87 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 25 Nov 2023 22:24:20 -0500 Subject: [PATCH] initial commit of MemoryOms class --- mocha/oms/MemoryOms.py | 35 +++++++++++++++++++++++++++++++++++ mocha/oms/__init__.py | 1 + 2 files changed, 36 insertions(+) create mode 100644 mocha/oms/MemoryOms.py diff --git a/mocha/oms/MemoryOms.py b/mocha/oms/MemoryOms.py new file mode 100644 index 0000000..71ffe99 --- /dev/null +++ b/mocha/oms/MemoryOms.py @@ -0,0 +1,35 @@ +from ..core import * +from ..oms import Oms + +class MemoryOms(Oms): + + def __init__(self): + self.__current_tenant = None + self.__instances = dict() + self.__tenants = dict() + + def get_instance_by_key(self, key : InstanceKey): + return self.__instances[key.to_tuple()] + + # def get_instance_by_global_identifier(self, global_identifier : Guid): + + def create_tenant(self, tenant_name : str): + if tenant_name in self.__tenants: + raise NameError("tenant with specified name already exists") + + self.__tenants[tenant_name] = TenantReference(tenant_name, None) + + def select_tenant(self, tenant : TenantReference): + self.__current_tenant = tenant + + def release_tenant(self): + self.__current_tenant = None + + def get_current_tenant(self): + return self.__current_tenant + + def get_tenant_by_name(self, tenant_name : str): + if tenant_name in self.__tenants: + return self.__tenants[tenant_name] + + return None \ No newline at end of file diff --git a/mocha/oms/__init__.py b/mocha/oms/__init__.py index a27689b..e021feb 100644 --- a/mocha/oms/__init__.py +++ b/mocha/oms/__init__.py @@ -1,3 +1,4 @@ from .Oms import Oms from .DatabaseOms import DatabaseOms +from .MemoryOms import MemoryOms from .MySQLDatabaseOms import MySQLDatabaseOms \ No newline at end of file