From deebc6986961d0e1d35728348d7186896146d8aa Mon Sep 17 00:00:00 2001 From: Florent Biville <445792+fbiville@users.noreply.github.com> Date: Tue, 10 Sep 2024 18:07:01 +0200 Subject: [PATCH] Work around regression introduced in core 4.29.2 (#650) [This commit](https://github.com/liquibase/liquibase/commit/631b7d42dd32d67f59f8294dc40d20d3c01085ab#diff-57b8a969c50e3c98da190e27b6887f88de5466091cf62518775f6fda91ce008bR191-R206) merged in core makes it so that parameters passed as `ArrayList` get flattened to individual parameters, which breaks internal prepared statements in `loadData` and `mergeNodes`. The workaround consists in using another `List` type which is not handled by the code linked above. --- .../liquibase/ext/neo4j/change/LoadGraphDataChange.java | 6 +++++- .../liquibase/ext/neo4j/change/refactoring/NodeMerger.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/liquibase/ext/neo4j/change/LoadGraphDataChange.java b/src/main/java/liquibase/ext/neo4j/change/LoadGraphDataChange.java index f871eb7f..f948b718 100644 --- a/src/main/java/liquibase/ext/neo4j/change/LoadGraphDataChange.java +++ b/src/main/java/liquibase/ext/neo4j/change/LoadGraphDataChange.java @@ -10,6 +10,7 @@ import liquibase.statement.core.RawParameterizedSqlStatement; import java.util.AbstractMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -58,7 +59,10 @@ private List> keyValuePairs(List rows) { .map(row -> row.getColumns().stream() .flatMap(LoadGraphDataChange::keyValuePair) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue))) - .collect(Collectors.toList()); + // note: this is explicitly NOT using an ArrayList because of a regression introduced in core v4.29.2 + // (see commit 631b7d42dd32d67f59f8294dc40d20d3c01085ab, JdbcExecutor#setParameters) + // ArrayList parameters get flattened instead of being treated as a whole list + .collect(Collectors.toCollection(LinkedList::new)); } private static Stream> keyValuePair(LoadDataColumnConfig column) { diff --git a/src/main/java/liquibase/ext/neo4j/change/refactoring/NodeMerger.java b/src/main/java/liquibase/ext/neo4j/change/refactoring/NodeMerger.java index a39ebb5f..b9d858e4 100644 --- a/src/main/java/liquibase/ext/neo4j/change/refactoring/NodeMerger.java +++ b/src/main/java/liquibase/ext/neo4j/change/refactoring/NodeMerger.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -42,7 +43,11 @@ public SqlStatement[] merge(MatchPattern pattern, List poli private List getNodeIds(MatchPattern pattern) throws LiquibaseException { String query = String.format("MATCH %s RETURN id(%s) AS id", pattern.cypherFragment(), pattern.outputVariable()); List> rows = database.run(new RawParameterizedSqlStatement(query)); - return rows.stream().map(row -> (Long) row.get("id")).collect(Collectors.toList()); + return rows.stream().map(row -> (Long) row.get("id")) + // note: this is explicitly NOT using an ArrayList because of a regression introduced in core v4.29.2 + // (see commit 631b7d42dd32d67f59f8294dc40d20d3c01085ab, JdbcExecutor#setParameters) + // ArrayList parameters get flattened instead of being treated as a whole list + .collect(Collectors.toCollection(LinkedList::new)); } private Optional generateLabelCopyStatement(List ids) throws LiquibaseException {