本文整理匯總了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}