diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2019-07-02 23:12:14 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-07-10 08:36:52 +0200 |
commit | 983f593231da12bd64d9df23c18d4f2c7aaa6da1 (patch) | |
tree | 7cb059b67a55896fdee6a845a33cd1b7abcf6193 /server/sonar-db-core | |
parent | ae5d2b804c69e4cd19ec13880b913881f620e518 (diff) | |
download | sonarqube-983f593231da12bd64d9df23c18d4f2c7aaa6da1.tar.gz sonarqube-983f593231da12bd64d9df23c18d4f2c7aaa6da1.zip |
SONAR-12246 remove MySQL dialect
Diffstat (limited to 'server/sonar-db-core')
11 files changed, 21 insertions, 225 deletions
diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java b/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java index 0349abf3a40..3c1b88ef24f 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/DefaultDatabase.java @@ -38,7 +38,6 @@ import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.DialectUtils; -import org.sonar.db.dialect.MySql; import org.sonar.db.profiling.NullConnectionInterceptor; import org.sonar.db.profiling.ProfiledConnectionInterceptor; import org.sonar.db.profiling.ProfiledDataSource; @@ -81,7 +80,6 @@ public class DefaultDatabase implements Database { @Override public void start() { initSettings(); - failIfMySql(); try { initDataSource(); checkConnection(); @@ -98,21 +96,22 @@ public class DefaultDatabase implements Database { completeDefaultProperty(properties, JDBC_URL.getKey(), DEFAULT_URL); doCompleteProperties(properties); - dialect = DialectUtils.find(properties.getProperty(SONAR_JDBC_DIALECT), properties.getProperty(JDBC_URL.getKey())); + String jdbcUrl = properties.getProperty(JDBC_URL.getKey()); + failIfMySql(jdbcUrl); + dialect = DialectUtils.find(properties.getProperty(SONAR_JDBC_DIALECT), jdbcUrl); properties.setProperty(SONAR_JDBC_DRIVER, dialect.getDefaultDriverClassName()); } - private void failIfMySql() { - if (!MySql.ID.equals(dialect.getId())) { - return; + private static void failIfMySql(String jdbcUrl) { + if (StringUtils.startsWithIgnoreCase(jdbcUrl, "jdbc:mysql")) { + throw MessageException.of("\n" + + "#############################################################################################################\n" + + "# End of Life of MySQL Support : SonarQube 7.9 and future versions do not support MySQL. #\n" + + "# Please migrate to a supported database. Get more details at #\n" + + "# https://community.sonarsource.com/t/end-of-life-of-mysql-support #\n" + + "# and https://github.com/SonarSource/mysql-migrator #\n" + + "#############################################################################################################\n"); } - throw MessageException.of("\n" + - "#############################################################################################################\n" + - "# End of Life of MySQL Support : SonarQube 7.9 and future versions do not support MySQL. #\n" + - "# Please migrate to a supported database. Get more details at #\n" + - "# https://community.sonarsource.com/t/end-of-life-of-mysql-support #\n" + - "# and https://github.com/SonarSource/mysql-migrator #\n" + - "#############################################################################################################\n"); } private void initDataSource() throws Exception { diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/AbstractDialect.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/AbstractDialect.java index 8836e59789f..410a70741e6 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/AbstractDialect.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/AbstractDialect.java @@ -78,16 +78,6 @@ abstract class AbstractDialect implements Dialect { } @Override - public int getScrollDefaultFetchSize() { - return 200; - } - - @Override - public int getScrollSingleRowFetchSize() { - return 1; - } - - @Override public boolean supportsUpsert() { return false; } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Dialect.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Dialect.java index 49c1b2b1ad4..b693d78d001 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Dialect.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Dialect.java @@ -51,13 +51,9 @@ public interface Dialect { /** * Fetch size to be used when scrolling large result sets. */ - int getScrollDefaultFetchSize(); - - /** - * Fetch size to scroll one row at a time. It sounds strange because obviously value is 1 in most cases, - * but it's different on MySQL... - */ - int getScrollSingleRowFetchSize(); + default int getScrollDefaultFetchSize() { + return 200; + } /** * Indicates whether DB migration can be perform on the DB vendor implementation associated with the current dialect. diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/DialectUtils.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/DialectUtils.java index 7739ad836fd..10d1e90a4d7 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/DialectUtils.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/DialectUtils.java @@ -29,7 +29,7 @@ import org.sonar.api.utils.MessageException; public final class DialectUtils { - private static final Set<Supplier<Dialect>> DIALECTS = ImmutableSet.of(H2::new, MySql::new, Oracle::new, PostgreSql::new, MsSql::new); + private static final Set<Supplier<Dialect>> DIALECTS = ImmutableSet.of(H2::new, Oracle::new, PostgreSql::new, MsSql::new); private DialectUtils() { // only static stuff diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MySql.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MySql.java deleted file mode 100644 index 08c5d887138..00000000000 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MySql.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.dialect; - -import java.sql.DatabaseMetaData; -import java.sql.SQLException; -import org.apache.commons.lang.StringUtils; -import org.sonar.api.utils.Version; - -public class MySql extends AbstractDialect { - - public static final String ID = "mysql"; - private static final Version MIN_SUPPORTED_VERSION = Version.create(5, 6, 0); - - public MySql() { - super(ID, "com.mysql.jdbc.Driver", "true", "false", "SELECT 1"); - } - - @Override - public boolean matchesJdbcUrl(String jdbcConnectionURL) { - return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:mysql:"); - } - - @Override - public int getScrollDefaultFetchSize() { - return Integer.MIN_VALUE; - } - - @Override - public int getScrollSingleRowFetchSize() { - return Integer.MIN_VALUE; - } - - @Override - public boolean supportsMigration() { - return true; - } - - @Override - public String getSqlFromDual() { - return "from dual"; - } - - @Override - public void init(DatabaseMetaData metaData) throws SQLException { - checkDbVersion(metaData, MIN_SUPPORTED_VERSION); - } -} diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCommands.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCommands.java index 6cc886b710c..17824d95bd4 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCommands.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCommands.java @@ -35,12 +35,10 @@ import org.dbunit.dataset.datatype.IDataTypeFactory; import org.dbunit.dataset.datatype.ToleratedDeltaMap; import org.dbunit.ext.h2.H2DataTypeFactory; import org.dbunit.ext.mssql.MsSqlDataTypeFactory; -import org.dbunit.ext.mysql.MySqlDataTypeFactory; import org.dbunit.ext.oracle.Oracle10DataTypeFactory; import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; import org.sonar.db.dialect.Dialect; import org.sonar.db.dialect.MsSql; -import org.sonar.db.dialect.MySql; import org.sonar.db.dialect.Oracle; import org.sonar.db.dialect.PostgreSql; import org.sonar.db.version.SqTables; @@ -74,7 +72,6 @@ public abstract class DatabaseCommands { DatabaseCommands command = ImmutableMap.of( org.sonar.db.dialect.H2.ID, H2, MsSql.ID, MSSQL, - MySql.ID, MYSQL, Oracle.ID, ORACLE, PostgreSql.ID, POSTGRESQL).get(dialect.getId()); @@ -132,17 +129,6 @@ public abstract class DatabaseCommands { } }; - private static final DatabaseCommands MYSQL = new DatabaseCommands(new MySqlDataTypeFactory()) { - @Override - public void resetPrimaryKeys(DataSource dataSource) { - } - - @Override - List<String> resetSequenceSql(String table, int minSequenceValue) { - return null; - } - }; - public void truncateDatabase(DataSource dataSource) throws SQLException { Connection connection = dataSource.getConnection(); Statement statement = null; diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DdlUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DdlUtilsTest.java index cd51a9e0e19..4972d77be33 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DdlUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DdlUtilsTest.java @@ -39,7 +39,7 @@ public class DdlUtilsTest { @Test public void shouldSupportOnlyH2() { Assertions.assertThat(DdlUtils.supportsDialect("h2")).isTrue(); - assertThat(DdlUtils.supportsDialect("mysql")).isFalse(); + assertThat(DdlUtils.supportsDialect("postgresql")).isFalse(); assertThat(DdlUtils.supportsDialect("oracle")).isFalse(); assertThat(DdlUtils.supportsDialect("mssql")).isFalse(); } diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/DialectUtilsTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/DialectUtilsTest.java index 433071998d9..b6a1196da77 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/DialectUtilsTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/DialectUtilsTest.java @@ -28,14 +28,14 @@ public class DialectUtilsTest { @Test public void testFindById() { - Dialect d = DialectUtils.find("mysql", null); - assertThat(d).isInstanceOf(MySql.class); + Dialect d = DialectUtils.find("postgresql", null); + assertThat(d).isInstanceOf(PostgreSql.class); } @Test public void testFindByJdbcUrl() { - Dialect d = DialectUtils.find(null, "jdbc:mysql:foo:bar"); - assertThat(d).isInstanceOf(MySql.class); + Dialect d = DialectUtils.find(null, "jdbc:postgresql:foo:bar"); + assertThat(d).isInstanceOf(PostgreSql.class); } @Test(expected = MessageException.class) diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java index fe7f8748859..44620116ba2 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MsSqlTest.java @@ -43,7 +43,6 @@ public class MsSqlTest { assertThat(underTest.matchesJdbcUrl("jdbc:sqlserver://localhost:1433;databasename=sonar")).isTrue(); assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); - assertThat(underTest.matchesJdbcUrl("jdbc:mysql:foo")).isFalse(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MySqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MySqlTest.java deleted file mode 100644 index 5982642cbfd..00000000000 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/MySqlTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.dialect; - -import java.sql.DatabaseMetaData; -import java.sql.SQLException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; -import org.sonar.api.utils.MessageException; -import org.sonar.api.utils.log.LogTester; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class MySqlTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Rule - public LogTester logs = new LogTester(); - - private MySql underTest = new MySql(); - - @Test - public void matchesJdbcURL() { - assertThat(underTest.matchesJdbcUrl("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8")).isTrue(); - assertThat(underTest.matchesJdbcUrl("JDBC:MYSQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8")).isTrue(); - - assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); - assertThat(underTest.matchesJdbcUrl("jdbc:oracle:foo")).isFalse(); - } - - @Test - public void testBooleanSqlValues() { - assertThat(underTest.getTrueSqlValue()).isEqualTo("true"); - assertThat(underTest.getFalseSqlValue()).isEqualTo("false"); - } - - @Test - public void should_configure() { - assertThat(underTest.getId()).isEqualTo("mysql"); - assertThat(underTest.getDefaultDriverClassName()).isEqualTo("com.mysql.jdbc.Driver"); - assertThat(underTest.getValidationQuery()).isEqualTo("SELECT 1"); - } - - @Test - public void testFetchSizeForScrolling() { - assertThat(underTest.getScrollDefaultFetchSize()).isEqualTo(Integer.MIN_VALUE); - assertThat(underTest.getScrollSingleRowFetchSize()).isEqualTo(Integer.MIN_VALUE); - } - - @Test - public void mysql_does_supportMigration() { - assertThat(underTest.supportsMigration()).isTrue(); - } - - @Test - public void getSqlFromDual() { - assertThat(underTest.getSqlFromDual()).isEqualTo("from dual"); - } - - @Test - public void init_throws_MessageException_if_mysql_5_5() throws Exception { - expectedException.expect(MessageException.class); - expectedException.expectMessage("Unsupported mysql version: 5.5. Minimal supported version is 5.6."); - - DatabaseMetaData metadata = newMetadata(5, 5); - underTest.init(metadata); - } - - @Test - public void init_does_not_fail_if_mysql_5_6() throws Exception { - DatabaseMetaData metadata = newMetadata(5, 6); - underTest.init(metadata); - } - - @Test - public void supportsUpsert_returns_false() { - assertThat(underTest.supportsUpsert()).isFalse(); - } - - private DatabaseMetaData newMetadata(int dbMajorVersion, int dbMinorVersion) throws SQLException { - DatabaseMetaData metadata = mock(DatabaseMetaData.class, Mockito.RETURNS_DEEP_STUBS); - when(metadata.getDatabaseMajorVersion()).thenReturn(dbMajorVersion); - when(metadata.getDatabaseMinorVersion()).thenReturn(dbMinorVersion); - return metadata; - } -} diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java index 60ef061987f..cc1477bca05 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/OracleTest.java @@ -56,7 +56,6 @@ public class OracleTest { @Test public void testFetchSizeForScrolling() { assertThat(underTest.getScrollDefaultFetchSize()).isEqualTo(200); - assertThat(underTest.getScrollSingleRowFetchSize()).isEqualTo(1); } @Test |