This commit is contained in:
Phillip Webb 2015-06-08 14:07:23 -07:00
parent be26cba01e
commit 196b9c9b2a
4 changed files with 20 additions and 17 deletions

View File

@ -159,13 +159,8 @@ public class JpaProperties {
DataSource dataSource) { DataSource dataSource) {
Map<String, String> result = new HashMap<String, String>(existing); Map<String, String> result = new HashMap<String, String>(existing);
if (!isAlreadyProvided(existing, "ejb.naming_strategy_delegator")) { if (!isAlreadyProvided(existing, "ejb.naming_strategy_delegator")) {
if (!isAlreadyProvided(existing, "ejb.naming_strategy") result.put("hibernate.ejb.naming_strategy",
&& this.namingStrategy != null) { getHibernateNamingStrategy(existing));
result.put("hibernate.ejb.naming_strategy", this.namingStrategy.getName());
}
else if (this.namingStrategy == null) {
result.put("hibernate.ejb.naming_strategy", DEFAULT_NAMING_STRATEGY);
}
} }
String ddlAuto = getOrDeduceDdlAuto(existing, dataSource); String ddlAuto = getOrDeduceDdlAuto(existing, dataSource);
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) { if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
@ -177,6 +172,14 @@ public class JpaProperties {
return result; return result;
} }
private String getHibernateNamingStrategy(Map<String, String> existing) {
if (!isAlreadyProvided(existing, "ejb.naming_strategy")
&& this.namingStrategy != null) {
return this.namingStrategy.getName();
}
return DEFAULT_NAMING_STRATEGY;
}
private String getOrDeduceDdlAuto(Map<String, String> existing, private String getOrDeduceDdlAuto(Map<String, String> existing,
DataSource dataSource) { DataSource dataSource) {
String ddlAuto = (this.ddlAuto != null ? this.ddlAuto String ddlAuto = (this.ddlAuto != null ? this.ddlAuto

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2014 the original author or authors. * Copyright 2012-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.orm.jpa; package org.springframework.boot.autoconfigure.orm.jpa;
import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.junit.After; import org.junit.After;
@ -87,8 +89,8 @@ public class CustomHibernateJpaAutoConfigurationTests {
@Test @Test
public void testNamingStrategyDelegatorTakesPrecedence() { public void testNamingStrategyDelegatorTakesPrecedence() {
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
"spring.jpa.properties.hibernate.ejb.naming_strategy_delegator:" + "spring.jpa.properties.hibernate.ejb.naming_strategy_delegator:"
"org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator"); + "org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator");
this.context.register(TestConfiguration.class, this.context.register(TestConfiguration.class,
EmbeddedDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
@ -96,8 +98,8 @@ public class CustomHibernateJpaAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
JpaProperties bean = this.context.getBean(JpaProperties.class); JpaProperties bean = this.context.getBean(JpaProperties.class);
DataSource dataSource = this.context.getBean(DataSource.class); DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(bean.getHibernateProperties(dataSource).get( Map<String, String> hibernateProperties = bean.getHibernateProperties(dataSource);
"hibernate.ejb.naming_strategy"), nullValue()); assertThat(hibernateProperties.get("hibernate.ejb.naming_strategy"), nullValue());
} }
@Configuration @Configuration

View File

@ -89,8 +89,7 @@ public class RedisAutoConfigurationTests {
load("spring.redis.host:foo", "spring.redis.timeout:100"); load("spring.redis.host:foo", "spring.redis.timeout:100");
assertEquals("foo", this.context.getBean(JedisConnectionFactory.class) assertEquals("foo", this.context.getBean(JedisConnectionFactory.class)
.getHostName()); .getHostName());
assertEquals(100, this.context.getBean(JedisConnectionFactory.class) assertEquals(100, this.context.getBean(JedisConnectionFactory.class).getTimeout());
.getTimeout());
} }
@Test @Test
@ -145,8 +144,7 @@ public class RedisAutoConfigurationTests {
this.context = doLoad(environment); this.context = doLoad(environment);
} }
private AnnotationConfigApplicationContext doLoad( private AnnotationConfigApplicationContext doLoad(String... environment) {
String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment); EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.register(RedisAutoConfiguration.class, applicationContext.register(RedisAutoConfiguration.class,