List of usage examples for org.springframework.jdbc.datasource.init ResourceDatabasePopulator populate
@Override public void populate(Connection connection) throws ScriptException
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"); }/* w w w. ja v a 2 s . c o 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.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 w w w . j av a2 s. co m*/ protected void tearDown() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); } }; }
From source file:org.wso2.carbon.metrics.impl.JDBCCleanupTest.java
@BeforeClass public static void setupDatasource() throws ScriptException, SQLException { dataSource = JdbcConnectionPool.create("jdbc:h2:mem:test-cleanup;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:org.wso2.carbon.metrics.impl.ReporterTest.java
public static Test suite() { return new TestSetup(new TestSuite(ReporterTest.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); // Set setup system property to cover database creator logic System.setProperty("setup", ""); }/*from w w w . j a v a 2 s . co m*/ protected void tearDown() throws Exception { InitialContext ic = new InitialContext(); ic.unbind("jdbc/WSO2MetricsDB"); ic.unbind("jdbc"); } }; }
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:org.wso2.carbon.metrics.jdbc.reporter.JdbcReporterTest.java
@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); }
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 {//from w w w . j av a 2 s .com populator.populate(connection); } catch (ScriptStatementFailedException e) { // ignore } finally { DataSourceUtils.releaseConnection(connection, dataSource); } }
From source file:sample.config.DataConfiguration.java
@Bean @DependsOn("entityManagerFactory") public ResourceDatabasePopulator initDatabase(DataSource dataSource) throws Exception { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("data.sql")); populator.populate(dataSource.getConnection()); return populator; }
From source file:org.codeqinvest.TestDataLoaderApplicationListener.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (alreadyExecuted.compareAndSet(false, true)) { log.info("Loading test data into database..."); Connection connection = null; try {// ww w . jav a 2 s. c om ResourceDatabasePopulator resourceDatabasePopulator = createConfiguredResourceDatabasePopulator(); try { connection = dataSource.getConnection(); resourceDatabasePopulator.populate(connection); } catch (SQLException e) { log.error("Error while populating database with test data...", e); throw new RuntimeException(e); } } finally { if (connection != null) { try { connection.close(); } catch (SQLException e) { log.error("Error while closing connection!", e); throw new RuntimeException(e); } } } } else { log.info("Already added test data to database."); } }
From source file:com.ofbizian.infinispan.AtomikosJtaConfiguration.java
private void executeScript(Connection connection, String location) { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); populator.addScript(resourceLoader.getResource(location)); try {/*from ww w. j av a 2 s. c om*/ populator.populate(connection); } catch (Exception e) { e.printStackTrace(); } }