diff --git a/pom.xml b/pom.xml index c59ccb713..9395cea7a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,306 +1,320 @@ - - 4.0.0 - org.springframework.data - spring-data-neo4j-dist - Spring Data Neo4j Distribution + + 4.0.0 + org.springframework.data + spring-data-neo4j-dist + Spring Data Neo4j Distribution - 2.1.0.BUILD-SNAPSHOT - pom - - spring-data-neo4j-parent - spring-data-neo4j - spring-data-neo4j-rest - spring-data-neo4j-tx - spring-data-neo4j-aspects - spring-data-neo4j-cross-store - + 2.1.0.BUILD-SNAPSHOT + pom + + spring-data-neo4j-parent + spring-data-neo4j + spring-data-neo4j-rest + spring-data-neo4j-tx + spring-data-neo4j-aspects + spring-data-neo4j-cross-store + http://www.springsource.org/spring-data/neo4j - SpringSource - http://www.springsource.com + SpringSource + http://www.springsource.com http://github.com/SpringSource/spring-data-neo4j scm:git:git://github.com/SpringSource/spring-data-neo4j.git scm:git:git://github.com/SpringSource/spring-data-neo4j.git - - JIRA - https://jira.springsource.org/browse/DATAGRAPH - - - - Spring Data Forums - http://forum.springsource.org/forumdisplay.php?f=80 - http://forum.springsource.org/forumdisplay.php?f=80 - - - - Bamboo - https://build.springsource.org/browse/SPRINGDATA-DATAGRAPH - + + JIRA + https://jira.springsource.org/browse/DATAGRAPH + + + + Spring Data Forums + http://forum.springsource.org/forumdisplay.php?f=80 + http://forum.springsource.org/forumdisplay.php?f=80 + + + + Bamboo + https://build.springsource.org/browse/SPRINGDATA-DATAGRAPH + - - - trisberg - Thomas Risberg - trisberg at vmware.com - SpringSource - http://www.SpringSource.com - - Project Admin - - -5 - - - mpollack - Mark Pollack - mpollack at vmware.com - SpringSource - http://www.SpringSource.com - - Project Admin - - -5 - - - mhunger - Michael Hunger - michael.hunger at neotechnology.com - Neo Technology - http://www.neotechnology.com - - Project Admin - Developer - - +1 - - - dmontag - David Montag - david.montag at neotechnology.com - Neo Technology - http://www.neotechnology.com - - Developer - - -7 - + - systay - Andres Taylor - andres at neotechnology.com - Neo Technology - http://www.neotechnology.com - - Developer - - +1 - - + trisberg + Thomas Risberg + trisberg at vmware.com + SpringSource + http://www.SpringSource.com + + Project Admin + + -5 + + + mpollack + Mark Pollack + mpollack at vmware.com + SpringSource + http://www.SpringSource.com + + Project Admin + + -5 + + + mhunger + Michael Hunger + michael.hunger at neotechnology.com + Neo Technology + http://www.neotechnology.com + + Project Admin + Developer + + +1 + + + dmontag + David Montag + david.montag at neotechnology.com + Neo Technology + http://www.neotechnology.com + + Developer + + -7 + + + systay + Andres Taylor + andres at neotechnology.com + Neo Technology + http://www.neotechnology.com + + Developer + + +1 + + - - - Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 - - Copyright 2010 the original author or authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied. - See the License for the specific language governing permissions and - limitations under the License. - - - + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + + Copyright 2010 the original author or authors. - - UTF-8 - - spring-data-neo4j - Spring Data Neo4j - SDNEO4J - ${project.version} - snapshot - ${dist.id}-${dist.version} - ${dist.finalName}.zip - target/${dist.fileName} - dist.springframework.org - - ${basedir}/src/docbkx - ${basedir}/spring-data-neo4j/target/docbkx - ${basedir}/target/classes - - - - fast - - true - - + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. + See the License for the specific language governing permissions and + limitations under the License. + + + + + + UTF-8 + + spring-data-neo4j + Spring Data Neo4j + SDNEO4J + ${project.version} + snapshot + ${dist.id}-${dist.version} + ${dist.finalName}.zip + target/${dist.fileName} + dist.springframework.org + + ${basedir}/src/docbkx + ${basedir}/spring-data-neo4j/target/docbkx + ${basedir}/target/classes + + + + fast + + true + + examples - spring-data-neo4j-examples/hello-worlds - spring-data-neo4j-examples/imdb - spring-data-neo4j-examples/cineasts - spring-data-neo4j-examples/cineasts-aspects - spring-data-neo4j-examples/cineasts-rest - spring-data-neo4j-examples/myrestaurants-social - spring-data-neo4j-examples/todos - spring-data-neo4j-examples/backwardscompatibility - + spring-data-neo4j-examples/hello-worlds + spring-data-neo4j-examples/imdb + spring-data-neo4j-examples/cineasts + spring-data-neo4j-examples/cineasts-aspects + spring-data-neo4j-examples/cineasts-rest + spring-data-neo4j-examples/myrestaurants-social + spring-data-neo4j-examples/todos + spring-data-neo4j-examples/backwardscompatibility + - + staging - - - spring-site-staging - file:///${java.io.tmpdir}/spring-data/data-neo4j/docs/${project.version} - - - spring-milestone-staging - file:///${java.io.tmpdir}/spring-data/data-neo4j/milestone - - - spring-snapshot-staging - file:///${java.io.tmpdir}/spring-data/data-neo4j/snapshot - - - - - snapshot - + + + spring-site-staging + file:///${java.io.tmpdir}/spring-data/data-neo4j/docs/${project.version} + + + spring-milestone-staging + file:///${java.io.tmpdir}/spring-data/data-neo4j/milestone + + + spring-snapshot-staging + file:///${java.io.tmpdir}/spring-data/data-neo4j/snapshot + + + + + snapshot + http://www.springsource.com/spring-data - - static.springframework.org - scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-graph/snapshot-site/ - - - spring-release - Spring Release Repository - s3://maven.springframework.org/release - - - spring-snapshot - Spring Snapshot Repository - s3://maven.springframework.org/snapshot - - - - - milestone - - - spring-milestone - Spring Milestone Repository - s3://maven.springframework.org/milestone - - - - - central - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - - - sonatype-nexus-staging - Nexus Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - - - - - - - - http://www.springsource.com/spring-data - - static.springframework.org - scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-graph/snapshot-site/ - + + static.springframework.org + + scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-graph/snapshot-site/ + + + + spring-release + Spring Release Repository + s3://maven.springframework.org/release + + + spring-snapshot + Spring Snapshot Repository + s3://maven.springframework.org/snapshot + + + + + milestone + + + spring-milestone + Spring Milestone Repository + s3://maven.springframework.org/milestone + + + + + central + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + + http://www.springsource.com/spring-data + + static.springframework.org + + scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-data/data-graph/snapshot-site/ + + spring-release Spring Release Repository s3://maven.springframework.org/release - - spring-snapshot - Spring Snapshot Repository - s3://maven.springframework.org/snapshot - - - - - - - org.springframework.build.aws - org.springframework.build.aws.maven - 3.1.0.RELEASE - - - - - ${docbook.srcDir} - false - - - ${docbook.snippetsDir} - false - - - - - org.apache.maven.plugins - maven-resources-plugin - 2.5 - - ${project.build.sourceEncoding} - - - - generate-sources - - resources - - - - + + spring-snapshot + Spring Snapshot Repository + s3://maven.springframework.org/snapshot + + + + + + + org.springframework.build.aws + org.springframework.build.aws.maven + 3.1.0.RELEASE + + + + + ${docbook.srcDir} + false + + + ${docbook.snippetsDir} + false + + + + + + com.agilejava.docbkx + docbkx-maven-plugin + 2.0.14 + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + ${project.build.sourceEncoding} + + + + generate-sources + + resources + + + + com.agilejava.docbkx docbkx-maven-plugin - 2.0.8 + 2.0.14 single-page @@ -311,55 +325,56 @@ ${docbook.generatedDir} true ${docbook.generatedDir}/resources/xsl/html.xsl - 1 - 1 - + 1 + 1 + - + - - - - + + + + - - - - + + + + pre-site - + single-pdf @@ -369,13 +384,15 @@ ${docbook.generatedDir} ${docbook.generatedDir}/ ${docbook.generatedDir}/resources/images/ - ${docbook.generatedDir}/resources/xsl/fopdf.xsl + ${docbook.generatedDir}/resources/xsl/fopdf.xsl index.xml - 1 - 1 - + 1 + 1 + - + pre-site @@ -389,13 +406,15 @@ ${docbook.generatedDir} ${docbook.generatedDir}/ ${docbook.generatedDir}/resources/images/ - ${docbook.generatedDir}/resources/xsl/fopdf.xsl - 1 - 1 + ${docbook.generatedDir}/resources/xsl/fopdf.xsl + 1 + 1 tutorial.xml - + - + pre-site @@ -410,30 +429,30 @@ true true ${docbook.generatedDir}/resources/xsl/html_chunk.xsl - 1 - 1 - + 1 + 1 + ${basedir}/target/docbkx/multi/ - + - - - + + + - - - - - + + + + + @@ -451,13 +470,13 @@ org.apache.xmlgraphics fop - 0.93 + 1.0 index.xml false - + css/html.css ${docbook.generatedDir}/ @@ -470,105 +489,105 @@ - - maven-javadoc-plugin - 2.7 - - true -
Spring Data Neo4j
- 1.6 - true - ${project.basedir}/src/main/javadoc - ${project.basedir}/src/main/javadoc/overview.html - ${project.basedir}/src/main/javadoc/spring-javadoc.css - - true - - http://static.springframework.org/spring/docs/3.0.x/javadoc-api - http://java.sun.com/javase/6/docs/api - -
- - - javadoc - - jar - - package - - -
- + true + + http://static.springframework.org/spring/docs/3.0.x/javadoc-api + http://java.sun.com/javase/6/docs/api + + + + + javadoc + + jar + + package + + + + - maven-assembly-plugin - 2.2-beta-5 - false + maven-assembly-plugin + 2.2-beta-5 + false ${project.basedir}/src/assembly/distribution.xml false - - - distribution - - single - - package - - - - - org.apache.maven.plugins - maven-antrun-plugin - 1.4 - - - upload-dist - deploy - - - - - - - - - run - - - - - - org.springframework.build - org.springframework.build.aws.ant - 3.0.5.RELEASE - - - net.java.dev.jets3t - jets3t - 0.7.2 - - - -
- - ${dist.finalName} -
+ + + distribution + + single + + package + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.4 + + + upload-dist + deploy + + + + + + + + + run + + + + + + org.springframework.build + org.springframework.build.aws.ant + 3.0.5.RELEASE + + + net.java.dev.jets3t + jets3t + 0.7.2 + + + +
+ + ${dist.finalName} +
repository.springsource.maven.bundles.release SpringSource Maven Release Repository http://repository.springsource.com/maven/bundles/release - - repository.springframework.maven.release - Spring Framework Maven Release Repository - http://maven.springframework.org/release - + + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + jboss-legacy-repository Old JBoss Public Repository @@ -576,35 +595,35 @@ - - central + + central http://uk.maven.org/maven2 - + jboss-legacy-repository Old JBoss Public Repository http://repository.jboss.org/maven2/ - - repository.springframework.maven.release - Spring Framework Maven Release Repository - http://maven.springframework.org/release - - - repository.springframework.maven.milestone - Spring Framework Maven Milestone Repository - http://maven.springframework.org/milestone - - - - repository.source.maven.release - SpringSource Maven Release Repository - http://repository.springsource.com/maven/bundles/release - + + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + + + repository.springframework.maven.milestone + Spring Framework Maven Milestone Repository + http://maven.springframework.org/milestone + + + + repository.source.maven.release + SpringSource Maven Release Repository + http://repository.springsource.com/maven/bundles/release + jboss-repository JBoss Public Repository http://repository.jboss.org/nexus/content/groups/public-jboss - +
diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/RelatedTo.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/RelatedTo.java index af29c7965..395c65df7 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/RelatedTo.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/annotation/RelatedTo.java @@ -60,4 +60,9 @@ public @interface RelatedTo { * @return target class, required for collection based fields (no generic inferring) */ Class elementClass() default Object.class; + + /** + * Used to discriminate between relationships with the same type based on end node type + */ + boolean enforceTargetType() default false; } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToCollectionFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToCollectionFieldAccessorFactory.java index 10d47791f..a8bf9b577 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToCollectionFieldAccessorFactory.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToCollectionFieldAccessorFactory.java @@ -47,35 +47,47 @@ public class RelatedToCollectionFieldAccessorFactory implements FieldAccessorFac } @Override - public FieldAccessor forField(final Neo4jPersistentProperty property) { + public FieldAccessor forField(final Neo4jPersistentProperty property) { final RelationshipInfo relationshipInfo = property.getRelationshipInfo(); final Class targetType = relationshipInfo.getTargetType().getType(); - return new RelatedToCollectionFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, template,property); - } + return new RelatedToCollectionFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), targetType, template, property); + } - public static class RelatedToCollectionFieldAccessor extends RelatedToFieldAccessor { + public static class RelatedToCollectionFieldAccessor extends RelatedToFieldAccessor { - public RelatedToCollectionFieldAccessor(final RelationshipType type, final Direction direction, final Class elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) { - super(elementClass, template, direction, type,property); - } + public RelatedToCollectionFieldAccessor(final RelationshipType type, final Direction direction, final Class elementClass, final Neo4jTemplate template, Neo4jPersistentProperty property) { + super(elementClass, template, direction, type, property); + } - public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) { - final Node node = checkAndGetNode(entity); + public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) { + final Node node = checkAndGetNode(entity); // null should not remove existing relationships but leave them alone - if (newVal == null) return null; - final Set targetNodes = createSetOfTargetNodes(newVal); - removeMissingRelationships(node, targetNodes); - createAddedRelationships(node, targetNodes); - return createManagedSet(entity, (Set) newVal, property.obtainMappingPolicy(mappingPolicy)); - } + if (newVal == null) return null; + final Set targetNodes = createSetOfTargetNodes(newVal); + removeMissingRelationships(node, targetNodes, property.getTargetType()); + createAddedRelationships(node, targetNodes); + return createManagedSet(entity, (Set) newVal, property.obtainMappingPolicy(mappingPolicy)); + } @Override - public Object getValue(final Object entity, MappingPolicy mappingPolicy) { - checkAndGetNode(entity); + public Object getValue(final Object entity, MappingPolicy mappingPolicy) { + checkAndGetNode(entity); final MappingPolicy currentPolicy = property.obtainMappingPolicy(mappingPolicy); - final Set result = createEntitySetFromRelationshipEndNodes(entity, currentPolicy); - return doReturn(createManagedSet(entity, result, currentPolicy)); - } + final Set result = property.isTargetTypeEnforced() ? + createEntitySetFromRelationshipEndNodesUsingTypeProperty(entity, currentPolicy) : + createEntitySetFromRelationshipEndNodes(entity, currentPolicy); + + Set values = new HashSet(); + Class targetType = property.getTargetType(); + + for (Object value : result) { + if (targetType == null || targetType.isAssignableFrom(value.getClass())) { + values.add(value); + } + } + + return doReturn(createManagedSet(entity, values, currentPolicy)); + } @Override public Object getDefaultValue() { diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToFieldAccessor.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToFieldAccessor.java index ebdca873d..8f4c1ab4a 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToFieldAccessor.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToFieldAccessor.java @@ -66,11 +66,16 @@ public abstract class RelatedToFieldAccessor implements FieldAccessor { } protected void removeMissingRelationships(Node node, Set targetNodes) { - relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(node, targetNodes); + removeMissingRelationships( node, targetNodes, null ); + } + + protected void removeMissingRelationships( Node node, Set targetNodes, Class targetType ) { + relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet( node, targetNodes, + targetType ); } protected void createAddedRelationships(Node node, Set targetNodes) { - relationshipHelper.createAddedRelationships(node, targetNodes); + relationshipHelper.createAddedRelationships( node, targetNodes ); } protected Set createSetOfTargetNodes(Object newVal) { @@ -78,6 +83,11 @@ public abstract class RelatedToFieldAccessor implements FieldAccessor { } protected Set createEntitySetFromRelationshipEndNodes(Object entity, MappingPolicy mappingPolicy) { - return relationshipHelper.createEntitySetFromRelationshipEndNodes(entity, mappingPolicy, relatedType); + return relationshipHelper.createEntitySetFromRelationshipEndNodes( entity, mappingPolicy, relatedType ); + } + + protected Set createEntitySetFromRelationshipEndNodesUsingTypeProperty( Object entity, MappingPolicy + mappingPolicy ) { + return relationshipHelper.createEntitySetFromRelationshipEndNodes(entity, mappingPolicy, null); } } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToSingleFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToSingleFieldAccessorFactory.java index 844847974..c35ed823c 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToSingleFieldAccessorFactory.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToSingleFieldAccessorFactory.java @@ -26,6 +26,7 @@ import org.springframework.data.neo4j.mapping.RelationshipInfo; import org.springframework.data.neo4j.support.Neo4jTemplate; import java.util.Collections; +import java.util.HashSet; import java.util.Set; import static org.springframework.data.neo4j.support.DoReturn.doReturn; @@ -35,46 +36,63 @@ public class RelatedToSingleFieldAccessorFactory implements FieldAccessorFactory protected Neo4jTemplate template; public RelatedToSingleFieldAccessorFactory(Neo4jTemplate template) { - this.template = template; - } + this.template = template; + } - @Override - public boolean accept(final Neo4jPersistentProperty property) { - if (!property.isRelationship()) return false; + @Override + public boolean accept(final Neo4jPersistentProperty property) { + if (!property.isRelationship()) return false; return property.getRelationshipInfo().isRelatedTo() && property.getRelationshipInfo().isSingle(); - } + } - @Override - public FieldAccessor forField(final Neo4jPersistentProperty property) { + @Override + public FieldAccessor forField(final Neo4jPersistentProperty property) { final RelationshipInfo relationshipInfo = property.getRelationshipInfo(); return new RelatedToSingleFieldAccessor(relationshipInfo.getRelationshipType(), relationshipInfo.getDirection(), (Class) relationshipInfo.getTargetType().getType(), template,property); - } + } - public static class RelatedToSingleFieldAccessor extends RelatedToFieldAccessor { - public RelatedToSingleFieldAccessor(final RelationshipType type, final Direction direction, final Class clazz, final Neo4jTemplate template, Neo4jPersistentProperty property) { - super(clazz, template, direction, type, property); - } + public static class RelatedToSingleFieldAccessor extends RelatedToFieldAccessor { + public RelatedToSingleFieldAccessor(final RelationshipType type, final Direction direction, final Class clazz, final Neo4jTemplate template, Neo4jPersistentProperty property) { + super(clazz, template, direction, type, property); + } - @Override - public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) { - final Node node= checkAndGetNode(entity); - if (newVal == null) { - removeMissingRelationships(node, Collections.emptySet()); - return null; - } - final Set target= createSetOfTargetNodes(Collections.singleton(newVal)); - removeMissingRelationships(node, target); - createAddedRelationships(node,target); - return newVal; - } + @Override + public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) { + final Node node = checkAndGetNode(entity); + if (newVal == null) { + removeMissingRelationships(node, Collections.emptySet()); + return null; + } + final Set target = createSetOfTargetNodes(Collections.singleton(newVal)); + removeMissingRelationships(node, target, property.getTargetType()); + createAddedRelationships(node, target); + return newVal; + } - @Override - public Object getValue(final Object entity, MappingPolicy mappingPolicy) { - checkAndGetNode(entity); - final Set result = createEntitySetFromRelationshipEndNodes(entity, property.obtainMappingPolicy(mappingPolicy)); - final Object singleEntity = result.isEmpty() ? null : result.iterator().next(); - return doReturn(singleEntity); - } + @Override + public Object getValue(final Object entity, MappingPolicy mappingPolicy) { + checkAndGetNode(entity); + MappingPolicy currentPolicy = property.obtainMappingPolicy(mappingPolicy); + final Set result = property.isTargetTypeEnforced() ? + createEntitySetFromRelationshipEndNodesUsingTypeProperty(entity, currentPolicy) : + createEntitySetFromRelationshipEndNodes(entity, currentPolicy); - } + if (result.isEmpty()) return doReturn(null); + + Set values = new HashSet(); + Class targetType = property.getTargetType(); + + for (Object value : result) { + if (targetType == null || targetType.isAssignableFrom(value.getClass())) { + values.add(value); + } + } + + if (values.size() == 0) return doReturn(null); + if (values.size() == 1) return doReturn(values.iterator().next()); + + throw new IllegalArgumentException("Cannot obtain single field value for field '" + property.getField().getName() + "'"); + } + + } } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaCollectionFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaCollectionFieldAccessorFactory.java index 37e34279d..509ce606f 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaCollectionFieldAccessorFactory.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaCollectionFieldAccessorFactory.java @@ -89,7 +89,7 @@ public class RelatedToViaCollectionFieldAccessorFactory implements FieldAccessor if (newVal == null) return null; final Map endNodeToEntityMapping = loadEndNodeToRelationshipEntityMapping(newVal, startNode); - relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet()); + relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet(), null); persistEntities(endNodeToEntityMapping.values(), relationshipHelper.getRelationshipType()); return createManagedSet(entity, (Set) newVal, property.obtainMappingPolicy(mappingPolicy)); } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaSingleFieldAccessorFactory.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaSingleFieldAccessorFactory.java index 679f74410..42e898e69 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaSingleFieldAccessorFactory.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelatedToViaSingleFieldAccessorFactory.java @@ -77,7 +77,7 @@ public class RelatedToViaSingleFieldAccessorFactory implements FieldAccessorFact public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) { final Node startNode = relationshipHelper.checkAndGetNode(entity); final Map endNodeToEntityMapping = relationshipEntities.loadEndNodeToRelationshipEntityMapping(startNode, toSet(newVal), relatedType); - relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet()); + relationshipHelper.removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(startNode, endNodeToEntityMapping.keySet(), null); persistEntities(endNodeToEntityMapping.values(), relationshipHelper.getRelationshipType() ); return newVal; } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelationshipHelper.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelationshipHelper.java index de738a563..d51fe6dd2 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelationshipHelper.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/fieldaccess/RelationshipHelper.java @@ -27,6 +27,8 @@ import org.springframework.util.Assert; import java.util.HashSet; import java.util.Set; +import static java.lang.String.format; + /** * @author mh * @since 28.02.12 @@ -67,10 +69,25 @@ public class RelationshipHelper { throw new IllegalStateException("Entity must have a backing Node"); } - protected void removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet(Node node, Set targetNodes) { - for (Relationship relationship : node.getRelationships(type, direction)) { - if (!targetNodes.remove(relationship.getOtherNode(node))) - template.delete(relationship); + protected void removeMissingRelationshipsInStoreAndKeepOnlyNewRelationShipsInSet( Node node, + Set targetNodes, + Class targetType ) { + for ( Relationship relationship : node.getRelationships( type, direction ) ) { + if ( !targetNodes.remove( relationship.getOtherNode( node ) ) ) { + if ( targetType != null ) { + Object actualTargetType = relationship.getOtherNode( node ).getProperty( "__type__" ); + + try { + if (! targetType.isAssignableFrom(Class.forName((String) actualTargetType))) { + continue; + } + } catch (ClassNotFoundException e) { + throw new IllegalStateException(format("Could not read type '%s' - type does not exist", actualTargetType), e); + } + } + + template.delete( relationship ); + } } } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/mapping/Neo4jPersistentProperty.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/mapping/Neo4jPersistentProperty.java index b354293f9..8d847b2fb 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/mapping/Neo4jPersistentProperty.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/mapping/Neo4jPersistentProperty.java @@ -98,4 +98,8 @@ public interface Neo4jPersistentProperty extends PersistentProperty getTargetType(); + + boolean isTargetTypeEnforced(); } diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/Neo4jTemplate.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/Neo4jTemplate.java index 1d7745f8f..0d431ae38 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/Neo4jTemplate.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/Neo4jTemplate.java @@ -167,17 +167,13 @@ public class Neo4jTemplate implements Neo4jOperations { return infrastructure.getTypeRepresentationStrategies().count(getEntityType(entityClass)); } - public T createEntityFromStoredType(S state) { - notNull(state,"node or relationship"); - return infrastructure.getEntityPersister().createEntityFromStoredType(state, this); - } public T createEntityFromStoredType(S state, MappingPolicy mappingPolicy) { notNull(state,"node or relationship"); return infrastructure.getEntityPersister().createEntityFromStoredType(state, mappingPolicy, this); } public T createEntityFromState(S state, Class type, MappingPolicy mappingPolicy) { - notNull(state,"node or relationship",type,"entity class"); + notNull(state,"node or relationship"); return infrastructure.getEntityPersister().createEntityFromState(state, type, mappingPolicy, this); } @Override diff --git a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/mapping/Neo4JPersistentPropertyImpl.java b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/mapping/Neo4JPersistentPropertyImpl.java index e16529559..dd9c28459 100644 --- a/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/mapping/Neo4JPersistentPropertyImpl.java +++ b/spring-data-neo4j/src/main/java/org/springframework/data/neo4j/support/mapping/Neo4JPersistentPropertyImpl.java @@ -382,4 +382,18 @@ class Neo4jPersistentPropertyImpl extends AbstractPersistentProperty getTargetType() { + if (! isTargetTypeEnforced()) return null; + + if (isCollectionLike()) return getComponentType(); + + return getType(); + } + + @Override + public boolean isTargetTypeEnforced() { + return getAnnotation( RelatedTo.class ) != null && getAnnotation( RelatedTo.class ).enforceTargetType(); + } } diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelatedToViaTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelatedToViaTests.java deleted file mode 100644 index 2f990cdc9..000000000 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelatedToViaTests.java +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright 2011 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.neo4j.annotation; - -import static java.util.Arrays.asList; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.junit.matchers.JUnitMatchers.hasItem; -import static org.neo4j.helpers.collection.IteratorUtil.first; - -import java.util.HashSet; -import java.util.Set; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.neo4j.graphdb.Relationship; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.data.neo4j.support.Neo4jTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.transaction.annotation.Transactional; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:related-to-via-test-context.xml"}) -@Transactional -public class RelatedToViaTests { - public static final String DISTRICT_LINE = "District Line"; - public static final String CENTRAL_LINE = "Central Line"; - - @Autowired - private UndergroundRepository tfl; - - @Autowired - private CountryRepository countries; - - @Autowired - private SuperStateRepository dystopia; - - @Autowired - private MetroLineRepository metroLines; - - @Autowired - private CityRepository cities; - - @Autowired - private PlayerRepository players; - - @Autowired - private TeamRepository teams; - - @Autowired - private Neo4jTemplate template; - - @Before - public void before() { - tfl.deleteAll(); - countries.deleteAll(); - dystopia.deleteAll(); - metroLines.deleteAll(); - cities.deleteAll(); - players.deleteAll(); - teams.deleteAll(); - } - - @Test - public void shouldMapRelationshipAsFirstClassCitizen() throws Exception { - TubeStation westHam = tfl.save( new TubeStation( "West Ham" ) ); - TubeStation stratford = tfl.save( new TubeStation( "Stratford" ) ); - TubeStation mileEnd = new TubeStation( "Mile End" ); - mileEnd.connectsTo( westHam, DISTRICT_LINE ); - mileEnd.connectsTo( stratford, CENTRAL_LINE ); - - tfl.save( mileEnd ); - - assertThat( first( template.getNode( mileEnd.getId() ).getRelationships() ).getType().name(), is( "route" ) ); - mileEnd = tfl.findOne( mileEnd.getId() ); - Line line = first( mileEnd.getLines()); - assertThat( mileEnd, is( equalTo( line.getOrigin() ) ) ); - assertThat( asList( DISTRICT_LINE, CENTRAL_LINE ), hasItem( line.getName() ) ); - assertThat( asList( westHam, stratford ), hasItem( line.getDestination() ) ); - } - - @Test - public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefault() throws Exception { - Country france = countries.save( new Country( "République française" ) ); - Country usa = countries.save( new Country( "United States of America" ) ); - Country uk = new Country( "United Kingdom of Great Britain and Northern Ireland" ); - uk.hasCordialRelationsWith( france, "Entente Cordiale" ); - uk.hasSpecialRelationsWith( usa ); - - countries.save( uk ); - - assertThat( getRelationshipNames( uk ), is( equalTo( asSet( "cordial", "special" ) ) ) ); - } - - @Test - public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefaultForCollections() throws Exception { - MetroLine m1 = metroLines.save( new MetroLine( "M1 - Vanløse to Vestamager" ) ); - MetroLine m2 = metroLines.save( new MetroLine( "M2 - Vanløse to Lufthavnen" ) ); - MetroLine m3 = metroLines.save( new MetroLine( "M3 - Cityringen" ) ); - MetroLine m4 = metroLines.save( new MetroLine( "M4 - Nørrebro to København H" ) ); - City copenhagen = new City( "Copenhagen" ); - copenhagen.has( m1, m2 ); - copenhagen.plans( m3, m4 ); - - cities.save( copenhagen ); - - assertThat( getRelationshipNames( copenhagen ), is( equalTo( asSet( "existing", "planned" ) ) ) ); - assertThat( copenhagen.getCurrentMetroLines(), is( equalTo( asSet( m1, m2 ) ) ) ); - assertThat( copenhagen.getFutureMetroLines(), is( equalTo( asSet( m3, m4 ) ) ) ); - } - - @Test - public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipType() throws Exception { - SuperState eastasia = dystopia.save( new SuperState( "Eastasia" ) ); - SuperState eurasia = dystopia.save( new SuperState( "Eurasia" ) ); - SuperState oceania = new SuperState( "Oceania" ); - oceania.isAlliedWith( eastasia ); - - dystopia.save( oceania ); - - assertThat( getFirstRelationshipName( oceania ), is( equalTo( "alliedWith" ) ) ); - - oceania = dystopia.findOne( oceania.getId() ); - oceania.isAtWarWith( eurasia ); - - dystopia.save( oceania ); - - assertThat( getFirstRelationshipName( oceania ), is( equalTo( "atWarWith" ) ) ); - } - - @Test - public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipTypeForCollections() - throws Exception { - Player jordan = players.save( new Player( "Michael Jordan" ) ); - Player pippen = players.save( new Player( "Scottie Pippen" ) ); - Team bulls = new Team( "Chicago Bulls" ); - bulls.add( new PlayerStatus( bulls, jordan ) ); - bulls.add( new PlayerStatus( bulls, pippen, "substitute" ) ); - - teams.save( bulls ); - - assertThat( getRelationshipNames( bulls ), is( equalTo( asSet( "starter", "substitute" ) ) ) ); - } - - @Test - public void shouldValidateEndNode() throws Exception { - TubeStation mileEnd = new TubeStation( "East Ham" ); - mileEnd.connectsTo( null, DISTRICT_LINE ); - - try { - tfl.save( mileEnd ); - - fail(); - } - catch ( InvalidDataAccessApiUsageException e ) { - assertThat( e.getCause().getMessage(), is( equalTo( "End node must not be null (org.springframework.data" + - ".neo4j.annotation.Line)" ) ) ); - } - } - - private String getFirstRelationshipName( IdentifiableEntity entity ) { - return first( template.getNode( entity.getId() ).getRelationships() ).getType().name(); - } - - private Set getRelationshipNames( IdentifiableEntity entity ) { - HashSet relationshipNames = new HashSet(); - - for ( Relationship relationship : template.getNode( entity.getId() ).getRelationships() ) { - relationshipNames.add( relationship.getType().name() ); - } - - return relationshipNames; - } - - private Set asSet( T... ts ) { - return new HashSet( asList( ts ) ); - } -} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelationshipDelegates.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelationshipDelegates.java new file mode 100644 index 000000000..3f023a26e --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/RelationshipDelegates.java @@ -0,0 +1,44 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation; + +import org.neo4j.graphdb.Relationship; +import org.springframework.data.neo4j.support.Neo4jTemplate; + +import java.util.HashSet; +import java.util.Set; + +import static org.neo4j.helpers.collection.IteratorUtil.count; + +public class RelationshipDelegates { + public static Set getRelationshipNames(Neo4jTemplate template, IdentifiableEntity entity) { + HashSet relationshipNames = new HashSet(); + + for (Relationship relationship : getRelationships(template, entity)) { + relationshipNames.add(relationship.getType().name()); + } + + return relationshipNames; + } + + public static Integer getNumberOfRelationships(Neo4jTemplate template, IdentifiableEntity entity) { + return count(getRelationships(template, entity)); + } + + private static Iterable getRelationships(Neo4jTemplate template, IdentifiableEntity entity) { + return template.getNode(entity.getId()).getRelationships(); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SetHelper.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SetHelper.java new file mode 100644 index 000000000..249741c8b --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SetHelper.java @@ -0,0 +1,27 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +public class SetHelper { + public static Set asSet(T... ts) { + return new HashSet(asList(ts)); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Activity.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Activity.java new file mode 100644 index 000000000..8f3f3b7bc --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Activity.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Activity extends IdentifiableEntity { + private String name; + + public Activity() { + } + + public Activity( String name ) { + + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ActivityRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ActivityRepository.java new file mode 100644 index 000000000..ba081d884 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ActivityRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ActivityRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Advisor.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Advisor.java new file mode 100644 index 000000000..bf223107c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Advisor.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Advisor extends IdentifiableEntity { + private String name; + + public Advisor() { + } + + public Advisor(String name) { + + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AdvisorRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AdvisorRepository.java new file mode 100644 index 000000000..6fff249d6 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AdvisorRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface AdvisorRepository extends CRUDRepository{ +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Animal.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Animal.java new file mode 100644 index 000000000..67adeee59 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Animal.java @@ -0,0 +1,22 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public interface Animal { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AnimalRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AnimalRepository.java new file mode 100644 index 000000000..e999864f5 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AnimalRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface AnimalRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Apple.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Apple.java new file mode 100644 index 000000000..7389b5596 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Apple.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Apple extends IdentifiableEntity { + private String colour; + + public Apple() { + } + + public Apple(String colour) { + this.colour = colour; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleRepository.java new file mode 100644 index 000000000..405b39f19 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface AppleRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStore.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStore.java new file mode 100644 index 000000000..443dd8d1c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStore.java @@ -0,0 +1,44 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class AppleStore extends IdentifiableEntity { + @RelatedTo(type = "supplies", enforceTargetType = true) + private MacBook macBook; + + @RelatedTo(type = "supplies", enforceTargetType = true) + private RetinaMacBook retinaMacbook; + + @RelatedTo(type = "supplies", enforceTargetType = true) + private Iterable supplies; + + public void suppliesMacBook(MacBook macbook) { + this.macBook = macbook; + } + + public void suppliesRetinaMacBook(RetinaMacBook retinaMacbook) { + this.retinaMacbook = retinaMacbook; + } + + public Iterable getSupplies() { + return supplies; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStoreRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStoreRepository.java new file mode 100644 index 000000000..8f9965f57 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/AppleStoreRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface AppleStoreRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMember.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMember.java new file mode 100644 index 000000000..84f31070a --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMember.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class BoardMember extends IdentifiableEntity { + private String name; + + public BoardMember() { + } + + public BoardMember(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMemberRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMemberRepository.java new file mode 100644 index 000000000..f0229746a --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BoardMemberRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface BoardMemberRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Book.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Book.java new file mode 100644 index 000000000..fda461e07 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Book.java @@ -0,0 +1,56 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Book extends IdentifiableEntity { + private String name; + + private Book prequel; + + private Set peers = new HashSet(); + + public Book() { + } + + public Book(String name) { + this.name = name; + } + + public void follows(Book prequel) { + this.prequel = prequel; + } + + public void hasTrilogyPeers(Book... books) { + peers.addAll(asList(books)); + } + + public Book getPrequel() { + return prequel; + } + + public Set getTrilogyPeers() { + return peers; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BookRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BookRepository.java new file mode 100644 index 000000000..bd02112d8 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/BookRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface BookRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfile.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfile.java new file mode 100644 index 000000000..3eb14228f --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfile.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class CareerProfile extends IdentifiableEntity { + private String name; + + @RelatedTo(enforceTargetType = true) + private Set experience = new HashSet(); + + @RelatedTo(type = "experience", enforceTargetType = true) + private Set jobs = new HashSet(); + + public CareerProfile() { + } + + public CareerProfile(String name) { + this.name = name; + } + + public void addExperience(Experience... experience) { + this.experience.addAll(asList(experience)); + } + + public void addJobs(Job... jobs) { + this.jobs.addAll(asList(jobs)); + } + + public Set getExperience() { + return experience; + } + + public Set getJobs() { + return jobs; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfileRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfileRepository.java new file mode 100644 index 000000000..3bee97f17 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CareerProfileRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface CareerProfileRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Carnivore.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Carnivore.java new file mode 100644 index 000000000..1b426cb4a --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Carnivore.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Carnivore extends IdentifiableEntity implements Animal { + private String name; + + public Carnivore() { + + } + + public Carnivore(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Chairman.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Chairman.java new file mode 100644 index 000000000..119787003 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Chairman.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Chairman extends IdentifiableEntity { + private String name; + + public Chairman() { + } + + public Chairman(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ChairmanRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ChairmanRepository.java new file mode 100644 index 000000000..cc59a91c7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ChairmanRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ChairmanRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachine.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachine.java new file mode 100644 index 000000000..32eed780f --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachine.java @@ -0,0 +1,45 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class CoffeeMachine extends IdentifiableEntity { + @RelatedTo(type = "produces") + private DripBrew dripBrew; + + @RelatedTo(type = "produces") + private EspressoBasedCoffee espressoBasedCoffee; + + public void produces(DripBrew dripBrew) { + this.dripBrew = dripBrew; + } + + public void produces(EspressoBasedCoffee espressoBasedCoffee) { + this.espressoBasedCoffee = espressoBasedCoffee; + } + + public DripBrew getDripBrew() { + return dripBrew; + } + + public EspressoBasedCoffee getEspressoBasedCoffee() { + return espressoBasedCoffee; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachineRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachineRepository.java new file mode 100644 index 000000000..a052f05e3 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CoffeeMachineRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface CoffeeMachineRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Course.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Course.java new file mode 100644 index 000000000..1a84241fb --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Course.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Course extends IdentifiableEntity { + private String name; + + public Course() { + } + + public Course(String name) { + + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CourseRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CourseRepository.java new file mode 100644 index 000000000..caedd8ed2 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/CourseRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface CourseRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrew.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrew.java new file mode 100644 index 000000000..3b4963d19 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrew.java @@ -0,0 +1,35 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class DripBrew extends IdentifiableEntity { + private String name; + + public DripBrew() { + } + + public DripBrew(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrewRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrewRepository.java new file mode 100644 index 000000000..cd0390798 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/DripBrewRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface DripBrewRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffee.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffee.java new file mode 100644 index 000000000..941d5edb6 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffee.java @@ -0,0 +1,35 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class EspressoBasedCoffee extends IdentifiableEntity { + private String name; + + public EspressoBasedCoffee() { + } + + public EspressoBasedCoffee(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffeeRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffeeRepository.java new file mode 100644 index 000000000..4e47636e5 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/EspressoBasedCoffeeRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface EspressoBasedCoffeeRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Experience.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Experience.java new file mode 100644 index 000000000..b8a53f398 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Experience.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Experience extends IdentifiableEntity { + private String description; + + public Experience() { + } + + public Experience(String description) { + this.description = description; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ExperienceRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ExperienceRepository.java new file mode 100644 index 000000000..6f8d12e32 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ExperienceRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ExperienceRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Friend.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Friend.java new file mode 100644 index 000000000..9ba83f6c4 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Friend.java @@ -0,0 +1,46 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class Friend extends IdentifiableEntity { + @RelatedTo(type = "friend", enforceTargetType = true) + private Friend friend; + + @RelatedTo(type = "friend", enforceTargetType = true) + private Friend bestFriend; + + private String name; + + public Friend() { + } + + public Friend(String name) { + this.name = name; + } + + public void isFriendsWith(Friend friend) { + this.friend = friend; + } + + public void isBestFriendsWith(Friend bestFriend) { + this.bestFriend = bestFriend; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FriendRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FriendRepository.java new file mode 100644 index 000000000..d1d99248c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FriendRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface FriendRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowl.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowl.java new file mode 100644 index 000000000..4e5713e9d --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowl.java @@ -0,0 +1,50 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class FruitBowl extends IdentifiableEntity { + @RelatedTo(type = "contains") + private Set redApples = new HashSet(); + + @RelatedTo(type = "contains") + private Apple greenApple; + + public void addRedApples(Apple... apples) { + redApples.addAll(asList(apples)); + } + + public void setGreenApple(Apple greenApple) { + this.greenApple = greenApple; + } + + public Set getRedApples() { + return redApples; + } + + public Apple getGreenApple() { + return greenApple; + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowlRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowlRepository.java new file mode 100644 index 000000000..5041bf4a4 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/FruitBowlRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface FruitBowlRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Herbivore.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Herbivore.java new file mode 100644 index 000000000..c58c49be7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Herbivore.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Herbivore extends IdentifiableEntity implements Animal { + private String name; + + public Herbivore() { + + } + + public Herbivore(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Hero.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Hero.java new file mode 100644 index 000000000..36eefe7d7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Hero.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Hero extends IdentifiableEntity { + private String name; + + public Hero() { + } + + public Hero(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HeroRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HeroRepository.java new file mode 100644 index 000000000..a3e09f95e --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HeroRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface HeroRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Human.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Human.java new file mode 100644 index 000000000..0e4049105 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Human.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Human extends IdentifiableEntity { + private String name; + + public Human() { + } + + public Human(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HumanRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HumanRepository.java new file mode 100644 index 000000000..3760e5a78 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/HumanRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface HumanRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Initiative.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Initiative.java new file mode 100644 index 000000000..a91d4a80a --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Initiative.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Initiative extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "hero", enforceTargetType = true) + private Hero leader; + + @RelatedTo(type = "hero", enforceTargetType = true) + private Set members = new HashSet(); + + public Initiative() { + } + + public Initiative(String name) { + this.name = name; + } + + public void setLeader(Hero leader) { + this.leader = leader; + } + + public void add(Superhero... members) { + this.members.addAll(asList(members)); + } + + public Hero getLeader() { + return leader; + } + + public Set getMembers() { + return members; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/InitiativeRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/InitiativeRepository.java new file mode 100644 index 000000000..0f42495d4 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/InitiativeRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface InitiativeRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Job.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Job.java new file mode 100644 index 000000000..512b60ce6 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Job.java @@ -0,0 +1,28 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Job extends Experience { + public Job() { + } + + public Job(String title) { + super(title); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/JobRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/JobRepository.java new file mode 100644 index 000000000..10a3088dd --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/JobRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface JobRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBook.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBook.java new file mode 100644 index 000000000..d5d2d1b84 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBook.java @@ -0,0 +1,23 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class MacBook extends IdentifiableEntity{ +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBookRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBookRepository.java new file mode 100644 index 000000000..0b7e71450 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MacBookRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface MacBookRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeapon.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeapon.java new file mode 100644 index 000000000..431a897a8 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeapon.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class MainHandWeapon extends IdentifiableEntity implements Weapon { + private String name; + + public MainHandWeapon() { + } + + public MainHandWeapon(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeaponRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeaponRepository.java new file mode 100644 index 000000000..2193372d7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MainHandWeaponRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface MainHandWeaponRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacter.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacter.java new file mode 100644 index 000000000..0776ce9c7 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacter.java @@ -0,0 +1,55 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class MarvelCharacter extends IdentifiableEntity { + private String name; + + @RelatedTo(enforceTargetType=true) + private MarvelCharacter favourite; + + @RelatedTo(type = "favourite", enforceTargetType=true) + private Activity favouriteActivity; + + public MarvelCharacter() { + + } + + public MarvelCharacter( String name ) { + this.name = name; + } + + public void favours( MarvelCharacter marvelCharacter ) { + favourite = marvelCharacter; + } + + public void loves( Activity activity ) { + favouriteActivity = activity; + } + + public MarvelCharacter getFavourite() { + return favourite; + } + + public Activity getFavouriteActivity() { + return favouriteActivity; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacterRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacterRepository.java new file mode 100644 index 000000000..631aff983 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MarvelCharacterRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface MarvelCharacterRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Mondrian.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Mondrian.java new file mode 100644 index 000000000..adb8a58f6 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Mondrian.java @@ -0,0 +1,70 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Mondrian extends IdentifiableEntity { + public static short RED = 1; + public static short YELLOW = 2; + public static short BLUE = 3; + + private String title; + + @RelatedTo(type = "includes", enforceTargetType = true) + private Square square; + + @RelatedTo(type = "includes", enforceTargetType = true) + private Set rectangles = new HashSet(); + + @RelatedTo(type = "includes", enforceTargetType = true) + private Iterable quadrilaterals; + + public Mondrian() { + } + + public Mondrian(String title) { + this.title = title; + } + + public void includes(Square square) { + this.square = square; + } + + public void includes(Rectangle... rectangles) { + this.rectangles.addAll(asList(rectangles)); + } + + public Square getSquare() { + return square; + } + + public Set getRectangles() { + return rectangles; + } + + public Iterable getQuadrilaterals() { + return quadrilaterals; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MondrianRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MondrianRepository.java new file mode 100644 index 000000000..163bbf3f4 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/MondrianRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface MondrianRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeapon.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeapon.java new file mode 100644 index 000000000..d267d5325 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeapon.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class OffHandWeapon extends IdentifiableEntity implements Weapon { + private String name; + + public OffHandWeapon() { + } + + public OffHandWeapon(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeaponRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeaponRepository.java new file mode 100644 index 000000000..a6bb474ef --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OffHandWeaponRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface OffHandWeaponRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Organisation.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Organisation.java new file mode 100644 index 000000000..7f48974af --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Organisation.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Organisation extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "executive", enforceTargetType = true) + private Chairman chairman; + + @RelatedTo(type = "executive", enforceTargetType = true) + private Set boardMembers = new HashSet(); + + public Organisation() { + } + + public Organisation(String name) { + this.name = name; + } + + public void setChairman(Chairman chairman) { + this.chairman = chairman; + } + + public void add(BoardMember... boardMembers) { + this.boardMembers.addAll(asList(boardMembers)); + } + + public Chairman getChairman() { + return chairman; + } + + public Set getBoardMembers() { + return boardMembers; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OrganisationRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OrganisationRepository.java new file mode 100644 index 000000000..55ebcdbdf --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/OrganisationRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface OrganisationRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Quadrilateral.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Quadrilateral.java new file mode 100644 index 000000000..1ac7db792 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Quadrilateral.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public abstract class Quadrilateral extends IdentifiableEntity{ + private short colour; + + public Quadrilateral() { + } + + public Quadrilateral(short colour) { + this.colour = colour; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Rectangle.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Rectangle.java new file mode 100644 index 000000000..7049f33ee --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Rectangle.java @@ -0,0 +1,29 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Rectangle extends Quadrilateral { + public Rectangle() { + + } + + public Rectangle(short colour) { + super(colour); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RectangleRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RectangleRepository.java new file mode 100644 index 000000000..7f8921ead --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RectangleRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface RectangleRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RelatedToTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RelatedToTests.java new file mode 100644 index 000000000..06078aa84 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RelatedToTests.java @@ -0,0 +1,493 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.convert.ConverterNotFoundException; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.neo4j.support.Neo4jTemplate; +import org.springframework.data.neo4j.support.node.Neo4jHelper; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.transaction.BeforeTransaction; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collections; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; +import static org.junit.matchers.JUnitMatchers.either; +import static org.junit.matchers.JUnitMatchers.hasItem; +import static org.neo4j.helpers.collection.IteratorUtil.single; +import static org.springframework.data.neo4j.annotation.RelationshipDelegates.getNumberOfRelationships; +import static org.springframework.data.neo4j.annotation.RelationshipDelegates.getRelationshipNames; +import static org.springframework.data.neo4j.annotation.SetHelper.asSet; +import static org.springframework.data.neo4j.annotation.relatedto.Mondrian.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:related-to-test-context.xml"}) +@Transactional +public class RelatedToTests { + @Autowired + private BookRepository books; + + @Autowired + private TownRepository towns; + + @Autowired + private WarchiefRepository warchiefs; + + @Autowired + private AdvisorRepository advisors; + + @Autowired + private MarvelCharacterRepository marvelCharacters; + + @Autowired + private ActivityRepository activities; + + @Autowired + private AnimalRepository animals; + + @Autowired + private ZooRepository zsl; + + @Autowired + private ShopRepository shops; + + @Autowired + private RestaurantRepository restaurants; + + @Autowired + private ShoppingCenterRepository shoppingCenters; + + @Autowired + private MainHandWeaponRepository mainHandWeapons; + + @Autowired + private OffHandWeaponRepository offHandWeapons; + @Autowired + private WorldOfWarcraftCharacterRepository worldOfWarcraftCharacters; + + @Autowired + private CourseRepository courses; + + @Autowired + private StudentRepository students; + + @Autowired + private ExperienceRepository experiences; + + @Autowired + private JobRepository jobs; + + @Autowired + private CareerProfileRepository linkedin; + + @Autowired + private DripBrewRepository dripBrews; + + @Autowired + private EspressoBasedCoffeeRepository americanos; + + @Autowired + private CoffeeMachineRepository coffeeMachines; + + @Autowired + private AppleRepository apples; + + @Autowired + private FruitBowlRepository fruitbowls; + + @Autowired + private MacBookRepository macBookRepository; + + @Autowired + private RetinaMacBookRepository retinaMacBooks; + + @Autowired + private AppleStoreRepository appleStores; + + @Autowired + private FriendRepository friends; + + @Autowired + private ChairmanRepository chairmen; + + @Autowired + private BoardMemberRepository boardMembers; + + @Autowired + private OrganisationRepository organisations; + + @Autowired + private SquareRepository squares; + + @Autowired + private RectangleRepository rectangles; + + @Autowired + private MondrianRepository mondrians; + + @Autowired + private TeamRepository teams; + + @Autowired + private HumanRepository humans; + + @Autowired + private SuperHumanRepository superHumans; + + @Autowired + private SuperheroRepository superheroes; + + @Autowired + private HeroRepository heroes; + + @Autowired + private InitiativeRepository initiatives; + + @Autowired + private Neo4jTemplate template; + + @BeforeTransaction + public void before() { + Neo4jHelper.cleanDb(template); + } + + @Test + public void shouldMapRelationshipEvenWithoutAnnotation() throws Exception { + Book theHobbit = books.save(new Book("The Hobbit")); + Book theTwoTowers = books.save(new Book("The Two Towers")); + Book theReturnOfTheKing = books.save(new Book("The Return of the King")); + Book theFellowship = new Book("The Fellowship of the Ring"); + theFellowship.follows(theHobbit); + theFellowship.hasTrilogyPeers(theTwoTowers, theReturnOfTheKing); + + books.save(theFellowship); + + assertThat(getRelationshipNames(template, theFellowship), is(asSet("prequel", "peers"))); + theFellowship = books.findOne(theFellowship.getId()); + assertThat(theFellowship.getPrequel(), is(equalTo(theHobbit))); + assertThat(theFellowship.getTrilogyPeers(), is(equalTo(asSet(theTwoTowers, theReturnOfTheKing)))); + } + + @Test + public void shouldRelateNodesUsingFieldNameAsRelationshipType() throws Exception { + Town malmo = towns.save(new Town("Malmö")); + Town newcastle = new Town("Newcastle"); + newcastle.isTwinnedWith(malmo); + Town gateshead = towns.save(new Town("Gateshead")); + Town sunderland = towns.save(new Town("Sunderland")); + newcastle.hasNeighbours(gateshead, sunderland); + + towns.save(newcastle); + + assertThat(getRelationshipNames(template, newcastle), is(asSet("twin", "neighbours"))); + newcastle = towns.findOne(newcastle.getId()); + assertThat(newcastle.getTwin(), is(equalTo(malmo))); + assertThat(newcastle.getNeighbours(), is(equalTo(asSet(gateshead, sunderland)))); + } + + @Test + public void shouldRelateNodesUsingAnnotationProvidedRelationshipType() throws Exception { + Warchief orgrim = warchiefs.save(new Warchief("Orgrim Doomhammer")); + Warchief thrall = new Warchief("Thrall, Son of Durotan"); + thrall.succeeds(orgrim); + Advisor garrosh = advisors.save(new Advisor("Garrosh Hellscream")); + Advisor rehgar = advisors.save(new Advisor("Rehgar Earthfury")); + thrall.hasAdvisors(garrosh, rehgar); + + warchiefs.save(thrall); + + assertThat(getRelationshipNames(template, thrall), is(asSet("succeeds", "is_advised_by"))); + thrall = warchiefs.findOne(thrall.getId()); + assertThat(thrall.getMentor(), is(equalTo(orgrim))); + assertThat(thrall.getAdvisors(), is(equalTo(asSet(garrosh, rehgar)))); + } + + /** + * stacked entity cache means we do not load the node back polymorphically - should we? + */ + @Test + public void shouldNotDifferentiateByEndNodeClassWhenTargetTypeNotEnforced() throws Exception { + DripBrew filteredCoffee = dripBrews.save(new DripBrew("Filtered Coffee")); + EspressoBasedCoffee americano = americanos.save(new EspressoBasedCoffee("Americano")); + CoffeeMachine coffeeMachine = new CoffeeMachine(); + coffeeMachine.produces(filteredCoffee); + coffeeMachine.produces(americano); + + try { + coffeeMachines.save(coffeeMachine); + + fail(); + } catch (ConverterNotFoundException e) { + assertThat(asSet(DripBrew.class.getName(), EspressoBasedCoffee.class.getName()), hasItem(e.getSourceType().getName())); + assertThat(asSet(DripBrew.class.getName(), EspressoBasedCoffee.class.getName()), hasItem(e.getTargetType().getName())); + assertThat(e.getSourceType().getName(), is(not(equalTo(e.getTargetType().getName())))); + } + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenFields() throws Exception { + MarvelCharacter betty = marvelCharacters.save(new MarvelCharacter("Betty Ross")); + Activity smashing = activities.save(new Activity("smashing")); + MarvelCharacter hulk = new MarvelCharacter("Hulk"); + hulk.favours(betty); + hulk.loves(smashing); + + marvelCharacters.save(hulk); + + assertThat(getRelationshipNames(template, hulk), is(equalTo(asSet("favourite")))); + hulk = marvelCharacters.findOne(hulk.getId()); + assertThat(hulk.getFavourite(), is(equalTo(betty))); + assertThat(hulk.getFavouriteActivity(), is(equalTo(smashing))); + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenCollections() throws Exception { + Shop appleStore = shops.save(new Shop("Apple Store")); + Shop hAndM = shops.save(new Shop("H&M")); + Restaurant wahaca = restaurants.save(new Restaurant("Wahaca")); + Restaurant busabaEathai = restaurants.save(new Restaurant("Busaba Eathai")); + + ShoppingCenter westfield = new ShoppingCenter("Westfield - Stratford City"); + westfield.houses(appleStore, hAndM); + westfield.houses(wahaca, busabaEathai); + shoppingCenters.save(westfield); + + assertThat(getRelationshipNames(template, westfield), is(equalTo(asSet("houses")))); + westfield = shoppingCenters.findOne(westfield.getId()); + assertThat(westfield.getShops(), is(equalTo(asSet(appleStore, hAndM)))); + assertThat(westfield.getRestaurants(), is(equalTo(asSet(wahaca, busabaEathai)))); + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedBetweenFieldAndCollection() throws Exception { + Chairman jacquesRogge = chairmen.save(new Chairman("Jacques Rogge")); + BoardMember boardMember1 = boardMembers.save(new BoardMember("Denis Oswald")); + BoardMember boardMember2 = boardMembers.save(new BoardMember("René Fasel")); + BoardMember boardMember3 = boardMembers.save(new BoardMember("Frank Fredericks")); + + Organisation ioc = new Organisation("THE INTERNATIONAL OLYMPIC COMMITTEE"); + ioc.setChairman(jacquesRogge); + ioc.add(boardMember1, boardMember2, boardMember3); + organisations.save(ioc); + + assertThat(getRelationshipNames(template, ioc), is(equalTo(asSet("executive")))); + ioc = organisations.findOne(ioc.getId()); + assertThat(ioc.getChairman(), is(equalTo(jacquesRogge))); + assertThat(ioc.getBoardMembers(), is(equalTo(asSet(boardMember1, boardMember2, boardMember3)))); + } + + /** + * We cannot distinguish the relationships, so one overwrites the other. It is not even deterministic + */ + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenFields() throws Exception { + Friend sam = friends.save(new Friend("Samwise Gamgee")); + Friend pippin = friends.save(new Friend("Peregrin Took")); + Friend frodo = new Friend("Frodo Baggins"); + frodo.isFriendsWith(pippin); + frodo.isBestFriendsWith(sam); + + friends.save(frodo); + + assertThat(getNumberOfRelationships(template, frodo), is(equalTo(1))); + } + + /** + * "Interesting" semantics - but we have no way of disallowing it + */ + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenCollections() throws Exception { + Course probabilityTheory = courses.save(new Course("Probability Theory")); + Course geometry = courses.save(new Course("Geometry")); + Course statistics = courses.save(new Course("Statistics")); + Course calculus = courses.save(new Course("Calculus")); + + Student student = new Student("Ferris Bueller"); + student.likes(probabilityTheory, geometry); + student.isBoredWith(statistics, calculus); + students.save(student); + + assertThat(getRelationshipNames(template, student), is(equalTo(asSet("attends")))); + student = students.findOne(student.getId()); + assertThat(student.getFavouriteCourses(), is(either(equalTo(asSet(probabilityTheory, geometry))).or(equalTo(asSet(statistics, calculus))))); + assertThat(student.getDislikedCourses(), is(either(equalTo(asSet(probabilityTheory, geometry))).or(equalTo(asSet(statistics, calculus))))); + } + + /** + * So, because you let your relationship types clash, and + * didn't want to distinguish by target type, you get either + * only green apples or an exception + */ + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypesIdenticalBetweenFieldAndCollection() throws Exception { + Apple redApple1 = apples.save(new Apple("red")); + Apple redApple2 = apples.save(new Apple("red")); + Apple greenApple = apples.save(new Apple("green")); + + FruitBowl fruitBowl = new FruitBowl(); + fruitBowl.addRedApples(redApple1, redApple2); + fruitBowl.setGreenApple(greenApple); + try { + fruitbowls.save(fruitBowl); + + assertThat(getRelationshipNames(template, fruitBowl), is(equalTo(asSet("contains")))); + + fruitBowl = fruitbowls.findOne(fruitBowl.getId()); + assertThat(fruitBowl.getRedApples(), is(equalTo(asSet(greenApple)))); + assertThat(fruitBowl.getGreenApple(), is(equalTo(greenApple))); + } catch (InvalidDataAccessApiUsageException e) { + assertThat(e.getCause().getMessage(), is(equalTo("Cannot obtain single field value for field 'greenApple'"))); + } + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnFieldsSharingSuperType() throws Exception { + MainHandWeapon mainHandWeapon = mainHandWeapons.save(new MainHandWeapon("Warglaive of Azzinoth")); + OffHandWeapon offHandWeapon = offHandWeapons.save(new OffHandWeapon("Warglaive of Azzinoth")); + WorldOfWarcraftCharacter illidanStormrage = new WorldOfWarcraftCharacter("Illidan Stormrage"); + illidanStormrage.wields(mainHandWeapon); + illidanStormrage.wields(offHandWeapon); + + worldOfWarcraftCharacters.save(illidanStormrage); + + assertThat(getRelationshipNames(template, illidanStormrage), is(equalTo(asSet("wields")))); + illidanStormrage = worldOfWarcraftCharacters.findOne(illidanStormrage.getId()); + assertThat(illidanStormrage.getWeapons(), is(equalTo((Iterable) asSet(mainHandWeapon, offHandWeapon)))); + assertThat(illidanStormrage.getMainHandWeapon(), is(equalTo(mainHandWeapon))); + assertThat(illidanStormrage.getOffHandWeapon(), is(equalTo(offHandWeapon))); + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnCollectionsSharingSuperType() throws Exception { + Herbivore deer = animals.save(new Herbivore("Deer")); + Herbivore giraffe = animals.save(new Herbivore("Giraffe")); + Carnivore lion = animals.save(new Carnivore("Lion")); + Carnivore tiger = animals.save(new Carnivore("Tiger")); + + Zoo zsl = new Zoo("ZSL London Zoo"); + zsl.exhibits(deer); + zsl.exhibits(giraffe); + zsl.exhibits(lion); + zsl.exhibits(tiger); + this.zsl.save(zsl); + + assertThat(getRelationshipNames(template, zsl), is(equalTo(asSet("exhibit")))); + zsl = this.zsl.findOne(zsl.getId()); + assertThat(zsl.getAllAnimals(), is(equalTo((Iterable) asSet(deer, giraffe, lion, tiger)))); + assertThat(zsl.getHerbivores(), is(equalTo(asSet(deer, giraffe)))); + assertThat(zsl.getCarnivores(), is(equalTo(asSet(lion, tiger)))); + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedOnFieldAndCollectionSharingSuperType() throws Exception { + Square redSquare = squares.save(new Square(RED)); + Rectangle yellowRectangle = rectangles.save(new Rectangle(YELLOW)); + Rectangle blueRectangle = rectangles.save(new Rectangle(BLUE)); + + Mondrian mondrian = new Mondrian("Composition with Yellow, Blue and Red"); + mondrian.includes(redSquare); + mondrian.includes(yellowRectangle, blueRectangle); + mondrians.save(mondrian); + + assertThat(getRelationshipNames(template, mondrian), is(equalTo(asSet("includes")))); + mondrian = mondrians.findOne(mondrian.getId()); + assertThat(mondrian.getQuadrilaterals(), is(equalTo((Iterable) asSet(redSquare, yellowRectangle, blueRectangle)))); + assertThat(mondrian.getSquare(), is(equalTo(redSquare))); + assertThat(mondrian.getRectangles(), is(equalTo(asSet(yellowRectangle, blueRectangle)))); + } + + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeSubstitutableBetweenFields() throws Exception { + MacBook macbook = macBookRepository.save(new MacBook()); + RetinaMacBook retinaMacbook = retinaMacBooks.save(new RetinaMacBook()); + AppleStore appleStore = new AppleStore(); + appleStore.suppliesMacBook(macbook); + appleStore.suppliesRetinaMacBook(retinaMacbook); + + try { + appleStores.save(appleStore); + + assertThat(getRelationshipNames(template, appleStore), is(equalTo(asSet("supplies")))); + appleStore = appleStores.findOne(appleStore.getId()); + assertThat(single(appleStore.getSupplies()), is(instanceOf(MacBook.class))); + } catch (InvalidDataAccessApiUsageException e) { + assertThat(e.getCause().getMessage(), is(equalTo("Cannot obtain single field value for field 'macBook'"))); + } + } + + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeSubstitutableBetweenCollections() { + Experience college = experiences.save(new Experience("Reed College (calligraphy mainly)")); + Experience sabbatical = experiences.save(new Experience("Neem Karoli ashram, found enlightenment")); + Job atari = jobs.save(new Job("Technician at Atari")); + Job apple = jobs.save(new Job("Co-founder, Chairman and CEO, Apple Inc.")); + CareerProfile steveJobs = new CareerProfile("Steven Paul Jobs"); + steveJobs.addExperience(college, sabbatical); + steveJobs.addJobs(atari, apple); + + linkedin.save(steveJobs); + + assertThat(getRelationshipNames(template, steveJobs), is(equalTo(asSet("experience")))); + steveJobs = linkedin.findOne(steveJobs.getId()); + assertThat(steveJobs.getExperience(), is(either(equalTo(asSet(college, sabbatical))).or(equalTo(asSet(college, sabbatical, atari, apple))))); + assertThat(steveJobs.getJobs(), is(either(equalTo(Collections.emptySet())).or(equalTo(asSet(atari, apple))))); + } + + @Test + public void shouldDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedAndEndNodeTypeForFieldInheritsFromEndNodeTypeForCollection() throws Exception { + Human sam = humans.save(new Human("Samantha Carter")); + Human daniel = humans.save(new Human("Daniel Jackson")); + Human tealc = humans.save(new Human("Tealc")); + SuperHuman jack = superHumans.save(new SuperHuman("Jack O'Neill")); + + Team sg1 = new Team("SG1"); + sg1.setLeader(jack); + sg1.add(sam, daniel, tealc); + teams.save(sg1); + + assertThat(getRelationshipNames(template, sg1), is(equalTo(asSet("member")))); + assertThat(sg1.getLeader(), is(equalTo(jack))); + assertThat(sg1.getMembers(), is(equalTo(asSet(sam, daniel, tealc)))); + } + + @Test + public void shouldNotDifferentiateClashingRelationshipTypesWhenTargetTypeEnforcedButEndNodeTypeForCollectionInheritsFromEndNodeTypeForField() throws Exception { + Superhero thor = superheroes.save(new Superhero("Thor")); + Superhero ironMan = superheroes.save(new Superhero("Iron Man")); + Superhero hulk = superheroes.save(new Superhero("Hulk")); + Hero nickFury = heroes.save(new Hero("Nick Fury")); + + Initiative avengers = new Initiative("Avengers"); + avengers.setLeader(nickFury); + avengers.add(thor, ironMan, hulk); + initiatives.save(avengers); + + assertThat(getRelationshipNames(template, avengers), is(equalTo(asSet("hero")))); + avengers = initiatives.findOne(avengers.getId()); + assertThat(avengers.getLeader(), is(equalTo(nickFury))); + assertThat(avengers.getMembers(), is(equalTo(asSet(thor, ironMan, hulk)))); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Restaurant.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Restaurant.java new file mode 100644 index 000000000..db0b9780c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Restaurant.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Restaurant extends IdentifiableEntity { + private String name; + + public Restaurant() { + } + + public Restaurant(String name) { + + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RestaurantRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RestaurantRepository.java new file mode 100644 index 000000000..d0ac12f4c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RestaurantRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface RestaurantRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBook.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBook.java new file mode 100644 index 000000000..a2a575e47 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBook.java @@ -0,0 +1,22 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class RetinaMacBook extends MacBook { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBookRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBookRepository.java new file mode 100644 index 000000000..23343013d --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/RetinaMacBookRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface RetinaMacBookRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Shop.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Shop.java new file mode 100644 index 000000000..6f3ac8267 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Shop.java @@ -0,0 +1,32 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Shop extends IdentifiableEntity { + private String name; + + public Shop() { + } + + public Shop(String name) { + + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShopRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShopRepository.java new file mode 100644 index 000000000..488b9538c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShopRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ShopRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenter.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenter.java new file mode 100644 index 000000000..d0ca4efe0 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenter.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class ShoppingCenter extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "houses", enforceTargetType = true) + private Set shops = new HashSet(); + + @RelatedTo(type = "houses", enforceTargetType = true) + private Set restaurants = new HashSet(); + + public ShoppingCenter() { + } + + public ShoppingCenter(String name) { + this.name = name; + } + + public void houses(Shop... shops) { + this.shops = new HashSet(asList(shops)); + } + + public void houses(Restaurant... restaurants) { + this.restaurants.addAll(asList(restaurants)); + } + + public Set getShops() { + return shops; + } + + public Set getRestaurants() { + return restaurants; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenterRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenterRepository.java new file mode 100644 index 000000000..6ce271854 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ShoppingCenterRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ShoppingCenterRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Square.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Square.java new file mode 100644 index 000000000..5d8d7c6c1 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Square.java @@ -0,0 +1,29 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Square extends Quadrilateral { + public Square() { + + } + + public Square(short colour) { + super(colour); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SquareRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SquareRepository.java new file mode 100644 index 000000000..a0a66d5ab --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SquareRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface SquareRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Student.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Student.java new file mode 100644 index 000000000..a80a927d8 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Student.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Student extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "attends") + private Set favouriteCourses = new HashSet(); + + @RelatedTo(type = "attends", enforceTargetType = true) + private Set dislikedCourses = new HashSet(); + + public Student() { + } + + public Student(String name) { + this.name = name; + } + + public void likes(Course... courses) { + favouriteCourses.addAll(asList(courses)); + } + + public void isBoredWith(Course... courses) { + dislikedCourses.addAll(asList(courses)); + } + + public Set getFavouriteCourses() { + return favouriteCourses; + } + + public Set getDislikedCourses() { + return dislikedCourses; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/StudentRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/StudentRepository.java new file mode 100644 index 000000000..66399cd49 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/StudentRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface StudentRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHuman.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHuman.java new file mode 100644 index 000000000..f9a959e85 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHuman.java @@ -0,0 +1,29 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class SuperHuman extends Human { + public SuperHuman() { + + } + + public SuperHuman(String name) { + super(name); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHumanRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHumanRepository.java new file mode 100644 index 000000000..034e1c4dd --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperHumanRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface SuperHumanRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Superhero.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Superhero.java new file mode 100644 index 000000000..15ff83217 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Superhero.java @@ -0,0 +1,31 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class Superhero extends IdentifiableEntity { + private String name; + + public Superhero() { + } + + public Superhero(String name) { + this.name = name; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperheroRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperheroRepository.java new file mode 100644 index 000000000..f6833a050 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/SuperheroRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface SuperheroRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Team.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Team.java new file mode 100644 index 000000000..9f359d09d --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Team.java @@ -0,0 +1,59 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Team extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "member", enforceTargetType = true) + private SuperHuman leader; + + @RelatedTo(type = "member", enforceTargetType = true) + private Set members = new HashSet(); + + public Team() { + } + + public Team(String name) { + this.name = name; + } + + public void setLeader(SuperHuman leader) { + this.leader = leader; + } + + public void add(Human... members) { + this.members.addAll(asList(members)); + } + + public SuperHuman getLeader() { + return leader; + } + + public Set getMembers() { + return members; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TeamRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TeamRepository.java new file mode 100644 index 000000000..8819e1f91 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TeamRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface TeamRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Town.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Town.java new file mode 100644 index 000000000..e815b276e --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Town.java @@ -0,0 +1,60 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Town extends IdentifiableEntity { + private String name; + + @RelatedTo + private Town twin; + + @RelatedTo + private Set neighbours = new HashSet(); + + public Town() { + + } + + public Town( String name ) { + this.name = name; + } + + public void isTwinnedWith( Town twin ) { + this.twin = twin; + } + + public Town getTwin() { + return twin; + } + + public void hasNeighbours(Town... towns) { + this.neighbours.addAll(asList(towns)); + } + + public Set getNeighbours() { + return neighbours; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TownRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TownRepository.java new file mode 100644 index 000000000..72a890f60 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/TownRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface TownRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Warchief.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Warchief.java new file mode 100644 index 000000000..1e467231d --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Warchief.java @@ -0,0 +1,60 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +import java.util.HashSet; +import java.util.Set; + +import static java.util.Arrays.asList; + +@NodeEntity +public class Warchief extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "succeeds") + private Warchief mentor; + + @RelatedTo(type = "is_advised_by") + private Set advisors = new HashSet(); + + public Warchief() { + + } + + public Warchief( String name ) { + this.name = name; + } + + public void succeeds( Warchief mentor ) { + this.mentor = mentor; + } + + public Warchief getMentor() { + return mentor; + } + + public void hasAdvisors(Advisor... advisors) { + this.advisors.addAll(asList(advisors)); + } + + public Set getAdvisors() { + return advisors; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WarchiefRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WarchiefRepository.java new file mode 100644 index 000000000..a5cc231f0 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WarchiefRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface WarchiefRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Weapon.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Weapon.java new file mode 100644 index 000000000..0ce304e29 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Weapon.java @@ -0,0 +1,22 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public interface Weapon { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacter.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacter.java new file mode 100644 index 000000000..11f7cbcb8 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacter.java @@ -0,0 +1,61 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class WorldOfWarcraftCharacter extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "wields", enforceTargetType = true) + private MainHandWeapon mainHandWeapon; + + @RelatedTo(type = "wields", enforceTargetType = true) + private OffHandWeapon offHandWeapon; + + @RelatedTo(type = "wields", enforceTargetType = true) + private Iterable weapons; + + public WorldOfWarcraftCharacter() { + } + + public WorldOfWarcraftCharacter(String name) { + this.name = name; + } + + public void wields(MainHandWeapon mainHandWeapon) { + this.mainHandWeapon = mainHandWeapon; + } + + public void wields(OffHandWeapon offHandWeapon) { + this.offHandWeapon = offHandWeapon; + } + + public Iterable getWeapons() { + return weapons; + } + + public MainHandWeapon getMainHandWeapon() { + return mainHandWeapon; + } + + public OffHandWeapon getOffHandWeapon() { + return offHandWeapon; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacterRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacterRepository.java new file mode 100644 index 000000000..c97f6ba03 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/WorldOfWarcraftCharacterRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface WorldOfWarcraftCharacterRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Zoo.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Zoo.java new file mode 100644 index 000000000..cbe5874be --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/Zoo.java @@ -0,0 +1,65 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedTo; + +@NodeEntity +public class Zoo extends IdentifiableEntity { + private String name; + + @RelatedTo(type = "exhibit", enforceTargetType = true) + private Iterable animals; + + @RelatedTo(type = "exhibit", enforceTargetType = true) + private Set herbivores = new HashSet(); + + @RelatedTo(type = "exhibit", enforceTargetType = true) + private Set carnivores = new HashSet(); + + public Zoo() { + + } + + public Zoo( String name ) { + this.name = name; + } + + public void exhibits( Herbivore herbivore ) { + herbivores.add(herbivore); + } + + public void exhibits( Carnivore carnivore ) { + carnivores.add(carnivore); + } + + public Iterable getAllAnimals() { + return animals; + } + + public Set getHerbivores() { + return herbivores; + } + + public Set getCarnivores() { + return carnivores; + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ZooRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ZooRepository.java new file mode 100644 index 000000000..a7627d906 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedto/ZooRepository.java @@ -0,0 +1,21 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedto; + +import org.springframework.data.neo4j.repository.CRUDRepository; + +public interface ZooRepository extends CRUDRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/City.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/City.java similarity index 89% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/City.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/City.java index 247e1604e..558211ed4 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/City.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/City.java @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import java.util.HashSet; import java.util.Set; +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedToVia; + @NodeEntity public class City extends IdentifiableEntity { private String name; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CityRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CityRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CityRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CityRepository.java index b67d61acb..04491c499 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CityRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CityRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Country.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Country.java similarity index 83% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Country.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Country.java index fa8416c73..44a2ba465 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Country.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Country.java @@ -13,7 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedToVia; @NodeEntity public class Country extends IdentifiableEntity diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CountryRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CountryRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CountryRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CountryRepository.java index f353bda02..572325188 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/CountryRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/CountryRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/InterCountryRelationship.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/InterCountryRelationship.java similarity index 73% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/InterCountryRelationship.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/InterCountryRelationship.java index 36d57b415..7dbd49710 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/InterCountryRelationship.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/InterCountryRelationship.java @@ -13,7 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.StartNode; +import org.springframework.data.neo4j.annotation.relatedtovia.Country; @RelationshipEntity(type = "cordial") public class InterCountryRelationship diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Line.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Line.java similarity index 80% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Line.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Line.java index d1fa5f2ea..32baa164e 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Line.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Line.java @@ -13,7 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.StartNode; @RelationshipEntity(type = "route") public class Line diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLine.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLine.java similarity index 80% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLine.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLine.java index bf39af8fb..8f8e18dc6 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLine.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLine.java @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; @NodeEntity public class MetroLine extends IdentifiableEntity { diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLineRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLineRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLineRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLineRepository.java index e55aef45c..31c12a060 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/MetroLineRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/MetroLineRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PerpetualRelations.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PerpetualRelations.java similarity index 72% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PerpetualRelations.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PerpetualRelations.java index d3c1b41c1..3e22a445c 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PerpetualRelations.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PerpetualRelations.java @@ -13,7 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.RelationshipType; +import org.springframework.data.neo4j.annotation.StartNode; +import org.springframework.data.neo4j.annotation.relatedtovia.SuperState; @RelationshipEntity(type = "unrelated") public class PerpetualRelations diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Player.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Player.java similarity index 80% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Player.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Player.java index 569dfb7d7..bbd680ca6 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Player.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Player.java @@ -13,7 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; @NodeEntity public class Player extends IdentifiableEntity diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerRepository.java index ff6476fe1..817c98d03 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerStatus.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerStatus.java similarity index 75% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerStatus.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerStatus.java index 835912ca8..823d2d8ae 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/PlayerStatus.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/PlayerStatus.java @@ -13,7 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.RelationshipType; +import org.springframework.data.neo4j.annotation.StartNode; @RelationshipEntity(type = "notplaying") public class PlayerStatus diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/RelatedToViaTests.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/RelatedToViaTests.java new file mode 100644 index 000000000..f98eb4650 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/RelatedToViaTests.java @@ -0,0 +1,174 @@ +/** + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.neo4j.support.Neo4jTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.transaction.annotation.Transactional; + +import static java.util.Arrays.asList; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; +import static org.junit.matchers.JUnitMatchers.hasItem; +import static org.neo4j.helpers.collection.IteratorUtil.first; +import static org.springframework.data.neo4j.annotation.RelationshipDelegates.getRelationshipNames; +import static org.springframework.data.neo4j.annotation.SetHelper.asSet; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = {"classpath:related-to-via-test-context.xml"}) +@Transactional +public class RelatedToViaTests { + public static final String DISTRICT_LINE = "District Line"; + public static final String CENTRAL_LINE = "Central Line"; + + @Autowired + private UndergroundRepository tfl; + + @Autowired + private CountryRepository countries; + + @Autowired + private SuperStateRepository dystopia; + + @Autowired + private MetroLineRepository metroLines; + + @Autowired + private CityRepository cities; + + @Autowired + private PlayerRepository players; + + @Autowired + private TeamRepository teams; + + @Autowired + private Neo4jTemplate template; + + @Before + public void before() { + tfl.deleteAll(); + countries.deleteAll(); + dystopia.deleteAll(); + metroLines.deleteAll(); + cities.deleteAll(); + players.deleteAll(); + teams.deleteAll(); + } + + @Test + public void shouldMapRelationshipAsFirstClassCitizen() throws Exception { + TubeStation westHam = tfl.save(new TubeStation("West Ham")); + TubeStation stratford = tfl.save(new TubeStation("Stratford")); + TubeStation mileEnd = new TubeStation("Mile End"); + mileEnd.connectsTo(westHam, DISTRICT_LINE); + mileEnd.connectsTo(stratford, CENTRAL_LINE); + + tfl.save(mileEnd); + + assertThat(first(template.getNode(mileEnd.getId()).getRelationships()).getType().name(), is("route")); + mileEnd = tfl.findOne(mileEnd.getId()); + Line line = first(mileEnd.getLines()); + assertThat(mileEnd, is(equalTo(line.getOrigin()))); + assertThat(asList(DISTRICT_LINE, CENTRAL_LINE), hasItem(line.getName())); + assertThat(asList(westHam, stratford), hasItem(line.getDestination())); + } + + @Test + public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefault() throws Exception { + Country france = countries.save(new Country("République française")); + Country usa = countries.save(new Country("United States of America")); + Country uk = new Country("United Kingdom of Great Britain and Northern Ireland"); + uk.hasCordialRelationsWith(france, "Entente Cordiale"); + uk.hasSpecialRelationsWith(usa); + + countries.save(uk); + + assertThat(getRelationshipNames(template, uk), is(equalTo(asSet("cordial", "special")))); + } + + @Test + public void shouldGivePrecedenceToAnnotationProvidedRelationshipTypeOverDefaultForCollections() throws Exception { + MetroLine m1 = metroLines.save(new MetroLine("M1 - Vanløse to Vestamager")); + MetroLine m2 = metroLines.save(new MetroLine("M2 - Vanløse to Lufthavnen")); + MetroLine m3 = metroLines.save(new MetroLine("M3 - Cityringen")); + MetroLine m4 = metroLines.save(new MetroLine("M4 - Nørrebro to København H")); + City copenhagen = new City("Copenhagen"); + copenhagen.has(m1, m2); + copenhagen.plans(m3, m4); + + cities.save(copenhagen); + + assertThat(getRelationshipNames(template, copenhagen), is(equalTo(asSet("existing", "planned")))); + assertThat(copenhagen.getCurrentMetroLines(), is(equalTo(asSet(m1, m2)))); + assertThat(copenhagen.getFutureMetroLines(), is(equalTo(asSet(m3, m4)))); + } + + @Test + public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipType() throws Exception { + SuperState eastasia = dystopia.save(new SuperState("Eastasia")); + SuperState eurasia = dystopia.save(new SuperState("Eurasia")); + SuperState oceania = new SuperState("Oceania"); + oceania.isAlliedWith(eastasia); + + dystopia.save(oceania); + + assertThat(getRelationshipNames(template, oceania), is(equalTo(asSet("alliedWith")))); + + oceania = dystopia.findOne(oceania.getId()); + oceania.isAtWarWith(eurasia); + + dystopia.save(oceania); + + assertThat(getRelationshipNames(template, oceania), is(equalTo(asSet("atWarWith")))); + } + + @Test + public void shouldGivePrecedenceToDynamicRelationshipTypeOverAnnotationProvidedRelationshipTypeForCollections() + throws Exception { + Player jordan = players.save(new Player("Michael Jordan")); + Player pippen = players.save(new Player("Scottie Pippen")); + Team bulls = new Team("Chicago Bulls"); + bulls.add(new PlayerStatus(bulls, jordan)); + bulls.add(new PlayerStatus(bulls, pippen, "substitute")); + + teams.save(bulls); + + assertThat(getRelationshipNames(template, bulls), is(equalTo(asSet("starter", "substitute")))); + } + + @Test + public void shouldValidateEndNode() throws Exception { + TubeStation mileEnd = new TubeStation("East Ham"); + mileEnd.connectsTo(null, DISTRICT_LINE); + + try { + tfl.save(mileEnd); + + fail(); + } catch (InvalidDataAccessApiUsageException e) { + assertThat(e.getCause().getMessage(), is(equalTo("End node must not be null (" + Line.class.getName() + ")"))); + } + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperState.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperState.java similarity index 81% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperState.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperState.java index 5a2e46412..d4549e086 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperState.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperState.java @@ -13,7 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedToVia; @NodeEntity public class SuperState extends IdentifiableEntity { diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperStateRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperStateRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperStateRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperStateRepository.java index a35357ed5..a74b9b475 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/SuperStateRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/SuperStateRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Team.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Team.java similarity index 80% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Team.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Team.java index 365991a3c..0c51940e1 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/Team.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/Team.java @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import java.util.HashSet; import java.util.Set; +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedToVia; + @NodeEntity public class Team extends IdentifiableEntity { diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TeamRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TeamRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TeamRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TeamRepository.java index e0b16413d..2ab919d09 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TeamRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TeamRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TransportInfrastructure.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TransportInfrastructure.java similarity index 71% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TransportInfrastructure.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TransportInfrastructure.java index 27f89b9c1..14e045c0d 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TransportInfrastructure.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TransportInfrastructure.java @@ -13,7 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.StartNode; +import org.springframework.data.neo4j.annotation.relatedtovia.City; +import org.springframework.data.neo4j.annotation.relatedtovia.MetroLine; @RelationshipEntity(type = "existing") public class TransportInfrastructure diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TubeStation.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TubeStation.java similarity index 82% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TubeStation.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TubeStation.java index 7dd0f4757..002f23c9b 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/TubeStation.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/TubeStation.java @@ -13,11 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import java.util.HashSet; import java.util.Set; +import org.springframework.data.neo4j.annotation.IdentifiableEntity; +import org.springframework.data.neo4j.annotation.NodeEntity; +import org.springframework.data.neo4j.annotation.RelatedToVia; + @NodeEntity public class TubeStation extends IdentifiableEntity { private String name; diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/UndergroundRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/UndergroundRepository.java similarity index 92% rename from spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/UndergroundRepository.java rename to spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/UndergroundRepository.java index b37280f13..2b2b40c21 100644 --- a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/UndergroundRepository.java +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/annotation/relatedtovia/UndergroundRepository.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.neo4j.annotation; +package org.springframework.data.neo4j.annotation.relatedtovia; import org.springframework.data.neo4j.repository.CRUDRepository; diff --git a/spring-data-neo4j/src/test/resources/related-to-test-context.xml b/spring-data-neo4j/src/test/resources/related-to-test-context.xml new file mode 100644 index 000000000..f54bef3e8 --- /dev/null +++ b/spring-data-neo4j/src/test/resources/related-to-test-context.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + diff --git a/spring-data-neo4j/src/test/resources/related-to-via-test-context.xml b/spring-data-neo4j/src/test/resources/related-to-via-test-context.xml index 818bc0d05..f380ac22f 100644 --- a/spring-data-neo4j/src/test/resources/related-to-via-test-context.xml +++ b/spring-data-neo4j/src/test/resources/related-to-via-test-context.xml @@ -8,14 +8,14 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd"> - - + + - + - + - + diff --git a/src/docbkx/reference/programming-model/relationships.xml b/src/docbkx/reference/programming-model/relationships.xml index 000340664..1891e2ece 100644 --- a/src/docbkx/reference/programming-model/relationships.xml +++ b/src/docbkx/reference/programming-model/relationships.xml @@ -245,4 +245,55 @@ new Acquaintance(frankSinatra, carloGambino, "its_complicated") Default +
+ Discriminating Relationships Based On End Node Type + In some cases, you want to model two different aspects of a conceptual relationship using the same relationship type. Here is a canonical example: + + Clashing Relationship Types + + + + + It is clear how we can map these relationships: by looking at the type of the end node. To enable this, we have introduced an boolean annotation parameter enforceTargetType, which is disabled by default. Our example now reads: + + Discriminating Relationship Types Using End Node Type + + + + + The example easily generalises to collections too of course, but there are a few note-worthy rules and corner cases: + + + You need to annotate all clashing relationships. + + + You can't have a two fields, two collections, or a field and a collection, with the same relationship type and identical end node types. SDN does not store metadata about the origin of a relationship. So when saving the entity, the first field or collection would be overwritten by the second, with the processing order being non-deterministic. + + + You can have clashing relation ship types when end nodes share a supertype. + + + A variation on the above, you cannot have two fields or two collections with the same relationship type and substitutable end node types. + + + You can however have a field and a collection where end node types inherit from eachother. + + +
\ No newline at end of file