當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceDatabasePopulator.addScript方法代碼示例

本文整理匯總了Java中org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.addScript方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceDatabasePopulator.addScript方法的具體用法?Java ResourceDatabasePopulator.addScript怎麽用?Java ResourceDatabasePopulator.addScript使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.jdbc.datasource.init.ResourceDatabasePopulator的用法示例。


在下文中一共展示了ResourceDatabasePopulator.addScript方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initialize

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@PostConstruct
protected void initialize() {
	if (this.properties.getInitializer().isEnabled()) {
		String platform = getDatabaseType();
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = this.properties.getSchema();
		schemaLocation = schemaLocation.replace("@@[email protected]@", platform);
		populator.addScript(this.resourceLoader.getResource(schemaLocation));
		populator.setContinueOnError(true);
		DatabasePopulatorUtils.execute(populator, this.dataSource);
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:22,代碼來源:BatchDatabaseInitializer.java

示例2: herdDataSource

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
/**
 * Get a new herd data source based on an in-memory HSQLDB database. This data source is used for loading the configuration table as an environment property
 * source as well as for the JPA entity manager. It will therefore create/re-create the configuration table which is required for the former. It also
 * inserts required values for both scenarios.
 *
 * @return the test herd data source.
 */
@Bean
public static DataSource herdDataSource()
{
    // Create and return a data source that can connect directly to a JDBC URL.
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setUsername("");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:h2:mem:herdTestDb");

    // Create and populate the configuration table.
    // This is needed for all data source method calls since it is used to create the environment property source which happens before
    // JPA and other non-static beans are initialized.
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.addScript(new ClassPathResource("createConfigurationTableAndData.sql"));
    DatabasePopulatorUtils.execute(resourceDatabasePopulator, basicDataSource); // This is what the DataSourceInitializer does.

    return basicDataSource;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:27,代碼來源:DaoEnvTestSpringModuleConfig.java

示例3: runScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
private void runScripts(List<Resource> resources, String username, String password) {
	if (resources.isEmpty()) {
		return;
	}
	ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setContinueOnError(this.properties.isContinueOnError());
	populator.setSeparator(this.properties.getSeparator());
	if (this.properties.getSqlScriptEncoding() != null) {
		populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
	}
	for (Resource resource : resources) {
		populator.addScript(resource);
	}
	DataSource dataSource = this.dataSource;
	if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
		dataSource = DataSourceBuilder.create(this.properties.getClassLoader())
				.driverClassName(this.properties.determineDriverClassName())
				.url(this.properties.determineUrl()).username(username)
				.password(password).build();
	}
	DatabasePopulatorUtils.execute(populator, dataSource);
}
 
開發者ID:muxiangqiu,項目名稱:spring-boot-multidatasource,代碼行數:23,代碼來源:DataSourceInitializer.java

示例4: runScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
private void runScripts(List<Resource> resources, DataSource dataSource) {
	if (resources.isEmpty()) {
		return;
	}
	ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setContinueOnError(configuration.isContinueOnError());
	populator.setSeparator(configuration.getConfigPropertyValue(SpringDataSourceConfigProperties.SEPARATOR, ";"));
	String encoding = configuration.getConfigPropertyValue(SpringDataSourceConfigProperties.SQL_SCRIPT_ENCODING,
			null);
	if (encoding != null) {
		populator.setSqlScriptEncoding(encoding);
	}
	for (Resource resource : resources) {
		populator.addScript(resource);
	}
	DatabasePopulatorUtils.execute(populator, dataSource);
}
 
開發者ID:holon-platform,項目名稱:holon-jdbc,代碼行數:18,代碼來源:DataContextDataSourceInitializer.java

示例5: nonBootDataSourceInitializer

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@ConditionalOnProperty("jdbc.initialize")
@Bean
public DataSourceInitializer nonBootDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader) {
	DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
	dataSourceInitializer.setDataSource(dataSource);
	ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
	databasePopulator.setIgnoreFailedDrops(true);
	dataSourceInitializer.setDatabasePopulator(databasePopulator);
	if ("true".equals(properties.getInitialize())) {
		databasePopulator.addScript(new DefaultInitializationScriptResource(properties.getTableName(),
				properties.getColumnsMap().keySet()));
	}
	else {
		databasePopulator.addScript(resourceLoader.getResource(properties.getInitialize()));
	}
	return dataSourceInitializer;
}
 
開發者ID:spring-cloud-stream-app-starters,項目名稱:jdbc,代碼行數:18,代碼來源:JdbcSinkConfiguration.java

示例6: executeSql

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
protected void executeSql(String path) {
    logger.info("executeSql : " + path);

    Resource resource = new ClassPathResource(path, getClass());
    ResourceDatabasePopulator rdp = new ResourceDatabasePopulator();
    rdp.addScript(resource);
    rdp.setSqlScriptEncoding("UTF-8");
    rdp.setIgnoreFailedDrops(true);
    rdp.setContinueOnError(false);

    try (Connection conn = DataSourceUtils.getConnection(dataSource)) {
        rdp.populate(conn);
    }
    catch (Exception e) {
        throw new IllegalStateException("executeSql failed, path=" + path, e);
    }
}
 
開發者ID:af-not-found,項目名稱:blog-java2,代碼行數:18,代碼來源:SpringTestBase.java

示例7: serverStartup

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Override
public void serverStartup()
{
    LOG.info("Initializing MySQL DB for highlighter");
    try (Connection connection = DriverManager.getConnection(url, user, password))
    {
        final ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
        resourceDatabasePopulator.setContinueOnError(true);
        resourceDatabasePopulator.addScript(new FileSystemResource("../webapps/ROOT/plugins/highlighter-plugin/sql/mysql_init_db.sql"));
        resourceDatabasePopulator.addScript(new FileSystemResource("../webapps/ROOT/plugins/highlighter-plugin/sql/mysql_init_table.sql"));
        resourceDatabasePopulator.populate(connection);

        LOG.info("Initialization complete!");
    }
    catch (Exception e)
    {
        LOG.log(Level.SEVERE, "MySQL DB initialization failed for highlighter", e);
    }
}
 
開發者ID:jpfeffer,項目名稱:teamcity-highlighter,代碼行數:20,代碼來源:MySQLDBAdapter.java

示例8: populateDatabase

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Bean
@Lazy(false)
public ResourceDatabasePopulator populateDatabase() throws SQLException {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("data.sql"));

    Connection connection = null;

    try {
        connection = DataSourceUtils.getConnection(dataSource());
        populator.populate(connection);
    } finally {
        if (connection != null) {
            DataSourceUtils.releaseConnection(connection, dataSource());
        }
    }

    return populator;
}
 
