From 8deb35064ca280e05d94a2e069e8639245ae2dae Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Fri, 28 Aug 2020 14:15:22 +0200 Subject: [PATCH] DATAGRAPH-1249 - Ensure flushing the mapping context on potentially generic write queries. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commits adds two tests ensuring that OGM 3.2.15 and 3.1.21 actually flushes the mapping context after a potential write query is executed which doesn’t involve any cached `NodeEntity` or `RelationshipEntity`. --- .../examples/movies/repo/UserRepository.java | 6 ++++ .../neo4j/queries/QueryIntegrationTests.java | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/movies/repo/UserRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/movies/repo/UserRepository.java index 058d4017a..6540e683d 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/movies/repo/UserRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/examples/movies/repo/UserRepository.java @@ -54,6 +54,12 @@ public interface UserRepository extends PersonRepository { List findByRatingsStarsIgnoreCase(int stars); + @Query("MATCH (c:User) SET c.surname = 'Helge' RETURN c") + List bulkUpdateReturningNode(); + + @Query("MATCH (c:User) SET c.surname = 'Helge'") + void bulkUpdateNoReturn(); + @Query("MATCH (user:User) RETURN COUNT(user)") int findTotalUsers(); diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryIntegrationTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryIntegrationTests.java index 11bc489aa..c4c171977 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryIntegrationTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/queries/QueryIntegrationTests.java @@ -769,4 +769,36 @@ public class QueryIntegrationTests { transaction.success(); } } + + @Test // DATAGRAPH-1249 + public void shouldFlushSessionAfterBulkUpdateReturningNodes() { + + executeUpdate("CREATE (:User {name:'Schneider'}), (:User {name:'Hundingsbane'})"); + transactionTemplate.execute(new TransactionCallbackWithoutResult() { + @Override + public void doInTransactionWithoutResult(TransactionStatus status) { + assertThat(userRepository.findAll()).hasSize(2); + + assertThat(userRepository.bulkUpdateReturningNode()).extracting(User::getSurname).containsOnly("Helge"); + + assertThat(userRepository.findAll()).extracting(User::getSurname).containsOnly("Helge"); + } + }); + } + + @Test // DATAGRAPH-1249 + public void shouldFlushSessionAfterBulkUpdateWithoutNodes() { + + executeUpdate("CREATE (:User {name:'Schneider'}), (:User {name:'Hundingsbane'})"); + transactionTemplate.execute(new TransactionCallbackWithoutResult() { + @Override + public void doInTransactionWithoutResult(TransactionStatus status) { + assertThat(userRepository.findAll()).hasSize(2); + + userRepository.bulkUpdateNoReturn(); + + assertThat(userRepository.findAll()).extracting(User::getSurname).containsOnly("Helge"); + } + }); + } }