当前位置: 首页>>代码示例>>Java>>正文


Java ResourceDatabasePopulator类代码示例

本文整理汇总了Java中org.springframework.jdbc.datasource.init.ResourceDatabasePopulator的典型用法代码示例。如果您正苦于以下问题:Java ResourceDatabasePopulator类的具体用法?Java ResourceDatabasePopulator怎么用?Java ResourceDatabasePopulator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceDatabasePopulator类属于org.springframework.jdbc.datasource.init包,在下文中一共展示了ResourceDatabasePopulator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@PostConstruct
protected void initialize() {
	if (this.properties.getInitializer().isEnabled()) {
		String platform = getDatabaseType();
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = this.properties.getSchema();
		schemaLocation = schemaLocation.replace("@@[email protected]@", platform);
		populator.addScript(this.resourceLoader.getResource(schemaLocation));
		populator.setContinueOnError(true);
		DatabasePopulatorUtils.execute(populator, this.dataSource);
	}
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:22,代码来源:BatchDatabaseInitializer.java

示例2: herdDataSource

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
/**
 * Get a new herd data source based on an in-memory HSQLDB database. This data source is used for loading the configuration table as an environment property
 * source as well as for the JPA entity manager. It will therefore create/re-create the configuration table which is required for the former. It also
 * inserts required values for both scenarios.
 *
 * @return the test herd data source.
 */
@Bean
public static DataSource herdDataSource()
{
    // Create and return a data source that can connect directly to a JDBC URL.
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setUsername("");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:h2:mem:herdTestDb");

    // Create and populate the configuration table.
    // This is needed for all data source method calls since it is used to create the environment property source which happens before
    // JPA and other non-static beans are initialized.
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.addScript(new ClassPathResource("createConfigurationTableAndData.sql"));
    DatabasePopulatorUtils.execute(resourceDatabasePopulator, basicDataSource); // This is what the DataSourceInitializer does.

    return basicDataSource;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:27,代码来源:DaoEnvTestSpringModuleConfig.java

示例3: conf

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@Test
public void conf() throws Exception {
    // 1. migrate
    String[] args = new String[4];
    args[0] = "migrate";
    args[1] = "--conf";
    args[2] = BASE_PATH + File.separator + "content12.xml";
    args[3] = BASE_PATH + File.separator + "MasterContent.xml";

    new MigrateCommand().execute(new Input(args));

    // 2. initialize db as persistence-jpa does
    DataSource dataSource = new DriverManagerDataSource("jdbc:h2:mem:syncopedb;DB_CLOSE_DELAY=-1", "sa", null);

    new ResourceDatabasePopulator(new ClassPathResource("/schema20.sql")).execute(dataSource);

    // 3. attempt to set initial content from the migrated MasterContent.xml
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try (InputStream in = new FileInputStream(args[3])) {

        SAXParser parser = factory.newSAXParser();
        parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false));
    }
}
 
开发者ID:apache,项目名称:syncope,代码行数:25,代码来源:MigrateTest.java

示例4: runScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
private void runScripts(List<Resource> resources, String username, String password) {
	if (resources.isEmpty()) {
		return;
	}
	ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setContinueOnError(this.properties.isContinueOnError());
	populator.setSeparator(this.properties.getSeparator());
	if (this.properties.getSqlScriptEncoding() != null) {
		populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
	}
	for (Resource resource : resources) {
		populator.addScript(resource);
	}
	DataSource dataSource = this.dataSource;
	if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
		dataSource = DataSourceBuilder.create(this.properties.getClassLoader())
				.driverClassName(this.properties.determineDriverClassName())
				.url(this.properties.determineUrl()).username(username)
				.password(password).build();
	}
	DatabasePopulatorUtils.execute(populator, dataSource);
}
 
开发者ID:muxiangqiu,项目名称:spring-boot-multidatasource,代码行数:23,代码来源:DataSourceInitializer.java

示例5: runScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
private void runScripts(List<Resource> resources, DataSource dataSource) {
	if (resources.isEmpty()) {
		return;
	}
	ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.setContinueOnError(configuration.isContinueOnError());
	populator.setSeparator(configuration.getConfigPropertyValue(SpringDataSourceConfigProperties.SEPARATOR, ";"));
	String encoding = configuration.getConfigPropertyValue(SpringDataSourceConfigProperties.SQL_SCRIPT_ENCODING,
			null);
	if (encoding != null) {
		populator.setSqlScriptEncoding(encoding);
	}
	for (Resource resource : resources) {
		populator.addScript(resource);
	}
	DatabasePopulatorUtils.execute(populator, dataSource);
}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:18,代码来源:DataContextDataSourceInitializer.java

示例6: createTable

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
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) {

	}
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:21,代码来源:DomainWhiteListConfigImpl.java

