-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19976 Don't adopt AdjustableBasicType name to create derived type #11426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
beikov
wants to merge
1
commit into
hibernate:6.6
Choose a base branch
from
beikov:HHH-19976-6.6
base: 6.6
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−85
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,13 @@ | |
| package org.hibernate.type; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.function.Supplier; | ||
|
|
||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.hibernate.HibernateException; | ||
| import org.hibernate.Internal; | ||
| import org.hibernate.MappingException; | ||
|
|
@@ -47,6 +50,7 @@ public class BasicTypeRegistry implements Serializable { | |
|
|
||
| private final Map<String, BasicType<?>> typesByName = new ConcurrentHashMap<>(); | ||
| private final Map<String, BasicTypeReference<?>> typeReferencesByName = new ConcurrentHashMap<>(); | ||
| private final Map<String, List<BasicTypeReference<?>>> typeReferencesByJavaTypeName = new ConcurrentHashMap<>(); | ||
|
|
||
| public BasicTypeRegistry(TypeConfiguration typeConfiguration){ | ||
| this.typeConfiguration = typeConfiguration; | ||
|
|
@@ -205,14 +209,28 @@ private <J> BasicType<J> createIfUnregistered( | |
| if ( registeredTypeMatches( javaType, jdbcType, registeredType ) ) { | ||
| return registeredType; | ||
| } | ||
| else { | ||
| final BasicType<J> createdType = creator.get(); | ||
| register( javaType, jdbcType, createdType ); | ||
| return createdType; | ||
| // Create an ad-hoc type since the java type doesn't come from the registry and is probably explicitly defined | ||
| else if ( typeConfiguration.getJavaTypeRegistry().resolveDescriptor( javaType.getJavaType() ) == javaType ) { | ||
| final var basicTypeReferences = typeReferencesByJavaTypeName.get( javaType.getTypeName() ); | ||
| if ( basicTypeReferences != null && !basicTypeReferences.isEmpty() ) { | ||
| final var jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry(); | ||
| for ( var typeReference : basicTypeReferences ) { | ||
| if ( jdbcTypeRegistry.getDescriptor( typeReference.getSqlTypeCode() ) == jdbcType ) { | ||
| final var basicType = typesByName.get( typeReference.getName() ); | ||
| //noinspection unchecked | ||
| return registeredTypeMatches( javaType, jdbcType, basicType ) | ||
| ? (BasicType<J>) basicType | ||
| : (BasicType<J>) createBasicType( typeReference.getName(), typeReference ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| final BasicType<J> createdType = creator.get(); | ||
| register( javaType, jdbcType, createdType ); | ||
| return createdType; | ||
| } | ||
|
|
||
| private static <J> boolean registeredTypeMatches(JavaType<J> javaType, JdbcType jdbcType, BasicType<J> registeredType) { | ||
| private static boolean registeredTypeMatches(JavaType<?> javaType, JdbcType jdbcType, @Nullable BasicType<?> registeredType) { | ||
| return registeredType != null | ||
| && registeredType.getJdbcType() == jdbcType | ||
| && registeredType.getMappedJavaType() == javaType; | ||
|
|
@@ -296,7 +314,7 @@ public void addTypeReferenceRegistrationKey(String typeReferenceKey, String... a | |
| throw new IllegalArgumentException( "Couldn't find type reference with name: " + typeReferenceKey ); | ||
| } | ||
| for ( String additionalTypeReferenceKey : additionalTypeReferenceKeys ) { | ||
| typeReferencesByName.put( additionalTypeReferenceKey, basicTypeReference ); | ||
| addTypeReference( additionalTypeReferenceKey, basicTypeReference ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -348,7 +366,7 @@ public void addPrimeEntry(BasicTypeReference<?> type, String legacyTypeClassName | |
|
|
||
| // Legacy name registration | ||
| if ( StringHelper.isNotEmpty( legacyTypeClassName ) ) { | ||
| typeReferencesByName.put( legacyTypeClassName, type ); | ||
| addTypeReference( legacyTypeClassName, type ); | ||
| } | ||
|
|
||
| // explicit registration keys | ||
|
|
@@ -417,16 +435,29 @@ private void applyRegistrationKeys(BasicTypeReference<?> type, String[] keys) { | |
| //Incidentally this might help with map lookup efficiency too. | ||
| key = key.intern(); | ||
|
|
||
| LOG.debugf( "Adding type registration %s -> %s", key, type ); | ||
| addTypeReference( key, type ); | ||
| } | ||
| } | ||
|
|
||
| final BasicTypeReference<?> old = typeReferencesByName.put( key, type ); | ||
| if ( old != null && old != type ) { | ||
| LOG.debugf( | ||
| "Type registration key [%s] overrode previous entry : `%s`", | ||
| key, | ||
| old | ||
| ); | ||
| } | ||
| private void addTypeReference(String name, BasicTypeReference<?> typeReference) { | ||
| // Incredibly verbose logging disabled | ||
| LOG.tracef( "Adding type registration %s -> %s", name, typeReference ); | ||
|
Comment on lines
+443
to
+444
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't turn this logging back on, it's so obnoxious it makes logging completely useless. |
||
|
|
||
| final BasicTypeReference<?> old = typeReferencesByName.put( name, typeReference ); | ||
| if ( old != null && old != typeReference ) { | ||
| LOG.tracef( | ||
| "Type registration key [%s] overrode previous entry : `%s`", | ||
| name, | ||
| old | ||
| ); | ||
| } | ||
|
|
||
| final var basicTypeReferences = typeReferencesByJavaTypeName.computeIfAbsent( | ||
| typeReference.getBindableJavaType().getTypeName(), | ||
| s -> new ArrayList<>() | ||
| ); | ||
| if ( !basicTypeReferences.contains( typeReference ) ) { | ||
| basicTypeReferences.add( typeReference ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just lost a week of my life getting rid of all the dangerous unchecked typecasts in this and related classes, and in the process found bugs.
If you're going to do an unchecked cast, please check it first. Otherwise you've opened the door for the bugs to come seeping back in.