Exemple #1
0
    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
Exemple #2
0
    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
Exemple #3
0
 def test_metadata_manager(self):
     key = 'test'
     self.assert_false(is_metadata_initialized(key))
     md = MetaData()
     set_metadata(key, md)
     self.assert_raises(ValueError, set_metadata, key, md)
     self.assert_true(is_metadata_initialized(key))
     self.assert_true(get_metadata(key) is md)
     reset_metadata()
     self.assert_false(is_metadata_initialized(key))
Exemple #4
0
 def test_metadata_manager(self):
     key = 'test'
     self.assert_false(is_metadata_initialized(key))
     md = MetaData()
     set_metadata(key, md)
     self.assert_raises(ValueError, set_metadata, key, md)
     self.assert_true(is_metadata_initialized(key))
     self.assert_true(get_metadata(key) is md)
     reset_metadata()
     self.assert_false(is_metadata_initialized(key))