예제 #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
예제 #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
예제 #3
0
파일: test_rdb.py 프로젝트: b8va/everest
 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))
예제 #4
0
 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))
예제 #5
0
 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)