当前位置: 首页>>代码示例>>Python>>正文


Python DatabaseServer.create_database方法代码示例

本文整理汇总了Python中opus_core.database_management.database_server.DatabaseServer.create_database方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseServer.create_database方法的具体用法?Python DatabaseServer.create_database怎么用?Python DatabaseServer.create_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在opus_core.database_management.database_server.DatabaseServer的用法示例。


在下文中一共展示了DatabaseServer.create_database方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
        def setUp(self):

            db_configs = []
            for engine in get_testable_engines():
                config = TestDatabaseConfiguration(protocol = engine)
                db_configs.append(config)
            
            self.database_name = 'test_database'
            self.dbs = []
            for config in db_configs:
                try:
                    server = DatabaseServer(config)
                    if server.has_database(self.database_name):
                        server.drop_database(self.database_name)
                    server.create_database(self.database_name)
                    self.assertTrue(server.has_database(database_name = self.database_name))
                    db = OpusDatabase(database_server_configuration = config, 
                                       database_name = self.database_name)
                    storage = sql_storage(
                                    storage_location = db
                                    )
                    self.dbs.append((db,server,storage))
                    self.storage = storage
                except:
                    import traceback
                    traceback.print_exc()
                    
                    print 'WARNING: could not start server for protocol %s'%config.protocol
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:30,代码来源:sql_storage.py

示例2: AbstractServiceTests

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
class AbstractServiceTests(opus_unittest.OpusTestCase):
    def setUp(self):
        self.database_name = 'test_services_database'
        self.config = TestDatabaseConfiguration(database_name = self.database_name)
        self.db_server = DatabaseServer(self.config)
    
    def tearDown(self):
        self.db_server.drop_database(self.database_name)
        self.db_server.close()
        
    def test_create_when_already_exists(self):
        """Shouldn't do anything if the database already exists."""
        self.db_server.create_database(self.database_name)
        db = self.db_server.get_database(self.database_name)
        self.assertFalse(db.table_exists('run_activity'))
        self.assertFalse(db.table_exists('computed_indicators'))

        services = AbstractService(self.config)
        services.services_db.close()
        self.assertTrue(db.table_exists('run_activity')) 
        self.assertTrue(db.table_exists('computed_indicators'))

    def test_create(self):
        """Should create services tables if the database doesn't exist."""
        services = AbstractService(self.config)
        services.services_db.close()
        self.assertTrue(self.db_server.has_database(self.database_name))
        db = self.db_server.get_database(self.database_name)
        self.assertTrue(db.table_exists('run_activity')) 
        self.assertTrue(db.table_exists('computed_indicators'))               
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:32,代码来源:abstract_service.py

示例3: setUp

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def setUp(self):
        db_configs = []
        for engine in _get_installed_database_engines():
            config = TestDatabaseConfiguration(protocol=engine)
            db_configs.append(config)

        self.test_db = "OpusDatabaseTestDatabase"
        test_table = "test_table"

        self.dbs = []
        for config in db_configs:
            try:
                server = DatabaseServer(config)
                if server.has_database(self.test_db):
                    server.drop_database(self.test_db)
                server.create_database(self.test_db)
                self.assertTrue(server.has_database(database_name=self.test_db))
                db = OpusDatabase(database_server_configuration=config, database_name=self.test_db)
                self.assertFalse(db.table_exists(test_table))
                self.dbs.append((db, server))
            except:
                import traceback

                traceback.print_exc()

                logger.log_warning("Could not start server for protocol %s" % config.protocol)
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:28,代码来源:opus_database.py

示例4: prepare_for_simulation

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def prepare_for_simulation(self, run_configuration, cache_directory=None):
        self.config = Resources(run_configuration)
        self.simulation_state = SimulationState(
            new_instance=True, base_cache_dir=cache_directory, start_time=self.config.get("base_year", 0)
        )

        ### TODO: Get rid of this! There is no good reason to be changing the
        ###       Configuration.
        if self.config["cache_directory"] is None:
            self.config["cache_directory"] = self.simulation_state.get_cache_directory()

        SessionConfiguration(
            new_instance=True,
            package_order=self.config["dataset_pool_configuration"].package_order,
            in_storage=AttributeCache(),
        )

        ForkProcess().fork_new_process(
            self.config["creating_baseyear_cache_configuration"].cache_scenario_database, self.config
        )

        # Create output database (normally done by run manager)
        if "estimation_database_configuration" in self.config:
            db_server = DatabaseServer(self.config["estimation_database_configuration"])
            if not db_server.has_database(self.config["estimation_database_configuration"].database_name):
                db_server.create_database(self.config["estimation_database_configuration"].database_name)
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:28,代码来源:run_simulation_from_mysql.py

