Skip to content

Commit

Permalink
GH-1792 - Ensure that internal database ids are accessed via id(n) in…
Browse files Browse the repository at this point in the history
… nested, derived query methods.

This closes #1792.
  • Loading branch information
michael-simons committed Jan 12, 2021
1 parent 6fa6158 commit cab1e78
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public interface UserRepository extends PersonRepository<User, Long> {

List<User> findAllByIdAndName(Long id, String name);

List<User> findAllByInterestedId(Long id);

@Query("invalid")
void invalidQuery();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -123,10 +124,7 @@ public void shouldFindUsersByMiddleName() {
assertFalse(iterator.hasNext());
}

/**
* @see DATAGRAPH-628
*/
@Test
@Test // DATAGRAPH-628
public void shouldFindNodeEntitiesWithLabels() {
executeUpdate(
"CREATE (u:User {name:'Michal'}) CREATE (p:Theatre {name:'Picturehouse', city:'London'}) CREATE (r:Theatre {name:'Ritzy', city:'London'}) CREATE (u)-[:VISITED]->(p)");
Expand Down Expand Up @@ -170,10 +168,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntitiesMultipleAndedProperties() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London'}) CREATE (r:Theatre {name:'Ritzy', city:'London'})"
Expand All @@ -184,10 +179,7 @@ public void shouldFindNodeEntitiesMultipleAndedProperties() {
assertEquals("Michal", theatres.get(0).getVisited().iterator().next().getName());
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesMultipleOredProperties() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London'}) CREATE (r:Theatre {name:'Ritzy', city:'London'})"
Expand All @@ -197,10 +189,7 @@ public void shouldFindNodeEntititiesMultipleOredProperties() {
assertEquals(2, theatres.size());
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldReturnNoResultsCorrectly() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London'}) CREATE (r:Theatre {name:'Ritzy', city:'London'})"
Expand All @@ -210,10 +199,7 @@ public void shouldReturnNoResultsCorrectly() {
assertEquals(0, theatres.size());
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithComparisonOperators() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500})"
Expand Down Expand Up @@ -243,10 +229,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithMultipleComparisonOperatorsAnded() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) CREATE (m:Theatre {name:'Regal', city:'Bombay', capacity: 4500})"
Expand All @@ -267,10 +250,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithMultipleComparisonOperatorsOred() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) CREATE (m:Theatre {name:'Regal', city:'Bombay', capacity: 9000})"
Expand All @@ -291,10 +271,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithNestedProperty() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500})"
Expand All @@ -305,10 +282,7 @@ public void shouldFindNodeEntititiesWithNestedProperty() {
assertTrue(theatres.contains(new Cinema("Ritzy")));
}

