From b6cd024b1909f2c6e21d664782f3c549c064b91a Mon Sep 17 00:00:00 2001 From: Michael Hunger Date: Fri, 23 Mar 2012 03:12:32 +0100 Subject: [PATCH] DATAGRAPH-213 inheritance with relationship-entities --- .../mapping/Neo4JPersistentPropertyImpl.java | 8 +++ .../neo4j/inheritance/InheritanceTest.java | 72 +++++++++++++++++++ .../neo4j/inheritance/model/BasicEntity.java | 34 +++++++++ .../inheritance/model/BasicRelationship.java | 47 ++++++++++++ .../data/neo4j/inheritance/model/Project.java | 32 +++++++++ .../inheritance/model/ProjectDetail.java | 43 +++++++++++ .../model/ProjectDetailRelationship.java | 34 +++++++++ .../repository/ProjectDetailRepository.java | 26 +++++++ .../repository/ProjectRepository.java | 22 ++++++ .../inheritance/InheritanceTest-context.xml | 16 +++++ 10 files changed, 334 insertions(+) create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/InheritanceTest.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicEntity.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicRelationship.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/Project.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetail.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetailRelationship.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectDetailRepository.java create mode 100644 spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectRepository.java create mode 100644 spring-data-neo4j/src/test/resources/org/springframework/data/neo4j/inheritance/InheritanceTest-context.xml 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 7e64fdc33..e54f26a13 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 @@ -353,4 +353,12 @@ class Neo4jPersistentPropertyImpl extends AbstractPersistentProperty but was:<0> + Project actualProject = projectRepository.findOne(project.getEntityId()); + assertEquals(1, actualProject.getProjectDetailRelationships().size()); + } +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicEntity.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicEntity.java new file mode 100644 index 000000000..3880ed47b --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicEntity.java @@ -0,0 +1,34 @@ +/** + * 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.inheritance.model; + +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.NodeEntity; + +@NodeEntity +public class BasicEntity { + @GraphId + private Long entityId; + + /* lots of other common properties here in our real domain */ + + public BasicEntity() { + } + + public Long getEntityId() { + return entityId; + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicRelationship.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicRelationship.java new file mode 100644 index 000000000..ff1378a91 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/BasicRelationship.java @@ -0,0 +1,47 @@ +/** + * 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.inheritance.model; + +import org.springframework.data.neo4j.annotation.EndNode; +import org.springframework.data.neo4j.annotation.Fetch; +import org.springframework.data.neo4j.annotation.GraphId; +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.StartNode; + +@RelationshipEntity +public class BasicRelationship { + @GraphId + private Long entityId; + + @Fetch + @StartNode + private BasicEntity startNode; + + @Fetch + @EndNode + private BasicEntity endNode; + + /* lots of other common properties here in our real domain */ + + public BasicRelationship() { + } + + public BasicRelationship(Long entityId, BasicEntity startNode, BasicEntity endNode) { + this.entityId = entityId; + this.startNode = startNode; + this.endNode = endNode; + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/Project.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/Project.java new file mode 100644 index 000000000..6809fa66d --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/Project.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.inheritance.model; + +import org.springframework.data.neo4j.annotation.Fetch; +import org.springframework.data.neo4j.annotation.RelatedToVia; + +import java.util.Set; + +public class Project extends BasicEntity { + + @Fetch + @RelatedToVia// (type = ProjectDetailRelationship.TYPE) + private Set projectDetailRelationships; + + public Set getProjectDetailRelationships() { + return projectDetailRelationships; + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetail.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetail.java new file mode 100644 index 000000000..b73381db6 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetail.java @@ -0,0 +1,43 @@ +/** + * 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.inheritance.model; + +import org.neo4j.graphdb.Direction; +import org.springframework.data.neo4j.annotation.Fetch; +import org.springframework.data.neo4j.annotation.RelatedTo; + +public class ProjectDetail extends BasicEntity { + private String name; + + @Fetch + @RelatedTo(type = ProjectDetailRelationship.TYPE, direction = Direction.INCOMING) + private Project parentProject; + + public ProjectDetail() { + } + + public ProjectDetail(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public Project getParentProject() { + return parentProject; + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetailRelationship.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetailRelationship.java new file mode 100644 index 000000000..1f869d883 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/model/ProjectDetailRelationship.java @@ -0,0 +1,34 @@ +/** + * 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.inheritance.model; + +import org.springframework.data.neo4j.annotation.RelationshipEntity; +import org.springframework.data.neo4j.annotation.RelationshipType; + +@RelationshipEntity(type = ProjectDetailRelationship.TYPE) +public class ProjectDetailRelationship extends BasicRelationship { + public static final String TYPE = "PROJECT_HAS_PROJECT_DETAIL"; + + //@RelationshipType + //private String type = TYPE; + + public ProjectDetailRelationship() { + } + + public ProjectDetailRelationship(Long entityId, Project project, ProjectDetail projectDetail) { + super(entityId, project, projectDetail); + } +} \ No newline at end of file diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectDetailRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectDetailRepository.java new file mode 100644 index 000000000..0636953c1 --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectDetailRepository.java @@ -0,0 +1,26 @@ +/** + * 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.inheritance.repository; + +import org.springframework.data.neo4j.inheritance.model.ProjectDetail; +import org.springframework.data.neo4j.repository.GraphRepository; + +/** + * @author mh + * @since 23.03.12 + */ +public interface ProjectDetailRepository extends GraphRepository { +} diff --git a/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectRepository.java b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectRepository.java new file mode 100644 index 000000000..51a40cd2c --- /dev/null +++ b/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/inheritance/repository/ProjectRepository.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.inheritance.repository; + +import org.springframework.data.neo4j.inheritance.model.Project; +import org.springframework.data.neo4j.repository.GraphRepository; + +public interface ProjectRepository extends GraphRepository { +} diff --git a/spring-data-neo4j/src/test/resources/org/springframework/data/neo4j/inheritance/InheritanceTest-context.xml b/spring-data-neo4j/src/test/resources/org/springframework/data/neo4j/inheritance/InheritanceTest-context.xml new file mode 100644 index 000000000..237e8d29f --- /dev/null +++ b/spring-data-neo4j/src/test/resources/org/springframework/data/neo4j/inheritance/InheritanceTest-context.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file