示例5: run_run

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def run_run(self, run_resources, run_name = None, run_as_multiprocess=True, run_in_background=False):
        """check run hasn't already been marked running
           log it in to run_activity
           run simulation
           mark run as done/failed
           """

        if not self.ready_to_run:
            raise 'RunManager.setup_new_run must be execute before RunManager.run_run'

        if run_resources['cache_directory'] != self.current_cache_directory:
            raise 'The configuration and the RunManager conflict on the proper cache_directory'

        self.add_row_to_history(self.run_id, run_resources, "started", run_name = run_name)

        try:
            # Test pre-conditions
            model_system_class_path = run_resources.get('model_system', None)
            if model_system_class_path is None:
                raise TypeError, ("The configuration must specify model_system, the"
                    " full Opus path to the model system to be used.")

            # Create baseyear cache
            self.create_baseyear_cache(run_resources)

            # Create brand-new output database (deletes any prior contents)
            if 'estimation_database_configuration' in run_resources:
                db_server = DatabaseServer(run_resources['estimation_database_configuration'])
                if not db_server.has_database(run_resources['estimation_database_configuration'].database_name):
                    db_server.create_database(run_resources['estimation_database_configuration'].database_name)


            # Run simulation
            exec('from %s import ModelSystem' % model_system_class_path)

            model_system = ModelSystem()
            self.model_system = model_system

            if 'base_year' not in run_resources:
                run_resources['base_year'] = run_resources['years'][0] - 1

            self._create_seed_dictionary(run_resources)
#            model_system.run_in_same_process(run_resources)
            if run_as_multiprocess:
                model_system.run_multiprocess(run_resources)
            else:
                model_system.run_in_one_process(run_resources, run_in_background=run_in_background, class_path=model_system_class_path)

            self.model_system = None

        except:
            self.add_row_to_history(self.run_id, run_resources, "failed", run_name = run_name)
            self.ready_to_run = False
            raise # This re-raises the last exception
        else:
            self.add_row_to_history(self.run_id, run_resources, "done", run_name = run_name)

        self.ready_to_run = False
        return self.run_id
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:61,代码来源:run_manager.py

示例6: TestCreateJobBuildingTypesTable

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
class TestCreateJobBuildingTypesTable(opus_unittest.OpusTestCase):
    def setUp(self):
        self.db_name = 'test_create_table'
        
        self.db_server = DatabaseServer(TestDatabaseConfiguration(protocol = 'mysql',))
        
        self.db_server.drop_database(self.db_name)
        self.db_server.create_database(self.db_name)
        self.db = self.db_server.get_database(self.db_name)
            
        
    def tearDown(self):
        self.db.close()
        self.db_server.drop_database(self.db_name)
        self.db_server.close()
        
        
    def test_setUp(self):
        try:
            self.db.DoQuery('select * from job_building_types;')
            self.fail('Output table job_building_tpes already exists. (Check setUp)')
        except: pass
        
        
    def test_create_table(self):
        CreateJobBuildingTypesTable().create_building_types_table(
            TestDatabaseConfiguration(protocol = 'mysql'), self.db_name)
        
        try:
            self.db.DoQuery('select * from job_building_types;')
        except:
            self.fail('Expected output table job_building_types does not exist.')
    
            
    def test_values(self):
        CreateJobBuildingTypesTable().create_building_types_table(
            TestDatabaseConfiguration(protocol = 'mysql'), self.db_name)
        
        expected_results = [
            ['id', 'name', 'home_based'],
            [1, "commercial", 0],
            [3, "industrial", 0],
            [2, "governmental", 0],
            [4, "home_based", 1]
            ]
        
        try:
            results = self.db.GetResultsFromQuery(
                'select * from job_building_types;')
        except:
            self.fail('Expected output table job_building_types does not exist.')
        
        self.assert_(expected_results == results,
            "Table job_building_types has incorrect values! "
            "Expected: %s. Received: %s" % (expected_results, results))
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:57,代码来源:create_job_building_types_table.py

