From 1c7021a8354c1e6891fcbdc23d8c021b18a783a9 Mon Sep 17 00:00:00 2001 From: xiaojiebao Date: Sun, 4 Feb 2024 11:09:45 +0800 Subject: [PATCH] fix update --- .../storage/relation/mysql/MySQLBackend.java | 10 ++++----- .../mysql/mapper/MetalakeMetaMapper.java | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/MySQLBackend.java b/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/MySQLBackend.java index 1ff8dca7f39..7f121d3b7dc 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/MySQLBackend.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/MySQLBackend.java @@ -130,10 +130,10 @@ public E update( try { switch (entityType) { case METALAKE: - BaseMetalake oldMetalakeEntity = - POConverters.fromMetalakePO( - ((MetalakeMetaMapper) SqlSessions.getMapper(MetalakeMetaMapper.class)) - .selectMetalakeMetaByName(ident.name())); + MetalakePO oldMetalakePO = + ((MetalakeMetaMapper) SqlSessions.getMapper(MetalakeMetaMapper.class)) + .selectMetalakeMetaByName(ident.name()); + BaseMetalake oldMetalakeEntity = POConverters.fromMetalakePO(oldMetalakePO); BaseMetalake newMetalakeEntity = (BaseMetalake) updater.apply((E) oldMetalakeEntity); Preconditions.checkArgument( Objects.equals(oldMetalakeEntity.id(), newMetalakeEntity.id()), @@ -141,7 +141,7 @@ public E update( "The updated metalake entity id: %s is not same with the metalake entity id before: %s", newMetalakeEntity.id(), oldMetalakeEntity.id())); ((MetalakeMetaMapper) SqlSessions.getMapper(MetalakeMetaMapper.class)) - .updateMetalakeMeta(POConverters.toMetalakePO(newMetalakeEntity)); + .updateMetalakeMeta(POConverters.toMetalakePO(newMetalakeEntity), oldMetalakePO); SqlSessions.commitAndCloseSqlSession(); return (E) newMetalakeEntity; case CATALOG: diff --git a/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/mapper/MetalakeMetaMapper.java b/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/mapper/MetalakeMetaMapper.java index 2ab836d6578..5a34889481c 100644 --- a/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/mapper/MetalakeMetaMapper.java +++ b/core/src/main/java/com/datastrato/gravitino/storage/relation/mysql/mapper/MetalakeMetaMapper.java @@ -72,13 +72,20 @@ public interface MetalakeMetaMapper { @Update( "UPDATE " + TABLE_NAME - + " SET metalake_name = #{metalakeMeta.metalakeName}," - + " metalake_comment = #{metalakeMeta.metalakeComment}," - + " properties = #{metalakeMeta.properties}," - + " audit_info = #{metalakeMeta.auditInfo}," - + " schema_version = #{metalakeMeta.schemaVersion}" - + " WHERE id = #{metalakeMeta.id}") - void updateMetalakeMeta(@Param("metalakeMeta") MetalakePO metalakePO); + + " SET metalake_name = #{newMetalakeMeta.metalakeName}," + + " metalake_comment = #{newMetalakeMeta.metalakeComment}," + + " properties = #{newMetalakeMeta.properties}," + + " audit_info = #{newMetalakeMeta.auditInfo}," + + " schema_version = #{newMetalakeMeta.schemaVersion}" + + " WHERE id = #{oldMetalakeMeta.id}" + + " and metalake_name = #{oldMetalakeMeta.metalakeComment}" + + " and metalake_comment = #{oldMetalakeMeta.metalakeComment}" + + " and properties = #{oldMetalakeMeta.properties}" + + " and audit_info = #{oldMetalakeMeta.auditInfo}" + + " and schema_version = #{oldMetalakeMeta.schemaVersion}") + void updateMetalakeMeta( + @Param("newMetalakeMeta") MetalakePO newMetalakePO, + @Param("oldMetalakeMeta") MetalakePO oldMetalakePO); @Delete("DELETE FROM " + TABLE_NAME + " WHERE id = #{id}") Integer deleteMetalakeMetaById(@Param("id") Long id);