Search in sources :

Example 36 with DatabaseConnection

use of liquibase.database.DatabaseConnection in project keycloak by keycloak.

the class CustomForeignKeySnapshotGenerator method driverUsesSpFkeys.

/*
    * Sql server JDBC drivers prior to 6.3.3 used sp_fkeys to determine the delete/cascade metadata.
    * The sp_fkeys stored procedure spec says that returned integer values of 0, 1, 2, or 4
    * translate to cascade, noAction, SetNull, or SetDefault which are not the values in the JDBC
    * standard.
    *
    * If this method returns true, the sp_fkeys values should be used. Otherwise use the standard jdbc logic
    *
    * The change in logic went in with https://github.com/Microsoft/mssql-jdbc/pull/490
    */
private boolean driverUsesSpFkeys(Database database) throws DatabaseException {
    if (!(database instanceof MSSQLDatabase)) {
        return false;
    }
    DatabaseConnection connection = database.getConnection();
    if (!(connection instanceof JdbcConnection)) {
        return false;
    }
    try {
        DatabaseMetaData metaData = ((JdbcConnection) connection).getMetaData();
        int driverMajorVersion = metaData.getDriverMajorVersion();
        int driverMinorVersion = metaData.getDriverMinorVersion();
        String driverName = metaData.getDriverName();
        if (!driverName.startsWith("Microsoft")) {
            return false;
        }
        return !(driverMajorVersion > 6 || (driverMajorVersion == 6 && driverMinorVersion >= 3));
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DatabaseConnection(liquibase.database.DatabaseConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) DatabaseMetaData(java.sql.DatabaseMetaData) DatabaseException(liquibase.exception.DatabaseException)

Aggregations

DatabaseConnection (liquibase.database.DatabaseConnection)36 JdbcConnection (liquibase.database.jvm.JdbcConnection)20 DatabaseException (liquibase.exception.DatabaseException)15 OfflineConnection (liquibase.database.OfflineConnection)12 Database (liquibase.database.Database)11 SQLException (java.sql.SQLException)10 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)5 RawSqlStatement (liquibase.statement.core.RawSqlStatement)5 Test (org.junit.Test)5 Statement (java.sql.Statement)4 DatabaseFactory (liquibase.database.DatabaseFactory)4 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)4 CallableStatement (java.sql.CallableStatement)3 Connection (java.sql.Connection)3 Liquibase (liquibase.Liquibase)3 PostgresDatabase (liquibase.database.core.PostgresDatabase)3 SqlStatement (liquibase.statement.SqlStatement)3 Method (java.lang.reflect.Method)2 BigInteger (java.math.BigInteger)2 DatabaseMetaData (java.sql.DatabaseMetaData)2