/**
* @see DATAGRAPH-???
*/
@Test
@Test // DATAGRAPH-???
public void shouldFindNodeEntititiesWithDeepNestedProperty() {
executeUpdate("CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500})"
+ " CREATE (u:User {name:'Michal'}) CREATE (u)-[:VISITED]->(r) CREATE (m1:Movie {name:'Speed'})"
Expand All @@ -319,10 +293,7 @@ public void shouldFindNodeEntititiesWithDeepNestedProperty() {
assertTrue(theatres.contains(new Cinema("Ritzy")));
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithBaseAndNestedProperty() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) CREATE (m:Theatre {name:'Regal', city:'Bombay', capacity: 5000})"
Expand All @@ -333,10 +304,7 @@ public void shouldFindNodeEntititiesWithBaseAndNestedProperty() {
assertTrue(theatres.contains(new Cinema("Ritzy")));
}

/**
* @see DATAGRAPH-662 //TODO FIXME
*/
@Test(expected = UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class) // DATAGRAPH-662
public void shouldFindNodeEntititiesWithBaseOrNestedProperty() {
executeUpdate(
"CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) CREATE (m:Theatre {name:'The Old Vic', city:'London', capacity: 5000})"
Expand All @@ -349,10 +317,7 @@ public void shouldFindNodeEntititiesWithBaseOrNestedProperty() {
assertTrue(theatres.contains(new Cinema("The Old Vic")));
}

/**
* @see DATAGRAPH-632
*/
@Test
@Test // DATAGRAPH-632
public void shouldFindNodeEntitiesWithNestedRelationshipEntityProperty() {
executeUpdate(
"CREATE (m1:Movie {title:'Speed'}) CREATE (m2:Movie {title:'The Matrix'}) CREATE (m:Movie {title:'Chocolat'})"
Expand All @@ -365,11 +330,7 @@ public void shouldFindNodeEntitiesWithNestedRelationshipEntityProperty() {
assertTrue(users.contains(new User("Vince")));
}

/**
* @see DATAGRAPH-629
* @see DATAGRAPH-705
*/
@Test
@Test // DATAGRAPH-629 DATAGRAPH-705
public void shouldFindNodeEntititiesWithTwoNestedPropertiesAndedAcrossDifferentRelatedNodeEntities() {
executeUpdate("CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) "
+ " CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) " + " CREATE (u:User {name:'Michal'}) "
Expand All @@ -390,11 +351,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-662
*/
// FIXME: OR is not supported for nested properties on an entity
@Test(expected = UnsupportedOperationException.class)
@Test(expected = UnsupportedOperationException.class) // DATAGRAPH-662
public void shouldFindNodeEntititiesWithTwoNestedPropertiesOred() {
executeUpdate("CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) "
+ " CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) " + " CREATE (u:User {name:'Michal'}) "
Expand All @@ -416,10 +373,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithMultipleNestedPropertiesAnded() {
executeUpdate("CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) "
+ " CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) "
Expand All @@ -439,10 +393,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-629
*/
@Test
@Test // DATAGRAPH-629
public void shouldFindNodeEntititiesWithRelationshipEntityAndNestedProperty() {
executeUpdate(
"CREATE (m1:Movie {title:'Speed'}) CREATE (m2:Movie {title:'The Matrix'}) CREATE (m:Movie {title:'Chocolat'})"
Expand All @@ -454,10 +405,7 @@ public void shouldFindNodeEntititiesWithRelationshipEntityAndNestedProperty() {
assertTrue(users.contains(new User("Michal")));
}

/**
* Relates to DATAGRAPH-601 and, to an extent, DATAGRAPH-761
*/
@Test
@Test // DATAGRAPH-601, DATAGRAPH-761
public void shouldFindNodeEntitiesByRegularExpressionMatchingOnPropertiesInDerivedFinderMethods() {
executeUpdate("CREATE (:Theatre {name:'Odeon', city:'Preston'}), " + "(:Theatre {name:'Vue', city:'Dumfries'}), "
+ "(:Theatre {name:'PVR', city:'Mumbai'}) ");
Expand All @@ -468,10 +416,7 @@ public void shouldFindNodeEntitiesByRegularExpressionMatchingOnPropertiesInDeriv
assertEquals("An unexpected cinema was retrieved", "Dumfries", cinemas.get(0).getLocation());
}

/**
* DATAGRAPH-761
*/
@Test
@Test // DATAGRAPH-761
public void shouldMatchNodeEntitiesUsingCaseInsensitiveLikeWithWildcards() {
executeUpdate("CREATE (:Theatre {name:'IMAX', city:'Chesterfield'}), "
+ "(:Theatre {name:'Odeon', city:'Manchester'}), " + "(:Theatre {name:'IMAX', city:'Edinburgh'}) ");
Expand All @@ -480,10 +425,7 @@ public void shouldMatchNodeEntitiesUsingCaseInsensitiveLikeWithWildcards() {
assertEquals("The wrong number of cinemas was returned", 2, cinemas.size());
}

/**
* DATAGRAPH-761
*/
@Test
@Test // DATAGRAPH-761
public void shouldMatchNodeEntitiesUsingLikeWithWildcardsAndSpecialCharacters() {
executeUpdate("CREATE (:Theatre {name:'IMAX', city:'Kolkata (Calcutta)'}), "
+ "(:Theatre {name:'PVR', city:'Bengaluru (Bangalore)'}), "
Expand All @@ -493,10 +435,7 @@ public void shouldMatchNodeEntitiesUsingLikeWithWildcardsAndSpecialCharacters()
assertEquals("The wrong number of cinemas was returned", 2, indianCinemas.size());
}

/**
* DATAGRAPH-761
*/
@Test
@Test // DATAGRAPH-761
public void shouldMatchNodeEntitiesUsingNotLikeWithAsteriskWildcards() {
executeUpdate("CREATE (:User {name:'Jeff'}), " + "(:User {name:'Jeremy'}), " + "(:User {name:'Alan'})");

Expand All @@ -505,10 +444,7 @@ public void shouldMatchNodeEntitiesUsingNotLikeWithAsteriskWildcards() {
assertEquals("The wrong user was returned", "Alan", nonMatchingUsers.get(0).getName());
}

/**
* @see DATAGRAPH-787
*/
@Test
@Test // DATAGRAPH-787
public void shouldFindDirectorsByName() {
executeUpdate(
"CREATE (m:User {name:'Michal'})<-[:FRIEND_OF]-(a:User {name:'Adam'}) CREATE (d:Director {name:'Vince'})");
Expand All @@ -530,10 +466,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-744
*/
@Test
@Test // DATAGRAPH-744
public void shouldFindUserWithCustomDepth() {
executeUpdate("CREATE (p:Theatre {name:'Picturehouse', city:'London', capacity:5000}) "
+ " CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500}) " + " CREATE (u:User {name:'Michal'}) "
Expand Down Expand Up @@ -567,10 +500,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
});
}

/**
* @see DATAGRAPH-744
*/
@Test
@Test // DATAGRAPH-744
public void shouldFindUsersByNameWithStaticDepth() {
executeUpdate(
"CREATE (m:User {name:'Michal', surname:'Bachman'})<-[:FRIEND_OF]-(a:User {name:'Adam', surname:'George'})");
Expand All @@ -582,10 +512,7 @@ public void shouldFindUsersByNameWithStaticDepth() {
assertEquals(0, user.getFriends().size());
}

/**
* @see DATAGRAPH-864
*/
@Test
@Test // DATAGRAPH-864
public void shouldSupportLiteralMapsInQueryResults() {
executeUpdate(
"CREATE (m1:Movie {title:'Speed'}) CREATE (m2:Movie {title:'The Matrix'}) CREATE (m:Movie {title:'Chocolat'})"
Expand All @@ -605,11 +532,7 @@ public void shouldSupportLiteralMapsInQueryResults() {
}
}

/**
* @throws InterruptedException
* @see DATAGRAPH-876
*/
@Test
@Test // DATAGRAPH-876
public void shouldAllowMultiThreadedDerivedFinderExecution() throws InterruptedException {
int numThreads = 3;
executeUpdate(
Expand All @@ -630,10 +553,7 @@ public void shouldAllowMultiThreadedDerivedFinderExecution() throws InterruptedE
executor.shutdownNow();
}

/**
* @see DATAGRAPH-680
*/
@Test
@Test // DATAGRAPH-680
@Transactional
public void shouldPageDerivedFinderQueries() {
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -675,10 +595,7 @@ public void shouldPageDerivedFinderQueries() {
assertFalse(page.hasNext());
}

/**
* @see DATAGRAPH-680
*/
@Test
@Test // DATAGRAPH-680
@Transactional
public void shouldSliceDerivedFinderQueries() {
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -759,6 +676,20 @@ public void findByIdEqualsInDerivedQueryMethodShouldWork() {
assertThat(users).hasSize(1);
}

@Test // GH-1792
public void findByIdInNestedPropertyTraversalShouldWork() {
executeUpdate("CREATE (r:Theatre {name:'Ritzy', city:'London', capacity: 7500})"
+ " CREATE (u:User {name:'Michal'}) CREATE (u)-[:VISITED]->(r) CREATE (m1:Movie {name:'Speed'})"
+ " CREATE (g:Genre {name:'Thriller'}) CREATE (u)-[:INTERESTED]->(g)");

long genreId = session.queryForObject(Long.class, "MATCH (g:Genre {name:'Thriller'}) RETURN id(g)",
Collections.emptyMap());

List<User> users = userRepository.findAllByInterestedId(genreId);
assertEquals(1, users.size());
assertEquals("Michal", users.get(0).getName());
}

@Test // DATAGRAPH-1093
public void shouldFindNodeEntitiesByAttributeIgnoringCase() {
executeUpdate("CREATE (:Director {name:'Patty Jenkins'})\n" + //
Expand Down

0 comments on commit cab1e78

Please sign in to comment.