removed new EmbeddedDatabaeBuilder methods that don't seem very useful for embedded scenarios; javadoc polishing
This commit is contained in:
parent
222ae33666
commit
3f65721ba8
|
|
@ -40,11 +40,11 @@ import org.springframework.util.xml.DomUtils;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses {@code initialize-database} element and
|
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses an {@code initialize-database} element and
|
||||||
* creates a {@link BeanDefinition} for {@link DataSourceInitializer}. Picks up nested {@code script} elements and
|
* creates a {@link BeanDefinition} of type {@link DataSourceInitializer}. Picks up nested {@code script} elements and
|
||||||
* configures a {@link ResourceDatabasePopulator} for them.
|
* configures a {@link ResourceDatabasePopulator} for them.
|
||||||
@author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
public class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
||||||
|
|
||||||
|
|
@ -70,7 +70,6 @@ public class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefiniti
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, ParserContext context) {
|
private BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, ParserContext context) {
|
||||||
|
|
||||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class);
|
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ResourceDatabasePopulator.class);
|
||||||
builder.addPropertyValue("ignoreFailedDrops", element.getAttribute("ignore-failures").equals("DROPS"));
|
builder.addPropertyValue("ignoreFailedDrops", element.getAttribute("ignore-failures").equals("DROPS"));
|
||||||
builder.addPropertyValue("continueOnError", element.getAttribute("ignore-failures").equals("ALL"));
|
builder.addPropertyValue("continueOnError", element.getAttribute("ignore-failures").equals("ALL"));
|
||||||
|
|
@ -89,7 +88,6 @@ public class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefiniti
|
||||||
builder.addPropertyValue("scripts", resourcesFactory.getBeanDefinition());
|
builder.addPropertyValue("scripts", resourcesFactory.getBeanDefinition());
|
||||||
|
|
||||||
return builder.getBeanDefinition();
|
return builder.getBeanDefinition();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source,
|
||||||
|
|
@ -104,6 +102,7 @@ public class InitializeDatabaseBeanDefinitionParser extends AbstractBeanDefiniti
|
||||||
private static final Log logger = LogFactory.getLog(SortedResourcesFactoryBean.class);
|
private static final Log logger = LogFactory.getLog(SortedResourcesFactoryBean.class);
|
||||||
|
|
||||||
private ResourceLoader resourceLoader;
|
private ResourceLoader resourceLoader;
|
||||||
|
|
||||||
private List<String> locations;
|
private List<String> locations;
|
||||||
|
|
||||||
public SortedResourcesFactoryBean(ResourceLoader resourceLoader, List<String> locations) {
|
public SortedResourcesFactoryBean(ResourceLoader resourceLoader, List<String> locations) {
|
||||||
|
|
|
||||||
|
|
@ -72,30 +72,6 @@ public class EmbeddedDatabaseBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a flag to say that the database populator should continue on
|
|
||||||
* errors in the scripts provided (if any).
|
|
||||||
*
|
|
||||||
* @param continueOnError the flag value
|
|
||||||
* @return this, for fluent call chaining
|
|
||||||
*/
|
|
||||||
public EmbeddedDatabaseBuilder continueOnError(boolean continueOnError) {
|
|
||||||
this.databasePopulator.setContinueOnError(continueOnError);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a flag to say that the database populator should continue on
|
|
||||||
* errors in DROP statements in the scripts provided (if any).
|
|
||||||
*
|
|
||||||
* @param ignoreFailedDrops the flag value
|
|
||||||
* @return this, for fluent call chaining
|
|
||||||
*/
|
|
||||||
public EmbeddedDatabaseBuilder ignoreFailedDrops(boolean ignoreFailedDrops) {
|
|
||||||
this.databasePopulator.setIgnoreFailedDrops(ignoreFailedDrops);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the type of embedded database.
|
* Sets the type of embedded database.
|
||||||
* Defaults to HSQL if not called.
|
* Defaults to HSQL if not called.
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ public class DataSourceInitializer implements InitializingBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag to explicitly enable or disable the database populator.
|
* Flag to explicitly enable or disable the database populator.
|
||||||
*
|
|
||||||
* @param enabled true if the database populator will be called on startup
|
* @param enabled true if the database populator will be called on startup
|
||||||
*/
|
*/
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
|
|
@ -45,7 +44,6 @@ public class DataSourceInitializer implements InitializingBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link DatabasePopulator} to use to populate the data source. Mandatory with no default.
|
* The {@link DatabasePopulator} to use to populate the data source. Mandatory with no default.
|
||||||
*
|
|
||||||
* @param databasePopulator the database populator to use.
|
* @param databasePopulator the database populator to use.
|
||||||
*/
|
*/
|
||||||
public void setDatabasePopulator(DatabasePopulator databasePopulator) {
|
public void setDatabasePopulator(DatabasePopulator databasePopulator) {
|
||||||
|
|
@ -54,7 +52,6 @@ public class DataSourceInitializer implements InitializingBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link DataSource} to populate when this component is initialized. Mandatory with no default.
|
* The {@link DataSource} to populate when this component is initialized. Mandatory with no default.
|
||||||
*
|
|
||||||
* @param dataSource the DataSource
|
* @param dataSource the DataSource
|
||||||
*/
|
*/
|
||||||
public void setDataSource(DataSource dataSource) {
|
public void setDataSource(DataSource dataSource) {
|
||||||
|
|
@ -63,7 +60,6 @@ public class DataSourceInitializer implements InitializingBean {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use the populator to set up data in the data source. Both properties are mandatory with no defaults.
|
* Use the populator to set up data in the data source. Both properties are mandatory with no defaults.
|
||||||
*
|
|
||||||
* @see InitializingBean#afterPropertiesSet()
|
* @see InitializingBean#afterPropertiesSet()
|
||||||
*/
|
*/
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -82,11 +82,8 @@
|
||||||
default="true">
|
default="true">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation>
|
<xsd:documentation>
|
||||||
Is this bean "enabled", that is, will the
|
Is this bean "enabled", meaning the scripts will be executed?
|
||||||
scripts be executed?
|
Defaults to true, but can be used to switch on and off the initialization depending on the environment.
|
||||||
Defaults to true, but can be used to switch on
|
|
||||||
and off the
|
|
||||||
initialization depending on the environment.
|
|
||||||
</xsd:documentation>
|
</xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
|
|
@ -130,8 +127,7 @@
|
||||||
<xsd:attribute name="location" type="xsd:string">
|
<xsd:attribute name="location" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
The resource location of an SQL script to execute. Can be a single script location or
|
The resource location of an SQL script to execute. Can be a single script location or a pattern (e.g. classpath:/com/foo/sql/*-data.sql).
|
||||||
a pattern (e.g. classpath:/com/foo/sql/*-data.sql).
|
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</xsd:attribute>
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,6 @@ public class EmbeddedDatabaseBuilderTests {
|
||||||
assertDatabaseCreatedAndShutdown(db);
|
assertDatabaseCreatedAndShutdown(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBuildWithCommentsAndFailedDrop() {
|
|
||||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
|
||||||
EmbeddedDatabase db = builder.ignoreFailedDrops(true).addScript("db-schema-failed-drop-comments.sql").addScript("db-test-data.sql").build();
|
|
||||||
assertDatabaseCreatedAndShutdown(db);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildH2() {
|
public void testBuildH2() {
|
||||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||||
|
|
@ -47,7 +40,6 @@ public class EmbeddedDatabaseBuilderTests {
|
||||||
assertDatabaseCreatedAndShutdown(db);
|
assertDatabaseCreatedAndShutdown(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildDerby() {
|
public void testBuildDerby() {
|
||||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass()));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue