RESOLVED - issue SPR-6345: ResourceDatabasePopulator does not handle comments properly when ignoring failures
http://jira.springframework.org/browse/SPR-6345
This commit is contained in:
@@ -106,7 +106,7 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
|
||||
* Returns an {@link OutputStream} that ignores all data given to it.
|
||||
* Used by {@link #getInstance()} to prevent writing to Derby.log file.
|
||||
*/
|
||||
static OutputStream getNoopOutputStream() {
|
||||
public static OutputStream getNoopOutputStream() {
|
||||
return new OutputStream() {
|
||||
public void write(int b) throws IOException {
|
||||
// ignore the output
|
||||
|
||||
@@ -32,17 +32,17 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @since 3.0
|
||||
*/
|
||||
public class EmbeddedDatabaseBuilder {
|
||||
|
||||
private final EmbeddedDatabaseFactory databaseFactory;
|
||||
|
||||
|
||||
private final ResourceDatabasePopulator databasePopulator;
|
||||
|
||||
private final ResourceLoader resourceLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new embedded database builder.
|
||||
*/
|
||||
@@ -51,7 +51,7 @@ public class EmbeddedDatabaseBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new embedded database builder withfor the given ResourceLoader.
|
||||
* Create a new embedded database builder with the given ResourceLoader.
|
||||
* @param resourceLoader the ResourceLoader to delegate to
|
||||
*/
|
||||
public EmbeddedDatabaseBuilder(ResourceLoader resourceLoader) {
|
||||
@@ -61,7 +61,6 @@ public class EmbeddedDatabaseBuilder {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the name of the embedded database
|
||||
* Defaults to 'testdb' if not called.
|
||||
@@ -73,6 +72,30 @@ public class EmbeddedDatabaseBuilder {
|
||||
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.
|
||||
* Defaults to HSQL if not called.
|
||||
@@ -83,7 +106,7 @@ public class EmbeddedDatabaseBuilder {
|
||||
this.databaseFactory.setDatabaseType(databaseType);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a SQL script to execute to populate the database.
|
||||
* @param sqlResource the sql resource location
|
||||
@@ -112,5 +135,5 @@ public class EmbeddedDatabaseBuilder {
|
||||
public EmbeddedDatabase build() {
|
||||
return this.databaseFactory.getDatabase();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
|
||||
private boolean ignoreFailedDrops = false;
|
||||
|
||||
private static String COMMENT_PREFIX = "--";
|
||||
|
||||
/**
|
||||
* Add a script to execute to populate the database.
|
||||
* @param script the path to a SQL script
|
||||
@@ -185,7 +187,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||
String currentStatement = lnr.readLine();
|
||||
StringBuilder scriptBuilder = new StringBuilder();
|
||||
while (currentStatement != null) {
|
||||
if (StringUtils.hasText(currentStatement)) {
|
||||
if (StringUtils.hasText(currentStatement) && !currentStatement.startsWith(COMMENT_PREFIX)) {
|
||||
if (scriptBuilder.length() > 0) {
|
||||
scriptBuilder.append('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user