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


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/storage/relational/po/IdpUserPO.java:
##########
@@ -0,0 +1,144 @@
+/*
+ * 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.po;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class IdpUserPO {
+  private Long userId;
+  private String userName;
+  private String passwordHash;
+  private Long currentVersion;
+  private Long lastVersion;
+  private Long deletedAt;
+
+  public Long getUserId() {
+    return userId;
+  }
+
+  public String getUserName() {
+    return userName;
+  }
+
+  public String getPasswordHash() {
+    return passwordHash;
+  }
+
+  public Long getCurrentVersion() {
+    return currentVersion;
+  }
+
+  public Long getLastVersion() {
+    return lastVersion;
+  }
+
+  public Long getDeletedAt() {
+    return deletedAt;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof IdpUserPO)) {
+      return false;
+    }
+    IdpUserPO userPO = (IdpUserPO) o;
+    return Objects.equal(getUserId(), userPO.getUserId())
+        && Objects.equal(getUserName(), userPO.getUserName())
+        && Objects.equal(getPasswordHash(), userPO.getPasswordHash())
+        && Objects.equal(getCurrentVersion(), userPO.getCurrentVersion())
+        && Objects.equal(getLastVersion(), userPO.getLastVersion())
+        && Objects.equal(getDeletedAt(), userPO.getDeletedAt());
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(
+        getUserId(),
+        getUserName(),
+        getPasswordHash(),
+        getCurrentVersion(),
+        getLastVersion(),
+        getDeletedAt());
+  }
+
+  public static class Builder {
+    private final IdpUserPO userPO;
+
+    private Builder() {
+      userPO = new IdpUserPO();
+    }
+
+    public Builder withUserId(Long userId) {
+      userPO.userId = userId;
+      return this;
+    }
+
+    public Builder withUserName(String userName) {
+      userPO.userName = userName;
+      return this;
+    }
+
+    public Builder withPasswordHash(String passwordHash) {
+      userPO.passwordHash = passwordHash;
+      return this;
+    }
+
+    public Builder withCurrentVersion(Long currentVersion) {
+      userPO.currentVersion = currentVersion;
+      return this;
+    }
+
+    public Builder withLastVersion(Long lastVersion) {
+      userPO.lastVersion = lastVersion;
+      return this;
+    }
+
+    public Builder withDeletedAt(Long deletedAt) {
+      userPO.deletedAt = deletedAt;
+      return this;
+    }
+
+    private void validate() {
+      Preconditions.checkArgument(userPO.userId != null, "User id is 
required");
+      Preconditions.checkArgument(userPO.userName != null, "User name is 
required");
+      Preconditions.checkArgument(userPO.passwordHash != null, "Password hash 
is required");
+      Preconditions.checkArgument(userPO.currentVersion != null, "Current 
version is required");
+      Preconditions.checkArgument(userPO.lastVersion != null, "Last version is 
required");
+      Preconditions.checkArgument(userPO.deletedAt != null, "Deleted at is 
required");
+    }
+
+    public IdpUserPO build() {
+      validate();
+      return userPO;
+    }
+  }

Review Comment:
   The builder holds a single mutable `IdpUserPO` instance and returns it 
directly from `build()`. If the same `Builder` instance is reused after calling 
`build()`, subsequent `withX(...)` calls will mutate the already-built object 
(because it’s the same reference), which can lead to very subtle data 
corruption. Consider making the builder create a new `IdpUserPO` on each 
`build()` (returning a copy), or make the builder one-shot by nulling/resetting 
internal state after `build()`.



##########
plugins/idp-basic/src/test/java/org/apache/gravitino/storage/relational/BackendTestExtension.java:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.sql.SQLException;
+import java.util.Comparator;
+import java.util.List;
+import java.util.UUID;
+import java.util.stream.Stream;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.Configs;
+import org.apache.gravitino.integration.test.util.BaseIT;
+import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper;
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.Extension;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
+import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
+
+class BackendTestExtension implements TestTemplateInvocationContextProvider {
+  private static final String DOCKER_TEST_FLAG = "dockerTest";
+
+  @Override
+  public boolean supportsTestTemplate(ExtensionContext context) {
+    return true;
+  }
+
+  @Override
+  public Stream<TestTemplateInvocationContext> 
provideTestTemplateInvocationContexts(
+      ExtensionContext context) {
+    List<String> backends =
+        "true".equalsIgnoreCase(System.getenv(DOCKER_TEST_FLAG))
+            ? List.of("h2", "mysql", "postgresql")
+            : List.of("h2");
+    return backends.stream().map(BackendInvocationContext::new);
+  }

Review Comment:
   The PR description shows running tests with `-PskipDockerTests=false`, but 
backend selection here is controlled by the `dockerTest` environment variable 
(not a Gradle property). As written, MySQL/PostgreSQL coverage will be skipped 
unless CI/exported env sets `dockerTest=true`. If the intent is to key off the 
existing Gradle flags, consider wiring this to the same mechanism used 
elsewhere in the build (e.g., a system property passed from Gradle), or update 
the documented test command to include `dockerTest=true`.



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/storage/relational/mapper/IdpUserMetaSQLProviderFactory.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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 com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.storage.relational.JDBCBackend.JDBCBackendType;
+import 
org.apache.gravitino.storage.relational.mapper.provider.base.IdpUserMetaBaseSQLProvider;
+import 
org.apache.gravitino.storage.relational.mapper.provider.h2.IdpUserMetaH2Provider;
+import 
org.apache.gravitino.storage.relational.mapper.provider.postgresql.IdpUserMetaPostgreSQLProvider;
+import org.apache.gravitino.storage.relational.po.IdpUserPO;
+import org.apache.gravitino.storage.relational.session.SqlSessionFactoryHelper;
+import org.apache.ibatis.annotations.Param;
+
+public class IdpUserMetaSQLProviderFactory {
+  private static final Map<JDBCBackendType, IdpUserMetaBaseSQLProvider>
+      IDP_USER_META_SQL_PROVIDER_MAP =
+          ImmutableMap.of(
+              JDBCBackendType.MYSQL, new IdpUserMetaMySQLProvider(),
+              JDBCBackendType.H2, new IdpUserMetaH2Provider(),
+              JDBCBackendType.POSTGRESQL, new IdpUserMetaPostgreSQLProvider());
+
+  public static IdpUserMetaBaseSQLProvider getProvider() {
+    String databaseId =
+        SqlSessionFactoryHelper.getInstance()
+            .getSqlSessionFactory()
+            .getConfiguration()
+            .getDatabaseId();
+
+    JDBCBackendType jdbcBackendType = JDBCBackendType.fromString(databaseId);
+    return IDP_USER_META_SQL_PROVIDER_MAP.get(jdbcBackendType);

Review Comment:
   `getProvider()` can return `null` (e.g., if `databaseId` is null/unset or 
`fromString(databaseId)` yields a backend not present in 
`IDP_USER_META_SQL_PROVIDER_MAP`). That will surface later as a 
`NullPointerException` when MyBatis invokes provider methods. Recommend failing 
fast with an explicit exception when the backend is unsupported/unrecognized 
(and include the resolved `databaseId`/backend type in the message), or provide 
a safe default provider if that’s intended.
   



-- 
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