Support for global separator in JDBC namespace
Previously, if a database needs to be initialized with several scripts and many (or all) use a custom separator, said separator must be repeated for each script. This commit introduces a `separator` property at the parent element level that can be used to customize the default separator. This is available for both the `initialize-database` and `embedded-database` elements. Issue: SPR-13792
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
*/
|
||||
class DatabasePopulatorConfigUtils {
|
||||
@@ -70,8 +71,9 @@ class DatabasePopulatorConfigUtils {
|
||||
if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) {
|
||||
delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding")));
|
||||
}
|
||||
if (StringUtils.hasLength(scriptElement.getAttribute("separator"))) {
|
||||
delegate.addPropertyValue("separator", new TypedStringValue(scriptElement.getAttribute("separator")));
|
||||
String separator = getSeparator(element, scriptElement);
|
||||
if (separator != null) {
|
||||
delegate.addPropertyValue("separator", new TypedStringValue(separator));
|
||||
}
|
||||
delegates.add(delegate.getBeanDefinition());
|
||||
}
|
||||
@@ -80,4 +82,16 @@ class DatabasePopulatorConfigUtils {
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
private static String getSeparator(Element element, Element scriptElement) {
|
||||
String scriptSeparator = scriptElement.getAttribute("separator");
|
||||
if (StringUtils.hasLength(scriptSeparator)) {
|
||||
return scriptSeparator;
|
||||
}
|
||||
String elementSeparator = element.getAttribute("separator");
|
||||
if (StringUtils.hasLength(elementSeparator)) {
|
||||
return elementSeparator;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user