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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]