From bdf59ea18a99dd401c0b912ee474ad2896e61779 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 7 Oct 2011 20:58:30 +0200 Subject: [PATCH] DATACMNS-84 - Adapted refactorings in SD Commons. --- .../neo4j/repository/query/MatchClause.java | 17 +++-- .../repository/query/MatchClauseUnitTest.java | 76 +++++++++---------- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/query/MatchClause.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/query/MatchClause.java index 201121d18..770c96ccd 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/query/MatchClause.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/repository/query/MatchClause.java @@ -16,10 +16,10 @@ package org.springframework.data.neo4j.repository.query; +import org.springframework.data.mapping.PropertyPath; import org.springframework.data.neo4j.mapping.Neo4jMappingContext; import org.springframework.data.neo4j.mapping.Neo4jPersistentProperty; import org.springframework.data.neo4j.mapping.RelationshipInfo; -import org.springframework.data.repository.query.parser.Property; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -33,18 +33,18 @@ class MatchClause { private final Iterable properties; /** - * Creates a new {@link MatchClause} using the given {@link org.springframework.data.neo4j.mapping.Neo4jMappingContext} and {@link Property}. + * Creates a new {@link MatchClause} using the given + * {@link org.springframework.data.neo4j.mapping.Neo4jMappingContext} and {@link PropertyPath}. * * @param context must not be {@literal null}. * @param property must not be {@literal null}. */ - public MatchClause(Neo4jMappingContext context, Property property) { + public MatchClause(Neo4jMappingContext context, PropertyPath property) { Assert.notNull(context); Assert.notNull(property); - Class rootType = property.getOwningType().getType(); - this.properties = context.getPersistentPropertyPath(rootType, property.toDotPath()); + this.properties = context.getPersistentPropertyPath(property); } /* @@ -65,9 +65,10 @@ class MatchClause { RelationshipInfo info = property.getRelationshipInfo(); Class ownerType = property.getOwner().getType(); - intermediate = intermediate == null ? asVariableReference(StringUtils.uncapitalize(ownerType.getSimpleName())) - : intermediate; - intermediate = String.format(getPattern(info), intermediate, info.getType(), asVariableReference(property.getName())); + intermediate = intermediate == null ? asVariableReference(StringUtils.uncapitalize(ownerType + .getSimpleName())) : intermediate; + intermediate = String.format(getPattern(info), intermediate, info.getType(), + asVariableReference(property.getName())); } return intermediate.toString(); diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/MatchClauseUnitTest.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/MatchClauseUnitTest.java index 0f495c763..184586818 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/MatchClauseUnitTest.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/query/MatchClauseUnitTest.java @@ -25,11 +25,11 @@ import java.util.Set; import org.junit.Before; import org.junit.Test; import org.neo4j.graphdb.Direction; +import org.springframework.data.mapping.PropertyPath; import org.springframework.data.neo4j.annotation.Indexed; import org.springframework.data.neo4j.annotation.NodeEntity; import org.springframework.data.neo4j.annotation.RelatedTo; import org.springframework.data.neo4j.mapping.Neo4jMappingContext; -import org.springframework.data.repository.query.parser.Property; /** * @@ -37,52 +37,52 @@ import org.springframework.data.repository.query.parser.Property; */ public class MatchClauseUnitTest { - Neo4jMappingContext context; + Neo4jMappingContext context; - @Before - public void setUp() { - context = new Neo4jMappingContext(); - context.setInitialEntitySet(Collections.singleton(Person.class)); - context.afterPropertiesSet(); - } + @Before + public void setUp() { + context = new Neo4jMappingContext(); + context.setInitialEntitySet(Collections.singleton(Person.class)); + context.afterPropertiesSet(); + } - @Test - public void buildsMatchExpressionForSimpleTraversalCorrectly() { + @Test + public void buildsMatchExpressionForSimpleTraversalCorrectly() { - MatchClause clause = new MatchClause(context, Property.from("group", Person.class)); - assertThat(clause.toString(), is("(person)<-[:members]-(group)")); - } + MatchClause clause = new MatchClause(context, PropertyPath.from("group", Person.class)); + assertThat(clause.toString(), is("(person)<-[:members]-(group)")); + } - @Test - public void createsMatchClassForDeepTraversal() { + @Test + public void createsMatchClassForDeepTraversal() { - MatchClause clause = new MatchClause(context, Property.from("group.members.age", Person.class)); - assertThat(clause.toString(), is("(person)<-[:members]-(group)-[:members]->(members)")); - } + MatchClause clause = new MatchClause(context, PropertyPath.from("group.members.age", Person.class)); + assertThat(clause.toString(), is("(person)<-[:members]-(group)-[:members]->(members)")); + } - @Test - public void stopsAtNonRelationShipProperty() { + @Test + public void stopsAtNonRelationShipPropertyPath() { - MatchClause clause = new MatchClause(context, Property.from("group.name", Person.class)); - assertThat(clause.toString(), is("(person)<-[:members]-(group)")); - } - - @NodeEntity - class Person { - - private int age; - - @RelatedTo(type = "members", direction = Direction.INCOMING) - private Group group; - } + MatchClause clause = new MatchClause(context, PropertyPath.from("group.name", Person.class)); + assertThat(clause.toString(), is("(person)<-[:members]-(group)")); + } @NodeEntity - class Group { + class Person { - @Indexed - private String name; + private int age; - @RelatedTo(type = "members", direction = Direction.OUTGOING) - private Set members; - } + @RelatedTo(type = "members", direction = Direction.INCOMING) + private Group group; + } + + @NodeEntity + class Group { + + @Indexed + private String name; + + @RelatedTo(type = "members", direction = Direction.OUTGOING) + private Set members; + } }