示例7: prepare_for_run

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def prepare_for_run(self, database_configuration, database_name):
        ## sql protocol, hostname, username and password are set in
        ## $OPUS_HOME/settings/database_server_setting.xml
        db_config = DatabaseConfiguration(database_name=database_name, database_configuration=database_configuration)
        db_server = DatabaseServer(db_config)
        if not db_server.has_database(database_name):
            db_server.create_database(database_name)
        db = db_server.get_database(database_name)
        self.out_storage = sql_storage(storage_location=db)

        return self.out_storage
开发者ID:psrc,项目名称:urbansim,代码行数:13,代码来源:dataset_export_model.py

示例8: save_results

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def save_results(self, out_storage=None, model_name=None):
        if self.specification is None or self.coefficients is None:
            raise ValueError, "model specification or coefficient is None"

        #invalid = self.coefficients.is_invalid()
        if False:
            logger.log_warning('Invalid coefficients. Not saving results!')
            return

        if model_name is None:
            model_name = self.config.get('model_name_for_coefficients', None)
            
        if model_name is None:
            if self.model_name is not None:
                model_name = self.model_name
            else:
                raise ValueError, "model_name unspecified"

        out_storage_available = True
        if out_storage:
            pass
        elif 'estimation_database_configuration' in self.config:
            try:
                db_server = DatabaseServer(self.config['estimation_database_configuration'])
                database_name = self.config["estimation_database_configuration"].database_name
    
                if not db_server.has_database(database_name):
                    db_server.create_database(database_name)
    
                output_db = db_server.get_database(database_name)
                out_storage = StorageFactory().get_storage(
                    type='sql_storage',
                    storage_location=output_db)
            except:
                logger.log_warning("Problem with connecting database given by 'estimation_database_configuration'.")
                out_storage_available = False
        else:
            logger.log_warning("No estimation_database_configuration given.")
            out_storage_available = False

        # the original model name of development_project_lcm is too long as a mysql db table name, truncate it
        if model_name.rfind("_development_project_location_choice_model") >=0:
            model_name = model_name.replace('_project', '')
        specification_table = '%s_specification' % model_name
        coefficients_table = '%s_coefficients' % model_name
        if out_storage_available:
            logger.start_block("Writing specification and coefficients into storage given by 'estimation_database_configuration'")
            self.specification.write(out_storage=out_storage, out_table_name=specification_table)
            self.coefficients.write(out_storage=out_storage, out_table_name=coefficients_table)
            logger.end_block()
        logger.start_block("Writing specification and coefficients into %s" % AttributeCache().get_storage_location())
        self.specification.write(out_storage=AttributeCache(), out_table_name=specification_table)
        self.coefficients.write(out_storage=AttributeCache(), out_table_name=coefficients_table)
        logger.end_block()
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:56,代码来源:estimator.py

示例9: __init__

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def __init__(self,
                 indicator_directory,
                 name = None,
                 output_type = None,
                 storage_location = None,
                 output_style = ALL,
                 fixed_field_format = None  # Only used with the 'fixed_field' output type
                ):

        if output_type == 'sql' and not isinstance(storage_location, DatabaseConfiguration):
            raise Exception("If Table output_type is 'sql', a Database object must be passed as storage_location.")
        elif output_type in ['dbf', 'csv', 'tab', 'esri', 'fixed_field'] and \
               storage_location is not None and \
               not isinstance(storage_location,str):
            raise Exception("If Table output_type is %s, storage_location must be a path to the output directory"%output_type)
        elif output_type not in ['dbf', 'csv', 'tab', 'sql', 'esri', 'fixed_field']:
            raise Exception("Table output_type must be either dbf, csv, tab, sql, esri, fixed_field, not %s"%output_type)

        if output_type == "fixed_field" and not fixed_field_format:
            raise ValueError("If Table output_type is 'fixed_field', an XML format string must be passed as fixed_field_format.")
        
        self.fixed_field_format = fixed_field_format

        if output_style not in [Table.ALL,
                                Table.PER_YEAR,
                                Table.PER_ATTRIBUTE]:
            raise Exception(('%s output_style is not appropriate.'%output_style,
                   'Choose from Table.ALL, Table.PER_YEAR, ',
                   'and Table.PER_ATTRIBUTE'))

        self.output_type = output_type
        self.output_style = output_style

        if storage_location is None:
            storage_location = indicator_directory
        elif output_type == 'sql':
            server = DatabaseServer(database_server_configuration = storage_location)
            if not server.has_database(database_name = storage_location.database_name):
                server.create_database(database_name = storage_location.database_name)
            storage_location = server.get_database(
                                   database_name = storage_location.database_name)
        self.storage_location = storage_location

        self.output_storage = StorageFactory().get_storage(
            type = '%s_storage'%(self.output_type),
            storage_location = storage_location
        )

        self.name = name
        self.indicator_directory = indicator_directory
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:52,代码来源:table.py

