SPR-8592: add SpEL support in <jdbc:/>
This commit is contained in:
parent
0c0ab97a84
commit
296099f222
|
|
@ -16,19 +16,18 @@
|
|||
|
||||
package org.springframework.jdbc.config;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -63,16 +62,15 @@ class DatabasePopulatorConfigUtils {
|
|||
delegate.addPropertyValue("ignoreFailedDrops", ignoreFailedDrops);
|
||||
delegate.addPropertyValue("continueOnError", continueOnError);
|
||||
|
||||
List<String> locations = Arrays.asList(scriptElement.getAttribute("location"));
|
||||
// Use a factory bean for the resources so they can be given an order if a pattern is used
|
||||
BeanDefinitionBuilder resourcesFactory = BeanDefinitionBuilder.genericBeanDefinition(SortedResourcesFactoryBean.class);
|
||||
resourcesFactory.addConstructorArgValue(locations);
|
||||
resourcesFactory.addConstructorArgValue(new TypedStringValue(scriptElement.getAttribute("location")));
|
||||
delegate.addPropertyValue("scripts", resourcesFactory.getBeanDefinition());
|
||||
if (StringUtils.hasLength(scriptElement.getAttribute("encoding"))) {
|
||||
delegate.addPropertyValue("sqlScriptEncoding", scriptElement.getAttribute("encoding"));
|
||||
delegate.addPropertyValue("sqlScriptEncoding", new TypedStringValue(scriptElement.getAttribute("encoding")));
|
||||
}
|
||||
if (StringUtils.hasLength(scriptElement.getAttribute("separator"))) {
|
||||
delegate.addPropertyValue("separator", scriptElement.getAttribute("separator"));
|
||||
delegate.addPropertyValue("separator", new TypedStringValue(scriptElement.getAttribute("separator")));
|
||||
}
|
||||
delegates.add(delegate.getBeanDefinition());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,13 @@ public class InitializeDatabaseIntegrationTests {
|
|||
assertCorrectSetup(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScriptNameWithExpressions() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-expression-config.xml");
|
||||
DataSource dataSource = context.getBean("dataSource", DataSource.class);
|
||||
assertCorrectSetup(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheInitialization() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext("org/springframework/jdbc/config/jdbc-initialize-cache-config.xml");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="HSQL" />
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" enabled="#{properties['data.source.init']}">
|
||||
<jdbc:script location="#{properties['schema.scripts']}" />
|
||||
<jdbc:script location="#{properties['insert.scripts']}" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<util:properties id="properties">
|
||||
<prop key="schema.scripts">classpath:org/springframework/jdbc/config/db-schema.sql</prop>
|
||||
<prop key="insert.scripts">classpath*:org/springframework/jdbc/config/*-data.sql</prop>
|
||||
<prop key="data.source.init">true</prop>
|
||||
</util:properties>
|
||||
|
||||
</beans>
|
||||
Loading…
Reference in New Issue