From 57b461fde90240cd8201b2dc93f1275fbb975c06 Mon Sep 17 00:00:00 2001 From: Yingjian Wu Date: Sat, 1 Jun 2024 22:58:35 -0700 Subject: [PATCH] fixTest --- .../MySqlParentChildRelMetaDataService.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MySqlParentChildRelMetaDataService.java b/metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MySqlParentChildRelMetaDataService.java index 71e4d794c..951cdb313 100644 --- a/metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MySqlParentChildRelMetaDataService.java +++ b/metacat-metadata-mysql/src/main/java/com/netflix/metacat/metadata/mysql/MySqlParentChildRelMetaDataService.java @@ -34,8 +34,10 @@ public class MySqlParentChildRelMetaDataService implements ParentChildRelMetadat + "WHERE NOT EXISTS (SELECT 1 FROM parent_child_relation WHERE child = ?) " + "AND NOT EXISTS (SELECT 1 FROM parent_child_relation WHERE child = ?)"; - static final String SQL_RENAME_ENTITY = "UPDATE parent_child_relation " - + "SET parent = ?, child = ? WHERE parent = ? OR child = ?"; + static final String SQL_RENAME_PARENT_ENTITY = "UPDATE parent_child_relation " + + "SET parent = ? WHERE parent = ?"; + static final String SQL_RENAME_CHILD_ENTITY = "UPDATE parent_child_relation " + + "SET child = ? WHERE child = ?"; static final String SQL_DROP_ENTITY = "DELETE FROM parent_child_relation " + "WHERE child = ? " @@ -73,7 +75,7 @@ public void createParentChildRelation(final QualifiedName parentName, ps.setString(1, parentName.toString()); ps.setString(2, childName.toString()); ps.setString(3, type); - ps.setString(4, childName.toString()); + ps.setString(4, parentName.toString()); ps.setString(5, childName.toString()); return ps; }); @@ -95,18 +97,23 @@ public void createParentChildRelation(final QualifiedName parentName, } } } - @Override public void rename(final QualifiedName oldName, final QualifiedName newName) { try { retryTemplate.execute((RetryCallback) context -> { jdbcTemplate.update(connection -> { - final PreparedStatement ps = connection.prepareStatement(SQL_RENAME_ENTITY); - ps.setString(1, newName.toString()); - ps.setString(2, newName.toString()); - ps.setString(3, oldName.toString()); - ps.setString(4, oldName.toString()); - return ps; + // Rename Parent Entity + final PreparedStatement renameParentPS = connection.prepareStatement(SQL_RENAME_PARENT_ENTITY); + renameParentPS.setString(1, newName.toString()); + renameParentPS.setString(2, oldName.toString()); + renameParentPS.executeUpdate(); + + // Rename Child Entity + final PreparedStatement renameChildPS = connection.prepareStatement(SQL_RENAME_CHILD_ENTITY); + renameChildPS.setString(1, newName.toString()); + renameChildPS.setString(2, oldName.toString()); + renameChildPS.executeUpdate(); + return null; }); return null; });