|
|
@ -21,7 +21,11 @@ import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.hibernate.cfg.AvailableSettings;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
|
|
|
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
|
|
|
|
|
|
|
|
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
@ -36,9 +40,6 @@ import org.springframework.util.StringUtils;
|
|
|
|
@ConfigurationProperties("spring.jpa.hibernate")
|
|
|
|
@ConfigurationProperties("spring.jpa.hibernate")
|
|
|
|
public class HibernateProperties {
|
|
|
|
public class HibernateProperties {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String USE_NEW_ID_GENERATOR_MAPPINGS = "hibernate.id."
|
|
|
|
|
|
|
|
+ "new_generator_mappings";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Naming naming = new Naming();
|
|
|
|
private final Naming naming = new Naming();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -97,10 +98,10 @@ public class HibernateProperties {
|
|
|
|
getNaming().applyNamingStrategies(result);
|
|
|
|
getNaming().applyNamingStrategies(result);
|
|
|
|
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
|
|
|
|
String ddlAuto = determineDdlAuto(existing, settings::getDdlAuto);
|
|
|
|
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
|
|
|
|
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
|
|
|
|
result.put("hibernate.hbm2ddl.auto", ddlAuto);
|
|
|
|
result.put(AvailableSettings.HBM2DDL_AUTO, ddlAuto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
result.remove("hibernate.hbm2ddl.auto");
|
|
|
|
result.remove(AvailableSettings.HBM2DDL_AUTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Collection<HibernatePropertiesCustomizer> customizers = settings
|
|
|
|
Collection<HibernatePropertiesCustomizer> customizers = settings
|
|
|
|
.getHibernatePropertiesCustomizers();
|
|
|
|
.getHibernatePropertiesCustomizers();
|
|
|
@ -112,17 +113,17 @@ public class HibernateProperties {
|
|
|
|
|
|
|
|
|
|
|
|
private void applyNewIdGeneratorMappings(Map<String, Object> result) {
|
|
|
|
private void applyNewIdGeneratorMappings(Map<String, Object> result) {
|
|
|
|
if (this.useNewIdGeneratorMappings != null) {
|
|
|
|
if (this.useNewIdGeneratorMappings != null) {
|
|
|
|
result.put(USE_NEW_ID_GENERATOR_MAPPINGS,
|
|
|
|
result.put(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
|
|
|
|
this.useNewIdGeneratorMappings.toString());
|
|
|
|
this.useNewIdGeneratorMappings.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!result.containsKey(USE_NEW_ID_GENERATOR_MAPPINGS)) {
|
|
|
|
else if (!result.containsKey(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS)) {
|
|
|
|
result.put(USE_NEW_ID_GENERATOR_MAPPINGS, "true");
|
|
|
|
result.put(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String determineDdlAuto(Map<String, String> existing,
|
|
|
|
private String determineDdlAuto(Map<String, String> existing,
|
|
|
|
Supplier<String> defaultDdlAuto) {
|
|
|
|
Supplier<String> defaultDdlAuto) {
|
|
|
|
String ddlAuto = existing.get("hibernate.hbm2ddl.auto");
|
|
|
|
String ddlAuto = existing.get(AvailableSettings.HBM2DDL_AUTO);
|
|
|
|
if (ddlAuto != null) {
|
|
|
|
if (ddlAuto != null) {
|
|
|
|
return ddlAuto;
|
|
|
|
return ddlAuto;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -131,10 +132,6 @@ public class HibernateProperties {
|
|
|
|
|
|
|
|
|
|
|
|
public static class Naming {
|
|
|
|
public static class Naming {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_PHYSICAL_STRATEGY = "org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String DEFAULT_IMPLICIT_STRATEGY = "org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Fully qualified name of the implicit naming strategy.
|
|
|
|
* Fully qualified name of the implicit naming strategy.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -162,10 +159,10 @@ public class HibernateProperties {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void applyNamingStrategies(Map<String, Object> properties) {
|
|
|
|
private void applyNamingStrategies(Map<String, Object> properties) {
|
|
|
|
applyNamingStrategy(properties, "hibernate.implicit_naming_strategy",
|
|
|
|
applyNamingStrategy(properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY,
|
|
|
|
this.implicitStrategy, DEFAULT_IMPLICIT_STRATEGY);
|
|
|
|
this.implicitStrategy, SpringImplicitNamingStrategy.class.getName());
|
|
|
|
applyNamingStrategy(properties, "hibernate.physical_naming_strategy",
|
|
|
|
applyNamingStrategy(properties, AvailableSettings.PHYSICAL_NAMING_STRATEGY,
|
|
|
|
this.physicalStrategy, DEFAULT_PHYSICAL_STRATEGY);
|
|
|
|
this.physicalStrategy, SpringPhysicalNamingStrategy.class.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void applyNamingStrategy(Map<String, Object> properties, String key,
|
|
|
|
private void applyNamingStrategy(Map<String, Object> properties, String key,
|
|
|
|