use of liquibase.exception.CustomChangeException in project ORCID-Source by ORCID.
the class AdministrativeChangesOptionChangeTask method execute.
@Override
public void execute(Database database) throws CustomChangeException {
LOGGER.info("Running...");
final JdbcConnection conn = (JdbcConnection) database.getConnection();
try (PreparedStatement selectStatement = conn.prepareStatement(SELECT_SQL);
PreparedStatement updateStatement = conn.prepareStatement(UPDATE_SQL)) {
boolean done = false;
conn.setAutoCommit(false);
while (!done) {
LOGGER.info("Getting next batch...");
done = true;
ResultSet resultsSet = selectStatement.executeQuery();
while (resultsSet.next()) {
done = false;
String orcid = resultsSet.getString(1);
LOGGER.debug("Processing orcid: {}", orcid);
updateStatement.setString(1, orcid);
updateStatement.addBatch();
}
updateStatement.executeBatch();
conn.commit();
}
} catch (DatabaseException | SQLException e) {
throw new CustomChangeException("Problem populating administrative changes option", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class AbstractUserFedToComponent method convertFedProviderToComponent.
protected void convertFedProviderToComponent(String providerId, String newMapperType) throws CustomChangeException {
try {
PreparedStatement statement = jdbcConnection.prepareStatement("select ID, REALM_ID, PRIORITY, DISPLAY_NAME, FULL_SYNC_PERIOD, CHANGED_SYNC_PERIOD, LAST_SYNC from " + getTableName("USER_FEDERATION_PROVIDER") + " WHERE PROVIDER_NAME=?");
statement.setString(1, providerId);
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
int index = 1;
String id = resultSet.getString(index++);
String realmId = resultSet.getString(index++);
int priority = resultSet.getInt(index++);
String displayName = resultSet.getString(index++);
int fullSyncPeriod = resultSet.getInt(index++);
int changedSyncPeriod = resultSet.getInt(index++);
int lastSync = resultSet.getInt(index++);
InsertStatement insertComponent = new InsertStatement(null, null, database.correctObjectName("COMPONENT", Table.class)).addColumnValue("ID", id).addColumnValue("REALM_ID", realmId).addColumnValue("PARENT_ID", realmId).addColumnValue("NAME", displayName).addColumnValue("PROVIDER_ID", providerId).addColumnValue("PROVIDER_TYPE", UserStorageProvider.class.getName());
statements.add(insertComponent);
statements.add(componentConfigStatement(id, "priority", Integer.toString(priority)));
statements.add(componentConfigStatement(id, "fullSyncPeriod", Integer.toString(fullSyncPeriod)));
statements.add(componentConfigStatement(id, "changedSyncPeriod", Integer.toString(changedSyncPeriod)));
statements.add(componentConfigStatement(id, "lastSync", Integer.toString(lastSync)));
PreparedStatement configStatement = jdbcConnection.prepareStatement("select name, VALUE from " + getTableName("USER_FEDERATION_CONFIG") + " WHERE USER_FEDERATION_PROVIDER_ID=?");
configStatement.setString(1, id);
try {
ResultSet configSet = configStatement.executeQuery();
try {
while (configSet.next()) {
String name = configSet.getString(1);
String value = configSet.getString(2);
// logger.info("adding component config: " + name + ": " + value);
statements.add(componentConfigStatement(id, name, value));
}
} finally {
configSet.close();
}
} finally {
configStatement.close();
}
if (newMapperType != null) {
convertFedMapperToComponent(realmId, id, newMapperType);
}
DeleteStatement configDelete = new DeleteStatement(null, null, database.correctObjectName("USER_FEDERATION_CONFIG", Table.class));
configDelete.setWhere("USER_FEDERATION_PROVIDER_ID=?");
configDelete.addWhereParameters(id);
statements.add(configDelete);
DeleteStatement deleteStatement = new DeleteStatement(null, null, database.correctObjectName("USER_FEDERATION_PROVIDER", 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_PROVIDER table for " + providerId + " 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 JpaUpdate13_0_0_MigrateDefaultRoles method isRoleNameAvailable.
private boolean isRoleNameAvailable(String realmId, String roleName) throws CustomChangeException {
try (PreparedStatement statement = jdbcConnection.prepareStatement("SELECT ID FROM " + getTableName("KEYCLOAK_ROLE") + " WHERE REALM_ID=? AND NAME=?")) {
statement.setString(1, realmId);
statement.setString(2, roleName);
try (ResultSet rs = statement.executeQuery()) {
// name is available
return !rs.next();
}
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when extracting data from previous version", e);
}
}
use of liquibase.exception.CustomChangeException in project keycloak by keycloak.
the class JpaUpdate1_2_0_Beta1 method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
realmTableName = database.correctObjectName("REALM", Table.class);
try {
convertSocialToIdFedRealms();
convertSocialToIdFedUsers();
addAccessCodeLoginTimeout();
addNewAdminRoles();
addDefaultProtocolMappers();
} 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_4_0_Final method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
String userAttributeTableName = database.correctObjectName("USER_ATTRIBUTE", Table.class);
try {
PreparedStatement statement = jdbcConnection.prepareStatement("select NAME, USER_ID from " + getTableName("USER_ATTRIBUTE"));
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
String name = resultSet.getString(1);
String userId = resultSet.getString(2);
UpdateStatement updateStatement = new UpdateStatement(null, null, userAttributeTableName).addNewColumnValue("ID", KeycloakModelUtils.generateId()).setWhereClause("NAME='" + name + "' AND USER_ID='" + userId + "'");
statements.add(updateStatement);
}
} finally {
resultSet.close();
}
} finally {
statement.close();
}
confirmationMessage.append("Updated " + statements.size() + " attributes in USER_ATTRIBUTE table");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
Aggregations