@@ -146,9 +146,9 @@ public <J> BasicType<J> resolve(java.lang.reflect.Type javaType, int sqlTypeCode
146146 return resolve ( typeConfiguration .getJavaTypeRegistry ().getDescriptor ( javaType ), sqlTypeCode );
147147 }
148148
149- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , int sqlTypeCode ) {
149+ public <J > BasicType <J > resolve (JavaType <J > javaType , int sqlTypeCode ) {
150150 return resolve (
151- jtdToUse ,
151+ javaType ,
152152 typeConfiguration .getJdbcTypeRegistry ().getDescriptor ( sqlTypeCode )
153153 );
154154 }
@@ -157,63 +157,54 @@ public <J> BasicType<J> resolve(JavaType<J> jtdToUse, int sqlTypeCode) {
157157 * Find an existing {@link BasicType} registration for the given {@link JavaType}
158158 * descriptor and {@link JdbcType} descriptor combo or create (and register) one.
159159 */
160- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , JdbcType stdToUse ) {
160+ public <J > BasicType <J > resolve (JavaType <J > javaType , JdbcType jdbcType ) {
161161 return resolve (
162- jtdToUse ,
163- stdToUse ,
164- () -> {
165- final BasicTypeImpl <J > basicType = new BasicTypeImpl <>( jtdToUse , stdToUse );
166-
167- // if we are still building mappings, register this ad-hoc type
168- // via a unique code. this is to support envers
169- try {
170- typeConfiguration .getMetadataBuildingContext ().getBootstrapContext ()
171- .registerAdHocBasicType ( basicType );
172- }
173- catch (Exception ignore ) {
174- }
175-
176- return basicType ;
177- }
162+ javaType ,
163+ jdbcType ,
164+ () -> new BasicTypeImpl <>( javaType , jdbcType )
178165 );
179166 }
180167
181- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , JdbcType stdToUse , String baseTypeName ) {
168+ public <J > BasicType <J > resolve (JavaType <J > javaType , JdbcType jdbcType , String baseTypeName ) {
182169 return resolve (
183- jtdToUse ,
184- stdToUse ,
185- () -> new NamedBasicTypeImpl <>( jtdToUse , stdToUse , baseTypeName )
170+ javaType ,
171+ jdbcType ,
172+ () -> new NamedBasicTypeImpl <>( javaType , jdbcType , baseTypeName )
186173 );
187174 }
188175
189176 /**
190177 * Find an existing BasicType registration for the given JavaType and
191178 * JdbcType combo or create (and register) one.
192179 */
193- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , JdbcType stdToUse , Supplier <BasicType <J >> creator ) {
194- final Map <JavaType <?>, BasicType <?>> typeByJtdForStd = registryValues .computeIfAbsent (
195- stdToUse ,
196- sqlTypeDescriptor -> new ConcurrentHashMap <>()
180+ public <J > BasicType <J > resolve (JavaType <J > javaType , JdbcType jdbcType , Supplier <BasicType <J >> creator ) {
181+ final Map <JavaType <?>, BasicType <?>> typeByJavaTypeForJdbcType = registryValues .computeIfAbsent (
182+ jdbcType ,
183+ key -> new ConcurrentHashMap <>()
197184 );
198185
199- final BasicType <?> foundBasicType = typeByJtdForStd .get ( jtdToUse );
186+ final BasicType <?> foundBasicType = typeByJavaTypeForJdbcType .get ( javaType );
200187 if ( foundBasicType != null ) {
201188 //noinspection unchecked
202189 return (BasicType <J >) foundBasicType ;
203190 }
204191 // Before simply creating the type, we try to find if there is a registered type for this java type,
205192 // and if so, if the jdbc type descriptor matches. Unless it does, we at least reuse the name
206- final BasicType <J > basicType = getRegisteredType ( jtdToUse .getJavaType () );
207- if ( basicType != null ) {
208- if ( basicType .getJdbcType () == stdToUse ) {
209- return basicType ;
210- }
211- else {
212- return new NamedBasicTypeImpl <>( jtdToUse , stdToUse , basicType .getName () );
213- }
193+ final BasicType <J > registeredType = getRegisteredType ( javaType .getJavaType () );
194+ if ( registeredType != null && registeredType .getJdbcType () == jdbcType && registeredType .getMappedJavaType () == javaType ) {
195+ return registeredType ;
214196 }
215197 final BasicType <J > createdBasicType = creator .get ();
216- typeByJtdForStd .put ( jtdToUse , createdBasicType );
198+ typeByJavaTypeForJdbcType .put ( javaType , createdBasicType );
199+
200+ // if we are still building mappings, register this ad-hoc type
201+ // via a unique code. this is to support envers
202+ try {
203+ typeConfiguration .getMetadataBuildingContext ().getBootstrapContext ()
204+ .registerAdHocBasicType ( createdBasicType );
205+ }
206+ catch (Exception ignore ) {
207+ }
217208 return createdBasicType ;
218209 }
219210
@@ -250,12 +241,12 @@ public void register(BasicType<?> type, String... keys) {
250241 }
251242
252243 private void applyOrOverwriteEntry (BasicType <?> type ) {
253- final Map <JavaType <?>, BasicType <?>> mappingsForStdToUse = registryValues .computeIfAbsent (
244+ final Map <JavaType <?>, BasicType <?>> typeByJavaTypeForJdbcType = registryValues .computeIfAbsent (
254245 type .getJdbcType (),
255- sqlTypeDescriptor -> new ConcurrentHashMap <>()
246+ jdbcType -> new ConcurrentHashMap <>()
256247 );
257248
258- final BasicType <?> existing = mappingsForStdToUse .put ( type .getMappedJavaType (), type );
249+ final BasicType <?> existing = typeByJavaTypeForJdbcType .put ( type .getMappedJavaType (), type );
259250 if ( existing != null ) {
260251 LOG .debugf (
261252 "BasicTypeRegistry registration overwritten (%s + %s); previous =`%s`" ,
@@ -350,12 +341,12 @@ public void addPrimeEntry(BasicTypeReference<?> type, String legacyTypeClassName
350341 }
351342
352343 private void primeRegistryEntry (BasicType <?> type ) {
353- final Map <JavaType <?>, BasicType <?>> mappingsForStdToUse = registryValues .computeIfAbsent (
344+ final Map <JavaType <?>, BasicType <?>> typeByJavaTypeForJdbcType = registryValues .computeIfAbsent (
354345 type .getJdbcType (),
355- sqlTypeDescriptor -> new ConcurrentHashMap <>()
346+ jdbcType -> new ConcurrentHashMap <>()
356347 );
357348
358- final BasicType <?> existing = mappingsForStdToUse .get ( type .getMappedJavaType () );
349+ final BasicType <?> existing = typeByJavaTypeForJdbcType .get ( type .getMappedJavaType () );
359350
360351 if ( existing != null ) {
361352 LOG .debugf (
@@ -366,7 +357,7 @@ private void primeRegistryEntry(BasicType<?> type) {
366357 );
367358 }
368359 else {
369- mappingsForStdToUse .put ( type .getMappedJavaType (), type );
360+ typeByJavaTypeForJdbcType .put ( type .getMappedJavaType (), type );
370361 }
371362 }
372363
0 commit comments