Skip to content

Commit

Permalink
fix: PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Feb 27, 2024
1 parent f271b94 commit 639ef0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ static int update(Start start, String QUERY, PreparedStatementValueSetter setter
}
}

static <T> T update(Start start, String QUERY, PreparedStatementValueSetter setter, ResultSetValueExtractor<T> mapper)
throws SQLException, StorageQueryException {
try (Connection con = ConnectionPool.getConnection(start)) {
try (PreparedStatement pst = con.prepareStatement(QUERY)) {
setter.setValues(pst);
try (ResultSet result = pst.executeQuery()) {
return mapper.extract(result);
}
}
}
}

static int update(Connection con, String QUERY, PreparedStatementValueSetter setter)
throws SQLException, StorageQueryException {
try (PreparedStatement pst = con.prepareStatement(QUERY)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -3086,9 +3086,9 @@ public void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier,
}

@Override
public void deleteBulkImportUsers(AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws StorageQueryException {
public List<String> deleteBulkImportUsers(AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws StorageQueryException {
try {
BulkImportQueries.deleteFailedBulkImportUsers(this, appIdentifier, bulkImportUserIds);
return BulkImportQueries.deleteBulkImportUsers(this, appIdentifier, bulkImportUserIds);
} catch (SQLException e) {
throw new StorageQueryException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public static List<BulkImportUserInfo> getBulkImportUsers(Start start, AppIdenti
});
}

public static void deleteFailedBulkImportUsers(Start start, AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws SQLException, StorageQueryException {
public static List<String> deleteBulkImportUsers(Start start, AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds) throws SQLException, StorageQueryException {
if (bulkImportUserIds.length == 0) {
return;
return new ArrayList<>();
}

String baseQuery = "DELETE FROM " + Config.getConfig(start).getBulkImportUsersTable();
Expand All @@ -190,14 +190,20 @@ public static void deleteFailedBulkImportUsers(Start start, AppIdentifier appIde
queryBuilder.append("?");
parameters.add(bulkImportUserIds[i]);
}
queryBuilder.append(")");
queryBuilder.append(") RETURNING id");

String query = queryBuilder.toString();

update(start, query, pst -> {
return update(start, query, pst -> {
for (int i = 0; i < parameters.size(); i++) {
pst.setObject(i + 1, parameters.get(i));
}
}, result -> {
List<String> deletedUserIds = new ArrayList<>();
while (result.next()) {
deletedUserIds.add(result.getString("id"));
}
return deletedUserIds;
});
}
private static class BulkImportUserInfoRowMapper implements RowMapper<BulkImportUserInfo, ResultSet> {
Expand Down

0 comments on commit 639ef0d

Please sign in to comment.