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


Java ResourceDatabasePopulator.populate方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: databasePopulator

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
@Bean
public DatabasePopulator databasePopulator(DataSource dataSource) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(true);
    populator.setIgnoreFailedDrops(true);
    populator.addScripts(new ClassPathResource("/db/h2schema.sql"),
            new ClassPathResource("/db/h2data.sql"));
    try {
        populator.populate(dataSource.getConnection());
    } catch (SQLException ignored) {
    }
    return populator;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:14,代码来源:H2Config.java

示例5: 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

示例6: initSQL

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
protected static void initSQL(DataSource dataSource, String... scripts) {
	try {
		ResourceLoader rl = new DefaultResourceLoader();
		ResourceDatabasePopulator rbp = new ResourceDatabasePopulator();
		for (String script : scripts) {
			rbp.addScripts(rl.getResource(script));
		}
		try (Connection connection = dataSource.getConnection()) {
			rbp.populate(connection);
		}
	} catch (Exception e) {
		throw new RuntimeException("Failed to init SQL scripts", e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-datastore-jdbc,代码行数:15,代码来源:AbstractDatastoreIntegrationTest.java

示例7: init

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
@BeforeSuite
private static void init() throws Exception {
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
    template = new JdbcTemplate(dataSource);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
    populator.populate(dataSource.getConnection());
    DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
    transactionTemplate = new TransactionTemplate(dataSourceTransactionManager);
}
 
开发者ID:wso2,项目名称:carbon-metrics,代码行数:11,代码来源:JdbcReporterTest.java

示例8: init

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
@BeforeSuite
protected static void init() throws Exception {
    if (logger.isInfoEnabled()) {
        logger.info("Initializing the data source and populating data");
    }
    // Setup datasource
    dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "");
    template = new JdbcTemplate(dataSource);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("dbscripts/h2.sql"));
    populator.populate(dataSource.getConnection());

    // Create initial context
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");
    InitialContext ic = new InitialContext();
    ic.createSubcontext("jdbc");
    ic.bind("jdbc/WSO2MetricsDB", dataSource);

    if (logger.isInfoEnabled()) {
        logger.info("Creating Metrics");
    }
    metrics = new Metrics(TestUtils.getConfigProvider("metrics.yaml"));
    metrics.activate();
    metricService = metrics.getMetricService();
    metricManagementService = metrics.getMetricManagementService();
}
 
开发者ID:wso2,项目名称:carbon-metrics,代码行数:28,代码来源:BaseReporterTest.java

示例9: initDatabase

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
@Bean
public ResourceDatabasePopulator initDatabase(final DataSource dataSource) throws Exception {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(new ClassPathResource("test-data.sql"));
    populator.populate(dataSource.getConnection());
    return populator;
}
 
开发者ID:ksokol,项目名称:carldav,代码行数:8,代码来源:TestData.java

示例10: dataSource

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入方法依赖的package包/类
/**
 * @return H2 pooled data source
 * @throws SQLException
 */
@Bean(destroyMethod = "dispose")
public DataSource dataSource() throws SQLException {
	final JdbcConnectionPool pool = JdbcConnectionPool.create(url, user, password);
	pool.setMaxConnections(maxPoolConnections);
	Connection con = null;
	con = pool.getConnection();

	final Flyway flyway = new Flyway();
	flyway.setLocations("classpath:sql/migration");
	flyway.setDataSource(pool);
	flyway.setSqlMigrationPrefix("VOS-");
	flyway.setIgnoreFailedFutureMigration(true);

	final JdbcTemplate tpl = new JdbcTemplate(pool);
	if (tpl.queryForObject("select count(*) from information_schema.tables where table_name = 'LOG_SOURCES'",
			int.class) == 0) {
		logger.info("H2 database not found, creating new schema and populate with default data");
		flyway.setBaselineVersion(MigrationVersion.fromVersion(DB_SETUP_VERSION));
		flyway.setBaselineOnMigrate(true);
		try {
			final ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator();
			dbPopulator.addScript(new ClassPathResource("/sql/quartz/tables_h2.sql"));
			dbPopulator.addScript(new ClassPathResource("/sql/model/schema_h2.sql"));
			dbPopulator.populate(con);
			newSchema = true;
			logger.info("Established H2 connection pool with new database");
		} finally {
			if (con != null) {
				con.close();
			}
		}
	} else {
		logger.info("Established H2 connection pool with existing database");
		if (tpl.queryForObject("select count(*) from information_schema.tables where table_name = 'schema_version'",
				int.class) == 0) {
			logger.info("Flyway's DB migration not setup in this version, set baseline version to 0.5.0");
			flyway.setBaselineVersion(MigrationVersion.fromVersion("0.5.0"));
			flyway.setBaselineOnMigrate(true);
		}
	}

	logger.debug("Migrating database, base version is: {}", flyway.getBaselineVersion());
	flyway.migrate();
	logger.debug("Database migrated from base version: {}", flyway.getBaselineVersion());

	return pool;
}
 
开发者ID:logsniffer,项目名称:logsniffer,代码行数:52,代码来源:DataSourceAppConfig.java


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