From b1de39df9a9bbbed4b98edf5bdfa8acd7fff14eb Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Fri, 2 Jun 2023 11:22:06 +0200 Subject: [PATCH] docs: Add another QBE example. --- .../neo4j/integration/issues/IssuesIT.java | 21 +++++++ .../data/neo4j/integration/issues/qbe/A.java | 61 +++++++++++++++++++ .../integration/issues/qbe/ARepository.java | 28 +++++++++ .../data/neo4j/integration/issues/qbe/B.java | 52 ++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 src/test/java/org/springframework/data/neo4j/integration/issues/qbe/A.java create mode 100644 src/test/java/org/springframework/data/neo4j/integration/issues/qbe/ARepository.java create mode 100644 src/test/java/org/springframework/data/neo4j/integration/issues/qbe/B.java diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java b/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java index c062016e5..e2aa604b4 100644 --- a/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java @@ -55,6 +55,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.data.domain.Example; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; @@ -141,6 +142,9 @@ import org.springframework.data.neo4j.integration.issues.gh2639.Individual; import org.springframework.data.neo4j.integration.issues.gh2639.LanguageRelationship; import org.springframework.data.neo4j.integration.issues.gh2639.ProgrammingLanguage; import org.springframework.data.neo4j.integration.issues.gh2639.Sales; +import org.springframework.data.neo4j.integration.issues.qbe.A; +import org.springframework.data.neo4j.integration.issues.qbe.ARepository; +import org.springframework.data.neo4j.integration.issues.qbe.B; import org.springframework.data.neo4j.integration.misc.ConcreteImplementationTwo; import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters; @@ -189,6 +193,8 @@ class IssuesIT extends TestBase { setupGH2572(transaction); setupGH2583(transaction); + transaction.run("CREATE (:A {name: 'A name', id: randomUUID()}) -[:HAS] ->(:B {anotherName: 'Whatever', id: randomUUID()})"); + transaction.commit(); } bookmarkCapture.seedWith(session.lastBookmarks()); @@ -266,6 +272,21 @@ class IssuesIT extends TestBase { cityModelRepository.saveAll(List.of(aachen, utrecht)); } + @Test + void qbeWithRelationship(@Autowired ARepository repository) { + + var probe = new A(); + probe.setB(new B("Whatever")); + var optionalResult = repository.findOne(Example.of(probe)); + assertThat(optionalResult).hasValueSatisfying(a -> { + assertThat(a.getName()).isEqualTo("A name"); + assertThat(a.getId()).isNotNull(); + }); + + var allResults = repository.findAll(Example.of(probe)); + assertThat(allResults).hasSize(1); + } + @Test @Tag("GH-2168") void findByIdShouldWork(@Autowired DomainObjectRepository domainObjectRepository) { diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/A.java b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/A.java new file mode 100644 index 000000000..1fbbe6677 --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/A.java @@ -0,0 +1,61 @@ +/* + * Copyright 2011-2023 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 + * + * https://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.integration.issues.qbe; + +import java.util.UUID; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; +import org.springframework.data.neo4j.core.schema.Relationship; + +/** + * Internally reported question / issue. + * + * @author Michael Simons + */ +@Node +public class A { + + @Id + @GeneratedValue(GeneratedValue.UUIDGenerator.class) + UUID id; + + private String name; + + @Relationship(type = "HAS") + private B b; + + public UUID getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public B getB() { + return b; + } + + public void setB(B b) { + this.b = b; + } +} diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/ARepository.java b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/ARepository.java new file mode 100644 index 000000000..fffe9f08d --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/ARepository.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011-2023 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 + * + * https://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.integration.issues.qbe; + +import java.util.UUID; + +import org.springframework.data.neo4j.repository.Neo4jRepository; + +/** + * Internally reported question / issue. + * + * @author Michael Simons + */ +public interface ARepository extends Neo4jRepository { +} diff --git a/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/B.java b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/B.java new file mode 100644 index 000000000..e64221bff --- /dev/null +++ b/src/test/java/org/springframework/data/neo4j/integration/issues/qbe/B.java @@ -0,0 +1,52 @@ +/* + * Copyright 2011-2023 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 + * + * https://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.integration.issues.qbe; + +import java.util.UUID; + +import org.springframework.data.neo4j.core.schema.GeneratedValue; +import org.springframework.data.neo4j.core.schema.Id; +import org.springframework.data.neo4j.core.schema.Node; + +/** + * Internally reported question / issue. + * + * @author Michael Simons + */ +@Node +public class B { + @Id + @GeneratedValue(GeneratedValue.UUIDGenerator.class) + UUID id; + + private String anotherName; + + public B(String anotherName) { + this.anotherName = anotherName; + } + + public UUID getId() { + return id; + } + + public String getAnotherName() { + return anotherName; + } + + public void setAnotherName(String anotherName) { + this.anotherName = anotherName; + } +}