Search in sources :

Example 1 with JdbcTemplate

use of org.flywaydb.core.internal.jdbc.JdbcTemplate in project flyway by flyway.

the class CockroachDBDatabase method rawDetermineVersion.

private MigrationVersion rawDetermineVersion() {
    String version;
    try {
        // Use rawMainJdbcConnection to avoid infinite recursion.
        JdbcTemplate template = new JdbcTemplate(rawMainJdbcConnection);
        version = template.queryForString("SELECT value FROM crdb_internal.node_build_info where field='Version'");
        if (version == null) {
            version = template.queryForString("SELECT value FROM crdb_internal.node_build_info where field='Tag'");
        }
    } catch (SQLException e) {
        throw new FlywaySqlException("Unable to determine CockroachDB version", e);
    }
    int firstDot = version.indexOf(".");
    int majorVersion = Integer.parseInt(version.substring(1, firstDot));
    String minorPatch = version.substring(firstDot + 1);
    int minorVersion = Integer.parseInt(minorPatch.substring(0, minorPatch.indexOf(".")));
    return MigrationVersion.fromVersion(majorVersion + "." + minorVersion);
}
Also used : FlywaySqlException(org.flywaydb.core.internal.exception.FlywaySqlException) SQLException(java.sql.SQLException) JdbcTemplate(org.flywaydb.core.internal.jdbc.JdbcTemplate)

Aggregations

SQLException (java.sql.SQLException)1 FlywaySqlException (org.flywaydb.core.internal.exception.FlywaySqlException)1 JdbcTemplate (org.flywaydb.core.internal.jdbc.JdbcTemplate)1