lasdf1234 commented on code in PR #11057:
URL: https://github.com/apache/gravitino/pull/11057#discussion_r3226311282


##########
plugins/idp-basic/src/main/java/org/apache/gravitino/storage/provider/IdpBasicUserMetaProvider.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.provider;
+
+import com.google.common.base.Preconditions;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import org.apache.gravitino.storage.relational.mapper.IdpGroupUserRelMapper;
+import org.apache.gravitino.storage.relational.mapper.IdpUserMetaMapper;
+import org.apache.gravitino.storage.relational.po.IdpUserPO;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+
+/** The provider class for user metadata. It provides the basic database 
operations for user. */
+public class IdpBasicUserMetaProvider implements IdpUserMetaProvider {
+  private static final IdpBasicUserMetaProvider INSTANCE = new 
IdpBasicUserMetaProvider();
+
+  public static IdpBasicUserMetaProvider getInstance() {
+    return INSTANCE;
+  }
+
+  public IdpBasicUserMetaProvider() {}
+
+  @Override
+  public Optional<IdpUserPO> findUser(String userName) {
+    return Optional.ofNullable(
+        SessionUtils.getWithoutCommit(
+            IdpUserMetaMapper.class, mapper -> 
mapper.selectIdpUser(userName)));
+  }
+
+  @Override
+  public List<IdpUserPO> findUsers(List<String> userNames) {
+    if (userNames.isEmpty()) {
+      return Collections.emptyList();
+    }
+
+    return SessionUtils.getWithoutCommit(
+        IdpUserMetaMapper.class, mapper -> mapper.selectIdpUsers(userNames));
+  }

Review Comment:
   Resolved.



##########
plugins/idp-basic/src/main/java/org/apache/gravitino/storage/provider/IdpBasicGroupMetaProvider.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.provider;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+import org.apache.gravitino.storage.relational.mapper.IdpGroupMetaMapper;
+import org.apache.gravitino.storage.relational.mapper.IdpGroupUserRelMapper;
+import org.apache.gravitino.storage.relational.po.IdpGroupPO;
+import org.apache.gravitino.storage.relational.po.IdpGroupUserRelPO;
+import org.apache.gravitino.storage.relational.utils.SessionUtils;
+
+/** The provider class for group metadata. It provides the basic database 
operations for group. */
+public class IdpBasicGroupMetaProvider implements IdpGroupMetaProvider {
+  private static final IdpBasicGroupMetaProvider INSTANCE = new 
IdpBasicGroupMetaProvider();
+
+  public static IdpBasicGroupMetaProvider getInstance() {
+    return INSTANCE;
+  }
+
+  public IdpBasicGroupMetaProvider() {}
+
+  @Override
+  public Optional<IdpGroupPO> findGroup(String groupName) {
+    return Optional.ofNullable(
+        SessionUtils.getWithoutCommit(
+            IdpGroupMetaMapper.class, mapper -> 
mapper.selectIdpGroup(groupName)));
+  }
+
+  @Override
+  public List<String> listUserNames(String groupName) {
+    Optional<IdpGroupPO> group = findGroup(groupName);
+    if (!group.isPresent()) {
+      return Collections.emptyList();
+    }
+
+    return SessionUtils.getWithoutCommit(
+        IdpGroupUserRelMapper.class,
+        mapper -> mapper.selectUserNamesByGroupId(group.get().getGroupId()));
+  }
+
+  @Override
+  public void createGroup(IdpGroupPO groupPO) {
+    SessionUtils.doWithCommit(IdpGroupMetaMapper.class, mapper -> 
mapper.insertIdpGroup(groupPO));
+  }
+
+  @Override
+  public boolean deleteGroup(IdpGroupPO groupPO, Long deletedAt) {
+    SessionUtils.doMultipleWithCommit(
+        () ->
+            SessionUtils.doWithoutCommit(
+                IdpGroupMetaMapper.class,
+                mapper -> mapper.softDeleteIdpGroup(groupPO.getGroupId(), 
deletedAt)),
+        () ->
+            SessionUtils.doWithoutCommit(
+                IdpGroupUserRelMapper.class,
+                mapper -> 
mapper.softDeleteGroupUsersByGroupId(groupPO.getGroupId(), deletedAt)));
+    return true;
+  }
+
+  @Override
+  public List<Long> selectRelatedUserIds(Long groupId, List<Long> userIds) {
+    return SessionUtils.getWithoutCommit(
+        IdpGroupUserRelMapper.class, mapper -> 
mapper.selectRelatedUserIds(groupId, userIds));
+  }
+
+  @Override
+  public void addUsersToGroup(List<IdpGroupUserRelPO> relations) {
+    if (relations.isEmpty()) {
+      return;
+    }
+    SessionUtils.doWithCommit(
+        IdpGroupUserRelMapper.class, mapper -> 
mapper.batchInsertIdpGroupUsers(relations));
+  }
+
+  @Override
+  public void removeUsersFromGroup(Long groupId, List<Long> userIds, Long 
deletedAt) {
+    if (userIds.isEmpty()) {
+      return;
+    }
+
+    SessionUtils.doWithCommit(
+        IdpGroupUserRelMapper.class,
+        mapper -> mapper.softDeleteIdpGroupUsers(groupId, userIds, deletedAt));

Review Comment:
   Resolved.



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