Fix #7908 Backend: Glossary term deletion executes partial deletion (#8042)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-10-07 18:21:26 -07:00 committed by GitHub
parent e141ab29db
commit ef51fc8dbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -24,7 +24,9 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.Builder;
import lombok.Getter;
@ -36,6 +38,7 @@ import org.jdbi.v3.sqlobject.CreateSqlObject;
import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindList;
import org.jdbi.v3.sqlobject.customizer.BindMap;
import org.jdbi.v3.sqlobject.customizer.Define;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
@ -1454,12 +1457,14 @@ public interface CollectionDAO {
default void deleteAllByPrefix(String fqnPrefix) {
String prefix = String.format("%s%s%%", fqnPrefix, Entity.SEPARATOR);
String cond = String.format("WHERE (toFQN LIKE '%s' OR fromFQN LIKE '%s')", prefix, prefix);
deleteAllByPrefixInternal(cond);
String condition = "WHERE (toFQN LIKE :prefix OR fromFQN LIKE :prefix)";
Map<String, String> bindMap = new HashMap<>();
bindMap.put("prefix", prefix);
deleteAllByPrefixInternal(condition, bindMap);
}
@SqlUpdate("DELETE from field_relationship <cond>")
void deleteAllByPrefixInternal(@Define("cond") String cond);
void deleteAllByPrefixInternal(@Define("cond") String cond, @BindMap Map<String, String> bindings);
@SqlUpdate(
"DELETE from field_relationship WHERE fromFQN = :fromFQN AND toFQN = :toFQN AND fromType = :fromType "

View File

@ -246,7 +246,7 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
TagLabel t1Label = EntityUtil.getTagLabel(t1);
// Create glossary term t11 under t1
create = createRequest("t11", "", "", null).withReviewers(null).withGlossary(g1Ref).withParent(tRef1);
create = createRequest("t11with'quote", "", "", null).withReviewers(null).withGlossary(g1Ref).withParent(tRef1);
GlossaryTerm t11 = createEntity(create, ADMIN_AUTH_HEADERS);
EntityReference tRef11 = t11.getEntityReference();
TagLabel t11Label = EntityUtil.getTagLabel(t11);