Skip to content

Commit 8baa2f1

Browse files
committed
minor code cleanups in Column class
1 parent 697bcfb commit 8baa2f1

File tree

1 file changed

+14
-15
lines changed
  • hibernate-core/src/main/java/org/hibernate/mapping

1 file changed

+14
-15
lines changed

hibernate-core/src/main/java/org/hibernate/mapping/Column.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.hibernate.type.Type;
3030
import org.hibernate.type.descriptor.JdbcTypeNameMapper;
3131
import org.hibernate.type.descriptor.jdbc.JdbcType;
32-
import org.hibernate.type.descriptor.jdbc.JdbcTypeConstructor;
3332
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
3433
import org.hibernate.type.descriptor.sql.DdlType;
3534
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
@@ -200,15 +199,19 @@ public String getAlias(Dialect dialect) {
200199
final int lastLetter = lastIndexOfLetter( name );
201200
final String suffix = AliasConstantsHelper.get( uniqueInteger );
202201

203-
String alias = name.toLowerCase( Locale.ROOT );
202+
final String alias;
204203
if ( lastLetter == -1 ) {
205204
alias = "column";
206205
}
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;
209211
}
210212

211-
boolean useRawName = name.length() + suffix.length() <= dialect.getMaxAliasLength()
213+
final boolean useRawName =
214+
name.length() + suffix.length() <= dialect.getMaxAliasLength()
212215
&& !quoted
213216
&& !name.equalsIgnoreCase( dialect.rowId(null) );
214217
if ( !useRawName ) {
@@ -221,7 +224,7 @@ else if ( alias.length() > lastLetter + 1 ) {
221224
);
222225
}
223226
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;
225228
}
226229
}
227230
return alias + suffix;
@@ -318,14 +321,10 @@ private String getSqlTypeName(TypeConfiguration typeConfiguration, Dialect diale
318321
final DdlTypeRegistry ddlTypeRegistry = typeConfiguration.getDdlTypeRegistry();
319322
final JdbcTypeRegistry jdbcTypeRegistry = typeConfiguration.getJdbcTypeRegistry();
320323
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();
329328
final DdlType descriptor = jdbcType == null
330329
? null
331330
: ddlTypeRegistry.getDescriptor( jdbcType.getDdlTypeCode() );
@@ -370,7 +369,7 @@ private static Type getUnderlyingType(MappingContext mappingContext, Type type,
370369
if ( type instanceof ComponentType componentType ) {
371370
int cols = 0;
372371
for ( Type subtype : componentType.getSubtypes() ) {
373-
int columnSpan = subtype.getColumnSpan( mappingContext );
372+
final int columnSpan = subtype.getColumnSpan( mappingContext );
374373
if ( cols+columnSpan > typeIndex ) {
375374
return getUnderlyingType( mappingContext, subtype, typeIndex-cols );
376375
}

0 commit comments

Comments
 (0)