use of liquibase.statement.core.InsertStatement in project keycloak by keycloak.
the class JpaUpdate1_2_0_Beta1 method convertSocialToIdFedUsers.
protected void convertSocialToIdFedUsers() throws SQLException, DatabaseException {
String federatedIdentityTableName = database.correctObjectName("FEDERATED_IDENTITY", Table.class);
PreparedStatement statement = jdbcConnection.prepareStatement("select REALM_ID, USER_ID, SOCIAL_PROVIDER, SOCIAL_USER_ID, SOCIAL_USERNAME from " + getTableName("USER_SOCIAL_LINK"));
try {
ResultSet resultSet = statement.executeQuery();
try {
int count = 0;
while (resultSet.next()) {
InsertStatement insert = new InsertStatement(null, null, federatedIdentityTableName).addColumnValue("REALM_ID", resultSet.getString("REALM_ID")).addColumnValue("USER_ID", resultSet.getString("USER_ID")).addColumnValue("IDENTITY_PROVIDER", resultSet.getString("SOCIAL_PROVIDER")).addColumnValue("FEDERATED_USER_ID", resultSet.getString("SOCIAL_USER_ID")).addColumnValue("FEDERATED_USERNAME", resultSet.getString("SOCIAL_USERNAME"));
count++;
statements.add(insert);
}
confirmationMessage.append("Updating " + count + " social links to federated identities. ");
} finally {
resultSet.close();
}
} finally {
statement.close();
}
}
use of liquibase.statement.core.InsertStatement in project keycloak by keycloak.
the class JpaUpdate1_2_0_CR1 method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
String realmClientTableName = database.correctObjectName("REALM_CLIENT", Table.class);
try {
String trueValue = DataTypeFactory.getInstance().getTrueBooleanValue(database);
PreparedStatement statement = jdbcConnection.prepareStatement("select CLIENT.REALM_ID, CLIENT.ID CLIENT_ID from " + getTableName("CLIENT") + " CLIENT where CLIENT.CONSENT_REQUIRED = " + trueValue);
try {
ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
String realmId = resultSet.getString("REALM_ID");
String oauthClientId = resultSet.getString("CLIENT_ID");
InsertStatement realmClientInsert = new InsertStatement(null, null, realmClientTableName).addColumnValue("REALM_ID", realmId).addColumnValue("CLIENT_ID", oauthClientId);
statements.add(realmClientInsert);
}
} finally {
resultSet.close();
}
} finally {
statement.close();
}
confirmationMessage.append("Inserted " + statements.size() + " OAuth Clients to REALM_CLIENT table");
} catch (Exception e) {
throw new CustomChangeException(getTaskId() + ": Exception when updating data from previous version", e);
}
}
use of liquibase.statement.core.InsertStatement in project keycloak by keycloak.
the class JpaUpdate14_0_0_MigrateSamlArtifactAttribute method generateStatementsImpl.
@Override
protected void generateStatementsImpl() throws CustomChangeException {
extractClientsData("SELECT C.ID, C.CLIENT_ID FROM " + getTableName("CLIENT") + " C " + "LEFT JOIN " + getTableName("CLIENT_ATTRIBUTES") + " CA " + "ON C.ID = CA.CLIENT_ID AND CA.NAME='" + SAML_ARTIFACT_BINDING_IDENTIFIER + "' " + "WHERE C.PROTOCOL='saml' AND CA.NAME IS NULL");
for (Map.Entry<String, String> clientPair : clientIds.entrySet()) {
String id = clientPair.getKey();
String clientId = clientPair.getValue();
String samlIdentifier = computeArtifactBindingIdentifierString(clientId);
statements.add(new InsertStatement(null, null, database.correctObjectName("CLIENT_ATTRIBUTES", Table.class)).addColumnValue("CLIENT_ID", id).addColumnValue("NAME", SAML_ARTIFACT_BINDING_IDENTIFIER).addColumnValue("VALUE", samlIdentifier));
}
}
use of liquibase.statement.core.InsertStatement in project keycloak by keycloak.
the class CustomInsertLockRecordGenerator method generateSql.
@Override
public Sql[] generateSql(InitializeDatabaseChangeLogLockTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
// get the IDs that are already in the database if migration
Set<Integer> currentIds = new HashSet<>();
if (statement instanceof CustomInitializeDatabaseChangeLogLockTableStatement) {
currentIds = ((CustomInitializeDatabaseChangeLogLockTableStatement) statement).getCurrentIds();
}
// generate all the IDs that are currently missing in the lock table
List<Sql> result = new ArrayList<>();
for (DBLockProvider.Namespace lock : DBLockProvider.Namespace.values()) {
if (!currentIds.contains(lock.getId())) {
InsertStatement insertStatement = new InsertStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName()).addColumnValue("ID", lock.getId()).addColumnValue("LOCKED", Boolean.FALSE);
result.addAll(Arrays.asList(SqlGeneratorFactory.getInstance().generateSql(insertStatement, database)));
}
}
return result.toArray(new Sql[result.size()]);
}
use of liquibase.statement.core.InsertStatement in project openmrs-core by openmrs.
the class InsertWithUuidDataChangeTest method shouldNotModifyUuidValueIfColumnExists.
@Test
public void shouldNotModifyUuidValueIfColumnExists() {
InsertWithUuidDataChange dataChange = new InsertWithUuidDataChange();
String expected = "expected_value_for_UUID";
ColumnConfig uuid = new ColumnConfig(new Column("uuid"));
uuid.setValue(expected);
dataChange.addColumn(uuid);
SqlStatement[] statements = dataChange.generateStatements(new MySQLDatabase());
InsertStatement insertStatement = (InsertStatement) statements[0];
Object actual = insertStatement.getColumnValue("uuid");
assertEquals(expected, actual);
}
Aggregations