Skip to content

Commit c8bdfa4

Browse files
GH-1985 - Make sure derived queries on the same property of the same entity but different relationships use multiple matches.
This closes #1985 by adding the same test that is available in Neo4j-OGM and prior versions of SDN.
1 parent 058f573 commit c8bdfa4

File tree

5 files changed

+161
-4
lines changed

5 files changed

+161
-4
lines changed

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
import org.springframework.data.neo4j.integration.imperative.repositories.PersonWithNoConstructorRepository;
8787
import org.springframework.data.neo4j.integration.imperative.repositories.PersonWithWitherRepository;
8888
import org.springframework.data.neo4j.integration.imperative.repositories.ThingRepository;
89+
import org.springframework.data.neo4j.integration.shared.common.Flight;
90+
import org.springframework.data.neo4j.integration.imperative.repositories.FlightRepository;
8991
import org.springframework.data.neo4j.integration.shared.common.AltHobby;
9092
import org.springframework.data.neo4j.integration.shared.common.AltLikedByPersonRelationship;
9193
import org.springframework.data.neo4j.integration.shared.common.AltPerson;
@@ -210,6 +212,20 @@ void setupData(Transaction transaction) {
210212
true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, createdAt.toInstant());
211213
person2 = new PersonWithAllConstructor(id2, TEST_PERSON2_NAME, TEST_PERSON2_FIRST_NAME, TEST_PERSON_SAMEVALUE,
212214
false, 2L, TEST_PERSON2_BORN_ON, null, Collections.emptyList(), SFO, null);
215+
216+
transaction.run("CREATE (lhr:Airport {code: 'LHR', name: 'London Heathrow'})\n" +
217+
"CREATE (lax:Airport {code: 'LAX', name: 'Los Angeles'})\n" +
218+
"CREATE (cdg:Airport {code: 'CDG', name: 'Paris Charles de Gaulle'})\n" +
219+
"CREATE (f1:Flight {name: 'FL 001'})\n" +
220+
"CREATE (f2:Flight {name: 'FL 002'})\n" +
221+
"CREATE (f3:Flight {name: 'FL 003'})\n" +
222+
"CREATE (f1) -[:DEPARTS] ->(lhr)\n" +
223+
"CREATE (f1) -[:ARRIVES] ->(lax)\n" +
224+
"CREATE (f2) -[:DEPARTS] ->(lhr)\n" +
225+
"CREATE (f2) -[:ARRIVES] ->(cdg)\n" +
226+
"CREATE (f3) -[:DEPARTS] ->(lax)\n" +
227+
"CREATE (f3) -[:ARRIVES] ->(lhr)\n" +
228+
"RETURN *");
213229
}
214230

215231
@Test
@@ -734,6 +750,14 @@ void findSliceByCustomQueryWithCountShouldWork(@Autowired PersonRepository repos
734750
assertThat(slice.get()).hasSize(1).extracting("name").containsExactly(TEST_PERSON1_NAME);
735751
assertThat(slice.hasNext()).isFalse();
736752
}
753+
754+
@Test // GH-1985
755+
void filtersOnSameEntitiesButDifferentRelationsShouldWork(@Autowired FlightRepository repository) {
756+
757+
List<Flight> flights = repository.findAllByDepartureCodeAndArrivalCode("LHR", "LAX");
758+
assertThat(flights).hasSize(1)
759+
.first().extracting(Flight::getName).isEqualTo("FL 001");
760+
}
737761
}
738762

