use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class AbstractUserFedToComponent method convertFedMapperToComponent.
protected void convertFedMapperToComponent(String realmId, String parentId, String newMapperType) throws CustomChangeException {
try {
PreparedStatement statement = jdbcConnection.prepareStatement("select ID, NAME, FEDERATION_MAPPER_TYPE from " + getTableName("USER_FEDERATION_MAPPER") + " WHERE FEDERATION_PROVIDER_ID=?");
statement.setString(1, parentId);
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
String id = resultSet.getString(1);
String mapperName = resultSet.getString(2);
String fedMapperType = resultSet.getString(3);
InsertStatement insertComponent = new InsertStatement(null, null, database.correctObjectName("COMPONENT", Table.class)).addColumnValue("ID", id).addColumnValue("REALM_ID", realmId).addColumnValue("PARENT_ID", parentId).addColumnValue("NAME", mapperName).addColumnValue("PROVIDER_ID", fedMapperType).addColumnValue("PROVIDER_TYPE", newMapperType);
statements.add(insertComponent);
PreparedStatement configStatement = jdbcConnection.prepareStatement("select name, VALUE from " + getTableName("USER_FEDERATION_MAPPER_CONFIG") + " WHERE USER_FEDERATION_MAPPER_ID=?");
configStatement.setString(1, id);
try {
ResultSet configSet = configStatement.executeQuery();
try {
while (configSet.next()) {
String name = configSet.getString(1);
String value = configSet.getString(2);
statements.add(componentConfigStatement(id, name, value));
}
} finally {
configSet.close();
}
} finally {
configStatement.close();
}
DeleteStatement configDelete = new DeleteStatement(null, null, database.correctObjectName("USER_FEDERATION_MAPPER_CONFIG", Table.class));
configDelete.setWhere("USER_FEDERATION_MAPPER_ID=?");
configDelete.addWhereParameters(id);
statements.add(configDelete);
DeleteStatement deleteStatement = new DeleteStatement(null, null, database.correctObjectName("USER_FEDERATION_MAPPER", Table.class));
deleteStatement.setWhere("ID=?");
deleteStatement.addWhereParameters(id);
statements.add(deleteStatement);
}
} finally {
resultSet.close();
}
} finally {
statement.close();
}
confirmationMessage.append("Updated " + statements.size() + " records in USER_FEDERATION_MAPPER table for " + parentId + " conversion to component model");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class AuthzResourceUseMoreURIs method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
try {
PreparedStatement statement = jdbcConnection.prepareStatement("select ID,URI from " + getTableName("RESOURCE_SERVER_RESOURCE") + " where URI is not null");
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
String resourceId = resultSet.getString(1);
String resourceUri = resultSet.getString(2);
InsertStatement insertComponent = new InsertStatement(null, null, database.correctObjectName("RESOURCE_URIS", Table.class)).addColumnValue("RESOURCE_ID", resourceId).addColumnValue("VALUE", resourceUri);
statements.add(insertComponent);
}
} finally {
resultSet.close();
}
} finally {
statement.close();
}
confirmationMessage.append("Moved " + statements.size() + " records from RESOURCE_SERVER_RESOURCE to RESOURCE_URIS table");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class JpaUpdate1_9_0_Final method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
String userFederationProviderTableName = database.correctObjectName("USER_FEDERATION_PROVIDER", Table.class);
try {
PreparedStatement statement = jdbcConnection.prepareStatement("select REALM_ID, USERFEDERATIONPROVIDERS_ID from " + getTableName("FED_PROVIDERS"));
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
String realmId = resultSet.getString(1);
String userFederationProviderId = resultSet.getString(2);
UpdateStatement updateStatement = new UpdateStatement(null, null, userFederationProviderTableName).addNewColumnValue("REALM_ID", realmId).setWhereClause("ID='" + userFederationProviderId + "'");
statements.add(updateStatement);
}
} finally {
resultSet.close();
}
} finally {
statement.close();
}
confirmationMessage.append("Updated " + statements.size() + " records in USER_FEDERATION_PROVIDER table");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class JpaUpdate4_7_0_OfflineSessionsTimestamps method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
String offlineUserSessionsTableName = database.correctObjectName("OFFLINE_USER_SESSION", Table.class);
try {
int currentTime = Time.currentTime();
UpdateStatement updateStatement = new UpdateStatement(null, null, offlineUserSessionsTableName).addNewColumnValue("LAST_SESSION_REFRESH", currentTime);
statements.add(updateStatement);
confirmationMessage.append("Updated column LAST_SESSION_REFRESH in OFFLINE_USER_SESSION table with time " + currentTime);
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class JpaUpdate4_0_0_DefaultClientScopes method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
String clientTableName = database.correctObjectName("CLIENT", Table.class);
String clientScopeClientTableName = database.correctObjectName("CLIENT_SCOPE_CLIENT", Table.class);
try (PreparedStatement statement = jdbcConnection.prepareStatement("SELECT ID, CLIENT_TEMPLATE_ID FROM " + clientTableName);
ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String clientId = rs.getString(1);
String clientTemplateId = rs.getString(2);
if (clientId == null || clientId.trim().isEmpty()) {
continue;
}
if (clientTemplateId == null || clientTemplateId.trim().isEmpty()) {
continue;
}
statements.add(new InsertStatement(null, null, clientScopeClientTableName).addColumnValue("CLIENT_ID", clientId.trim()).addColumnValue("SCOPE_ID", clientTemplateId.trim()).addColumnValue("DEFAULT_SCOPE", Boolean.TRUE));
}
confirmationMessage.append("Updated " + statements.size() + " records in CLIENT_SCOPE_CLIENT table");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
Aggregations