mchades commented on code in PR #7560:
URL: https://github.com/apache/gravitino/pull/7560#discussion_r2199960843


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/PolicyMetaBaseSQLProvider.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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 static 
org.apache.gravitino.storage.relational.mapper.PolicyMetaMapper.POLICY_META_TABLE_NAME;
+import static 
org.apache.gravitino.storage.relational.mapper.PolicyVersionMapper.POLICY_VERSION_TABLE_NAME;
+
+import org.apache.gravitino.storage.relational.mapper.MetalakeMetaMapper;
+import org.apache.gravitino.storage.relational.po.PolicyPO;
+import org.apache.ibatis.annotations.Param;
+
+public class PolicyMetaBaseSQLProvider {
+
+  public String listPolicyPOsByMetalake(@Param("metalakeName") String 
metalakeName) {
+    return "SELECT pm.policy_id, pm.policy_name, pm.policy_type, 
pm.metalake_id, pm.inheritable,"
+        + " pm.exclusive, pm.supported_object_types, pm.audit_info, 
pm.current_version, pm.last_version,"
+        + " pm.deleted_at, pvi.id, pvi.metalake_id as version_metalake_id, 
pvi.policy_id as version_policy_id,"
+        + " pvi.version, pvi.policy_comment, pvi.enabled, pvi.content, 
pvi.deleted_at as version_deleted_at"
+        + " FROM "
+        + POLICY_META_TABLE_NAME
+        + " pm JOIN "
+        + MetalakeMetaMapper.TABLE_NAME
+        + " mm ON pm.metalake_id = mm.metalake_id"
+        + " JOIN "
+        + POLICY_VERSION_TABLE_NAME
+        + " pvi ON pm.policy_id = pvi.policy_id"
+        + " AND pm.current_version = pvi.version"
+        + " WHERE mm.metalake_name = #{metalakeName}"
+        + " AND pm.deleted_at = 0 AND mm.deleted_at = 0"
+        + " AND pvi.deleted_at = 0";
+  }
+
+  public String insertPolicyMetaOnDuplicateKeyUpdate(@Param("policyMeta") 
PolicyPO policyPO) {
+    return "INSERT INTO "
+        + POLICY_META_TABLE_NAME
+        + " (policy_id, policy_name, policy_type, metalake_id, inheritable, 
exclusive,"
+        + " supported_object_types, audit_info, current_version, last_version, 
deleted_at)"
+        + " VALUES (#{policyMeta.policyId}, #{policyMeta.policyName}, 
#{policyMeta.policyType},"
+        + " #{policyMeta.metalakeId}, #{policyMeta.inheritable}, 
#{policyMeta.exclusive},"
+        + " #{policyMeta.supportedObjectTypes}, #{policyMeta.auditInfo}, 
#{policyMeta.currentVersion},"
+        + " #{policyMeta.lastVersion}, #{policyMeta.deletedAt})"
+        + " ON DUPLICATE KEY UPDATE"
+        + " policy_name = #{policyMeta.policyName},"
+        + " policy_type = #{policyMeta.policyType},"
+        + " metalake_id = #{policyMeta.metalakeId},"
+        + " inheritable = #{policyMeta.inheritable},"
+        + " exclusive = #{policyMeta.exclusive},"
+        + " supported_object_types = #{policyMeta.supportedObjectTypes},"
+        + " audit_info = #{policyMeta.auditInfo},"
+        + " current_version = #{policyMeta.currentVersion},"
+        + " last_version = #{policyMeta.lastVersion},"
+        + " deleted_at = #{policyMeta.deletedAt}";
+  }
+
+  public String insertPolicyMeta(@Param("policyMeta") PolicyPO policyPO) {
+    return "INSERT INTO "
+        + POLICY_META_TABLE_NAME
+        + " (policy_id, policy_name, policy_type, metalake_id, inheritable, 
exclusive,"
+        + " supported_object_types, audit_info, current_version, last_version, 
deleted_at)"
+        + " VALUES (#{policyMeta.policyId}, #{policyMeta.policyName}, 
#{policyMeta.policyType},"
+        + " #{policyMeta.metalakeId}, #{policyMeta.inheritable}, 
#{policyMeta.exclusive},"
+        + " #{policyMeta.supportedObjectTypes}, #{policyMeta.auditInfo}, 
#{policyMeta.currentVersion},"
+        + " #{policyMeta.lastVersion}, #{policyMeta.deletedAt})";
+  }
+
+  public String selectPolicyMetaByMetalakeAndName(
+      @Param("metalakeName") String metalakeName, @Param("policyName") String 
policyName) {
+    return "SELECT pm.policy_id, pm.policy_name, pm.policy_type, 
pm.metalake_id, pm.inheritable,"
+        + " pm.exclusive, pm.supported_object_types, pm.audit_info, 
pm.current_version, pm.last_version,"
+        + " pm.deleted_at, pvi.id, pvi.metalake_id as version_metalake_id, 
pvi.policy_id as version_policy_id,"
+        + " pvi.version, pvi.policy_comment, pvi.enabled, pvi.content, 
pvi.deleted_at as version_deleted_at"
+        + " FROM "
+        + POLICY_META_TABLE_NAME
+        + " pm JOIN "
+        + MetalakeMetaMapper.TABLE_NAME
+        + " mm ON pm.metalake_id = mm.metalake_id"
+        + " JOIN "
+        + POLICY_VERSION_TABLE_NAME
+        + " pvi ON pm.policy_id = pvi.policy_id"
+        + " AND pm.current_version = pvi.version"
+        + " WHERE mm.metalake_name = #{metalakeName}"
+        + " AND pm.policy_name = #{policyName}"
+        + " AND pm.deleted_at = 0 AND mm.deleted_at = 0"
+        + " AND pvi.deleted_at = 0";
+  }
+
+  public String updatePolicyMeta(
+      @Param("newPolicyMeta") PolicyPO newPolicyMeta,
+      @Param("oldPolicyMeta") PolicyPO oldPolicyMeta) {
+    return "UPDATE "
+        + POLICY_META_TABLE_NAME
+        + " SET policy_name = #{newPolicyMeta.policyName},"
+        + " policy_type = #{newPolicyMeta.policyType},"
+        + " metalake_id = #{newPolicyMeta.metalakeId},"
+        + " inheritable = #{newPolicyMeta.inheritable},"
+        + " exclusive = #{newPolicyMeta.exclusive},"
+        + " supported_object_types = #{newPolicyMeta.supportedObjectTypes},"
+        + " audit_info = #{newPolicyMeta.auditInfo},"
+        + " current_version = #{newPolicyMeta.currentVersion},"
+        + " last_version = #{newPolicyMeta.lastVersion},"
+        + " deleted_at = #{newPolicyMeta.deletedAt}"
+        + " WHERE policy_id = #{oldPolicyMeta.policyId}"
+        + " AND policy_name = #{oldPolicyMeta.policyName}"
+        + " AND policy_type = #{oldPolicyMeta.policyType}"
+        + " AND metalake_id = #{oldPolicyMeta.metalakeId}"
+        + " AND inheritable = #{oldPolicyMeta.inheritable}"
+        + " AND exclusive = #{oldPolicyMeta.exclusive}"
+        + " AND supported_object_types = #{oldPolicyMeta.supportedObjectTypes}"
+        + " AND audit_info = #{oldPolicyMeta.auditInfo}"
+        + " AND current_version = #{oldPolicyMeta.currentVersion}"
+        + " AND last_version = #{oldPolicyMeta.lastVersion}"
+        + " AND deleted_at = 0";
+  }

Review Comment:
   yes, plz see the `updatePolicy` method in `PolicyMetaService`



-- 
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-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to