739763
@Nested
@@ -4271,7 +4295,10 @@ public Driver driver() {
42714295

42724296
@Override
42734297
protected Collection<String> getMappingBasePackages() {
4274-
return Arrays.asList(PersonWithAllConstructor.class.getPackage().getName());
4298+
return Arrays.asList(
4299+
PersonWithAllConstructor.class.getPackage().getName(),
4300+
Flight.class.getPackage().getName()
4301+
);
42754302
}
42764303

42774304
@Bean
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2011-2021 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.imperative.repositories;
17+
18+
import org.springframework.data.neo4j.integration.shared.common.Flight;
19+
import org.springframework.data.neo4j.repository.Neo4jRepository;
20+
21+
import java.util.List;
22+
23+
/**
24+
* @author Michael J. Simons
25+
*/
26+
public interface FlightRepository extends Neo4jRepository<Flight, Long> {
27+
List<Flight> findAllByDepartureCodeAndArrivalCode(String departureCode, String arrivalCode);
28+
}

src/test/java/org/springframework/data/neo4j/integration/issues/gh2210/GH2210IT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.junit.jupiter.api.BeforeAll;
1919
import org.junit.jupiter.api.Test;
2020
import org.neo4j.driver.Driver;
21-
import org.neo4j.driver.Record;
2221
import org.neo4j.driver.Transaction;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.context.annotation.Bean;
@@ -70,14 +69,14 @@ protected static void setupData() {
7069
params.put("numberB", numberB);
7170
params.put("numberC", numberC);
7271
params.put("numberD", numberD);
73-
Record r = transaction.run("create (a:SomeEntity {number: $numberA, name: \"A\"})\n"
72+
transaction.run("create (a:SomeEntity {number: $numberA, name: \"A\"})\n"
7473
+ "create (b:SomeEntity {number: $numberB, name: \"B\"})\n"
7574
+ "create (c:SomeEntity {number: $numberC, name: \"C\"})\n"
7675
+ "create (d:SomeEntity {number: $numberD, name: \"D\"})\n"
7776
+ "create (a) -[:SOME_RELATION_TO {someData: \"d1\"}] -> (b)\n"
7877
+ "create (b) <-[:SOME_RELATION_TO {someData: \"d2\"}] - (c)\n"
7978
+ "create (c) <-[:SOME_RELATION_TO {someData: \"d3\"}] - (d)\n"
80-
+ "return * ", params).single();
79+
+ "return * ", params);
8180
transaction.commit();
8281
}
8382
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2011-2021 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.shared.common;
17+
18+
import org.springframework.data.neo4j.core.schema.Id;
19+
import org.springframework.data.neo4j.core.schema.Node;
20+
21+
/**
22+
* @author Michael J. Simons
23+
*/
24+
@Node
25+
public class Airport {
26+
27+
@Id
28+
String code; // e.g. "LAX"
29+
String name; // e.g. "Los Angeles"
30+
31+
public Airport(String code, String name) {
32+
this.code = code;
33+
this.name = name;
34+
}
35+
36+
public String getCode() {
37+
return code;
38+
}
39+
40+
public String getName() {
41+
return name;
42+
}
43+
44+
public void setName(String name) {
45+
this.name = name;
46+
}
47+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2011-2021 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.shared.common;
17+
18+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
19+
import org.springframework.data.neo4j.core.schema.Id;
20+
import org.springframework.data.neo4j.core.schema.Node;
21+
import org.springframework.data.neo4j.core.schema.Relationship;
22+
23+
/**
24+
* @author Michael J. Simons
25+
*/
26+
@Node
27+
public class Flight {
28+
29+
@Id @GeneratedValue
30+
private Long id;
31+
32+
private final String name;
33+
34+
@Relationship(type = "DEPARTS")
35+
private final Airport departure;
36+
@Relationship(type = "ARRIVES")
37+
private final Airport arrival;
38+
39+
public Flight(String name, Airport departure, Airport arrival) {
40+
this.name = name;
41+
this.departure = departure;
42+
this.arrival = arrival;
43+
}
44+
45+
public String getName() {
46+
return name;
47+
}
48+
49+
public Airport getDeparture() {
50+
return departure;
51+
}
52+
53+
public Airport getArrival() {
54+
return arrival;
55+
}
56+
}

0 commit comments

Comments
 (0)