Skip to content

Commit

Permalink
fixTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingjian Wu committed Jun 2, 2024
1 parent 726e73d commit 57b461f
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ? "
Expand Down Expand Up @@ -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;
});
Expand All @@ -95,18 +97,23 @@ public void createParentChildRelation(final QualifiedName parentName,
}
}
}

@Override
public void rename(final QualifiedName oldName, final QualifiedName newName) {
try {
retryTemplate.execute((RetryCallback<Void, RuntimeException>) 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;
});
Expand Down

0 comments on commit 57b461f

Please sign in to comment.