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);
}
}
Aggregations