List of usage examples for org.springframework.jdbc.datasource.init ResourceDatabasePopulator ResourceDatabasePopulator
public ResourceDatabasePopulator()
From source file:org.camelcookbook.transactions.util.DataSourceInitializer.java
public static DataSource initializeDataSource(DataSource dataSource, Resource script) { // here we use the same classes that Spring does under the covers to run the schema into the database ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(script);/*from w w w . j a v a2 s . c o m*/ DatabasePopulatorUtils.execute(populator, dataSource); return dataSource; }
From source file:org.cloudfoundry.identity.uaa.scim.test.TestUtils.java
public static void runScript(DataSource dataSource, String stem) throws Exception { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); String packageName = ClassUtils.getPackageName(TestUtils.class).replace(".", "/"); populator.addScript(new ClassPathResource( packageName.substring(0, packageName.lastIndexOf("/")) + "/" + stem + "-" + platform + ".sql")); Connection connection = dataSource.getConnection(); try {/*www . j av a 2s.c o m*/ populator.populate(connection); } catch (ScriptStatementFailedException e) { // ignore } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }
From source file:org.wso2.carbon.metrics.data.service.MetricsDataServiceTest.java
public static Test suite() { return new TestSetup(new TestSuite(MetricsDataServiceTest.class)) { protected void setUp() throws Exception { 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); }/*from ww w . ja v a 2 s .c o m*/ protected void tearDown() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); } }; }
From source file:org.cloudfoundry.samples.handson.ex5.Ex5Config.java
public void databasePopulator() { try {/* www . j a v a 2 s. com*/ ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("schema.sql", Ex5Config.class)); DatabasePopulatorUtils.execute(populator, fromDataSource()); } catch (DataAccessResourceFailureException e) { //ignore if table already exists } }
From source file:org.wso2.carbon.metrics.jdbc.core.BaseReporterTest.java
@BeforeSuite protected static void init() throws Exception { if (logger.isInfoEnabled()) { logger.info("Initializing the data source and populating data"); }/*from ww w .j a v a 2 s. co m*/ // 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(); }
From source file:org.wso2.carbon.metrics.reporter.JDBCReporterTest.java
@BeforeClass public static void setupDatasource() 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()); }
From source file:sf.wicklet.site.gwt.test.db.TestSpringJDBCH201.java
protected EmbeddedDatabase createDatabase(final File dbfile, final String dbpath) throws ClassNotFoundException { final EmbeddedDatabaseFactory f = new EmbeddedDatabaseFactory(); final ResourceDatabasePopulator p = new ResourceDatabasePopulator(); final ResourceLoader l = new DefaultResourceLoader(); if (!dbfile.exists()) { final String classname = getClass().getName().replace('.', '/'); p.addScript(l.getResource(String.format("classpath:/%s-schema.sql", classname))); p.addScript(l.getResource(String.format("classpath:/%s-init.sql", classname))); }/*w ww . ja v a 2s .c o m*/ f.setDatabasePopulator(p); f.setDatabaseConfigurer(sf.wicklet.gwt.site.server.db.H2Configurator.getInstance(dbpath)); // Database name now a dont' care. // f.setDatabaseName("db01"); return f.getDatabase(); }
From source file:com.oreilly.springdata.jpa.AbstractIntegrationTest.java
/** * Populates the configured {@link DataSource} with data from {@code data.sql}. * //from www . java2s. co m * @throws SQLException */ @Before public void populateDatabase() throws SQLException { 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); } } }
From source file:com.backend.test.repository.AbstractIntegrationTest.java
/** * Populates the configured {@link DataSource} with data from {@code data.sql}. * /*from ww w . j av a2 s .c o m*/ * @throws SQLException */ @Before public void populateDatabase() throws SQLException { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("foodies.sql")); Connection connection = null; try { connection = DataSourceUtils.getConnection(dataSource); populator.populate(connection); } finally { if (connection != null) { DataSourceUtils.releaseConnection(connection, dataSource); } } }
From source file:org.dawnsci.marketplace.config.DatabaseConfiguration.java
private DatabasePopulator createDatabasePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); // populate the database with required tables databasePopulator.addScript(new ClassPathResource("schema.sql")); return databasePopulator; }