開發者ID:mhmxs,項目名稱:SpringClips,代碼行數:20,代碼來源:PersistenceConfigurarion.java

示例9: dataSourceInitializer

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Inject @Bean
public DataSourceInitializer dataSourceInitializer( @Named("presets-datasource") DataSource dataSource) {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    
    String scriptDropAll = environment.getProperty("mev.presets.db.schema.script.dropall");
    log.info ("***dataSourceInitializer-dropAllPresetsScript-TEST:"+scriptDropAll);
    //populator.addScript(new ClassPathResource(scriptDropAll));
    String scriptTestPresetValuesFlatTable = environment.getProperty("mev.presets.db.schema.script.TestPresetValuesFlatTable");
    populator.addScript(new ClassPathResource(scriptTestPresetValuesFlatTable));
          
    initializer.setDatabasePopulator(populator);
     return initializer;
}
 
開發者ID:dfci-cccb,項目名稱:mev,代碼行數:17,代碼來源:PresetsRestConfigurationTest.java

示例10: dataSourceInitializer

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Inject @Bean
public DataSourceInitializer dataSourceInitializer( @Named("probe-annotations-datasource") DataSource dataSource) {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    
    String scriptDropAll = environment.getProperty(MEV_PROBE_ANNOTATIONS_PROPERTY_PREFIX+"db.schema.script.dropall");
    log.info ("***dataSourceInitializer-dropAllScript-TEST:"+scriptDropAll);
    populator.addScript(new ClassPathResource(scriptDropAll));
    
    String scriptCreate = environment.getProperty(MEV_PROBE_ANNOTATIONS_PROPERTY_PREFIX+"db.schema.script");
    log.info ("***dataSourceInitializer-createScript-TEST:"+scriptCreate);
    populator.addScript(new ClassPathResource(scriptCreate));
    
    
    initializer.setDatabasePopulator(populator);
    return initializer;
}
 