示例7: nonBootDataSourceInitializer

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@ConditionalOnProperty("pgcopy.initialize")
@Bean
public DataSourceInitializer nonBootDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader) {
	DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
	dataSourceInitializer.setDataSource(dataSource);
	ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
	databasePopulator.setIgnoreFailedDrops(true);
	dataSourceInitializer.setDatabasePopulator(databasePopulator);
	if ("true".equals(properties.getInitialize())) {
		databasePopulator.addScript(new DefaultInitializationScriptResource(properties.getTableName(),
				properties.getColumns()));
	} else {
		databasePopulator.addScript(resourceLoader.getResource(properties.getInitialize()));
	}
	return dataSourceInitializer;
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:jdbc,代码行数:17,代码来源:PgcopySinkConfiguration.java

示例8: nonBootDataSourceInitializer

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@ConditionalOnProperty("jdbc.initialize")
@Bean
public DataSourceInitializer nonBootDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader) {
	DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
	dataSourceInitializer.setDataSource(dataSource);
	ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
	databasePopulator.setIgnoreFailedDrops(true);
	dataSourceInitializer.setDatabasePopulator(databasePopulator);
	if ("true".equals(properties.getInitialize())) {
		databasePopulator.addScript(new DefaultInitializationScriptResource(properties.getTableName(),
				properties.getColumnsMap().keySet()));
	}
	else {
		databasePopulator.addScript(resourceLoader.getResource(properties.getInitialize()));
	}
	return dataSourceInitializer;
}
 
开发者ID:spring-cloud-stream-app-starters,项目名称:jdbc,代码行数:18,代码来源:JdbcSinkConfiguration.java

示例9: before

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@Override
protected void before() {
  ResourceDatabasePopulator populator = new ResourceDatabasePopulator(
      new ClassPathResource("sql/cache-data-remove.sql"),
      new ClassPathResource("sql/cache-data-insert.sql")
  );
  DatabasePopulatorUtils.execute(populator, cacheDataSource);

  CacheManager.getInstance().clearAll();
  controlTagCache.init();
  processCache.init();
  dataTagCache.init();
  equipmentCache.init();
  aliveTimerCache.init();
  commFaultTagCache.init();
  subEquipmentCache.init();
  alarmCache.init();
  ruleTagCache.init();
  commandTagCache.init();
  deviceClassCache.init();
  deviceCache.init();
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:23,代码来源:RuleCachePopulationRule.java

示例10: build

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
public DataSource build() {
  DataSource dataSource;

  if (url == null || url.contains("hsqldb:mem")) {
    // Start an in-process, in-memory HSQL server
    dataSource = new EmbeddedDatabaseBuilder().setType(HSQL).setName("c2mondb").build();
  } else if (url.contains("hsql://")) {
    // Start an externally visible, file-based HSQL server
    HsqlServer.start("file:///tmp/c2mondb", "c2mondb");
    url += ";sql.syntax_ora=true;hsqldb.default_table_type=cached;hsqldb.cache_rows=1000;hsqldb.result_max_memory_rows=2000;hsqldb.cache_size=100";
    dataSource = DataSourceBuilder.create().url(url).username(username).password(password).build();

  } else {
    throw new RuntimeException("The given URL was not a valid HSQL JDBC URL!");
  }

  if (!scripts.isEmpty()) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(scripts.toArray(new Resource[scripts.size()]));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource);
  }

  return dataSource;
}
 
开发者ID:c2mon,项目名称:c2mon,代码行数:25,代码来源:HsqlDatabaseBuilder.java

示例11: 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

示例12: 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

示例13: applyScripts

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
private void applyScripts(String url) throws SQLException, IOException {
    log.info("Apply Scripts ...");
    Connection connection = getConnection(url);
    DataSource ds = new SingleConnectionDataSource(connection, false);
    FileSystemScanner scanner = new FileSystemScanner();
    for (String location : builder.locations) {
        File directory = new File(location);
        if (directory.exists() && directory.isDirectory()) {
            Resource[] resources = scanner.scanForResources(location, "", ".sql");
            ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resources);
            populator.setSeparator(builder.separator);
            populator.execute(ds);
        } else {
            // log not existing directory
        }
    }
    log.info("Scripts applied!");
}
 
开发者ID:zalando-stups,项目名称:booties,代码行数:19,代码来源:PostgreSqlRule.java

示例14: contextInitialized

import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; //导入依赖的package包/类
@Override
public void contextInitialized(final ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);

    try {
        Server h2TestDb = new Server();
        h2TestDb.runTool("-tcp", "-tcpDaemon", "-web", "-webDaemon",
                "-webPort", ctx.getBean("testdb.webport", String.class));

        context.setAttribute(H2_TESTDB, h2TestDb);
    } catch (SQLException e) {
        LOG.error("Could not start H2 test db", e);
    }

    DataSource datasource = ctx.getBean(DataSource.class);

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(ctx.getResource("classpath:/testdb.sql"));
    populator.setSqlScriptEncoding("UTF-8");
    DataSourceInitializer init = new DataSourceInitializer();
    init.setDataSource(datasource);
    init.setEnabled(true);
    init.setDatabasePopulator(populator);
    init.afterPropertiesSet();
    LOG.info("Database successfully initialized");
}
 
开发者ID:apache,项目名称:syncope,代码行数:27,代码来源:H2StartStopListener.java

示例15: 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


注:本文中的org.springframework.jdbc.datasource.init.ResourceDatabasePopulator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。