use of com.google.gerrit.server.account.HashedPassword in project gerrit by GerritCodeReview.
the class Schema_142 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
try (PreparedStatement updateStmt = ((JdbcSchema) db).getConnection().prepareStatement("UPDATE account_external_ids " + "SET password = ? " + "WHERE external_id = ?")) {
int batchCount = 0;
try (Statement stmt = newStatement(db);
ResultSet rs = stmt.executeQuery("SELECT external_id, password FROM account_external_ids")) {
while (rs.next()) {
String externalId = rs.getString("external_id");
String password = rs.getString("password");
if (!ExternalId.Key.parse(externalId).isScheme(SCHEME_USERNAME) || Strings.isNullOrEmpty(password)) {
continue;
}
HashedPassword hashed = HashedPassword.fromPassword(password);
updateStmt.setString(1, hashed.encode());
updateStmt.setString(2, externalId);
updateStmt.addBatch();
batchCount++;
if (batchCount >= MAX_BATCH_SIZE) {
updateStmt.executeBatch();
batchCount = 0;
}
}
}
if (batchCount > 0) {
updateStmt.executeBatch();
}
}
}
Aggregations