From: Simon Brandhof Date: Tue, 3 Mar 2020 14:15:40 +0000 (+0100) Subject: SONAR-13155 Drop usage of commons-dbutils X-Git-Tag: 8.3.0.34182~125 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3351fb7e24c0c1e420cc7524029a735198f30ccf;p=sonarqube.git SONAR-13155 Drop usage of commons-dbutils except for unit tests --- diff --git a/server/sonar-db-core/build.gradle b/server/sonar-db-core/build.gradle index f8bb54ca373..2ab4e3e0148 100644 --- a/server/sonar-db-core/build.gradle +++ b/server/sonar-db-core/build.gradle @@ -10,7 +10,6 @@ dependencies { compile 'ch.qos.logback:logback-classic' compile 'ch.qos.logback:logback-core' compile 'com.google.guava:guava' - compile 'commons-dbutils:commons-dbutils' compile 'commons-io:commons-io' compile 'commons-lang:commons-lang' compile 'org.apache.commons:commons-dbcp2' @@ -37,6 +36,7 @@ dependencies { testRuntime 'com.oracle.jdbc:ojdbc8' testRuntime 'org.postgresql:postgresql' + testFixturesApi 'commons-dbutils:commons-dbutils' testFixturesApi 'junit:junit' testFixturesApi 'org.assertj:assertj-core' 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 02c4ad51fc7..40991c11ca9 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 @@ -30,7 +30,6 @@ import java.util.Properties; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.commons.dbcp2.BasicDataSourceFactory; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.config.Settings; import org.sonar.api.utils.log.Logger; @@ -118,7 +117,7 @@ public class DefaultDatabase implements Database { } catch (SQLException e) { throw new IllegalStateException("Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').", e); } finally { - DbUtils.closeQuietly(connection); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java b/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java index 0264b9d655a..bc6ab1f167b 100644 --- a/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java +++ b/server/sonar-db-core/src/main/java/org/sonar/db/ResultSetIterator.java @@ -25,7 +25,6 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; import java.util.NoSuchElementException; -import org.apache.commons.dbutils.DbUtils; /** * Forward-only {@link java.util.Iterator} over a {@link java.sql.ResultSet}. Rows are @@ -98,8 +97,8 @@ public abstract class ResultSetIterator implements Iterator, Closeable { @Override public void close() { closed = true; - DbUtils.closeQuietly(rs); - DbUtils.closeQuietly(stmt); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(stmt); } protected abstract E read(ResultSet rs) throws SQLException; diff --git a/server/sonar-db-dao/build.gradle b/server/sonar-db-dao/build.gradle index 2b0f2d86f6e..b443df09fd4 100644 --- a/server/sonar-db-dao/build.gradle +++ b/server/sonar-db-dao/build.gradle @@ -9,7 +9,6 @@ dependencies { compile 'com.google.guava:guava' compile 'com.google.protobuf:protobuf-java' - compile 'commons-dbutils:commons-dbutils' compile 'commons-io:commons-io' compile 'commons-lang:commons-lang' compile 'net.jpountz.lz4:lz4' @@ -23,6 +22,7 @@ dependencies { compileOnly 'com.google.code.findbugs:jsr305' testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'commons-dbutils:commons-dbutils' testCompile 'junit:junit' testCompile 'org.assertj:assertj-core' testCompile 'org.assertj:assertj-guava' diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java index ff006368b28..b2e3a0daf1d 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/source/FileSourceDao.java @@ -30,10 +30,10 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; import javax.annotation.CheckForNull; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.io.IOUtils; import org.apache.ibatis.session.ResultHandler; import org.sonar.db.Dao; +import org.sonar.db.DatabaseUtils; import org.sonar.db.DbSession; import static org.sonar.db.DatabaseUtils.toUniqueAndSortedPartitions; @@ -73,7 +73,9 @@ public class FileSourceDao implements Dao { } catch (SQLException e) { throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e); } finally { - DbUtils.closeQuietly(connection, pstmt, rs); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(pstmt); + DatabaseUtils.closeQuietly(connection); } } @@ -106,7 +108,9 @@ public class FileSourceDao implements Dao { throw new IllegalStateException("Fail to read FILE_SOURCES.LINE_HASHES of file " + fileUuid, e); } finally { IOUtils.closeQuietly(reader); - DbUtils.closeQuietly(connection, pstmt, rs); + DatabaseUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(pstmt); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java index 1c4ab5125a4..b04f133ee51 100644 --- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java +++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/SQDatabase.java @@ -24,7 +24,6 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.List; import javax.sql.DataSource; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.io.output.NullWriter; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; @@ -97,7 +96,7 @@ public class SQDatabase extends DefaultDatabase { } catch (SQLException e) { throw new IllegalStateException("Fail to create schema", e); } finally { - DbUtils.closeQuietly(connection); + DatabaseUtils.closeQuietly(connection); } } diff --git a/server/sonar-db-migration/build.gradle b/server/sonar-db-migration/build.gradle index 4dd9a0d0b58..b6d51d37714 100644 --- a/server/sonar-db-migration/build.gradle +++ b/server/sonar-db-migration/build.gradle @@ -11,7 +11,6 @@ dependencies { compile 'commons-lang:commons-lang' compile 'commons-codec:commons-codec' compile 'org.picocontainer:picocontainer' - compile 'commons-dbutils:commons-dbutils' compile project(':server:sonar-db-core') compile project(':server:sonar-process') @@ -21,6 +20,7 @@ dependencies { testCompile 'com.google.code.findbugs:jsr305' testCompile 'com.tngtech.java:junit-dataprovider' + testCompile 'commons-dbutils:commons-dbutils' testCompile 'junit:junit' testCompile 'org.assertj:assertj-core' testCompile 'org.mindrot:jbcrypt' diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java index 2d7af722ab9..e02bc9de48b 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/step/BaseSqlStatement.java @@ -25,7 +25,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Date; import javax.annotation.Nullable; -import org.apache.commons.dbutils.DbUtils; +import org.sonar.db.DatabaseUtils; class BaseSqlStatement implements SqlStatement { protected PreparedStatement pstmt; @@ -36,7 +36,7 @@ class BaseSqlStatement implements SqlStatement implements Select { @@ -47,7 +47,7 @@ public class SelectImpl extends BaseSqlStatement implements Select { } catch (Exception e) { throw newExceptionWithRowDetails(row, e); } finally { - DbUtils.closeQuietly(rs); + DatabaseUtils.closeQuietly(rs); close(); } } @@ -80,7 +80,7 @@ public class SelectImpl extends BaseSqlStatement