protected void createTable() { StringBuilder sb = new StringBuilder(); sb.append("CREATE TABLE if not exists `leopard_domainwhitelist` ("); sb.append("`domain` varchar(50) NOT NULL DEFAULT '',"); sb.append("`username` varchar(50) NOT NULL DEFAULT '',"); sb.append("`posttime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',"); sb.append("`comment` varchar(255) NOT NULL DEFAULT '',"); sb.append("PRIMARY KEY (`domain`)"); sb.append(");"); String sql = sb.toString(); Resource scripts = new ByteArrayResource(sql.getBytes()); DatabasePopulator populator = new ResourceDatabasePopulator(scripts); try { DatabasePopulatorUtils.execute(populator, jdbcTemplate.getDataSource()); } catch (ScriptStatementFailedException e) { } }
@Bean DataSourceInitializer hiveInitializer(final DataSource dataSource) { final String ddl = "create external table if not exists tweetdata (value STRING) LOCATION '" + input + "'"; final DataSourceInitializer dsi = new DataSourceInitializer(); dsi.setDataSource(dataSource); dsi.setDatabasePopulator(new DatabasePopulator() { @Override public void populate(Connection conn) throws SQLException, ScriptException { Statement st = conn.createStatement(); st.execute(ddl); st.close(); } }); return dsi; }
@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; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.setIgnoreFailedDrops(true); populator.setContinueOnError(true); populator.addScript(dropScript); populator.addScript(schemaScript); return populator; }
private DatabasePopulator createDatabasePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); // populate the database with required tables databasePopulator.addScript(new ClassPathResource("schema.sql")); return databasePopulator; }
@Bean public InitializingBean dataPopulator(final DataSource dataSource) { return () -> { final DatabasePopulator populator = new ResourceDatabasePopulator(new ClassPathResource("data.sql")); DatabasePopulatorUtils.execute(populator, dataSource); }; }
@Bean DatabasePopulator databasePopulator(DataSource dataSource) throws SQLException, InterruptedException { DatabasePopulator dbp = new ResourceDatabasePopulator(false, false, "UTF-8", new ClassPathResource("sqoop-test-schema-ddl.sql"), new ClassPathResource("sqoop-test-data.sql")); dbp.populate(DataSourceUtils.getConnection(dataSource)); return dbp; }
@Bean DatabasePopulator databasePopulator(DataSource dataSource) throws SQLException, InterruptedException { DatabasePopulator dbp = new ResourceDatabasePopulator(false, false, "UTF-8", new ClassPathResource("sqoop-schema-ddl.sql"), new ClassPathResource("sqoop-root-data.sql"), new ClassPathResource("sqoop-sessions-data.sql"), new ClassPathResource("sqoop-test-schema-ddl.sql"), new ClassPathResource("sqoop-test-data.sql")); dbp.populate(DataSourceUtils.getConnection(dataSource)); return dbp; }
private DatabasePopulator dataSourcePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setScripts( new ClassPathResource(dropScript), new ClassPathResource(schemaScript) ); return databasePopulator; }
private DatabasePopulator dataSourcePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setScripts( new ClassPathResource("org/springframework/batch/core/schema-drop-hsqldb.sql"), new ClassPathResource("org/springframework/batch/core/schema-hsqldb.sql") ); return databasePopulator; }
private DatabasePopulator databasePopulator() { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("Account.sql", JdbcAccountRepository.class)); populator.addScript(new ClassPathResource("data.sql", JdbcAccountRepository.class)); populator.addScript(new ClassPathResource("rememberme.sql", JdbcAccountRepository.class)); return populator; }
private DatabasePopulator databasePopulator() { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("JdbcUsersConnectionRepository.sql", JdbcUsersConnectionRepository.class)); populator.addScript(new ClassPathResource("Account.sql", JdbcAccountRepository.class)); populator.addScript(new ClassPathResource("data.sql", JdbcAccountRepository.class)); return populator; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.setSqlScriptEncoding("utf-8"); populator.addScript(dataScript); return populator; }
private DatabasePopulator databasePopulator() { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(schemaScript); return populator; }
@Bean public DatabasePopulator databasePopulator() { return null; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(schemaScript); populator.addScript(dataScript); return populator; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(schemaScript); return populator; }
private DatabasePopulator createDatabasePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); databasePopulator.addScript(new ClassPathResource("database/database.sql")); return databasePopulator; }
private DatabasePopulator databasePopulator() { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(new ClassPathResource("JdbcUsersConnectionRepository.sql", JdbcUsersConnectionRepository.class)); return populator; }
private DatabasePopulator databasePopulator() { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(schemaScript); populator.addScript(dataScript); return populator; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript((org.springframework.core.io.Resource) schemaScript); return populator; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.addScript(HSQL_SCHEMA_SCRIPT); return populator; }
private DatabasePopulator databasePopulator() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); return populator; }
private DatabasePopulator databaseCleaner() { final ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); return populator; }
private DatabasePopulator createDatabasePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); databasePopulator.addScript(new ClassPathResource("schema.sql")); return databasePopulator; }
/** * Set a script execution to be run in the bean destruction callback, * cleaning up the database and leaving it in a known state for others. * @param databaseCleaner the database script executor to run on destroy * @see #setDatabasePopulator * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabaseCleaner */ public void setDatabaseCleaner(DatabasePopulator databaseCleaner) { this.databaseCleaner = databaseCleaner; }
/** * Set the strategy that will be used to initialize or populate the embedded * database. * <p>Defaults to {@code null}. */ public void setDatabasePopulator(DatabasePopulator populator) { this.databasePopulator = populator; }