開發者ID:dfci-cccb,項目名稱:mev,代碼行數:20,代碼來源:ProbeAnnotationsPersistanceConfigTest.java

示例11: batchMetaDataDataSource

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public PoolingDataSource batchMetaDataDataSource() {
	PoolingDataSource ds = new PoolingDataSource();

	ds.setClassName(org.hsqldb.jdbc.pool.JDBCXADataSource.class.getName());
	ds.setUniqueName("batchdb");
	ds.setMaxPoolSize(100);

	Properties props = new Properties();
	props.setProperty("databaseName", "spring-batch-metadata");
	// props.setProperty("createDatabase", "create");
	ds.setDriverProperties(props);

	ds.setAllowLocalTransactions(true);

	final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.addScript(batchDropSchemaScript);
	populator.addScript(batchCreateSchemaScript);
	DatabasePopulatorUtils.execute(populator, ds);

	return ds;
}
 
開發者ID:debop,項目名稱:spring-batch-experiments,代碼行數:23,代碼來源:JtaConfiguration.java

示例12: applicationDataSource

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Bean(initMethod = "init", destroyMethod = "close")
public PoolingDataSource applicationDataSource() {
	PoolingDataSource ds = new PoolingDataSource();

	ds.setClassName(org.hsqldb.jdbc.pool.JDBCXADataSource.class.getName());
	ds.setUniqueName("appdb");
	ds.setMaxPoolSize(100);

	final Properties props = new Properties();
	props.setProperty("databaseName", "chapter09-application");
	// props.setProperty("createDatabase", "create");
	ds.setDriverProperties(props);

	ds.setAllowLocalTransactions(true);

	final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.addScript(dropTablesScript);
	populator.addScript(createTableScript);
	DatabasePopulatorUtils.execute(populator, ds);

	return ds;
}
 
開發者ID:debop,項目名稱:spring-batch-experiments,代碼行數:23,代碼來源:JtaConfiguration.java

示例13: runScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
private void runScripts(List<Resource> resources, String username, String password) {
    if (resources.isEmpty()) {
        return;
    }
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(this.properties.isContinueOnError());
    populator.setSeparator(this.properties.getSeparator());
    if (this.properties.getSqlScriptEncoding() != null) {
        populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
    }
    for (Resource resource : resources) {
        populator.addScript(resource);
    }
    DataSource dataSource = this.dataSource;
    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        dataSource = DataSourceBuilder.create(this.properties.getClassLoader())
                .driverClassName(this.properties.determineDriverClassName())
                .url(this.properties.determineUrl()).username(username)
                .password(password).build();
    }
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
開發者ID:drtrang,項目名稱:druid-spring-boot,代碼行數:23,代碼來源:DruidDataSourceInitializer.java

示例14: initDatabase

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
@Bean
@DependsOn("entityManagerFactory")
public ResourceDatabasePopulator initDatabase(DataSource dataSource) throws Exception {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("db/h2/insert-data.sql"));
    populator.populate(dataSource.getConnection());
    return populator;
}
 
開發者ID:jaschenk,項目名稱:Your-Microservice,代碼行數:9,代碼來源:YourMicroserviceEnvironmentConfiguration.java

示例15: databasePopulator

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //導入方法依賴的package包/類
private DatabasePopulator databasePopulator() {
	final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setIgnoreFailedDrops(true);
	populator.setContinueOnError(true);
	populator.addScript(dropScript);
	populator.addScript(schemaScript);
	return populator;
}
 
開發者ID:vadivelmurugesan,項目名稱:spring-batch-admin,代碼行數:9,代碼來源:DataSourceConfig.java


注:本文中的org.springframework.jdbc.datasource.init.ResourceDatabasePopulator.addScript方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。