Copilot commented on code in PR #11066:
URL: https://github.com/apache/gravitino/pull/11066#discussion_r3231868048


##########
plugins/idp-basic/src/test/java/org/apache/gravitino/storage/relational/mapper/IdpMapperTestBase.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.storage.relational.mapper;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Comparator;
+import java.util.UUID;
+import java.util.stream.Stream;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.storage.relational.JDBCBackend;
+import org.apache.gravitino.storage.relational.po.IdpUserPO;
+import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper;
+import org.apache.ibatis.session.SqlSession;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+
+abstract class IdpMapperTestBase {
+  private static final String JDBC_STORE_PATH =
+      "/tmp/gravitino_jdbc_idpMappers_" + 
UUID.randomUUID().toString().replace("-", "");
+  private static final String DB_DIR = JDBC_STORE_PATH + "/testdb";
+
+  protected static JDBCBackend backend;
+  protected static SqlSession sharedSession;
+  protected static IdpUserMetaMapper idpUserMetaMapper;
+
+  @BeforeAll
+  static void setup() throws Exception {
+    File dir = new File(DB_DIR);
+    if (dir.exists()) {
+      deleteDirectory(dir.toPath());
+    }
+    dir.mkdirs();

Review Comment:
   `dir.mkdirs()` is not checked for failure here. If the directory cannot be 
created (permissions, disk issues), the tests will fail later with less 
actionable errors. Please check the return value (or use 
`Files.createDirectories`) and throw an IOException/RuntimeException with a 
clear message when creation fails.
   



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/IdpUserMetaBaseSQLProvider.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.storage.relational.mapper.provider.base;
+
+import java.util.List;
+import org.apache.gravitino.storage.relational.mapper.IdpUserMetaMapper;
+import org.apache.gravitino.storage.relational.po.IdpUserPO;
+import org.apache.ibatis.annotations.Param;
+
+public class IdpUserMetaBaseSQLProvider {
+
+  public String selectIdpUser(@Param("userName") String userName) {
+    return "SELECT user_id as userId, user_name as userName, password_hash as 
passwordHash,"
+        + " current_version as currentVersion,"
+        + " last_version as lastVersion, deleted_at as deletedAt"
+        + " FROM "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " WHERE user_name = #{userName} AND deleted_at = 0";
+  }
+
+  public String selectIdpUsers(@Param("userNames") List<String> userNames) {
+    return "<script>"
+        + "SELECT user_id as userId, user_name as userName, password_hash as 
passwordHash,"
+        + " current_version as currentVersion,"
+        + " last_version as lastVersion, deleted_at as deletedAt"
+        + " FROM "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " WHERE deleted_at = 0 "
+        + "<choose>"
+        + "<when test='userNames != null and userNames.size() > 0'>"
+        + "AND user_name IN ("
+        + "<foreach item='item' collection='userNames' separator=','>"
+        + "#{item}"
+        + "</foreach>"
+        + ") "
+        + "</when>"
+        + "<otherwise>"
+        + "AND 1 = 0 "
+        + "</otherwise>"
+        + "</choose>"
+        + "</script>";
+  }
+
+  public String insertIdpUser(@Param("userMeta") IdpUserPO userPO) {
+    return "INSERT INTO "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " (user_id, user_name, password_hash, current_version, last_version, 
deleted_at)"
+        + " VALUES ("
+        + " #{userMeta.userId},"
+        + " #{userMeta.userName},"
+        + " #{userMeta.passwordHash},"
+        + " #{userMeta.currentVersion},"
+        + " #{userMeta.lastVersion},"
+        + " #{userMeta.deletedAt}"
+        + " )";
+  }
+
+  public String updateIdpUserPassword(
+      @Param("userId") Long userId,
+      @Param("passwordHash") String passwordHash,
+      @Param("currentVersion") Long currentVersion,
+      @Param("newCurrentVersion") Long newCurrentVersion,
+      @Param("newLastVersion") Long newLastVersion) {
+    return "UPDATE "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " SET password_hash = #{passwordHash},"
+        + " current_version = #{newCurrentVersion},"
+        + " last_version = #{newLastVersion}"
+        + " WHERE user_id = #{userId}"
+        + " AND current_version = #{currentVersion}"
+        + " AND deleted_at = 0";
+  }
+
+  public String softDeleteIdpUser(
+      @Param("userId") Long userId, @Param("deletedAt") Long deletedAt) {
+    return "UPDATE "
+        + IdpUserMetaMapper.IDP_USER_TABLE_NAME
+        + " SET deleted_at = #{deletedAt},"

Review Comment:
   softDeleteIdpUser currently requires the caller to provide deletedAt and 
sets `deleted_at = #{deletedAt}`. In the rest of the relational storage layer, 
soft-delete timestamps are typically generated by the database (e.g., via 
`UNIX_TIMESTAMP()` in base providers and `EXTRACT(EPOCH ...)` in PostgreSQL 
providers), which avoids cross-backend semantic drift and removes a required 
input from call sites. Consider switching this SQL to a DB-generated timestamp 
(and then removing the `deletedAt` parameter from the mapper/factory API), 
keeping PostgreSQL as an override only for syntax differences.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to