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


Java DataSourceInitializer类代码示例

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


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

示例1: nonBootDataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的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

示例2: nonBootDataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的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

示例3: testCreateAndDestroy

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Test
public void testCreateAndDestroy() throws Exception {
	ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
			"org/springframework/jdbc/config/jdbc-destroy-config.xml");
	try {
		DataSource dataSource = context.getBean(DataSource.class);
		JdbcTemplate template = new JdbcTemplate(dataSource);
		assertEquals(1, template.queryForInt("select count(*) from T_TEST"));
		context.getBean(DataSourceInitializer.class).destroy();
		expected.expect(BadSqlGrammarException.class); // Table has been dropped
		assertEquals(1, template.queryForInt("select count(*) from T_TEST"));
	}
	finally {
		context.close();
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:17,代码来源:JdbcNamespaceIntegrationTests.java

示例4: hiveInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@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;
}
 
开发者ID:SpringOne2GX-2014,项目名称:Intro-to-Spring-Hadoop,代码行数:17,代码来源:Application.java

示例5: contextInitialized

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的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

示例6: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Inject @Bean
public DataSourceInitializer dataSourceInitializer( @Named("presets-datasource") DataSource dataSource) {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    
    String scriptDropAll = environment.getProperty("mev.presets.db.schema.script.dropall");
    log.info ("***dataSourceInitializer-dropAllPresetsScript-TEST:"+scriptDropAll);
    //populator.addScript(new ClassPathResource(scriptDropAll));
    String scriptTestPresetValuesFlatTable = environment.getProperty("mev.presets.db.schema.script.TestPresetValuesFlatTable");
    populator.addScript(new ClassPathResource(scriptTestPresetValuesFlatTable));
          
    initializer.setDatabasePopulator(populator);
     return initializer;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:17,代码来源:PresetsRestConfigurationTest.java

示例7: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Inject @Bean
public DataSourceInitializer dataSourceInitializer( @Named("probe-annotations-datasource") DataSource dataSource) {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);

    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    
    String scriptDropAll = environment.getProperty(MEV_PROBE_ANNOTATIONS_PROPERTY_PREFIX+"db.schema.script.dropall");
    log.info ("***dataSourceInitializer-dropAllScript-TEST:"+scriptDropAll);
    populator.addScript(new ClassPathResource(scriptDropAll));
    
    String scriptCreate = environment.getProperty(MEV_PROBE_ANNOTATIONS_PROPERTY_PREFIX+"db.schema.script");
    log.info ("***dataSourceInitializer-createScript-TEST:"+scriptCreate);
    populator.addScript(new ClassPathResource(scriptCreate));
    
    
    initializer.setDatabasePopulator(populator);
    return initializer;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:20,代码来源:ProbeAnnotationsPersistanceConfigTest.java

示例8: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean(name = "dataSourceInitializer")
public DataSourceInitializer dataSourceInitializer(
    final DataSource dataSource) {
    final DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:9,代码来源:DatabaseConfiguration.java

示例9: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean
public DataSourceInitializer dataSourceInitializer(
        final DataSource dataSource) {
    final DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
}
 
开发者ID:oncecloud,项目名称:devops-cstack,代码行数:9,代码来源:DatabaseConfigurationTest.java

示例10: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
	DataSourceInitializer initializer = new DataSourceInitializer();
	initializer.setDataSource(dataSource);
	initializer.setDatabasePopulator(databasePopulator());
	return initializer;
}
 
开发者ID:rhawan,项目名称:microservices-tcc-alfa,代码行数:8,代码来源:AuthorizationServerConfiguration.java

示例11: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
    final DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
}
 
开发者ID:PacktPublishing,项目名称:Building-Web-Apps-with-Spring-5-and-Angular,代码行数:8,代码来源:AppConfig.java

示例12: parseInternal

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DataSourceInitializer.class);
	builder.addPropertyReference("dataSource", element.getAttribute("data-source"));
	builder.addPropertyValue("enabled", element.getAttribute("enabled"));
	DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder);
	builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	return builder.getBeanDefinition();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:InitializeDatabaseBeanDefinitionParser.java

示例13: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
	final DataSourceInitializer initializer = new DataSourceInitializer();
	initializer.setEnabled(Boolean.valueOf(env.getProperty("batch.data.source.init")));
	initializer.setDataSource(dataSource);
	initializer.setDatabasePopulator(databasePopulator());
	return initializer;
}
 
开发者ID:vadivelmurugesan,项目名称:spring-batch-admin,代码行数:9,代码来源:DataSourceConfig.java

示例14: createAndDestroy

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Test
public void createAndDestroy() throws Exception {
	ClassPathXmlApplicationContext context = context("jdbc-destroy-config.xml");
	try {
		DataSource dataSource = context.getBean(DataSource.class);
		JdbcTemplate template = new JdbcTemplate(dataSource);
		assertNumRowsInTestTable(template, 1);
		context.getBean(DataSourceInitializer.class).destroy();
		expected.expect(BadSqlGrammarException.class); // Table has been dropped
		assertNumRowsInTestTable(template, 1);
	}
	finally {
		context.close();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:JdbcNamespaceIntegrationTests.java

示例15: dataSourceInitializer

import org.springframework.jdbc.datasource.init.DataSourceInitializer; //导入依赖的package包/类
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
}
 
开发者ID:jeesun,项目名称:spring-boot-oauth2-server,代码行数:8,代码来源:DataSourceConfig.java


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