示例10: _create_db_from_chain_via_python

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
 def _create_db_from_chain_via_python(self, 
                                      from_database_configuration, 
                                      to_database_configuration,
                                      tables_to_copy):
             
     db_server_from = DatabaseServer(from_database_configuration)
     db_server_to = DatabaseServer(to_database_configuration)
     db_server_to.drop_database(to_database_configuration.database_name)
     db_server_to.create_database(to_database_configuration.database_name)
     
     database_out = db_server_to.get_database(to_database_configuration.database_name)
     
     scenario_db_manager = ScenarioDatabaseManager(
         server_configuration = from_database_configuration, 
         base_scenario_database_name = from_database_configuration.database_name)
     table_mapping = scenario_db_manager.get_database_to_table_mapping()
 
     cross_db_operations = CrossDatabaseOperations()
     
     #by default, copy all tables
     if tables_to_copy == []:
         tables_to_copy = sum(table_mapping.values(), [])  # flat a list of lists
     elif 'scenario_information' not in tables_to_copy:
         tables_to_copy.append('scenario_information')
         
     for database_name, tables in table_mapping.items():
         database_in = db_server_from.get_database(database_name)
         for table in tables:
             if table not in tables_to_copy:
                 continue
             
             logger.start_block("Copying table '%s' from database '%s'" 
                                % (table, database_name)) 
             
             try:               
                 cross_db_operations.copy_table(table_to_copy = table, 
                                                database_in = database_in, 
                                                database_out = database_out, 
                                                use_chunking = True)
             finally:
                 logger.end_block()        
         database_in.close()
         
     self._fix_scenario_information_table(database_out)            
     database_out.close()
     db_server_from.close()
     db_server_to.close()
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:49,代码来源:flatten_scenario_database_chain.py

示例11: create_storage

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    def create_storage(self):

        try:
            server = DatabaseServer(self.server_config)
        except:
            logger.log_error('Cannot connect to the database server that the services database is hosted on %s.' % self.server_config.database_name)
            raise
        
        if not server.has_database(self.server_config.database_name):
            server.create_database(self.server_config.database_name)

        try:
            services_db = server.get_database(self.server_config.database_name)
        except:
            logger.log_error('Cannot connect to a services database on %s.'% server.get_connection_string(scrub = True))
            raise

        metadata.bind = services_db.engine
        setup_all()
        create_all()
        
        return services_db
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:24,代码来源:abstract_service.py

