Java 类org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean 实例源码

项目:class-guard    文件:JdbcNamespaceIntegrationTests.java   
@Test
public void testCreateAndDestroyNested() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "org/springframework/jdbc/config/jdbc-destroy-nested-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(EmbeddedDatabaseFactoryBean.class).destroy();
        expected.expect(BadSqlGrammarException.class); // Table has been dropped
        assertEquals(1, template.queryForInt("select count(*) from T_TEST"));
    }
    finally {
        context.close();
    }
}
项目:lams    文件:EmbeddedDatabaseBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(EmbeddedDatabaseFactoryBean.class);
    setDatabaseType(element, builder);
    DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder);
    useIdAsDatabaseNameIfGiven(element, builder);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    return builder.getBeanDefinition();
}
项目:spring4-understanding    文件:EmbeddedDatabaseBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(EmbeddedDatabaseFactoryBean.class);
    setGenerateUniqueDatabaseNameFlag(element, builder);
    setDatabaseName(element, builder);
    setDatabaseType(element, builder);
    DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    return builder.getBeanDefinition();
}
项目:spring4-understanding    文件:JdbcNamespaceIntegrationTests.java   
@Test
public void createAndDestroyNestedWithHsql() throws Exception {
    ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config.xml");
    try {
        DataSource dataSource = context.getBean(DataSource.class);
        JdbcTemplate template = new JdbcTemplate(dataSource);
        assertNumRowsInTestTable(template, 1);
        context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
        expected.expect(BadSqlGrammarException.class); // Table has been dropped
        assertNumRowsInTestTable(template, 1);
    }
    finally {
        context.close();
    }
}
项目:spring4-understanding    文件:JdbcNamespaceIntegrationTests.java   
@Test
public void createAndDestroyNestedWithH2() throws Exception {
    ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config-h2.xml");
    try {
        DataSource dataSource = context.getBean(DataSource.class);
        JdbcTemplate template = new JdbcTemplate(dataSource);
        assertNumRowsInTestTable(template, 1);
        context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
        expected.expect(BadSqlGrammarException.class); // Table has been dropped
        assertNumRowsInTestTable(template, 1);
    }
    finally {
        context.close();
    }
}
项目:class-guard    文件:EmbeddedDatabaseBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(EmbeddedDatabaseFactoryBean.class);
    setDatabaseType(element, builder);
    DatabasePopulatorConfigUtils.setDatabasePopulator(element, builder);
    useIdAsDatabaseNameIfGiven(element, builder);
    builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
    return builder.getBeanDefinition();
}
项目:debop4j    文件:HibernateConfig.java   
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.addScript(new ClassPathResource("kr/debop4j/data/hibernate/config/java/schema.sql"));
    bean.setDatabasePopulator(databasePopulator);
    bean.afterPropertiesSet();   // EmbeddedDatabaseFactoryBean가 FactoryBean이므로 필요합니다.
    return bean.getObject();
}
项目:adaptive-spring    文件:Main.java   
@Bean
public DataSource dataSource() {

    ClassPathResource classPathResource = new ClassPathResource("/crm-schema-h2.sql");

    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.addScript(classPathResource);

    EmbeddedDatabaseFactoryBean embeddedDatabaseFactoryBean = new EmbeddedDatabaseFactoryBean();
    embeddedDatabaseFactoryBean.setDatabasePopulator(resourceDatabasePopulator);
    embeddedDatabaseFactoryBean.setDatabaseName("crm");
    embeddedDatabaseFactoryBean.setDatabaseType(EmbeddedDatabaseType.H2);
    embeddedDatabaseFactoryBean.afterPropertiesSet();
    return embeddedDatabaseFactoryBean.getObject();
}
项目:angular-ui    文件:AppConfig.java   
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseFactoryBean databaseFactoryBean = new EmbeddedDatabaseFactoryBean();
    databaseFactoryBean.setDatabaseType(EmbeddedDatabaseType.H2);
    databaseFactoryBean.afterPropertiesSet();
    return databaseFactoryBean.getObject();
}