]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6552 Replace jTDS by Microsoft JDBC driver 4.1
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 17 Mar 2015 15:54:54 +0000 (16:54 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 17 Sep 2015 12:54:23 +0000 (14:54 +0200)
sonar-application/src/main/assembly/conf/sonar.properties
sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar [new file with mode: 0644]
sonar-application/src/main/java/org/sonar/application/JdbcSettings.java
sonar-application/src/test/java/org/sonar/application/JdbcSettingsTest.java
sonar-db/src/main/java/org/sonar/db/dialect/MsSql.java
sonar-db/src/test/java/org/sonar/db/dialect/MsSqlTest.java

index c4ac178e12bef9ce1eadf99873f5c9c15c9cae95..e9626756fffe7dc0be97ee06a880c5202ec59360 100644 (file)
@@ -43,9 +43,8 @@
 
 
 #----- Microsoft SQLServer 2008/2012
-# Only the bundled jTDS driver is supported.
 # Collation must be case-sensitive (CS) and accent-sensitive (AS).
-#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
+#sonar.jdbc.url=jdbc:sqlserver://localhost;databaseName=sonar
 
 
 #----- Connection pool settings
diff --git a/sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar b/sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar
new file mode 100644 (file)
index 0000000..5cb586c
Binary files /dev/null and b/sonar-application/src/main/assembly/lib/jdbc/mssql/sqljdbc41.jar differ
index 7794cb745b128fec57d44d4ae37279af43228a67..54fc71545b8cfd90787cf4ffa6216247a3179d60 100644 (file)
@@ -34,7 +34,7 @@ import org.sonar.process.Props;
 public class JdbcSettings {
 
   enum Provider {
-    H2("lib/jdbc/h2"), JTDS("lib/jdbc/jtds"), MYSQL("lib/jdbc/mysql"), ORACLE("extensions/jdbc-driver/oracle"),
+    H2("lib/jdbc/h2"), SQLSERVER("lib/jdbc/mssql"), MYSQL("lib/jdbc/mysql"), ORACLE("extensions/jdbc-driver/oracle"),
     POSTGRESQL("lib/jdbc/postgresql");
 
     final String path;
index 9e809a2aeab28c225f4580c79690a20d2ccc6fe1..eb418f9f4056d774c7df556107db6d508c8a8591 100644 (file)
@@ -46,10 +46,10 @@ public class JdbcSettingsTest {
     assertThat(settings.driverProvider("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance"))
       .isEqualTo(JdbcSettings.Provider.MYSQL);
     try {
-      settings.driverProvider("jdbc:sqlserver://localhost");
+      settings.driverProvider("jdbc:microsoft:sqlserver://localhost");
       fail();
     } catch (MessageException e) {
-      assertThat(e).hasMessage("Unsupported JDBC driver provider: sqlserver");
+      assertThat(e).hasMessage("Unsupported JDBC driver provider: microsoft");
     }
     try {
       settings.driverProvider("oracle:thin:@localhost/XE");
@@ -118,11 +118,11 @@ public class JdbcSettingsTest {
   @Test
   public void check_mssql() throws Exception {
     File home = temp.newFolder();
-    File driverFile = new File(home, "lib/jdbc/jtds/jtds.jar");
+    File driverFile = new File(home, "lib/jdbc/mssql/sqljdbc4.jar");
     FileUtils.touch(driverFile);
 
     Props props = new Props(new Properties());
-    props.set("sonar.jdbc.url", "jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor");
+    props.set("sonar.jdbc.url", "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor");
     settings.checkAndComplete(home, props);
     assertThat(props.nonNullValueAsFile(ProcessProperties.JDBC_DRIVER_PATH)).isEqualTo(driverFile);
   }
index d55139113c246dfb1ddf759b42c4516e31cc4d3d..27443bf49a1faceb1358caa30ca36bcf76d1ba02 100644 (file)
@@ -26,13 +26,12 @@ public class MsSql extends AbstractDialect {
   public static final String ID = "mssql";
 
   public MsSql() {
-    super(ID, "sqlserver", "net.sourceforge.jtds.jdbc.Driver", "1", "0", "SELECT 1");
+    super(ID, "sqlserver", "com.microsoft.sqlserver.jdbc.SQLServerDriver", "1", "0", "SELECT 1");
   }
 
   @Override
   public boolean matchesJdbcURL(String jdbcConnectionURL) {
-    return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:microsoft:sqlserver:")
-      || StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:jtds:sqlserver:");
+    return StringUtils.startsWithIgnoreCase(jdbcConnectionURL, "jdbc:sqlserver:");
   }
 
   @Override
index 3b1ebb14989718a3d62122827a78339f050e5206..f1159fc153c885850646b172c57c99461925b452 100644 (file)
@@ -29,8 +29,7 @@ public class MsSqlTest {
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(msSql.matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor")).isTrue();
-    assertThat(msSql.matchesJdbcURL("jdbc:microsoft:sqlserver://localhost:1433;databasename=sonar")).isTrue();
+    assertThat(msSql.matchesJdbcURL("jdbc:sqlserver://localhost:1433;databasename=sonar")).isTrue();
 
     assertThat(msSql.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
     assertThat(msSql.matchesJdbcURL("jdbc:mysql:foo")).isFalse();
@@ -46,10 +45,16 @@ public class MsSqlTest {
   public void should_configure() {
     assertThat(msSql.getId()).isEqualTo("mssql");
     assertThat(msSql.getActiveRecordDialectCode()).isEqualTo("sqlserver");
-    assertThat(msSql.getDefaultDriverClassName()).isEqualTo("net.sourceforge.jtds.jdbc.Driver");
+    assertThat(msSql.getDefaultDriverClassName()).isEqualTo("com.microsoft.sqlserver.jdbc.SQLServerDriver");
     assertThat(msSql.getValidationQuery()).isEqualTo("SELECT 1");
   }
 
+  @Test
+  public void do_not_support_jtds_since_5_2() throws Exception {
+    assertThat(msSql.matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor")).isFalse();
+
+  }
+
   @Test
   public void msSql_does_supportMigration() {
     assertThat(msSql.supportsMigration()).isTrue();