def _initialize(self): # Manages a RDB engine and a metadata instance for this repository. # Both are global objects that should only be created once per process # (for each RDB repository), hence we use a global object manager. if not is_engine_initialized(self.name): engine = self.__make_engine() set_engine(self.name, engine) # Bind the engine to the session factory and the metadata. self.session_factory.configure(bind=engine) else: engine = get_engine(self.name) if not is_metadata_initialized(self.name): md_fac = self._config["metadata_factory"] if self._config.get("messaging_enable", False): # Wrap the metadata callback to also call the mapping # function for system entities. reset_on_start = self._config.get("messaging_reset_on_start", False) def wrapper(engine, reset_on_start=reset_on_start): metadata = md_fac(engine) map_system_entities(engine, metadata, reset_on_start) return metadata metadata = wrapper(engine) else: metadata = md_fac(engine) set_metadata(self.name, metadata) else: metadata = get_metadata(self.name) metadata.bind = engine
def _initialize(self): # Manages a RDB engine and a metadata instance for this repository. # Both are global objects that should only be created once per process # (for each RDB repository), hence we use a global object manager. if not is_engine_initialized(self.name): engine = self.__make_engine() set_engine(self.name, engine) # Bind the engine to the session factory and the metadata. self.session_factory.configure(bind=engine) else: engine = get_engine(self.name) if not is_metadata_initialized(self.name): md_fac = self._config['metadata_factory'] if self._config.get('messaging_enable', False): # Wrap the metadata callback to also call the mapping # function for system entities. reset_on_start = \ self._config.get('messaging_reset_on_start', False) def wrapper(engine, reset_on_start=reset_on_start): metadata = md_fac(engine) map_system_entities(engine, metadata, reset_on_start) return metadata metadata = wrapper(engine) else: metadata = md_fac(engine) set_metadata(self.name, metadata) else: metadata = get_metadata(self.name) metadata.bind = engine
def test_rdb_engine_manager(self): key = 'test' self.assert_false(is_engine_initialized(key)) eng = create_engine('sqlite://') set_engine(key, eng) self.assert_raises(ValueError, set_engine, key, eng) self.assert_true(is_engine_initialized(key)) self.assert_true(get_engine(key) is eng) reset_engines() self.assert_false(is_engine_initialized(key))
def _initialize(self): if not is_engine_initialized(self.name): engine = self.__make_engine() set_engine(self.name, engine) else: engine = get_engine(self.name) db_name = self._config['db_name'] self.__db = operator.getitem(engine, db_name) if db_name == 'test': # Reset the test database. for coll_name in \ self.__db.collection_names(include_system_collections=False): self.__db.drop_collection(coll_name) # Set up the class registry. for rc in self.registered_resources: ent_cls = get_entity_class(rc) if not MongoClassRegistry.is_registered(ent_cls): MongoClassRegistry.register(ent_cls, self.__db)