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;
}
@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);
}
}
public Upsert prepareUpsert(String sql) throws SQLException {
- return UpsertImpl.create(db, writeConnection, sql);
+ return UpsertImpl.create(writeConnection, sql);
}
public MassUpdate prepareMassUpdate() {
}
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;
}
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
// 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);
}
}
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;
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
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));
}
}
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 {
}
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");
}
}