示例12: TestDBSubPattern

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
class TestDBSubPattern(opus_unittest.OpusTestCase):
    def setUp(self):
        self.test_db_names = [
            'convert_database_test_db1', 
            'convert_database_test_db2',
            ]
        
        self.test_table_names = [
            'table1',
            'table2',
            'table3',
            ]
            
        table_schema = 'id INT, do_not_change_this_column TEXT, variable_name TEXT'
        table_data = (
            '(1,"Does not match P A T T E R N.","Matches pattern."),'
            '(2,"Matches pattern.","Does not match P A T T E R N."),'
            '(3,NULL,NULL),'
            '(4,"","")'
            )
            
        self.expected_output_unchanged = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1,"Does not match P A T T E R N.","Matches pattern."],
            [2,"Matches pattern.","Does not match P A T T E R N."],
            [3,None,None],
            [4,"",""]
            ]
        
        self.patterns = [
            (r'(pattern)(\.)', r'\1 well\2'),
            (r'^Matches pattern well\.$', r'Matches pattern perfectly!')
            ]
        
        self.expected_output_changed = [
            ['id', 'do_not_change_this_column', 'variable_name'],
            [1,"Does not match P A T T E R N.","Matches pattern perfectly!"],
            [2,"Matches pattern.","Does not match P A T T E R N."],
            [3,None,None],
            [4,"",""]
            ]
            
        insert_items_template = (
            "insert into %(table)s values %(data)s;")
      
        table_list = {}
        for db_name in self.test_db_names:
            table_list[db_name] = []
            for table in self.test_table_names:
                table_list[db_name] += [table]
        
        self.config = {
            'databases':self.test_db_names,
            'tables':table_list,
            
            'backup':True,
            'backup_postfix':'_old',
            }
            
        self.db_server = DatabaseServer(TestDatabaseConfiguration(protocol = 'mysql'))
        
        self.dbs = []
        for db_name in self.test_db_names:
            self.db_server.drop_database(db_name)
            self.db_server.create_database(db_name)
            self.dbs += [self.db_server.get_database(db_name)]
        
        for db in self.dbs:
            for table_name in self.test_table_names:
                db.DoQuery('create table %s (%s)' 
                    % (table_name,
                       table_schema))
                
                db.DoQuery(insert_items_template 
                            % {'table':table_name, 'data':table_data})
                
        
    def tearDown(self):
        for db_name in self.test_db_names:
            self.db_server.drop_database(db_name)
            
        for db in self.dbs:
            db.close()
            
        self.db_server.close()
        
        
    def test_convert_table(self):
        DBSubPattern().convert_table(self.dbs[0], self.test_table_names[0], 
            self.patterns)
        
        db = self.dbs[0]
        
        table0 = self.test_table_names[0]
        results = db.GetResultsFromQuery('select * from %s;' % table0)
        self.assert_(results == self.expected_output_changed,
            "Convert failed for single table (%s) -- incorrect conversion."
            " Expected %s. Recieved %s." 
                % (table0,
                   self.expected_output_changed,
#.........这里部分代码省略.........
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:103,代码来源:db_sub_pattern.py

示例13: DatabaseServer

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
    cache_path = options.cache_path
    database_name = options.database_name    
    if database_name is None or cache_path is None:
        parser.print_help()
        sys.exit(1)
    
    table_name = options.table_name
    
    logger.log_status('Initializing database...')
    db_server = DatabaseServer(EstimationDatabaseConfiguration(
            database_name = database_name,
            database_configuration = options.database_configuration
            )
        )
    if not db_server.has_database(database_name): # if only one table should be exported,
        db_server.create_database(database_name)                            # the database can exist

    db = db_server.get_database(database_name)
   
    input_storage = flt_storage(storage_location = cache_path)
    
    output_storage = sql_storage(
                        storage_location = db)
            
    with logger.block('Exporting cache to sql...'):
        if table_name is None:
            ExportStorage().export(in_storage=input_storage, out_storage=output_storage)
        else:
            db.drop_table(table_name)
            ExportStorage().export_dataset(table_name, in_storage=input_storage, out_storage=output_storage)        
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:32,代码来源:do_export_cache_to_sql.py

示例14: DatabaseManagementTestInterface

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
class DatabaseManagementTestInterface(opus_unittest.OpusTestCase):
    def setUp(self):
        self.databases = ["db_chain_son", "db_chain_dad", "db_chain_granddad"]

        self.config = TestDatabaseConfiguration(protocol=get_default_database_engine())
        self.server = DatabaseServer(self.config)
        self._create_databases()
        self.db_chain_granddad = self.server.get_database("db_chain_granddad")
        self.db_chain_dad = self.server.get_database("db_chain_dad")
        self.db_chain_son = self.server.get_database("db_chain_son")

        self._create_tables()
        self.granddad_schema = self.db_chain_granddad.get_table("base_schema")
        self.dad_schema = self.db_chain_dad.get_table("base_schema")
        self.granddad_schema2 = self.db_chain_granddad.get_table("base_schema2")
        self.son_schema2 = self.db_chain_son.get_table("base_schema2")

        self._seed_values()

    def _create_databases(self):

        for db in self.databases:
            try:
                self.server.drop_database(db)
            except:
                pass

            self.server.create_database(db)

    def _create_tables(self):
        self.db_chain_granddad.create_table_from_schema("base_schema", base_schema)
        self.db_chain_granddad.create_table_from_schema("base_schema2", base_schema2)
        self.db_chain_granddad.create_table_from_schema("scenario_information", base_scenario_information_schema)

        self.db_chain_dad.create_table_from_schema("base_schema", base_schema)
        self.db_chain_dad.create_table_from_schema("scenario_information", base_scenario_information_schema)

        self.db_chain_son.create_table_from_schema("base_schema2", base_schema2)
        self.db_chain_son.create_table_from_schema("scenario_information", base_scenario_information_schema)

    def _seed_values(self):
        u = self.db_chain_granddad.get_table("scenario_information").insert(
            values={self.db_chain_granddad.get_table("scenario_information").c.parent_database_url: ""}
        )
        self.db_chain_granddad.execute(u)

        u = self.db_chain_dad.get_table("scenario_information").insert(
            values={self.db_chain_dad.get_table("scenario_information").c.parent_database_url: "db_chain_granddad"}
        )

        self.db_chain_dad.execute(u)
        u = self.db_chain_son.get_table("scenario_information").insert(
            values={self.db_chain_son.get_table("scenario_information").c.parent_database_url: "db_chain_dad"}
        )
        self.db_chain_son.execute(u)

        granddad_vals = [
            {"integer_col": 0, "clob_col": "0", "smallinteger_col": 0, "float_col": 0.0},
            {"integer_col": 2, "clob_col": "2", "smallinteger_col": 2, "float_col": 2.0},
            {"integer_col": 4, "clob_col": "4", "smallinteger_col": 4, "float_col": 4.0},
        ]

        dad_vals = [
            {"integer_col": 0, "clob_col": "0", "smallinteger_col": 0, "float_col": 0.0},
            {"integer_col": 1, "clob_col": "1", "smallinteger_col": 1, "float_col": 1.0},
            {"integer_col": 2, "clob_col": "2", "smallinteger_col": 2, "float_col": 2.0},
            {"integer_col": 3, "clob_col": "3", "smallinteger_col": 3, "float_col": 3.0},
            {"integer_col": 4, "clob_col": "4", "smallinteger_col": 4, "float_col": 4.0},
        ]

        granddad_vals2 = [
            {"integer_col": 0, "varchar_col": "0", "boolean_col": True, "numeric_col": 0.0},
            {"integer_col": 2, "varchar_col": "2", "boolean_col": True, "numeric_col": 2.0},
            {"integer_col": 4, "varchar_col": "4", "boolean_col": True, "numeric_col": 4.0},
        ]

        son_vals2 = [
            {"integer_col": 0, "varchar_col": "0", "boolean_col": False, "numeric_col": 0.0},
            {"integer_col": 4, "varchar_col": "4", "boolean_col": False, "numeric_col": 4.0},
        ]

        self.db_chain_granddad.engine.execute(self.granddad_schema.insert(), granddad_vals)
        self.db_chain_granddad.engine.execute(self.granddad_schema2.insert(), granddad_vals2)
        self.db_chain_dad.engine.execute(self.dad_schema.insert(), dad_vals)
        self.db_chain_son.engine.execute(self.son_schema2.insert(), son_vals2)

    def tearDown(self):
        self.db_chain_granddad.close()
        self.db_chain_dad.close()
        self.db_chain_son.close()

        self.server.drop_database("db_chain_granddad")
        self.server.drop_database("db_chain_dad")
        self.server.drop_database("db_chain_son")

        self.server.close()
开发者ID:apdjustino,项目名称:DRCOG_Urbansim,代码行数:98,代码来源:database_management_test_interface.py

示例15: DatabaseManagementTestInterface

# 需要导入模块: from opus_core.database_management.database_server import DatabaseServer [as 别名]
# 或者: from opus_core.database_management.database_server.DatabaseServer import create_database [as 别名]
class DatabaseManagementTestInterface(opus_unittest.OpusTestCase):
    def setUp(self):        
        self.databases = ['db_chain_son', 'db_chain_dad', 'db_chain_granddad']
        
        self.config = TestDatabaseConfiguration(protocol = get_default_database_engine())
        self.server = DatabaseServer(self.config)
        self._create_databases()
        self.db_chain_granddad = self.server.get_database('db_chain_granddad')
        self.db_chain_dad = self.server.get_database('db_chain_dad')
        self.db_chain_son = self.server.get_database('db_chain_son')
        
        self._create_tables()
        self.granddad_schema = self.db_chain_granddad.get_table('base_schema')
        self.dad_schema = self.db_chain_dad.get_table('base_schema')
        self.granddad_schema2 = self.db_chain_granddad.get_table('base_schema2')
        self.son_schema2 = self.db_chain_son.get_table('base_schema2')
        
        self._seed_values()
        
    def _create_databases(self):
        
        for db in self.databases:
            try: 
                self.server.drop_database(db)
            except:
                pass
            
            self.server.create_database(db)
        
    def _create_tables(self):
        self.db_chain_granddad.create_table_from_schema('base_schema', base_schema)
        self.db_chain_granddad.create_table_from_schema('base_schema2', base_schema2)
        self.db_chain_granddad.create_table_from_schema('scenario_information', base_scenario_information_schema)
        
        self.db_chain_dad.create_table_from_schema('base_schema', base_schema)
        self.db_chain_dad.create_table_from_schema('scenario_information', base_scenario_information_schema)

        self.db_chain_son.create_table_from_schema('base_schema2', base_schema2)
        self.db_chain_son.create_table_from_schema('scenario_information', base_scenario_information_schema)
        
    def _seed_values(self):
        u = self.db_chain_granddad.get_table('scenario_information').insert(
              values = {
                self.db_chain_granddad.get_table('scenario_information').c.parent_database_url:''})   
        self.db_chain_granddad.execute(u)
        
        u = self.db_chain_dad.get_table('scenario_information').insert(
              values = {
                self.db_chain_dad.get_table('scenario_information').c.parent_database_url:'db_chain_granddad'})

        self.db_chain_dad.execute(u)
        u = self.db_chain_son.get_table('scenario_information').insert(
              values = {
                self.db_chain_son.get_table('scenario_information').c.parent_database_url:'db_chain_dad'})   
        self.db_chain_son.execute(u)
        
        granddad_vals = [
            {'integer_col': 0, 'clob_col': '0', 'smallinteger_col': 0, 'float_col': 0.0},                      
            {'integer_col': 2, 'clob_col': '2', 'smallinteger_col': 2, 'float_col': 2.0},                          
            {'integer_col': 4, 'clob_col': '4', 'smallinteger_col': 4, 'float_col': 4.0}                                         
        ]

        dad_vals = [
            {'integer_col': 0, 'clob_col': '0', 'smallinteger_col': 0, 'float_col': 0.0},  
            {'integer_col': 1, 'clob_col': '1', 'smallinteger_col': 1, 'float_col': 1.0},                   
            {'integer_col': 2, 'clob_col': '2', 'smallinteger_col': 2, 'float_col': 2.0},  
            {'integer_col': 3, 'clob_col': '3', 'smallinteger_col': 3, 'float_col': 3.0},                        
            {'integer_col': 4, 'clob_col': '4', 'smallinteger_col': 4, 'float_col': 4.0}                                         
        ]    
        
        granddad_vals2 = [
            {'integer_col': 0, 'varchar_col': '0', 'boolean_col': True, 'numeric_col': 0.0},                      
            {'integer_col': 2, 'varchar_col': '2', 'boolean_col': True, 'numeric_col': 2.0},                          
            {'integer_col': 4, 'varchar_col': '4', 'boolean_col': True, 'numeric_col': 4.0}                                         
        ]

        son_vals2 = [
            {'integer_col': 0, 'varchar_col': '0', 'boolean_col': False, 'numeric_col': 0.0},                      
            {'integer_col': 4, 'varchar_col': '4', 'boolean_col': False, 'numeric_col': 4.0}                                         
        ]
        
        self.db_chain_granddad.engine.execute(self.granddad_schema.insert(), granddad_vals)
        self.db_chain_granddad.engine.execute(self.granddad_schema2.insert(), granddad_vals2)        
        self.db_chain_dad.engine.execute(self.dad_schema.insert(), dad_vals)
        self.db_chain_son.engine.execute(self.son_schema2.insert(), son_vals2)
                     
    def tearDown(self):
        self.db_chain_granddad.close()
        self.db_chain_dad.close()
        self.db_chain_son.close()
        
        self.server.drop_database('db_chain_granddad')
        self.server.drop_database('db_chain_dad')
        self.server.drop_database('db_chain_son')
        
        self.server.close()
        
开发者ID:christianurich,项目名称:VIBe2UrbanSim,代码行数:98,代码来源:database_management_test_interface.py


注:本文中的opus_core.database_management.database_server.DatabaseServer.create_database方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。