]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12273 use setNull(Double) for decimal column on all SGDBs
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 9 Jul 2019 15:48:30 +0000 (17:48 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 30 Jul 2019 18:24:27 +0000 (20:24 +0200)
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/DataChange.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/MassUpdate.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/SelectImpl.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/UpsertImpl.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/UpsertImplTest.java

index e3a3dbcd2e7f7dcd84087b67af0f3d09948a51a5..cdbe4c88638d12a0a48f556eb4bd1576e1d5edd9 100644 (file)
@@ -26,15 +26,11 @@ import java.sql.Types;
 import java.util.Date;
 import javax.annotation.Nullable;
 import org.apache.commons.dbutils.DbUtils;
-import org.sonar.db.dialect.Dialect;
-import org.sonar.db.dialect.MsSql;
 
 class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD> {
-  private final Dialect dialect;
   protected PreparedStatement pstmt;
 
-  protected BaseSqlStatement(Dialect dialect, PreparedStatement pstmt) {
-    this.dialect = dialect;
+  protected BaseSqlStatement(PreparedStatement pstmt) {
     this.pstmt = pstmt;
   }
 
@@ -99,7 +95,7 @@ class BaseSqlStatement<CHILD extends SqlStatement> implements SqlStatement<CHILD
   @SuppressWarnings("unchecked")
   public CHILD setDouble(int columnIndex, @Nullable Double value) throws SQLException {
     if (value == null) {
-      pstmt.setNull(columnIndex, MsSql.ID.equals(dialect.getId()) ? Types.DOUBLE : Types.DECIMAL);
+      pstmt.setNull(columnIndex, Types.DOUBLE);
     } else {
       pstmt.setDouble(columnIndex, value);
     }
index 292b06ae53501705bc14973e5513cf0ca21eb023..a6beab641fc40f1bed45ee360a565e6dc18a0d20 100644 (file)
@@ -83,7 +83,7 @@ public abstract class DataChange implements MigrationStep {
     }
 
     public Upsert prepareUpsert(String sql) throws SQLException {
-      return UpsertImpl.create(db, writeConnection, sql);
+      return UpsertImpl.create(writeConnection, sql);
     }
 
     public MassUpdate prepareMassUpdate() {
index d5ab64df4574cd0a0b6d7cdb57b1eeb325e60192..804cbeb0b25b3a0a64e092e30b71d92223b5da92 100644 (file)
@@ -73,7 +73,7 @@ public class MassUpdate {
   }
 
   public Upsert update(String sql) throws SQLException {
-    UpsertImpl upsert = UpsertImpl.create(db, writeConnection, sql);
+    UpsertImpl upsert = UpsertImpl.create(writeConnection, sql);
     this.updates.add(upsert);
     return upsert;
   }
index a079c08d4f9e969393d485c3675c4077bfdaffc0..4d0ef0f7916e2e5e9005db355f381d1b5a5d434a 100644 (file)
@@ -27,12 +27,11 @@ import java.util.ArrayList;
 import java.util.List;
 import org.apache.commons.dbutils.DbUtils;
 import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
 
 public class SelectImpl extends BaseSqlStatement<Select> implements Select {
 
-  private SelectImpl(Dialect dialect, PreparedStatement pstmt) {
-    super(dialect, pstmt);
+  private SelectImpl(PreparedStatement pstmt) {
+    super(pstmt);
   }
 
   @Override
@@ -94,6 +93,6 @@ public class SelectImpl extends BaseSqlStatement<Select> implements Select {
     // TODO use DbClient#newScrollingSelectStatement()
     PreparedStatement pstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
     pstmt.setFetchSize(db.getDialect().getScrollDefaultFetchSize());
-    return new SelectImpl(db.getDialect(), pstmt);
+    return new SelectImpl(pstmt);
   }
 }
index f1c4bd5525ebdd712febc3920e6c13b91c97233f..97007636427c10d1607221a1b2498729e852d22f 100644 (file)
@@ -22,8 +22,6 @@ package org.sonar.server.platform.db.migration.step;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
@@ -34,8 +32,8 @@ public class UpsertImpl extends BaseSqlStatement<Upsert> implements Upsert {
   private int maxBatchSize = MAX_BATCH_SIZE;
   private long batchCount = 0L;
 
-  private UpsertImpl(Dialect dialect, PreparedStatement pstmt) {
-    super(dialect, pstmt);
+  private UpsertImpl(PreparedStatement pstmt) {
+    super(pstmt);
   }
 
   @Override
@@ -82,7 +80,7 @@ public class UpsertImpl extends BaseSqlStatement<Upsert> implements Upsert {
     return this;
   }
 
-  public static UpsertImpl create(Database db, Connection connection, String sql) throws SQLException {
-    return new UpsertImpl(db.getDialect(), connection.prepareStatement(sql));
+  public static UpsertImpl create(Connection connection, String sql) throws SQLException {
+    return new UpsertImpl(connection.prepareStatement(sql));
   }
 }
index e4eb9e35641b2a6489f39aa5c15f603b2a5ff88b..4e64063e643edf01e25f371dbd35750440da0aab 100644 (file)
@@ -23,12 +23,9 @@ import java.sql.Connection;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.sonar.db.Database;
-import org.sonar.db.dialect.Dialect;
 
 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 public class UpsertImplTest {
 
@@ -71,8 +68,6 @@ public class UpsertImplTest {
   }
 
   private UpsertImpl create() throws Exception {
-    Database database = mock(Database.class);
-    when(database.getDialect()).thenReturn(mock(Dialect.class));
-    return UpsertImpl.create(database, mock(Connection.class), "sql");
+    return UpsertImpl.create(mock(Connection.class), "sql");
   }
 }