From e1416b658fe808e57446787c167db2a14e37e877 Mon Sep 17 00:00:00 2001 From: mposolda Date: Wed, 27 Jan 2016 22:01:35 +0100 Subject: [PATCH] KEYCLOAK-1402 Postgresplus 9.4 support --- .../LiquibaseJpaUpdaterProvider.java | 4 ++ .../liquibase/PostgresPlusDatabase.java | 56 +++++++++++++++++++ testsuite/integration/pom.xml | 1 + 3 files changed, 61 insertions(+) create mode 100644 model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/PostgresPlusDatabase.java diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/LiquibaseJpaUpdaterProvider.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/LiquibaseJpaUpdaterProvider.java index 464e51f365..211c00eb21 100755 --- a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/LiquibaseJpaUpdaterProvider.java +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/LiquibaseJpaUpdaterProvider.java @@ -109,6 +109,10 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider { } LogFactory.setInstance(new LogWrapper()); + + // Adding PostgresPlus support to liquibase + DatabaseFactory.getInstance().register(new PostgresPlusDatabase()); + Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); if (defaultSchema != null) { database.setDefaultSchemaName(defaultSchema); diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/PostgresPlusDatabase.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/PostgresPlusDatabase.java new file mode 100644 index 0000000000..ffea018bcd --- /dev/null +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/updater/liquibase/PostgresPlusDatabase.java @@ -0,0 +1,56 @@ +package org.keycloak.connections.jpa.updater.liquibase; + +import liquibase.database.DatabaseConnection; +import liquibase.database.core.PostgresDatabase; +import liquibase.exception.DatabaseException; +import liquibase.executor.ExecutorService; +import liquibase.statement.core.RawSqlStatement; + +/** + * @author Marek Posolda + */ +public class PostgresPlusDatabase extends PostgresDatabase { + + public static final String POSTGRESPLUS_PRODUCT_NAME = "EnterpriseDB"; + + @Override + public String getShortName() { + return "postgresplus"; + } + + @Override + protected String getDefaultDatabaseProductName() { + return POSTGRESPLUS_PRODUCT_NAME; + } + + @Override + public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException { + return POSTGRESPLUS_PRODUCT_NAME.equalsIgnoreCase(conn.getDatabaseProductName()); + } + + @Override + public String getDefaultDriver(String url) { + String defaultDriver = super.getDefaultDriver(url); + + if (defaultDriver == null) { + if (url.startsWith("jdbc:edb:")) { + defaultDriver = "com.edb.Driver"; + } + } + + return defaultDriver; + } + + @Override + protected String getConnectionSchemaName() { + try { + String currentSchema = ExecutorService.getInstance().getExecutor(this) + .queryForObject(new RawSqlStatement("select current_schema"), String.class); + return currentSchema; + + } catch (Exception e) { + throw new RuntimeException("Failed to get current schema", e); + } + } + +} diff --git a/testsuite/integration/pom.xml b/testsuite/integration/pom.xml index 20f0387621..83596c4ea3 100755 --- a/testsuite/integration/pom.xml +++ b/testsuite/integration/pom.xml @@ -502,6 +502,7 @@ ${keycloak.connectionsJpa.password} false + ${keycloak.connectionsJpa.liquibaseDatabaseClass}