29
29
import org .hibernate .type .Type ;
30
30
import org .hibernate .type .descriptor .JdbcTypeNameMapper ;
31
31
import org .hibernate .type .descriptor .jdbc .JdbcType ;
32
- import org .hibernate .type .descriptor .jdbc .JdbcTypeConstructor ;
33
32
import org .hibernate .type .descriptor .jdbc .spi .JdbcTypeRegistry ;
34
33
import org .hibernate .type .descriptor .sql .DdlType ;
35
34
import org .hibernate .type .descriptor .sql .spi .DdlTypeRegistry ;
@@ -200,15 +199,19 @@ public String getAlias(Dialect dialect) {
200
199
final int lastLetter = lastIndexOfLetter ( name );
201
200
final String suffix = AliasConstantsHelper .get ( uniqueInteger );
202
201
203
- String alias = name . toLowerCase ( Locale . ROOT ) ;
202
+ final String alias ;
204
203
if ( lastLetter == -1 ) {
205
204
alias = "column" ;
206
205
}
207
- else if ( alias .length () > lastLetter + 1 ) {
208
- alias = alias .substring ( 0 , lastLetter + 1 );
206
+ else {
207
+ final String lowerCaseName = name .toLowerCase ( Locale .ROOT );
208
+ alias = lowerCaseName .length () > lastLetter + 1
209
+ ? lowerCaseName .substring ( 0 , lastLetter + 1 )
210
+ : lowerCaseName ;
209
211
}
210
212
211
- boolean useRawName = name .length () + suffix .length () <= dialect .getMaxAliasLength ()
213
+ final boolean useRawName =
214
+ name .length () + suffix .length () <= dialect .getMaxAliasLength ()
212
215
&& !quoted
213
216
&& !name .equalsIgnoreCase ( dialect .rowId (null ) );
214
217
if ( !useRawName ) {
@@ -221,7 +224,7 @@ else if ( alias.length() > lastLetter + 1 ) {
221
224
);
222
225
}
223
226
if ( alias .length () + suffix .length () > dialect .getMaxAliasLength () ) {
224
- alias = alias .substring ( 0 , dialect .getMaxAliasLength () - suffix .length () );
227
+ return alias .substring ( 0 , dialect .getMaxAliasLength () - suffix .length () ) + suffix ;
225
228
}
226
229
}
227
230
return alias + suffix ;
@@ -318,14 +321,10 @@ private String getSqlTypeName(TypeConfiguration typeConfiguration, Dialect diale
318
321
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration .getDdlTypeRegistry ();
319
322
final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration .getJdbcTypeRegistry ();
320
323
final int sqlTypeCode = getSqlTypeCode ( mapping );
321
- final JdbcTypeConstructor constructor = jdbcTypeRegistry .getConstructor ( sqlTypeCode );
322
- final JdbcType jdbcType ;
323
- if ( constructor == null ) {
324
- jdbcType = jdbcTypeRegistry .findDescriptor ( sqlTypeCode );
325
- }
326
- else {
327
- jdbcType = ( (BasicType <?>) getUnderlyingType ( mapping , getValue ().getType (), typeIndex ) ).getJdbcType ();
328
- }
324
+ final JdbcType jdbcType =
325
+ jdbcTypeRegistry .getConstructor ( sqlTypeCode ) == null
326
+ ? jdbcTypeRegistry .findDescriptor ( sqlTypeCode )
327
+ : ( (BasicType <?>) getUnderlyingType ( mapping , getValue ().getType (), typeIndex ) ).getJdbcType ();
329
328
final DdlType descriptor = jdbcType == null
330
329
? null
331
330
: ddlTypeRegistry .getDescriptor ( jdbcType .getDdlTypeCode () );
@@ -370,7 +369,7 @@ private static Type getUnderlyingType(MappingContext mappingContext, Type type,
370
369
if ( type instanceof ComponentType componentType ) {
371
370
int cols = 0 ;
372
371
for ( Type subtype : componentType .getSubtypes () ) {
373
- int columnSpan = subtype .getColumnSpan ( mappingContext );
372
+ final int columnSpan = subtype .getColumnSpan ( mappingContext );
374
373
if ( cols +columnSpan > typeIndex ) {
375
374
return getUnderlyingType ( mappingContext , subtype , typeIndex -cols );
376
375
}
0 commit comments