aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorMatteo Mara <matteo.mara@sonarsource.com>2023-01-06 12:59:21 +0100
committersonartech <sonartech@sonarsource.com>2023-01-10 20:03:01 +0000
commit18f91c25d369917f3a99841f6bb31b94a02467fc (patch)
tree9939b8dfb10c74b95a5addbcadb8fb91ba296f31 /server/sonar-db-migration
parent215dd7343dc55f91613b820d43c208c19a50d176 (diff)
downloadsonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.tar.gz
sonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.zip
[NO-JIRA] Remove reported code smells about switch statements
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BlobColumnDef.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BooleanColumnDef.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/DecimalColumnDef.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/IntegerColumnDef.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TimestampColumnDef.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TinyIntColumnDef.java17
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java13
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java18
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java3
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexBuilder.java17
11 files changed, 50 insertions, 92 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BlobColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BlobColumnDef.java
index f26640bb767..a47e58666a4 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BlobColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BlobColumnDef.java
@@ -37,17 +37,12 @@ public class BlobColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case MsSql.ID:
- return "VARBINARY(MAX)";
- case Oracle.ID:
- case H2.ID:
- return "BLOB";
- case PostgreSql.ID:
- return "BYTEA";
- default:
- throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
- }
+ return switch (dialect.getId()) {
+ case MsSql.ID -> "VARBINARY(MAX)";
+ case Oracle.ID, H2.ID -> "BLOB";
+ case PostgreSql.ID -> "BYTEA";
+ default -> throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
+ };
}
public static Builder newBlobColumnDefBuilder() {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BooleanColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BooleanColumnDef.java
index cc0d302b4a5..057ef1a1df6 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BooleanColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/BooleanColumnDef.java
@@ -50,8 +50,7 @@ public class BooleanColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
switch (dialect.getId()) {
- case PostgreSql.ID:
- case H2.ID:
+ case PostgreSql.ID, H2.ID:
return "BOOLEAN";
case Oracle.ID:
return "NUMBER(1)";
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
index 52edf32821b..d5015e1e477 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/ClobColumnDef.java
@@ -47,8 +47,7 @@ public class ClobColumnDef extends AbstractColumnDef {
switch (dialect.getId()) {
case MsSql.ID:
return "NVARCHAR (MAX)";
- case Oracle.ID:
- case H2.ID:
+ case Oracle.ID, H2.ID:
return "CLOB";
case PostgreSql.ID:
return "TEXT";
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/DecimalColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/DecimalColumnDef.java
index f2ebd095a08..2dd8e7002fe 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/DecimalColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/DecimalColumnDef.java
@@ -58,17 +58,12 @@ public class DecimalColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case PostgreSql.ID:
- case Oracle.ID:
- return String.format("NUMERIC (%s,%s)", precision, scale);
- case MsSql.ID:
- return String.format("DECIMAL (%s,%s)", precision, scale);
- case H2.ID:
- return "DOUBLE";
- default:
- throw new UnsupportedOperationException(String.format("Unknown dialect '%s'", dialect.getId()));
- }
+ return switch (dialect.getId()) {
+ case PostgreSql.ID, Oracle.ID -> String.format("NUMERIC (%s,%s)", precision, scale);
+ case MsSql.ID -> String.format("DECIMAL (%s,%s)", precision, scale);
+ case H2.ID -> "DOUBLE";
+ default -> throw new UnsupportedOperationException(String.format("Unknown dialect '%s'", dialect.getId()));
+ };
}
public static class Builder {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/IntegerColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/IntegerColumnDef.java
index 128c2ce9800..3242e155334 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/IntegerColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/IntegerColumnDef.java
@@ -43,17 +43,12 @@ public class IntegerColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case PostgreSql.ID:
- case H2.ID:
- return "INTEGER";
- case MsSql.ID:
- return "INT";
- case Oracle.ID:
- return "NUMBER(38,0)";
- default:
- throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
- }
+ return switch (dialect.getId()) {
+ case PostgreSql.ID, H2.ID -> "INTEGER";
+ case MsSql.ID -> "INT";
+ case Oracle.ID -> "NUMBER(38,0)";
+ default -> throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
+ };
}
public static class Builder {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TimestampColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TimestampColumnDef.java
index 4074b2e5f99..18372dc634a 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TimestampColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TimestampColumnDef.java
@@ -48,17 +48,12 @@ public class TimestampColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case MsSql.ID:
- return "DATETIME";
- case Oracle.ID:
- return "TIMESTAMP (6)";
- case H2.ID:
- case PostgreSql.ID:
- return "TIMESTAMP";
- default:
- throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
- }
+ return switch (dialect.getId()) {
+ case MsSql.ID -> "DATETIME";
+ case Oracle.ID -> "TIMESTAMP (6)";
+ case H2.ID, PostgreSql.ID -> "TIMESTAMP";
+ default -> throw new IllegalArgumentException("Unsupported dialect id " + dialect.getId());
+ };
}
public static class Builder {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TinyIntColumnDef.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TinyIntColumnDef.java
index 622e8c6a4d0..419645d3da6 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TinyIntColumnDef.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/def/TinyIntColumnDef.java
@@ -45,17 +45,12 @@ public class TinyIntColumnDef extends AbstractColumnDef {
@Override
public String generateSqlType(Dialect dialect) {
- switch (dialect.getId()) {
- case PostgreSql.ID:
- return "SMALLINT";
- case Oracle.ID:
- return "NUMBER(3)";
- case MsSql.ID:
- case H2.ID:
- return "TINYINT";
- default:
- throw new UnsupportedOperationException(String.format("Unknown dialect '%s'", dialect.getId()));
- }
+ return switch (dialect.getId()) {
+ case PostgreSql.ID -> "SMALLINT";
+ case Oracle.ID -> "NUMBER(3)";
+ case MsSql.ID, H2.ID -> "TINYINT";
+ default -> throw new UnsupportedOperationException(String.format("Unknown dialect '%s'", dialect.getId()));
+ };
}
public static class Builder {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java
index 52d8ce20898..7acf545e77f 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropConstraintBuilder.java
@@ -65,14 +65,9 @@ public class DropConstraintBuilder {
}
private String createSqlStatement() {
- switch (dialect.getId()) {
- case MsSql.ID:
- case Oracle.ID:
- case PostgreSql.ID:
- case H2.ID:
- return "ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName;
- default:
- throw new IllegalStateException("Unsupported dialect for drop of constraint: " + dialect);
- }
+ return switch (dialect.getId()) {
+ case MsSql.ID, Oracle.ID, PostgreSql.ID, H2.ID -> "ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName;
+ default -> throw new IllegalStateException("Unsupported dialect for drop of constraint: " + dialect);
+ };
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java
index bce1e12699b..6ac5948e373 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/DropTableBuilder.java
@@ -42,18 +42,14 @@ public class DropTableBuilder {
}
public List<String> build() {
- switch (dialect.getId()) {
- case Oracle.ID:
- return forOracle(tableName);
- case H2.ID:
- case PostgreSql.ID:
- return singletonList("drop table if exists " + tableName);
- case MsSql.ID:
+ return switch (dialect.getId()) {
+ case Oracle.ID -> forOracle(tableName);
+ case H2.ID, PostgreSql.ID -> singletonList("drop table if exists " + tableName);
+ case MsSql.ID ->
// "if exists" is supported only since MSSQL 2016.
- return singletonList("drop table " + tableName);
- default:
- throw new IllegalStateException("Unsupported DB: " + dialect.getId());
- }
+ singletonList("drop table " + tableName);
+ default -> throw new IllegalStateException("Unsupported DB: " + dialect.getId());
+ };
}
private static List<String> forOracle(String tableName) {
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java
index 415f209e004..6cf70f766b4 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/RenameTableBuilder.java
@@ -73,8 +73,7 @@ public class RenameTableBuilder {
private List<String> createSqlStatement() {
switch (dialect.getId()) {
- case H2.ID:
- case PostgreSql.ID:
+ case H2.ID, PostgreSql.ID:
return singletonList("ALTER TABLE " + name + " RENAME TO " + newName);
case MsSql.ID:
return singletonList("EXEC sp_rename '" + name + "', '" + newName + "'");
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexBuilder.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexBuilder.java
index 1757c272e3c..d1a013cf428 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexBuilder.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DropIndexBuilder.java
@@ -61,16 +61,11 @@ class DropIndexBuilder {
}
private String createSqlStatement() {
- switch (dialect.getId()) {
- case MsSql.ID:
- return "DROP INDEX " + indexName + " ON " + tableName;
- case Oracle.ID:
- return "DROP INDEX " + indexName;
- case H2.ID:
- case PostgreSql.ID:
- return "DROP INDEX IF EXISTS " + indexName;
- default:
- throw new IllegalStateException("Unsupported dialect for drop of index: " + dialect);
- }
+ return switch (dialect.getId()) {
+ case MsSql.ID -> "DROP INDEX " + indexName + " ON " + tableName;
+ case Oracle.ID -> "DROP INDEX " + indexName;
+ case H2.ID, PostgreSql.ID -> "DROP INDEX IF EXISTS " + indexName;
+ default -> throw new IllegalStateException("Unsupported dialect for drop of index: " + dialect);
+ };
}
}