polishing
This commit is contained in:
parent
19c2672dc3
commit
e63e6cdbde
|
|
@ -64,13 +64,6 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
private String separator = null;
|
private String separator = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param separator the statement separator
|
|
||||||
*/
|
|
||||||
public void setSeparator(String separator) {
|
|
||||||
this.separator = separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a script to execute to populate the database.
|
* Add a script to execute to populate the database.
|
||||||
* @param script the path to a SQL script
|
* @param script the path to a SQL script
|
||||||
|
|
@ -123,6 +116,13 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
this.ignoreFailedDrops = ignoreFailedDrops;
|
this.ignoreFailedDrops = ignoreFailedDrops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the statement separator, if a custom one.
|
||||||
|
*/
|
||||||
|
public void setSeparator(String separator) {
|
||||||
|
this.separator = separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void populate(Connection connection) throws SQLException {
|
public void populate(Connection connection) throws SQLException {
|
||||||
for (Resource script : this.scripts) {
|
for (Resource script : this.scripts) {
|
||||||
|
|
@ -149,8 +149,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
* @param continueOnError whether or not to continue without throwing an exception in the event of an error
|
* @param continueOnError whether or not to continue without throwing an exception in the event of an error
|
||||||
* @param ignoreFailedDrops whether of not to continue in the event of specifically an error on a <code>DROP</code>
|
* @param ignoreFailedDrops whether of not to continue in the event of specifically an error on a <code>DROP</code>
|
||||||
*/
|
*/
|
||||||
private void executeSqlScript(Connection connection, EncodedResource resource, boolean continueOnError,
|
private void executeSqlScript(Connection connection, EncodedResource resource,
|
||||||
boolean ignoreFailedDrops) throws SQLException {
|
boolean continueOnError, boolean ignoreFailedDrops) throws SQLException {
|
||||||
|
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("Executing SQL script from " + resource);
|
logger.info("Executing SQL script from " + resource);
|
||||||
|
|
@ -160,10 +160,11 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
String script;
|
String script;
|
||||||
try {
|
try {
|
||||||
script = readScript(resource);
|
script = readScript(resource);
|
||||||
} catch (IOException ex) {
|
}
|
||||||
|
catch (IOException ex) {
|
||||||
throw new CannotReadScriptException(resource, ex);
|
throw new CannotReadScriptException(resource, ex);
|
||||||
}
|
}
|
||||||
String delimiter = separator;
|
String delimiter = this.separator;
|
||||||
if (delimiter == null) {
|
if (delimiter == null) {
|
||||||
delimiter = ";";
|
delimiter = ";";
|
||||||
if (!containsSqlScriptDelimiters(script, delimiter)) {
|
if (!containsSqlScriptDelimiters(script, delimiter)) {
|
||||||
|
|
@ -186,8 +187,8 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop");
|
boolean dropStatement = StringUtils.startsWithIgnoreCase(statement.trim(), "drop");
|
||||||
if (continueOnError || (dropStatement && ignoreFailedDrops)) {
|
if (continueOnError || (dropStatement && ignoreFailedDrops)) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Failed to execute SQL script statement at line " + lineNumber
|
logger.debug("Failed to execute SQL script statement at line " + lineNumber +
|
||||||
+ " of resource " + resource + ": " + statement, ex);
|
" of resource " + resource + ": " + statement, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -222,7 +223,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
StringBuilder scriptBuilder = new StringBuilder();
|
StringBuilder scriptBuilder = new StringBuilder();
|
||||||
while (currentStatement != null) {
|
while (currentStatement != null) {
|
||||||
if (StringUtils.hasText(currentStatement) &&
|
if (StringUtils.hasText(currentStatement) &&
|
||||||
this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix)) {
|
(this.commentPrefix != null && !currentStatement.startsWith(this.commentPrefix))) {
|
||||||
if (scriptBuilder.length() > 0) {
|
if (scriptBuilder.length() > 0) {
|
||||||
scriptBuilder.append('\n');
|
scriptBuilder.append('\n');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue