From: Sébastien Lesaint Date: Thu, 9 Jun 2016 13:55:10 +0000 (+0200) Subject: SONAR-7692 add DdlChange#getDialect() and use it in subclasses X-Git-Tag: 6.0-RC1~342 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7841afb59d065cc27e9914f18bad7fdbc1961f46;p=sonarqube.git SONAR-7692 add DdlChange#getDialect() and use it in subclasses this avoid having two private property with the same object --- diff --git a/sonar-db/src/main/java/org/sonar/db/version/DdlChange.java b/sonar-db/src/main/java/org/sonar/db/version/DdlChange.java index 559649f6ebe..8c03055856f 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/DdlChange.java +++ b/sonar-db/src/main/java/org/sonar/db/version/DdlChange.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import java.util.List; import org.apache.commons.dbutils.DbUtils; import org.sonar.db.Database; +import org.sonar.db.dialect.Dialect; import static java.lang.String.*; import static java.util.Arrays.asList; @@ -56,6 +57,10 @@ public abstract class DdlChange implements MigrationStep { return db; } + protected Dialect getDialect() { + return db.getDialect(); + } + public static class Context { private final Connection writeConnection; diff --git a/sonar-db/src/main/java/org/sonar/db/version/v51/AddIssuesColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v51/AddIssuesColumns.java index 0f6c81883d2..6eeaeb3166d 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v51/AddIssuesColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v51/AddIssuesColumns.java @@ -38,11 +38,8 @@ import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; */ public class AddIssuesColumns extends DdlChange { - private final Database db; - public AddIssuesColumns(Database db) { super(db); - this.db = db; } @Override @@ -51,7 +48,7 @@ public class AddIssuesColumns extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(db.getDialect(), "issues") + return new AddColumnsBuilder(getDialect(), "issues") .addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_creation_date_ms").setIsNullable(true).build()) .addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_update_date_ms").setIsNullable(true).build()) .addColumn(newBigDecimalColumnDefBuilder().setColumnName("issue_close_date_ms").setIsNullable(true).build()) diff --git a/sonar-db/src/main/java/org/sonar/db/version/v51/DropIssuesColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v51/DropIssuesColumns.java index 4816579d3d6..15256fddbf4 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v51/DropIssuesColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v51/DropIssuesColumns.java @@ -35,11 +35,8 @@ import org.sonar.db.version.DropColumnsBuilder; */ public class DropIssuesColumns extends DdlChange { - private final Database db; - public DropIssuesColumns(Database db) { super(db); - this.db = db; } @Override @@ -49,7 +46,7 @@ public class DropIssuesColumns extends DdlChange { @VisibleForTesting String generateSql() { - return new DropColumnsBuilder(db.getDialect(), "issues", + return new DropColumnsBuilder(getDialect(), "issues", "issue_creation_date", "issue_update_date", "issue_close_date", "component_id", "root_component_id") .build(); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v52/AddManualMeasuresComponentUuidColumn.java b/sonar-db/src/main/java/org/sonar/db/version/v52/AddManualMeasuresComponentUuidColumn.java index a7187a3aa16..9dc46ec7c07 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v52/AddManualMeasuresComponentUuidColumn.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v52/AddManualMeasuresComponentUuidColumn.java @@ -42,7 +42,7 @@ public class AddManualMeasuresComponentUuidColumn extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(getDatabase().getDialect(), "manual_measures") + return new AddColumnsBuilder(getDialect(), "manual_measures") .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(50).setIsNullable(true).build()) .build(); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v52/IncreasePrecisionOfNumerics.java b/sonar-db/src/main/java/org/sonar/db/version/v52/IncreasePrecisionOfNumerics.java index 8e47e7e8b8a..3f77dd686bc 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v52/IncreasePrecisionOfNumerics.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v52/IncreasePrecisionOfNumerics.java @@ -63,7 +63,7 @@ public class IncreasePrecisionOfNumerics extends DdlChange { } private List generateSql(String table, String... columns) { - AlterColumnsTypeBuilder columnsBuilder = new AlterColumnsTypeBuilder(getDatabase().getDialect(), table); + AlterColumnsTypeBuilder columnsBuilder = new AlterColumnsTypeBuilder(getDialect(), table); for (String column : columns) { columnsBuilder.updateColumn(newDecimalColumnDefBuilder().setColumnName(column).build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v54/AddUsersIdentityColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v54/AddUsersIdentityColumns.java index e9fcdd6e440..95b1435ebaf 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v54/AddUsersIdentityColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v54/AddUsersIdentityColumns.java @@ -33,11 +33,8 @@ import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; */ public class AddUsersIdentityColumns extends DdlChange { - private final Database db; - public AddUsersIdentityColumns(Database db) { super(db); - this.db = db; } @Override @@ -46,7 +43,7 @@ public class AddUsersIdentityColumns extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(db.getDialect(), "users") + return new AddColumnsBuilder(getDialect(), "users") .addColumn(newVarcharColumnDefBuilder().setColumnName("external_identity").setLimit(255).setIsNullable(true).build()) .addColumn(newVarcharColumnDefBuilder().setColumnName("external_identity_provider").setLimit(100).setIsNullable(true).build()) .build(); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java b/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java index 0cc378ec74d..6ab6727743f 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v54/IncreaseProjectsNameColumnsSize.java @@ -34,11 +34,8 @@ import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder; */ public class IncreaseProjectsNameColumnsSize extends DdlChange { - private final Database db; - public IncreaseProjectsNameColumnsSize(Database db) { super(db); - this.db = db; } @Override @@ -47,7 +44,7 @@ public class IncreaseProjectsNameColumnsSize extends DdlChange { } private List generateSql() { - return new AlterColumnsTypeBuilder(db.getDialect(), "projects") + return new AlterColumnsTypeBuilder(getDialect(), "projects") .updateColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(2000).setIsNullable(true).build()) .updateColumn(newVarcharColumnDefBuilder().setColumnName("long_name").setLimit(2000).setIsNullable(true).build()) .build(); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/AddActiveRulesLongDateColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddActiveRulesLongDateColumns.java index 4074e238fb5..f9e381b226d 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/AddActiveRulesLongDateColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/AddActiveRulesLongDateColumns.java @@ -33,11 +33,8 @@ import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBui */ public class AddActiveRulesLongDateColumns extends DdlChange { - private final Database db; - public AddActiveRulesLongDateColumns(Database db) { super(db); - this.db = db; } @Override @@ -46,7 +43,7 @@ public class AddActiveRulesLongDateColumns extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(db.getDialect(), "active_rules") + return new AddColumnsBuilder(getDialect(), "active_rules") .addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build()) .addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build()) .build(); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/AddIssuesType.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddIssuesType.java index 734dc8bb31b..f1e5d602487 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/AddIssuesType.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/AddIssuesType.java @@ -27,11 +27,8 @@ import org.sonar.db.version.TinyIntColumnDef; public class AddIssuesType extends DdlChange { - private final Database db; - public AddIssuesType(Database db) { super(db); - this.db = db; } @Override @@ -40,7 +37,7 @@ public class AddIssuesType extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(db.getDialect(), "issues") + return new AddColumnsBuilder(getDialect(), "issues") .addColumn(new TinyIntColumnDef.Builder().setColumnName("issue_type").setIsNullable(true).build()) .build(); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java index 8b2d748d521..400b4c7702f 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/AddRulesColumns.java @@ -35,11 +35,8 @@ import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBui */ public class AddRulesColumns extends DdlChange { - private final Database db; - public AddRulesColumns(Database db) { super(db); - this.db = db; } @Override @@ -48,7 +45,7 @@ public class AddRulesColumns extends DdlChange { } private String generateSql() { - return new AddColumnsBuilder(db.getDialect(), "rules") + return new AddColumnsBuilder(getDialect(), "rules") .addColumn(newBigDecimalColumnDefBuilder().setColumnName("created_at_ms").setIsNullable(true).build()) .addColumn(newBigDecimalColumnDefBuilder().setColumnName("updated_at_ms").setIsNullable(true).build()) .addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build()) diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/DropActiveRulesDateColumns.java b/sonar-db/src/main/java/org/sonar/db/version/v55/DropActiveRulesDateColumns.java index 73d48056fde..79de7e585fe 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/DropActiveRulesDateColumns.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/DropActiveRulesDateColumns.java @@ -32,11 +32,8 @@ import org.sonar.db.version.DropColumnsBuilder; */ public class DropActiveRulesDateColumns extends DdlChange { - private final Database db; - public DropActiveRulesDateColumns(Database db) { super(db); - this.db = db; } @Override @@ -46,7 +43,7 @@ public class DropActiveRulesDateColumns extends DdlChange { @VisibleForTesting String generateSql() { - return new DropColumnsBuilder(db.getDialect(), "active_rules", + return new DropColumnsBuilder(getDialect(), "active_rules", "created_at", "updated_at") .build(); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDatesAndCharacteristics.java b/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDatesAndCharacteristics.java index 5eb37083e1e..05f48dfdedc 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDatesAndCharacteristics.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v55/DropRulesDatesAndCharacteristics.java @@ -32,11 +32,8 @@ import org.sonar.db.version.DropColumnsBuilder; */ public class DropRulesDatesAndCharacteristics extends DdlChange { - private final Database db; - public DropRulesDatesAndCharacteristics(Database db) { super(db); - this.db = db; } @Override @@ -46,7 +43,7 @@ public class DropRulesDatesAndCharacteristics extends DdlChange { @VisibleForTesting String generateSql() { - return new DropColumnsBuilder(db.getDialect(), "rules", + return new DropColumnsBuilder(getDialect(), "rules", "created_at", "updated_at", "characteristic_id", "default_characteristic_id") .build(); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v56/FixLengthOfIssuesMessageOnOracle.java b/sonar-db/src/main/java/org/sonar/db/version/v56/FixLengthOfIssuesMessageOnOracle.java index 4ad5ae6f61b..3fcf5de3271 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v56/FixLengthOfIssuesMessageOnOracle.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v56/FixLengthOfIssuesMessageOnOracle.java @@ -32,7 +32,7 @@ public class FixLengthOfIssuesMessageOnOracle extends DdlChange { @Override public void execute(Context context) throws SQLException { - if (getDatabase().getDialect().getId().equals(Oracle.ID)) { + if (getDialect().getId().equals(Oracle.ID)) { // in order to not depend on value of variable NLS_LENGTH_SEMANTICS, unit of length // is enforced to CHAR so that we're sure that type can't be 4000 BYTE. context.execute("ALTER TABLE issues MODIFY (message VARCHAR (4000 CHAR))"); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v56/FixTypeOfRuleTypeOnMysql.java b/sonar-db/src/main/java/org/sonar/db/version/v56/FixTypeOfRuleTypeOnMysql.java index 09820a00ee6..e0b52843575 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v56/FixTypeOfRuleTypeOnMysql.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v56/FixTypeOfRuleTypeOnMysql.java @@ -44,7 +44,7 @@ public class FixTypeOfRuleTypeOnMysql extends DdlChange { // In SQ 5.5, migration 1100 create columns with type TINYINT(1) instead of TINYINT(2) // In SQ 5.4 and lower, the type TINYINT(1) was used only for boolean columns, so no problem // As an optimization fix must be applied only for instances upgrading from 5.5.x - if (getDatabase().getDialect().getId().equals(MySql.ID) && + if (getDialect().getId().equals(MySql.ID) && dbVersion.getInitialDbVersion() >= SQ_5_5 && dbVersion.getInitialDbVersion() < SQ_5_6) { Loggers.get(getClass()).info("Changing TINYINT(1) to TINYINT(2)"); context.execute("ALTER TABLE rules MODIFY COLUMN rule_type TINYINT (2)"); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToResourceIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToResourceIndex.java index 784db311490..45f54d9d1c3 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToResourceIndex.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/AddUuidColumnsToResourceIndex.java @@ -31,16 +31,13 @@ public class AddUuidColumnsToResourceIndex extends DdlChange { private static final String TABLE_RESOURCE_INDEX = "resource_index"; - private final Database db; - public AddUuidColumnsToResourceIndex(Database db) { super(db); - this.db = db; } @Override public void execute(Context context) throws SQLException { - context.execute(new AddColumnsBuilder(db.getDialect(), TABLE_RESOURCE_INDEX) + context.execute(new AddColumnsBuilder(getDialect(), TABLE_RESOURCE_INDEX) .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) .addColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(true).build()) .build()); diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIdColumnsFromResourceIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIdColumnsFromResourceIndex.java index f7fe94c38e0..19f4ac4e22a 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/DropIdColumnsFromResourceIndex.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/DropIdColumnsFromResourceIndex.java @@ -28,18 +28,15 @@ public class DropIdColumnsFromResourceIndex extends DdlChange { private static final String TABLE_RESOURCE_INDEX = "resource_index"; - private final Database db; - public DropIdColumnsFromResourceIndex(Database db) { super(db); - this.db = db; } @Override public void execute(Context context) throws SQLException { context.execute( new DropColumnsBuilder( - db.getDialect(), TABLE_RESOURCE_INDEX, + getDialect(), TABLE_RESOURCE_INDEX, "resource_id", "root_project_id") .build()); } diff --git a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java index 16e01b30323..fb50b2dfdf7 100644 --- a/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java +++ b/sonar-db/src/main/java/org/sonar/db/version/v60/MakeUuidColumnsNotNullOnResourceIndex.java @@ -31,16 +31,13 @@ public class MakeUuidColumnsNotNullOnResourceIndex extends DdlChange { private static final String TABLE_RESOURCE_INDEX = "resource_index"; - private final Database db; - public MakeUuidColumnsNotNullOnResourceIndex(Database db) { super(db); - this.db = db; } @Override public void execute(Context context) throws SQLException { - context.execute(new AlterColumnsTypeBuilder(db.getDialect(), TABLE_RESOURCE_INDEX) + context.execute(new AlterColumnsTypeBuilder(getDialect(), TABLE_RESOURCE_INDEX) .updateColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) .updateColumn(newVarcharColumnDefBuilder().setColumnName("root_component_uuid").setLimit(UUID_VARCHAR_SIZE).setIsNullable(false).build()) .build());