diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2018-10-28 23:20:02 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-10-30 20:21:25 +0100 |
commit | c9d72ec34409a3ebbf6f14ef6b9c427d0ec6565d (patch) | |
tree | 7d523c9349b3019671dacf9924145d6ba5ebc1d6 | |
parent | 3a36d3979ca1971e4625e5cfd8a145aa3eb47044 (diff) | |
download | sonarqube-c9d72ec34409a3ebbf6f14ef6b9c427d0ec6565d.tar.gz sonarqube-c9d72ec34409a3ebbf6f14ef6b9c427d0ec6565d.zip |
SONARCLOUD-161 improve Dialect#matchesJdbcUrl()
12 files changed, 22 insertions, 25 deletions
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 960329858fe..81bc2ecac6f 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 @@ -29,12 +29,9 @@ public interface Dialect { String getId(); /** - * Used to autodetect a dialect for a given driver URL - * - * @param jdbcConnectionURL a jdbc driver url such as jdbc:mysql://localhost:3306/sonar - * @return true if the dialect supports surch url + * Used to autodetect dialect from connection URL */ - boolean matchesJdbcURL(String jdbcConnectionURL); + boolean matchesJdbcUrl(String jdbcConnectionURL); /** * @since 2.13 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 abe02c45aae..8ecd7cb83cd 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 @@ -40,7 +40,7 @@ public final class DialectUtils { } private static Optional<Dialect> findByJdbcUrl(String jdbcConnectionUrl) { - return findDialect(dialect -> dialect != null && dialect.matchesJdbcURL(StringUtils.trimToEmpty(jdbcConnectionUrl))); + return findDialect(dialect -> dialect != null && dialect.matchesJdbcUrl(StringUtils.trimToEmpty(jdbcConnectionUrl))); } private static Optional<Dialect> findById(String dialectId) { diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/H2.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/H2.java index 02d609363b7..19451197ed2 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/H2.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/H2.java @@ -30,7 +30,7 @@ public class H2 extends AbstractDialect { } @Override - public boolean matchesJdbcURL(String jdbcConnectionURL) { + public boolean matchesJdbcUrl(String jdbcConnectionURL) { return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:h2:"); } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MsSql.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MsSql.java index 59372ab9c3a..416ac8cca35 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MsSql.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/MsSql.java @@ -30,7 +30,7 @@ public class MsSql extends AbstractDialect { } @Override - public boolean matchesJdbcURL(String jdbcConnectionURL) { + public boolean matchesJdbcUrl(String jdbcConnectionURL) { return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:sqlserver:"); } 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 index 9c2629062d2..cf0e4bcda9c 100644 --- 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 @@ -30,7 +30,7 @@ public class MySql extends AbstractDialect { } @Override - public boolean matchesJdbcURL(String jdbcConnectionURL) { + public boolean matchesJdbcUrl(String jdbcConnectionURL) { return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:mysql:"); } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java index d31432ecd4c..59a7e61a5f9 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/Oracle.java @@ -33,7 +33,7 @@ public class Oracle extends AbstractDialect { } @Override - public boolean matchesJdbcURL(String jdbcConnectionURL) { + public boolean matchesJdbcUrl(String jdbcConnectionURL) { return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:oracle:"); } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java index 1a295e40232..9e19910575e 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/dialect/PostgreSql.java @@ -33,7 +33,7 @@ public class PostgreSql extends AbstractDialect { } @Override - public boolean matchesJdbcURL(String jdbcConnectionURL) { + public boolean matchesJdbcUrl(String jdbcConnectionURL) { return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:postgresql:"); } diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java index 064c48fa259..1ed49200180 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/H2Test.java @@ -29,8 +29,8 @@ public class H2Test { @Test public void matchesJdbcURL() { - assertThat(underTest.matchesJdbcURL("jdbc:h2:foo")).isTrue(); - assertThat(underTest.matchesJdbcURL("jdbc:hsql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:h2:foo")).isTrue(); + assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); } @Test 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 6785f0bc126..1f12cc186d7 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 @@ -29,10 +29,10 @@ public class MsSqlTest { @Test public void matchesJdbcURL() { - assertThat(underTest.matchesJdbcURL("jdbc:sqlserver://localhost:1433;databasename=sonar")).isTrue(); + assertThat(underTest.matchesJdbcUrl("jdbc:sqlserver://localhost:1433;databasename=sonar")).isTrue(); - assertThat(underTest.matchesJdbcURL("jdbc:hsql:foo")).isFalse(); - assertThat(underTest.matchesJdbcURL("jdbc:mysql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:mysql:foo")).isFalse(); } @Test @@ -50,7 +50,7 @@ public class MsSqlTest { @Test public void do_not_support_jtds_since_5_2() { - assertThat(underTest.matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor")).isFalse(); } 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 index f9004ec9679..7ebc61f278d 100644 --- 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 @@ -29,11 +29,11 @@ public class MySqlTest { @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: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(); + assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:oracle:foo")).isFalse(); } @Test 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 f2a2e3a502a..0f596b49a5e 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 @@ -29,8 +29,8 @@ public class OracleTest { @Test public void matchesJdbcURL() { - assertThat(underTest.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE")).isTrue(); - assertThat(underTest.matchesJdbcURL("jdbc:hsql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:oracle:thin:@localhost/XE")).isTrue(); + assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); } @Test diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java index ef2ffadd329..f0b9576ee4e 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/dialect/PostgreSqlTest.java @@ -29,8 +29,8 @@ public class PostgreSqlTest { @Test public void matchesJdbcURL() { - assertThat(underTest.matchesJdbcURL("jdbc:postgresql://localhost/sonar")).isTrue(); - assertThat(underTest.matchesJdbcURL("jdbc:hsql:foo")).isFalse(); + assertThat(underTest.matchesJdbcUrl("jdbc:postgresql://localhost/sonar")).isTrue(); + assertThat(underTest.matchesJdbcUrl("jdbc:hsql:foo")).isFalse(); } @Test |