HHH-14446 Add PostgresqlDatabaseCleaner checks
Since the PostgreSQL JDBC driver is also used for CockroachDB, we need to test explicitly if the database is indeed PostgreSQL.
This commit is contained in:
parent
0d140cc30c
commit
6cead49fec
|
@ -31,7 +31,8 @@ public class PostgreSQLDatabaseCleaner implements DatabaseCleaner {
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(Connection connection) {
|
public boolean isApplicable(Connection connection) {
|
||||||
try {
|
try {
|
||||||
return connection.getMetaData().getDatabaseProductName().startsWith( "PostgreSQL" );
|
return connection.getMetaData().getDatabaseProductName().startsWith( "PostgreSQL" )
|
||||||
|
&& isPostgresql( connection );
|
||||||
}
|
}
|
||||||
catch (SQLException e) {
|
catch (SQLException e) {
|
||||||
throw new RuntimeException( "Could not resolve the database metadata!", e );
|
throw new RuntimeException( "Could not resolve the database metadata!", e );
|
||||||
|
@ -211,4 +212,19 @@ public class PostgreSQLDatabaseCleaner implements DatabaseCleaner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need this check to differentiate between Postgresql and Cockroachdb
|
||||||
|
private boolean isPostgresql(Connection connection) {
|
||||||
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
ResultSet rs = stmt.executeQuery( "select version() " );
|
||||||
|
while ( rs.next() ) {
|
||||||
|
String version = rs.getString( 1 );
|
||||||
|
return version.contains( "PostgreSQL" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
throw new RuntimeException( e );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue