Skip to content

Commit 140fbb4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into wip/6.0
2 parents 59f902f + 99a4edf commit 140fbb4

File tree

121 files changed

+798
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+798
-269
lines changed

documentation/src/test/java/org/hibernate/userguide/naming/AcmeCorpPhysicalNamingStrategy.java

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
*/
77
package org.hibernate.userguide.naming;
88

9-
import java.util.LinkedList;
9+
import java.util.Arrays;
1010
import java.util.List;
1111
import java.util.Locale;
1212
import java.util.Map;
1313
import java.util.TreeMap;
14+
import java.util.stream.Collectors;
1415

1516
import org.hibernate.boot.model.naming.Identifier;
16-
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
17+
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
1718
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
1819

1920
import org.apache.commons.lang3.StringUtils;
@@ -27,40 +28,35 @@
2728
* Additionally standards call for the replacement of certain words with abbreviations.
2829
*
2930
* @author Steve Ebersole
31+
* @author Nathan Xu
3032
*/
31-
public class AcmeCorpPhysicalNamingStrategy implements PhysicalNamingStrategy {
32-
private static final Map<String,String> ABBREVIATIONS = buildAbbreviationMap();
33+
public class AcmeCorpPhysicalNamingStrategy extends PhysicalNamingStrategyStandardImpl {
34+
private static final Map<String, String> ABBREVIATIONS;
3335

34-
@Override
35-
public Identifier toPhysicalCatalogName(Identifier name, JdbcEnvironment jdbcEnvironment) {
36-
// Acme naming standards do not apply to catalog names
37-
return name;
38-
}
39-
40-
@Override
41-
public Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment jdbcEnvironment) {
42-
// Acme naming standards do not apply to schema names
43-
return name;
36+
static {
37+
ABBREVIATIONS = new TreeMap<>( String.CASE_INSENSITIVE_ORDER );
38+
ABBREVIATIONS.put( "account", "acct" );
39+
ABBREVIATIONS.put( "number", "num" );
4440
}
4541

4642
@Override
4743
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {
4844
final List<String> parts = splitAndReplace( name.getText() );
4945
return jdbcEnvironment.getIdentifierHelper().toIdentifier(
50-
join( parts ),
46+
StringUtils.join( parts, '_' ),
5147
name.isQuoted()
5248
);
5349
}
5450

5551
@Override
5652
public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {
57-
final LinkedList<String> parts = splitAndReplace( name.getText() );
53+
final List<String> parts = splitAndReplace( name.getText() );
5854
// Acme Corp says all sequences should end with _seq
59-
if ( !"seq".equalsIgnoreCase( parts.getLast() ) ) {
55+
if ( !"seq".equals( parts.get( parts.size() - 1 ) ) ) {
6056
parts.add( "seq" );
6157
}
6258
return jdbcEnvironment.getIdentifierHelper().toIdentifier(
63-
join( parts ),
59+
StringUtils.join( parts, '_' ),
6460
name.isQuoted()
6561
);
6662
}
@@ -69,50 +65,15 @@ public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEn
6965
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
7066
final List<String> parts = splitAndReplace( name.getText() );
7167
return jdbcEnvironment.getIdentifierHelper().toIdentifier(
72-
join( parts ),
68+
StringUtils.join( parts, '_' ),
7369
name.isQuoted()
7470
);
7571
}
7672

77-
private static Map<String, String> buildAbbreviationMap() {
78-
TreeMap<String,String> abbreviationMap = new TreeMap<> ( String.CASE_INSENSITIVE_ORDER );
79-
abbreviationMap.put( "account", "acct" );
80-
abbreviationMap.put( "number", "num" );
81-
return abbreviationMap;
82-
}
83-
84-
private LinkedList<String> splitAndReplace(String name) {
85-
LinkedList<String> result = new LinkedList<>();
86-
for ( String part : StringUtils.splitByCharacterTypeCamelCase( name ) ) {
87-
if ( part == null || part.trim().isEmpty() ) {
88-
// skip null and space
89-
continue;
90-
}
91-
part = applyAbbreviationReplacement( part );
92-
result.add( part.toLowerCase( Locale.ROOT ) );
93-
}
94-
return result;
95-
}
96-
97-
private String applyAbbreviationReplacement(String word) {
98-
if ( ABBREVIATIONS.containsKey( word ) ) {
99-
return ABBREVIATIONS.get( word );
100-
}
101-
102-
return word;
103-
}
104-
105-
private String join(List<String> parts) {
106-
boolean firstPass = true;
107-
String separator = "";
108-
StringBuilder joined = new StringBuilder();
109-
for ( String part : parts ) {
110-
joined.append( separator ).append( part );
111-
if ( firstPass ) {
112-
firstPass = false;
113-
separator = "_";
114-
}
115-
}
116-
return joined.toString();
73+
private List<String> splitAndReplace(String name) {
74+
return Arrays.stream( StringUtils.splitByCharacterTypeCamelCase( name ) )
75+
.filter( StringUtils::isNotBlank )
76+
.map( p -> ABBREVIATIONS.getOrDefault( p, p ).toLowerCase( Locale.ROOT ) )
77+
.collect( Collectors.toList() );
11778
}
11879
}

gradle/libraries.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ext {
1414
junit5Version = '5.3.1'
1515

1616
h2Version = '1.4.199'
17-
bytemanVersion = '4.0.13' //Compatible with JDK14
17+
bytemanVersion = '4.0.13' //Compatible with JDK16
1818
jnpVersion = '5.0.6.CR1'
1919

2020
hibernateCommonsVersion = '5.1.0.Final'

hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void execute() throws HibernateException {
224224
session
225225
);
226226
if ( persister.hasUpdateGeneratedProperties() ) {
227-
// this entity defines proeprty generation, so process those generated
227+
// this entity defines property generation, so process those generated
228228
// values...
229229
persister.processUpdateGeneratedProperties( id, instance, state, session );
230230
if ( persister.isVersionPropertyGenerated() ) {

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public MetadataBuilderImpl(MetadataSources sources, StandardServiceRegistry serv
116116
this.sources = sources;
117117
this.options = new MetadataBuildingOptionsImpl( serviceRegistry );
118118
this.bootstrapContext = new BootstrapContextImpl( serviceRegistry, options );
119-
//this is needed only fro implementig deprecated method
119+
//this is needed only for implementing deprecated method
120120
options.setBootstrapContext( bootstrapContext );
121121

122122
for ( MetadataSourcesContributor contributor :

hibernate-core/src/main/java/org/hibernate/boot/model/convert/internal/AutoApplicableConverterDescriptorStandardImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
2121
import org.hibernate.boot.spi.MetadataBuildingContext;
2222
import org.hibernate.cfg.annotations.HCANNHelper;
23+
import org.hibernate.internal.util.type.PrimitiveWrapperHelper;
2324

2425
import com.fasterxml.classmate.ResolvedType;
2526
import com.fasterxml.classmate.ResolvedTypeWithMembers;
@@ -147,7 +148,11 @@ private static Member toMember(XProperty xProperty) {
147148
}
148149

149150
private boolean typesMatch(ResolvedType converterDefinedType, ResolvedType checkType) {
150-
if ( !converterDefinedType.getErasedType().isAssignableFrom( checkType.getErasedType() ) ) {
151+
Class<?> erasedCheckType = checkType.getErasedType();
152+
if ( erasedCheckType.isPrimitive() ) {
153+
erasedCheckType = PrimitiveWrapperHelper.getDescriptorByPrimitiveType( erasedCheckType ).getWrapperClass();
154+
}
155+
if ( !converterDefinedType.getErasedType().isAssignableFrom( erasedCheckType ) ) {
151156
return false;
152157
}
153158

@@ -180,4 +185,5 @@ private boolean typesMatch(ResolvedType converterDefinedType, ResolvedType check
180185

181186
return true;
182187
}
188+
183189
}

hibernate-core/src/main/java/org/hibernate/boot/registry/BootstrapServiceRegistryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public BootstrapServiceRegistry build() {
208208
final ClassLoaderService classLoaderService;
209209
if ( providedClassLoaderService == null ) {
210210
// Use a set. As an example, in JPA, OsgiClassLoader may be in both
211-
// the providedClassLoaders and the overridenClassLoader.
211+
// the providedClassLoaders and the overriddenClassLoader.
212212
final Set<ClassLoader> classLoaders = new HashSet<>();
213213

214214
if ( providedClassLoaders != null ) {

hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ else if ( !session.isConnected() ) {
129129
finally {
130130
if ( isTempSession ) {
131131
try {
132-
// Commit the JDBC transaction is we started one.
132+
// Commit the JDBC transaction if we started one.
133133
if ( !isJta ) {
134134
BytecodeLogger.LOGGER.debug( "Enhancement interception Helper#performWork committing transaction on temporary Session" );
135135
session.getTransaction().commit();

hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/DomainDataRegionConfigImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Builder addEntityConfig(PersistentClass bootEntityDescriptor, AccessType
117117
}
118118

119119

120-
// todo (6.0) : `EntityPersister` and `CollectionPersister` references here should be replaces with `EntityHierarchy` and `PersistentCollectionDescriptor`
120+
// todo (6.0) : `EntityPersister` and `CollectionPersister` references here should be replaced with `EntityHierarchy` and `PersistentCollectionDescriptor`
121121
//
122122
// todo : although ^^, couldn't this just be the boot-time model? Is there a specific need for it to be the run-time model?
123123
// that would alleviate the difference between 5.3 and 6.0 from the SPI POV

hibernate-core/src/main/java/org/hibernate/cache/internal/NaturalIdCacheKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private void initTransients() {
8686
@Override
8787
public String initialize() {
8888
//Complex toString is needed as naturalIds for entities are not simply based on a single value like primary keys
89-
//the only same way to differentiate the keys is to included the disassembled values in the string.
89+
//the only same way to differentiate the keys is to include the disassembled values in the string.
9090
final StringBuilder toStringBuilder = new StringBuilder().append( entityName ).append(
9191
"##NaturalId[" );
9292
for ( int i = 0; i < naturalIdValues.length; i++ ) {

hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ protected RegionFactory resolveRegionFactory(Map configurationValues, ServiceReg
8383
final Collection<Class<? extends RegionFactory>> implementors = selector.getRegisteredStrategyImplementors( RegionFactory.class );
8484

8585
if ( setting == null && implementors.size() != 1 ) {
86-
// if either are explicitly defined as TRUE we need a RegionFactory
87-
if ( useSecondLevelCache == TRUE || useQueryCache == TRUE ) {
86+
// if either is explicitly defined as TRUE we need a RegionFactory
87+
if ( ( useSecondLevelCache != null && useSecondLevelCache == TRUE )
88+
|| ( useQueryCache != null && useQueryCache == TRUE ) ) {
8889
throw new CacheException( "Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory" );
8990
}
9091
}

0 commit comments

Comments
 (0)