From bdf42836fba37d3f96ea4f3d9a85ad1d96783a1f Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Wed, 12 Feb 2014 20:20:50 +0100 Subject: [PATCH] update to neo4j 2.0.1 --- pom.xml | 10 ++++---- spring-data-neo4j-rest/pom.xml | 6 ++++- spring-data-neo4j/pom.xml | 4 +++ .../data/neo4j/support/node/Neo4jHelper.java | 6 +++++ .../TypeRepresentationStrategyFactory.java | 2 +- .../neo4j/repository/DerivedFinderTests.java | 25 ++++++++++++++++--- .../SpatialGraphRepositoryTests.java | 17 +++++++++++++ 7 files changed, 59 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index bfeeb4c4b..9a9f41a79 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ org.springframework.data.build spring-data-parent - 1.3.0.RC1 + 1.3.0.BUILD-SNAPSHOT ../spring-data-build/parent/pom.xml @@ -38,11 +38,11 @@ 1.7 1.7 - 2.0.0 + 2.0.1 - 0.12-neo4j-2.0.0 - 0.7.1-neo4j-2.0.0 - 2.0.0 + 0.12-neo4j-2.0.1-SNAPSHOT + 0.7.1-neo4j-2.0.1-SNAPSHOT + 2.0.1-SNAPSHOT diff --git a/spring-data-neo4j-rest/pom.xml b/spring-data-neo4j-rest/pom.xml index 62e1bc832..16f471fea 100644 --- a/spring-data-neo4j-rest/pom.xml +++ b/spring-data-neo4j-rest/pom.xml @@ -19,7 +19,7 @@ 1.0.0.GA 1.9 - 2.0.0 + 2.0.1-SNAPSHOT @@ -115,6 +115,10 @@ org.neo4j neo4j-lucene-index + + org.neo4j + server-api + diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index cc7e4c2dd..52bd1515b 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -197,6 +197,10 @@ org.neo4j neo4j + + org.neo4j + neo4j-lucene-index + diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java index c587a609d..1914a1d47 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/node/Neo4jHelper.java @@ -20,6 +20,8 @@ import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.Index; import org.neo4j.graphdb.index.IndexManager; import org.neo4j.graphdb.index.RelationshipIndex; +import org.neo4j.kernel.GraphDatabaseAPI; +import org.neo4j.kernel.impl.core.NodeManager; import org.neo4j.tooling.GlobalGraphOperations; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,10 +82,13 @@ public abstract class Neo4jHelper { } private static void removeNodes(GraphDatabaseService graphDatabaseService, boolean includeReferenceNode) { + GraphDatabaseAPI api = (GraphDatabaseAPI) graphDatabaseService; + NodeManager nodeManager = api.getDependencyResolver().resolveDependency(NodeManager.class); final GlobalGraphOperations globalGraphOperations = GlobalGraphOperations.at(graphDatabaseService); for (Node node : globalGraphOperations.getAllNodes()) { for (Relationship rel : node.getRelationships(Direction.OUTGOING)) { try { + if (nodeManager.isDeleted(rel)) continue; rel.delete(); } catch(IllegalStateException ise) { if (!ise.getMessage().contains("since it has already been deleted")) throw ise; @@ -93,6 +98,7 @@ public abstract class Neo4jHelper { } for (Node node : globalGraphOperations.getAllNodes()) { try { + if (nodeManager.isDeleted(node)) continue; node.delete(); } catch(IllegalStateException ise) { if (!ise.getMessage().contains("since it has already been deleted")) throw ise; diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/TypeRepresentationStrategyFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/TypeRepresentationStrategyFactory.java index eb8e4c8e3..e66707e23 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/TypeRepresentationStrategyFactory.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/typerepresentation/TypeRepresentationStrategyFactory.java @@ -56,7 +56,7 @@ public class TypeRepresentationStrategyFactory { if (SubReferenceNodeTypeRepresentationStrategy.isStrategyAlreadyInUse(graphDatabaseService)) return Strategy.SubRef; if (LabelBasedNodeTypeRepresentationStrategy.isStrategyAlreadyInUse(graphDatabaseService)) return Strategy.Labeled; tx.success(); - return Strategy.Labeled; + return Strategy.Indexed; } } diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/DerivedFinderTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/DerivedFinderTests.java index 92e4503b7..b69cceb4c 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/DerivedFinderTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/DerivedFinderTests.java @@ -21,6 +21,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Transaction; import org.neo4j.helpers.collection.IteratorUtil; import org.neo4j.test.TestGraphDatabaseFactory; @@ -205,7 +206,7 @@ public class DerivedFinderTests { CRUDRepository ingredientRepository = template.repositoryFor(Ingredient.class); - transaction = graphDatabaseService.beginTx(); + Transaction tx = graphDatabaseService.beginTx(); try { chocolate = ingredientRepository.save(new Ingredient("chocolate")); fish = ingredientRepository.save(new Ingredient("fish")); @@ -224,17 +225,29 @@ public class DerivedFinderTests { whiteChocolateSquares = recipeRepository.save(new Recipe("Heston", "White Chocolate squares", chocolate, null, null)); dish = dishRepository.save(new Dish(100)); - transaction.success(); + tx.success(); } finally { - transaction.finish(); + tx.close(); } + tx = graphDatabaseService.beginTx(); + try { + for (Node node : graphDatabaseService.getAllNodes()) { + System.out.println("node = " + node); + } + tx.success(); + } finally { + tx.close(); + } + transaction = graphDatabaseService.beginTx(); } @After public void tearDown() throws Exception { if (transaction!=null) { - transaction.success();transaction.finish(); + transaction.success(); + transaction.close(); + transaction = null; } } @@ -340,6 +353,10 @@ public class DerivedFinderTests { public void shouldFindUsingEntityAndPropertyTraversal() throws Exception { Set recipes = recipeRepository.findByIngredientAndCookBookTitle(oliveOil, "Naked Chef"); + for (Node node : graphDatabaseService.getAllNodes()) { + System.out.println("in test = " + node); + } + assertThat(single(recipes).title, is(equalTo("pesto"))); } @Test diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/SpatialGraphRepositoryTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/SpatialGraphRepositoryTests.java index 943e0d61b..a55c6d046 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/SpatialGraphRepositoryTests.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/SpatialGraphRepositoryTests.java @@ -17,6 +17,7 @@ package org.springframework.data.neo4j.repository; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -97,4 +98,20 @@ public class SpatialGraphRepositoryTests { Iterable teamMembers = personRepository.findWithinDistance("personLayer", 16,56,70); assertThat(asCollection(teamMembers), hasItems(testTeam.michael, testTeam.david)); } + + @Test + @Ignore + public void testPerformance() throws Exception { + long time=System.currentTimeMillis(); + for (int i=0;i<5000;i++) { + if (i % 1000 == 0) { + long now = System.currentTimeMillis(); + System.out.println(i+". entries " + (now-time)); + time=now; + } + Person person = new Person("John " + i, 40 + i); + person.setLocation((i % 180) - 90,(i % 180) - 90); + personRepository.save(person); + } + } }