Skip to content

Commit 1b93dd0

Browse files
docs: Add another QBE example.
1 parent 5126fca commit 1b93dd0

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

src/test/java/org/springframework/data/neo4j/integration/issues/IssuesIT.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.springframework.context.annotation.ComponentScan;
5656
import org.springframework.context.annotation.Configuration;
5757
import org.springframework.dao.DataIntegrityViolationException;
58+
import org.springframework.data.domain.Example;
5859
import org.springframework.data.domain.Page;
5960
import org.springframework.data.domain.PageRequest;
6061
import org.springframework.data.domain.Sort;
@@ -141,6 +142,9 @@
141142
import org.springframework.data.neo4j.integration.issues.gh2639.LanguageRelationship;
142143
import org.springframework.data.neo4j.integration.issues.gh2639.ProgrammingLanguage;
143144
import org.springframework.data.neo4j.integration.issues.gh2639.Sales;
145+
import org.springframework.data.neo4j.integration.issues.qbe.A;
146+
import org.springframework.data.neo4j.integration.issues.qbe.ARepository;
147+
import org.springframework.data.neo4j.integration.issues.qbe.B;
144148
import org.springframework.data.neo4j.integration.misc.ConcreteImplementationTwo;
145149
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
146150
import org.springframework.data.neo4j.repository.query.QueryFragmentsAndParameters;
@@ -189,6 +193,8 @@ protected static void setupData(@Autowired BookmarkCapture bookmarkCapture) {
189193
setupGH2572(transaction);
190194
setupGH2583(transaction);
191195

196+
transaction.run("CREATE (:A {name: 'A name', id: randomUUID()}) -[:HAS] ->(:B {anotherName: 'Whatever', id: randomUUID()})");
197+
192198
transaction.commit();
193199
}
194200
bookmarkCapture.seedWith(session.lastBookmarks());
@@ -266,6 +272,21 @@ protected void prepareIndividual(
266272
cityModelRepository.saveAll(List.of(aachen, utrecht));
267273
}
268274

275+
@Test
276+
void qbeWithRelationship(@Autowired ARepository repository) {
277+
278+
var probe = new A();
279+
probe.setB(new B("Whatever"));
280+
var optionalResult = repository.findOne(Example.of(probe));
281+
assertThat(optionalResult).hasValueSatisfying(a -> {
282+
assertThat(a.getName()).isEqualTo("A name");
283+
assertThat(a.getId()).isNotNull();
284+
});
285+
286+
var allResults = repository.findAll(Example.of(probe));
287+
assertThat(allResults).hasSize(1);
288+
}
289+
269290
@Test
270291
@Tag("GH-2168")
271292
void findByIdShouldWork(@Autowired DomainObjectRepository domainObjectRepository) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2011-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.qbe;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
import org.springframework.data.neo4j.core.schema.Relationship;
24+
25+
/**
26+
* Internally reported question / issue.
27+
*
28+
* @author Michael Simons
29+
*/
30+
@Node
31+
public class A {
32+
33+
@Id
34+
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
35+
UUID id;
36+
37+
private String name;
38+
39+
@Relationship(type = "HAS")
40+
private B b;
41+
42+
public UUID getId() {
43+
return id;
44+
}
45+
46+
public String getName() {
47+
return name;
48+
}
49+
50+
public void setName(String name) {
51+
this.name = name;
52+
}
53+
54+
public B getB() {
55+
return b;
56+
}
57+
58+
public void setB(B b) {
59+
this.b = b;
60+
}
61+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2011-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.qbe;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.repository.Neo4jRepository;
21+
22+
/**
23+
* Internally reported question / issue.
24+
*
25+
* @author Michael Simons
26+
*/
27+
public interface ARepository extends Neo4jRepository<A, UUID> {
28+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2011-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.qbe;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
24+
/**
25+
* Internally reported question / issue.
26+
*
27+
* @author Michael Simons
28+
*/
29+
@Node
30+
public class B {
31+
@Id
32+
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
33+
UUID id;
34+
35+
private String anotherName;
36+
37+
public B(String anotherName) {
38+
this.anotherName = anotherName;
39+
}
40+
41+
public UUID getId() {
42+
return id;
43+
}
44+
45+
public String getAnotherName() {
46+
return anotherName;
47+
}
48+
49+
public void setAnotherName(String anotherName) {
50+
this.anotherName = anotherName;
51+
}
52+
}

0 commit comments

Comments
 (0)