Merge pull request #2922 from mposolda/master

KEYCLOAK-2714 Remove the pre-liquibase workarounds
This commit is contained in:
Marek Posolda 2016-06-08 15:54:36 +02:00
commit f6d075fbe4
3 changed files with 5 additions and 36 deletions

View file

@ -166,20 +166,7 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
}
if (databaseSchema.equals("update")) {
String currentVersion = null;
try {
ResultSet resultSet = connection.createStatement().executeQuery(updater.getCurrentVersionSql(schema));
if (resultSet.next()) {
currentVersion = resultSet.getString(1);
}
} catch (SQLException e) {
}
if (currentVersion == null || !JpaUpdaterProvider.LAST_VERSION.equals(currentVersion)) {
updater.update(connection, schema);
} else {
logger.debug("Database is up to date");
}
} else if (databaseSchema.equals("validate")) {
updater.validate(connection, schema);
} else {

View file

@ -28,10 +28,6 @@ public interface JpaUpdaterProvider extends Provider {
public String FIRST_VERSION = "1.0.0.Final";
public String LAST_VERSION = "1.9.2";
public String getCurrentVersionSql(String defaultSchema);
public void update(Connection connection, String defaultSchema);
public void validate(Connection connection, String defaultSchema);

View file

@ -28,8 +28,6 @@ import org.keycloak.connections.jpa.updater.liquibase.conn.LiquibaseConnectionPr
import org.keycloak.models.KeycloakSession;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
/**
@ -48,11 +46,6 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
this.session = session;
}
@Override
public String getCurrentVersionSql(String defaultSchema) {
return "SELECT ID from " + getTable("DATABASECHANGELOG", defaultSchema) + " ORDER BY DATEEXECUTED DESC LIMIT 1";
}
@Override
public void update(Connection connection, String defaultSchema) {
logger.debug("Starting database update");
@ -66,15 +59,7 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
List<ChangeSet> changeSets = liquibase.listUnrunChangeSets((Contexts) null);
if (!changeSets.isEmpty()) {
if (changeSets.get(0).getId().equals(FIRST_VERSION)) {
Statement statement = connection.createStatement();
try {
statement.executeQuery("SELECT id FROM " + getTable("REALM", defaultSchema));
logger.infov("Updating database from {0} to {1}", FIRST_VERSION, changeSets.get(changeSets.size() - 1).getId());
liquibase.markNextChangeSetRan(null);
} catch (SQLException e) {
logger.info("Initializing database schema");
}
} else {
if (logger.isDebugEnabled()) {
List<RanChangeSet> ranChangeSets = liquibase.getDatabase().getRanChangeSetList();
@ -85,14 +70,15 @@ public class LiquibaseJpaUpdaterProvider implements JpaUpdaterProvider {
}
liquibase.update((Contexts) null);
logger.debug("Completed database update");
} else {
logger.debug("Database is up to date");
}
} catch (Exception e) {
throw new RuntimeException("Failed to update database", e);
} finally {
ThreadLocalSessionContext.removeCurrentSession();
}
logger.debug("Completed database update");
}
@Override