Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
ec845c93
Commit
ec845c93
authored
Jun 14, 2018
by
Johnny Lim
Committed by
Stephane Nicoll
Jun 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish HibernateProperties and its test
Closes gh-13484
parent
60b109cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
24 deletions
+21
-24
HibernateProperties.java
...ework/boot/autoconfigure/orm/jpa/HibernateProperties.java
+14
-17
HibernatePropertiesTests.java
.../boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java
+7
-7
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateProperties.java
View file @
ec845c93
...
@@ -21,7 +21,11 @@ import java.util.HashMap;
...
@@ -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;
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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
,
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernatePropertiesTests.java
View file @
ec845c93
...
@@ -63,10 +63,10 @@ public class HibernatePropertiesTests {
...
@@ -63,10 +63,10 @@ public class HibernatePropertiesTests {
assertThat
(
hibernateProperties
)
assertThat
(
hibernateProperties
)
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
assertThat
(
hibernateProperties
).
containsEntry
(
assertThat
(
hibernateProperties
).
containsEntry
(
"hibernate.physical_naming_strategy"
,
AvailableSettings
.
PHYSICAL_NAMING_STRATEGY
,
SpringPhysicalNamingStrategy
.
class
.
getName
());
SpringPhysicalNamingStrategy
.
class
.
getName
());
assertThat
(
hibernateProperties
).
containsEntry
(
assertThat
(
hibernateProperties
).
containsEntry
(
"hibernate.implicit_naming_strategy"
,
AvailableSettings
.
IMPLICIT_NAMING_STRATEGY
,
SpringImplicitNamingStrategy
.
class
.
getName
());
SpringImplicitNamingStrategy
.
class
.
getName
());
}));
}));
}
}
...
@@ -78,9 +78,9 @@ public class HibernatePropertiesTests {
...
@@ -78,9 +78,9 @@ public class HibernatePropertiesTests {
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical"
)
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical"
)
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
assertThat
(
hibernateProperties
).
contains
(
assertThat
(
hibernateProperties
).
contains
(
entry
(
"hibernate.implicit_naming_strategy"
,
entry
(
AvailableSettings
.
IMPLICIT_NAMING_STRATEGY
,
"com.example.Implicit"
),
"com.example.Implicit"
),
entry
(
"hibernate.physical_naming_strategy"
,
entry
(
AvailableSettings
.
PHYSICAL_NAMING_STRATEGY
,
"com.example.Physical"
));
"com.example.Physical"
));
assertThat
(
hibernateProperties
)
assertThat
(
hibernateProperties
)
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
...
@@ -95,9 +95,9 @@ public class HibernatePropertiesTests {
...
@@ -95,9 +95,9 @@ public class HibernatePropertiesTests {
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
.
run
(
assertHibernateProperties
((
hibernateProperties
)
->
{
// You can override them as we don't provide any default
// You can override them as we don't provide any default
assertThat
(
hibernateProperties
).
contains
(
assertThat
(
hibernateProperties
).
contains
(
entry
(
"hibernate.implicit_naming_strategy"
,
entry
(
AvailableSettings
.
IMPLICIT_NAMING_STRATEGY
,
"com.example.Implicit"
),
"com.example.Implicit"
),
entry
(
"hibernate.physical_naming_strategy"
,
entry
(
AvailableSettings
.
PHYSICAL_NAMING_STRATEGY
,
"com.example.Physical"
));
"com.example.Physical"
));
assertThat
(
hibernateProperties
)
assertThat
(
hibernateProperties
)
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
.
doesNotContainKeys
(
"hibernate.ejb.naming_strategy"
);
...
@@ -139,7 +139,7 @@ public class HibernatePropertiesTests {
...
@@ -139,7 +139,7 @@ public class HibernatePropertiesTests {
private
ContextConsumer
<
AssertableApplicationContext
>
assertDefaultDdlAutoNotInvoked
(
private
ContextConsumer
<
AssertableApplicationContext
>
assertDefaultDdlAutoNotInvoked
(
String
expectedDdlAuto
)
{
String
expectedDdlAuto
)
{
return
assertHibernateProperties
((
hibernateProperties
)
->
{
return
assertHibernateProperties
((
hibernateProperties
)
->
{
assertThat
(
hibernateProperties
).
containsEntry
(
"hibernate.hbm2ddl.auto"
,
assertThat
(
hibernateProperties
).
containsEntry
(
AvailableSettings
.
HBM2DDL_AUTO
,
expectedDdlAuto
);
expectedDdlAuto
);
verify
(
this
.
ddlAutoSupplier
,
never
()).
get
();
verify
(
this
.
ddlAutoSupplier
,
never
()).
get
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment