Skip to content

Commit 4bd5223

Browse files
committed
use switch expression in ColumnDefinitions
Signed-off-by: Gavin King <[email protected]>
1 parent ba77bd2 commit 4bd5223

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

hibernate-core/src/main/java/org/hibernate/tool/schema/internal/ColumnDefinitions.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static boolean hasMatchingLength(Column column, ColumnInformation columnInformat
5757
return true;
5858
}
5959
else {
60-
int sqlType = columnInformation.getTypeCode();
60+
final int sqlType = columnInformation.getTypeCode();
6161
if ( isStringType( sqlType ) ) {
6262
final int actualLength = columnInformation.getColumnSize();
6363
final Size size = column.getColumnSize( dialect, metadata );
@@ -91,14 +91,14 @@ static String getFullColumnDeclaration(
9191
Metadata metadata,
9292
Dialect dialect,
9393
SqlStringGenerationContext context) {
94-
StringBuilder definition = new StringBuilder();
94+
final StringBuilder definition = new StringBuilder();
9595
appendColumn( definition, column, table, metadata, dialect, context );
9696
return definition.toString();
9797
}
9898

9999

100100
static String getColumnDefinition(Column column, Metadata metadata, Dialect dialect) {
101-
StringBuilder definition = new StringBuilder();
101+
final StringBuilder definition = new StringBuilder();
102102
appendColumnDefinition( definition, column, metadata, dialect );
103103
appendComment( definition, column, dialect );
104104
return definition.toString();
@@ -235,28 +235,19 @@ private static String normalize(String typeName) {
235235
}
236236
else {
237237
final String lowercaseTypeName = typeName.toLowerCase(Locale.ROOT);
238-
switch (lowercaseTypeName) {
239-
case "int":
240-
return "integer";
241-
case "character":
242-
return "char";
243-
case "character varying":
244-
return "varchar";
245-
case "binary varying":
246-
return "varbinary";
247-
case "character large object":
248-
return "clob";
249-
case "binary large object":
250-
return "blob";
251-
case "interval second":
252-
return "interval";
253-
case "double precision":
254-
return "double";
238+
return switch ( lowercaseTypeName ) {
239+
case "int" -> "integer";
240+
case "character" -> "char";
241+
case "character varying" -> "varchar";
242+
case "binary varying" -> "varbinary";
243+
case "character large object" -> "clob";
244+
case "binary large object" -> "blob";
245+
case "interval second" -> "interval";
246+
case "double precision" -> "double";
255247
// todo: normalize DECIMAL to NUMERIC?
256248
// normalize REAL to FLOAT?
257-
default:
258-
return lowercaseTypeName;
259-
}
249+
default -> lowercaseTypeName;
250+
};
260251
}
261252
}
262253

@@ -265,7 +256,7 @@ private static String stripArgs(String typeExpression) {
265256
return null;
266257
}
267258
else {
268-
int i = typeExpression.indexOf('(');
259+
final int i = typeExpression.indexOf('(');
269260
return i>0 ? typeExpression.substring(0,i).trim() : typeExpression;
270261
}
271262
}

0 commit comments

Comments
 (0)