You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jerqi (via GitHub)" <gi...@apache.org> on 2024/08/26 12:45:20 UTC
[PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
jerqi opened a new pull request, #4690:
URL: https://github.com/apache/gravitino/pull/4690
### What changes were proposed in this pull request?
Supports to load fileds lazily.
### Why are the changes needed?
Fix: #4608
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Add new uts and pass the existing uts
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1746396924
##########
core/src/main/java/org/apache/gravitino/meta/RoleEntity.java:
##########
@@ -91,16 +95,7 @@ public Map<String, String> properties() {
*/
@Override
public List<SecurableObject> securableObjects() {
- // The securable object is a special kind of entities. Some entity types aren't the securable
- // object, such as
- // User, Role, etc.
- // The securable object identifier must be unique.
- // Gravitino assumes that the identifiers of the entities may be the same if they have different
- // types.
- // So one type of them can't be the securable object at least if there are the two same
- // identifier
- // entities .
Review Comment:
This is legacy comments. We can remove it.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #4690:
URL: https://github.com/apache/gravitino/pull/4690
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1744842857
##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/SupplierUtils.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.storage.relational.po.GroupPO;
+import org.apache.gravitino.storage.relational.po.RolePO;
+import org.apache.gravitino.storage.relational.po.SecurableObjectPO;
+import org.apache.gravitino.storage.relational.po.UserPO;
+import org.apache.gravitino.storage.relational.service.MetadataObjectService;
+import org.apache.gravitino.storage.relational.service.RoleMetaService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/* This class is a utilization class for creating kinds of suppliers */
+public class SupplierUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SupplierUtils.class);
+
+ private SupplierUtils() {}
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(UserPO userPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOs;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ rolePOs = RoleMetaService.getInstance().listRolesByUserId(userPO.getUserId());
+ waitToLoad = false;
+ }
+
+ return rolePOs;
+ }
+ };
+ }
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(GroupPO groupPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOS;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ rolePOS = RoleMetaService.getInstance().listRolesByGroupId(groupPO.getGroupId());
+ waitToLoad = false;
+ }
+
+ return rolePOS;
+ }
+ };
+ }
+
+ public static Supplier<List<SecurableObject>> createSecurableObjectsSupplier(RolePO rolePO) {
+ return new Supplier<List<SecurableObject>>() {
+ private List<SecurableObject> securableObjects;
+
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<SecurableObject> get() {
+ if (waitToLoad) {
+ List<SecurableObjectPO> securableObjectPOs =
+ RoleMetaService.getInstance().listSecurableObjectsByRoleId(rolePO.getRoleId());
+
+ securableObjects = Lists.newArrayList();
+
+ for (SecurableObjectPO securableObjectPO : securableObjectPOs) {
+ String fullName =
+ MetadataObjectService.getMetadataObjectFullName(
+ securableObjectPO.getType(), securableObjectPO.getMetadataObjectId());
+ if (fullName != null) {
+ securableObjects.add(
Review Comment:
You can see the line 88. I have cleared it.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#issuecomment-2324238463
@xunliu @yuqi1129 @jerryshao Could you take a look?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1746396924
##########
core/src/main/java/org/apache/gravitino/meta/RoleEntity.java:
##########
@@ -91,16 +95,7 @@ public Map<String, String> properties() {
*/
@Override
public List<SecurableObject> securableObjects() {
- // The securable object is a special kind of entities. Some entity types aren't the securable
- // object, such as
- // User, Role, etc.
- // The securable object identifier must be unique.
- // Gravitino assumes that the identifiers of the entities may be the same if they have different
- // types.
- // So one type of them can't be the securable object at least if there are the two same
- // identifier
- // entities .
Review Comment:
This is legacy comments. The interface has more accurate comments.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1741635872
##########
core/src/main/java/org/apache/gravitino/meta/UserEntity.java:
##########
@@ -44,18 +45,22 @@ public class UserEntity implements User, Entity, Auditable, HasIdentifier {
public static final Field AUDIT_INFO =
Field.required("audit_info", AuditInfo.class, "The audit details of the user entity.");
- public static final Field ROLE_NAMES =
- Field.optional("role_names", List.class, "The role names of the user entity");
+ public static final Field ROLE_NAMES_SUPPLIER =
+ Field.required(
+ "role_names_supplier", Supplier.class, "The role names supplier of the user entity");
- public static final Field ROLE_IDS =
- Field.optional("role_ids", List.class, "The role ids of the user entity");
+ public static final Field ROLE_IDS_SUPPLIER =
+ Field.required(
+ "role_ids_supplier", Supplier.class, "The role ids supplier of the user entity");
private Long id;
private String name;
private AuditInfo auditInfo;
- private List<String> roleNames;
- private List<Long> roleIds;
private Namespace namespace;
+ // The roleIds is a lazy field to avoid unnecessary cost.
+ private Supplier<List<Long>> roleIdsSupplier = () -> null;
+ // The roleNames is a lazy field to avoid unnecessary cost.
+ private Supplier<List<String>> roleNamesSupplier = () -> null;
Review Comment:
I think we need to use one `Role` object variable to replace `roleIds` and `roleNames` two variable.
##########
core/src/main/java/org/apache/gravitino/meta/GroupEntity.java:
##########
@@ -38,21 +39,25 @@ public class GroupEntity implements Group, Entity, Auditable, HasIdentifier {
public static final Field NAME =
Field.required("name", String.class, "The name of the group entity.");
- public static final Field ROLE_NAMES =
- Field.optional("role_names", List.class, "The role names of the group entity.");
+ public static final Field ROLE_NAMES_SUPPLIER =
+ Field.required(
+ "role_names_supplier", Supplier.class, "The role names supplier of the group entity.");
- public static final Field ROLE_IDS =
- Field.optional("role_ids", List.class, "The role names of the group entity.");
+ public static final Field ROLE_IDS_SUPPLIER =
+ Field.required(
+ "role_ids_supplier", Supplier.class, "The role ids supplier of the group entity.");
public static final Field AUDIT_INFO =
Field.required("audit_info", AuditInfo.class, "The audit details of the group entity.");
private Long id;
private String name;
private AuditInfo auditInfo;
- private List<String> roleNames;
- private List<Long> roleIds;
private Namespace namespace;
+ // The roleIds is a lazy field to avoid unnecessary cost.
+ private Supplier<List<Long>> roleIdsSupplier = () -> null;
+ // The roleNames is a lazy field to avoid unnecessary cost.
+ private Supplier<List<String>> roleNamesSupplier = () -> null;
Review Comment:
I think we need to use one `Role` object variable to replace `roleIds` and `roleNames` two variable.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1744772577
##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/SupplierUtils.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.storage.relational.po.GroupPO;
+import org.apache.gravitino.storage.relational.po.RolePO;
+import org.apache.gravitino.storage.relational.po.SecurableObjectPO;
+import org.apache.gravitino.storage.relational.po.UserPO;
+import org.apache.gravitino.storage.relational.service.MetadataObjectService;
+import org.apache.gravitino.storage.relational.service.RoleMetaService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/* This class is a utilization class for creating kinds of suppliers */
+public class SupplierUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SupplierUtils.class);
+
+ private SupplierUtils() {}
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(UserPO userPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOs;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ rolePOs = RoleMetaService.getInstance().listRolesByUserId(userPO.getUserId());
+ waitToLoad = false;
+ }
+
+ return rolePOs;
+ }
+ };
+ }
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(GroupPO groupPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOS;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ rolePOS = RoleMetaService.getInstance().listRolesByGroupId(groupPO.getGroupId());
+ waitToLoad = false;
+ }
+
+ return rolePOS;
+ }
+ };
+ }
+
+ public static Supplier<List<SecurableObject>> createSecurableObjectsSupplier(RolePO rolePO) {
+ return new Supplier<List<SecurableObject>>() {
+ private List<SecurableObject> securableObjects;
+
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<SecurableObject> get() {
+ if (waitToLoad) {
+ List<SecurableObjectPO> securableObjectPOs =
+ RoleMetaService.getInstance().listSecurableObjectsByRoleId(rolePO.getRoleId());
+
+ securableObjects = Lists.newArrayList();
+
+ for (SecurableObjectPO securableObjectPO : securableObjectPOs) {
+ String fullName =
+ MetadataObjectService.getMetadataObjectFullName(
+ securableObjectPO.getType(), securableObjectPO.getMetadataObjectId());
+ if (fullName != null) {
+ securableObjects.add(
Review Comment:
I believe you need to clear `securableObjects` before you try to load them from storage, `securableObjects` is not empty when `get` fails halfway.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#issuecomment-2311390704
I will wait this after the 0.6.0 release.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "xunliu (via GitHub)" <gi...@apache.org>.
xunliu commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1746360390
##########
core/src/main/java/org/apache/gravitino/meta/RoleEntity.java:
##########
@@ -91,16 +95,7 @@ public Map<String, String> properties() {
*/
@Override
public List<SecurableObject> securableObjects() {
- // The securable object is a special kind of entities. Some entity types aren't the securable
- // object, such as
- // User, Role, etc.
- // The securable object identifier must be unique.
- // Gravitino assumes that the identifiers of the entities may be the same if they have different
- // types.
- // So one type of them can't be the securable object at least if there are the two same
- // identifier
- // entities .
Review Comment:
We don't need these comments any more?
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1743432300
##########
core/src/main/java/org/apache/gravitino/meta/GroupEntity.java:
##########
@@ -38,21 +39,25 @@ public class GroupEntity implements Group, Entity, Auditable, HasIdentifier {
public static final Field NAME =
Field.required("name", String.class, "The name of the group entity.");
- public static final Field ROLE_NAMES =
- Field.optional("role_names", List.class, "The role names of the group entity.");
+ public static final Field ROLE_NAMES_SUPPLIER =
+ Field.required(
+ "role_names_supplier", Supplier.class, "The role names supplier of the group entity.");
- public static final Field ROLE_IDS =
- Field.optional("role_ids", List.class, "The role names of the group entity.");
+ public static final Field ROLE_IDS_SUPPLIER =
+ Field.required(
+ "role_ids_supplier", Supplier.class, "The role ids supplier of the group entity.");
public static final Field AUDIT_INFO =
Field.required("audit_info", AuditInfo.class, "The audit details of the group entity.");
private Long id;
private String name;
private AuditInfo auditInfo;
- private List<String> roleNames;
- private List<Long> roleIds;
private Namespace namespace;
+ // The roleIds is a lazy field to avoid unnecessary cost.
+ private Supplier<List<Long>> roleIdsSupplier = () -> null;
+ // The roleNames is a lazy field to avoid unnecessary cost.
+ private Supplier<List<String>> roleNamesSupplier = () -> null;
Review Comment:
Done.
##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/SupplierUtils.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.storage.relational.po.GroupPO;
+import org.apache.gravitino.storage.relational.po.RolePO;
+import org.apache.gravitino.storage.relational.po.SecurableObjectPO;
+import org.apache.gravitino.storage.relational.po.UserPO;
+import org.apache.gravitino.storage.relational.service.MetadataObjectService;
+import org.apache.gravitino.storage.relational.service.RoleMetaService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/* This class is a utilization class for creating kinds of suppliers */
+public class SupplierUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SupplierUtils.class);
+
+ private SupplierUtils() {}
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(UserPO userPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOs;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
+ rolePOs = RoleMetaService.getInstance().listRolesByUserId(userPO.getUserId());
+ }
+
+ return rolePOs;
+ }
+ };
+ }
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(GroupPO groupPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOS;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
+ rolePOS = RoleMetaService.getInstance().listRolesByGroupId(groupPO.getGroupId());
+ }
+
+ return rolePOS;
+ }
+ };
+ }
+
+ public static Supplier<List<SecurableObject>> createSecurableObjectsSupplier(RolePO rolePO) {
+ return new Supplier<List<SecurableObject>>() {
+ private List<SecurableObject> securableObjects;
+
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<SecurableObject> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
Review Comment:
Done.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#4608] feat(core): Supports to load fields lazily [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #4690:
URL: https://github.com/apache/gravitino/pull/4690#discussion_r1741686736
##########
core/src/main/java/org/apache/gravitino/storage/relational/utils/SupplierUtils.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.utils;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import java.util.function.Supplier;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.authorization.SecurableObject;
+import org.apache.gravitino.storage.relational.po.GroupPO;
+import org.apache.gravitino.storage.relational.po.RolePO;
+import org.apache.gravitino.storage.relational.po.SecurableObjectPO;
+import org.apache.gravitino.storage.relational.po.UserPO;
+import org.apache.gravitino.storage.relational.service.MetadataObjectService;
+import org.apache.gravitino.storage.relational.service.RoleMetaService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/* This class is a utilization class for creating kinds of suppliers */
+public class SupplierUtils {
+
+ private static final Logger LOG = LoggerFactory.getLogger(SupplierUtils.class);
+
+ private SupplierUtils() {}
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(UserPO userPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOs;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
+ rolePOs = RoleMetaService.getInstance().listRolesByUserId(userPO.getUserId());
+ }
+
+ return rolePOs;
+ }
+ };
+ }
+
+ public static Supplier<List<RolePO>> createRolePOsSupplier(GroupPO groupPO) {
+ return new Supplier<List<RolePO>>() {
+ private List<RolePO> rolePOS;
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<RolePO> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
+ rolePOS = RoleMetaService.getInstance().listRolesByGroupId(groupPO.getGroupId());
+ }
+
+ return rolePOS;
+ }
+ };
+ }
+
+ public static Supplier<List<SecurableObject>> createSecurableObjectsSupplier(RolePO rolePO) {
+ return new Supplier<List<SecurableObject>>() {
+ private List<SecurableObject> securableObjects;
+
+ private boolean waitToLoad = true;
+
+ @Override
+ public List<SecurableObject> get() {
+ if (waitToLoad) {
+ waitToLoad = false;
Review Comment:
The value of `waitToLoad` should be set to false after `securableObjects` has been assigned successfully.
--
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: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org