diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-03-15 10:14:26 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-03-16 19:42:59 +0100 |
commit | 13f9918a47199fdbd35261e49e6d15b5c8bfdc36 (patch) | |
tree | 577388e3d55a34cd20b89d3456f2be906822fbd3 /sonar-db | |
parent | 17402317a7bff902f6e1311da38f2cdc16a10f87 (diff) | |
download | sonarqube-13f9918a47199fdbd35261e49e6d15b5c8bfdc36.tar.gz sonarqube-13f9918a47199fdbd35261e49e6d15b5c8bfdc36.zip |
SONAR-7458 new component org.sonar.api.utils.Version
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java b/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java index eb436a8a155..d4ce26de573 100644 --- a/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java +++ b/sonar-db/src/main/java/org/sonar/db/DatabaseChecker.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.picocontainer.Startable; import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.Version; import org.sonar.api.utils.log.Loggers; import org.sonar.db.dialect.H2; import org.sonar.db.dialect.MsSql; @@ -44,10 +45,10 @@ public class DatabaseChecker implements Startable { // MsSQL 2012 is 11.x // MsSQL 2014 is 12.x // https://support.microsoft.com/en-us/kb/321185 - MsSql.ID, new Version(10, 0), - MySql.ID, new Version(5, 6), - Oracle.ID, new Version(11, 0), - PostgreSql.ID, new Version(8, 0)); + MsSql.ID, Version.create(10, 0, 0), + MySql.ID, Version.create(5, 6, 0), + Oracle.ID, Version.create(11, 0, 0), + PostgreSql.ID, Version.create(8, 0, 0)); private final Database db; @@ -82,8 +83,8 @@ public class DatabaseChecker implements Startable { try (Connection connection = db.getDataSource().getConnection()) { int dbMajorVersion = connection.getMetaData().getDatabaseMajorVersion(); int dbMinorVersion = connection.getMetaData().getDatabaseMinorVersion(); - Version dbVersion = new Version(dbMajorVersion, dbMinorVersion); - if (!dbVersion.isGreaterThanOrEqual(minDbVersion)) { + Version dbVersion = Version.create(dbMajorVersion, dbMinorVersion, 0); + if (dbVersion.compareTo(minDbVersion) < 0) { throw MessageException.of(String.format( "Unsupported %s version: %s. Minimal supported version is %s.", db.getDialect().getId(), dbVersion, minDbVersion)); } @@ -102,23 +103,4 @@ public class DatabaseChecker implements Startable { } } } - - private static class Version { - private final int major; - private final int minor; - - public Version(int major, int minor) { - this.major = major; - this.minor = minor; - } - - public boolean isGreaterThanOrEqual(Version other) { - return major >= other.major && (major != other.major || minor >= other.minor); - } - - @Override - public String toString() { - return new StringBuilder().append(major).append(".").append(minor).toString(); - } - } } |