@@ -146,9 +146,9 @@ public <J> BasicType<J> resolve(java.lang.reflect.Type javaType, int sqlTypeCode
146
146
return resolve ( typeConfiguration .getJavaTypeRegistry ().getDescriptor ( javaType ), sqlTypeCode );
147
147
}
148
148
149
- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , int sqlTypeCode ) {
149
+ public <J > BasicType <J > resolve (JavaType <J > javaType , int sqlTypeCode ) {
150
150
return resolve (
151
- jtdToUse ,
151
+ javaType ,
152
152
typeConfiguration .getJdbcTypeRegistry ().getDescriptor ( sqlTypeCode )
153
153
);
154
154
}
@@ -157,63 +157,54 @@ public <J> BasicType<J> resolve(JavaType<J> jtdToUse, int sqlTypeCode) {
157
157
* Find an existing {@link BasicType} registration for the given {@link JavaType}
158
158
* descriptor and {@link JdbcType} descriptor combo or create (and register) one.
159
159
*/
160
- public <J > BasicType <J > resolve (JavaType <J > jtdToUse , JdbcType stdToUse ) {
160
+ public <J > BasicType <J > resolve (JavaType <J > javaType , JdbcType jdbcType ) {
161
161
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 )
178
165
);
179
166
}
180
167
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 ) {
182
169
return resolve (
183
- jtdToUse ,
184
- stdToUse ,
185
- () -> new NamedBasicTypeImpl <>( jtdToUse , stdToUse , baseTypeName )
170
+ javaType ,
171
+ jdbcType ,
172
+ () -> new NamedBasicTypeImpl <>( javaType , jdbcType , baseTypeName )
186
173
);
187
174
}
188
175
189
176
/**
190
177
* Find an existing BasicType registration for the given JavaType and
191
178
* JdbcType combo or create (and register) one.
192
179
*/
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 <>()
197
184
);
198
185
199
- final BasicType <?> foundBasicType = typeByJtdForStd .get ( jtdToUse );
186
+ final BasicType <?> foundBasicType = typeByJavaTypeForJdbcType .get ( javaType );
200
187
if ( foundBasicType != null ) {
201
188
//noinspection unchecked
202
189
return (BasicType <J >) foundBasicType ;
203
190
}
204
191
// Before simply creating the type, we try to find if there is a registered type for this java type,
205
192
// 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 ;
214
196
}
215
197
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
+ }
217
208
return createdBasicType ;
218
209
}
219
210
@@ -250,12 +241,12 @@ public void register(BasicType<?> type, String... keys) {
250
241
}
251
242
252
243
private void applyOrOverwriteEntry (BasicType <?> type ) {
253
- final Map <JavaType <?>, BasicType <?>> mappingsForStdToUse = registryValues .computeIfAbsent (
244
+ final Map <JavaType <?>, BasicType <?>> typeByJavaTypeForJdbcType = registryValues .computeIfAbsent (
254
245
type .getJdbcType (),
255
- sqlTypeDescriptor -> new ConcurrentHashMap <>()
246
+ jdbcType -> new ConcurrentHashMap <>()
256
247
);
257
248
258
- final BasicType <?> existing = mappingsForStdToUse .put ( type .getMappedJavaType (), type );
249
+ final BasicType <?> existing = typeByJavaTypeForJdbcType .put ( type .getMappedJavaType (), type );
259
250
if ( existing != null ) {
260
251
LOG .debugf (
261
252
"BasicTypeRegistry registration overwritten (%s + %s); previous =`%s`" ,
@@ -350,12 +341,12 @@ public void addPrimeEntry(BasicTypeReference<?> type, String legacyTypeClassName
350
341
}
351
342
352
343
private void primeRegistryEntry (BasicType <?> type ) {
353
- final Map <JavaType <?>, BasicType <?>> mappingsForStdToUse = registryValues .computeIfAbsent (
344
+ final Map <JavaType <?>, BasicType <?>> typeByJavaTypeForJdbcType = registryValues .computeIfAbsent (
354
345
type .getJdbcType (),
355
- sqlTypeDescriptor -> new ConcurrentHashMap <>()
346
+ jdbcType -> new ConcurrentHashMap <>()
356
347
);
357
348
358
- final BasicType <?> existing = mappingsForStdToUse .get ( type .getMappedJavaType () );
349
+ final BasicType <?> existing = typeByJavaTypeForJdbcType .get ( type .getMappedJavaType () );
359
350
360
351
if ( existing != null ) {
361
352
LOG .debugf (
@@ -366,7 +357,7 @@ private void primeRegistryEntry(BasicType<?> type) {
366
357
);
367
358
}
368
359
else {
369
- mappingsForStdToUse .put ( type .getMappedJavaType (), type );
360
+ typeByJavaTypeForJdbcType .put ( type .getMappedJavaType (), type );
370
361
}
371
362
}
372
363
0 commit comments