Java Code Examples for org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@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();
		// Table has been dropped
		assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() ->
				assertNumRowsInTestTable(template, 1));
	}
	finally {
		context.close();
	}
}
 
Example 2
@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();
		 // Table has been dropped
		assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() ->
				assertNumRowsInTestTable(template, 1));
	}
	finally {
		context.close();
	}
}
 
Example 3
@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();
}
 
Example 4
@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();
}
 
Example 5
@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();
	}
}
 
Example 6
@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();
	}
}
 
Example 7
@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();
}
 
Example 8
@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();
}
 
Example 9
@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();
	}
}
 
Example 10
@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();
	}
}
 
Example 11
@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();
}
 
Example 12
@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();
	}
}
 
Example 13
@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();
	}
}
 
Example 14
Source Project: spring-data-examples   Source File: DataConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  EmbeddedDatabaseFactoryBean databaseFactoryBean = new EmbeddedDatabaseFactoryBean();
  databaseFactoryBean.setDatabaseType(EmbeddedDatabaseType.H2);
  databaseFactoryBean.afterPropertiesSet();
  return databaseFactoryBean.getObject();
}