Search in sources :

Example 1 with HashedPassword

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();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashedPassword(com.google.gerrit.server.account.HashedPassword)

Aggregations

HashedPassword (com.google.gerrit.server.account.HashedPassword)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1