Commit 196b9c9b authored by Phillip Webb's avatar Phillip Webb

Polish

parent be26cba0
...@@ -159,13 +159,8 @@ public class JpaProperties { ...@@ -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 { ...@@ -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
......
...@@ -84,7 +84,7 @@ public class RedisAutoConfiguration { ...@@ -84,7 +84,7 @@ public class RedisAutoConfiguration {
factory.setPassword(this.properties.getPassword()); factory.setPassword(this.properties.getPassword());
} }
factory.setDatabase(this.properties.getDatabase()); factory.setDatabase(this.properties.getDatabase());
if(this.properties.getTimeout() > 0) { if (this.properties.getTimeout() > 0) {
factory.setTimeout(this.properties.getTimeout()); factory.setTimeout(this.properties.getTimeout());
} }
return factory; return factory;
......
/* /*
* 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 @@ ...@@ -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 { ...@@ -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 { ...@@ -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
......
...@@ -89,8 +89,7 @@ public class RedisAutoConfigurationTests { ...@@ -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 { ...@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment