From baf76808d51a7f8d0fe6141fdb90cce55a7f1fd4 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Wed, 28 Feb 2024 12:32:50 +0530 Subject: [PATCH] fix: PR changes --- .../supertokens/storage/postgresql/Start.java | 4 +-- .../postgresql/queries/BulkImportQueries.java | 26 +++++-------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/Start.java b/src/main/java/io/supertokens/storage/postgresql/Start.java index ce0d27f2..75f60f89 100644 --- a/src/main/java/io/supertokens/storage/postgresql/Start.java +++ b/src/main/java/io/supertokens/storage/postgresql/Start.java @@ -3064,7 +3064,7 @@ public void addBulkImportUsers(AppIdentifier appIdentifier, List } @Override - public List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status, + public List getBulkImportUsers(AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BULK_IMPORT_USER_STATUS status, @Nullable String bulkImportUserId, @Nullable Long createdAt) throws StorageQueryException { try { return BulkImportQueries.getBulkImportUsers(this, appIdentifier, limit, status, bulkImportUserId, createdAt); @@ -3074,7 +3074,7 @@ public List getBulkImportUsers(AppIdentifier appIdentifier, @Non } @Override - public void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BulkImportUserStatus status) + public void updateBulkImportUserStatus_Transaction(AppIdentifier appIdentifier, TransactionConnection con, @Nonnull String[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status) throws StorageQueryException { Connection sqlCon = (Connection) con.getConnection(); try { diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java index 2566d923..44d05765 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java @@ -28,11 +28,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.google.gson.Gson; -import com.google.gson.JsonObject; - import io.supertokens.pluginInterface.RowMapper; -import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BulkImportUserStatus; +import io.supertokens.pluginInterface.bulkimport.BulkImportStorage.BULK_IMPORT_USER_STATUS; import io.supertokens.pluginInterface.bulkimport.BulkImportUser; import io.supertokens.pluginInterface.exceptions.StorageQueryException; import io.supertokens.pluginInterface.multitenancy.AppIdentifier; @@ -90,12 +87,12 @@ public static void insertBulkImportUsers(Start start, AppIdentifier appIdentifie for (BulkImportUser user : users) { pst.setString(parameterIndex++, user.id); pst.setString(parameterIndex++, appIdentifier.getAppId()); - pst.setString(parameterIndex++, user.toString()); + pst.setString(parameterIndex++, user.toRawDataForDbStorage()); } }); } - public static void updateBulkImportUserStatus_Transaction(Start start, Connection con, AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds, @Nonnull BulkImportUserStatus status) + public static void updateBulkImportUserStatus_Transaction(Start start, Connection con, AppIdentifier appIdentifier, @Nonnull String[] bulkImportUserIds, @Nonnull BULK_IMPORT_USER_STATUS status) throws SQLException, StorageQueryException { if (bulkImportUserIds.length == 0) { return; @@ -128,7 +125,7 @@ public static void updateBulkImportUserStatus_Transaction(Start start, Connectio }); } - public static List getBulkImportUsers(Start start, AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BulkImportUserStatus status, + public static List getBulkImportUsers(Start start, AppIdentifier appIdentifier, @Nonnull Integer limit, @Nullable BULK_IMPORT_USER_STATUS status, @Nullable String bulkImportUserId, @Nullable Long createdAt) throws SQLException, StorageQueryException { @@ -183,18 +180,9 @@ private static BulkImportUserRowMapper getInstance() { @Override public BulkImportUser map(ResultSet result) throws Exception { - JsonObject flattenedJson = new JsonObject(); - flattenedJson.addProperty("id", result.getString("id")); - flattenedJson.addProperty("status", result.getString("status")); - flattenedJson.addProperty("createdAt", result.getString("created_at")); - flattenedJson.addProperty("updatedAt", result.getString("updated_at")); - - JsonObject rawData = new Gson().fromJson(result.getString("raw_data"), JsonObject.class); - for (var entry : rawData.entrySet()) { - flattenedJson.add(entry.getKey(), entry.getValue()); - } - - return BulkImportUser.fromJson(flattenedJson); + return BulkImportUser.fromRawDataFromDbStorage(result.getString("id"), result.getString("raw_data"), + BULK_IMPORT_USER_STATUS.valueOf(result.getString("status")), + result.getLong("created_at"), result.getLong("updated_at")); } } }