當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。