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

View File

@ -84,7 +84,7 @@ public class RedisAutoConfiguration {
factory.setPassword(this.properties.getPassword());
}
factory.setDatabase(this.properties.getDatabase());
if(this.properties.getTimeout() > 0) {
if (this.properties.getTimeout() > 0) {
factory.setTimeout(this.properties.getTimeout());
}
return factory;

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

View File

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