DATAGRAPH-761 - Adding support for negated derived queries.
Also improved character escaping for LIKE queries.
This commit is contained in:
@@ -29,7 +29,7 @@ import org.neo4j.ogm.session.result.RowModel;
|
||||
import org.neo4j.ogm.session.transaction.Transaction;
|
||||
|
||||
/**
|
||||
* Specialisation of {@link GraphRepositoryQuery} that handles mapping to object annotated with <code>@QueryResult</code>.
|
||||
* Specialisation of {@link GraphRepositoryQuery} that handles mapping to objects annotated with <code>@QueryResult</code>.
|
||||
*
|
||||
* @author Adam George
|
||||
*/
|
||||
|
||||
@@ -52,6 +52,7 @@ public class CypherFinderQuery implements DerivedQueryDefinition {
|
||||
parameter.setPropertyName(property);
|
||||
parameter.setOwnerEntityType(entityType);
|
||||
parameter.setComparisonOperator(convertToComparisonOperator(part.getType()));
|
||||
parameter.setNegated(part.getType().name().startsWith("NOT"));
|
||||
parameter.setBooleanOperator(booleanOperator);
|
||||
|
||||
if (part.getProperty().next() != null) {
|
||||
@@ -74,6 +75,8 @@ public class CypherFinderQuery implements DerivedQueryDefinition {
|
||||
return ComparisonOperator.MATCHES;
|
||||
case LIKE:
|
||||
return ComparisonOperator.LIKE;
|
||||
case NOT_LIKE:
|
||||
return ComparisonOperator.LIKE;
|
||||
default:
|
||||
return ComparisonOperator.EQUALS;
|
||||
}
|
||||
|
||||
@@ -83,10 +83,12 @@ public interface UserRepository extends GraphRepository<User> {
|
||||
@Query("MATCH (user:User) WHERE ID(user)={userId} RETURN user")
|
||||
User loadUserByNamedId(@Param("userId") User user);
|
||||
|
||||
|
||||
@Query("MATCH (user:User) RETURN user")
|
||||
Iterable<User> getAllUsersIterable();
|
||||
|
||||
@Query("MATCH (user:User) set user.name={0}")
|
||||
void setNamesNull(String name);
|
||||
|
||||
List<User> findByNameIsNotLike(String name);
|
||||
|
||||
}
|
||||
|
||||
@@ -382,5 +382,31 @@ public class DerivedQueryTest {
|
||||
assertEquals("The wrong number of cinemas was returned", 2, cinemas.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* DATAGRAPH-761
|
||||
*/
|
||||
@Test
|
||||
public void shouldMatchNodeEntitiesUsingLikeWithWildcardsAndSpecialCharacters() {
|
||||
executeUpdate("CREATE (:Theatre {name:'IMAX', city:'Kolkata (Calcutta)'}), "
|
||||
+ "(:Theatre {name:'PVR', city:'Bengaluru (Bangalore)'}), "
|
||||
+ "(:Theatre {name:'Metro Big Cinema', city:'Mumbai (Bombay)'}) ");
|
||||
|
||||
List<Cinema> indianCinemas = cinemaRepository.findByLocationLike("*(B*");
|
||||
assertEquals("The wrong number of cinemas was returned", 2, indianCinemas.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* DATAGRAPH-761
|
||||
*/
|
||||
@Test
|
||||
public void shouldMatchNodeEntitiesUsingNotLikeWithAsteriskWildcards() {
|
||||
executeUpdate("CREATE (:User {name:'Jeff'}), "
|
||||
+ "(:User {name:'Jeremy'}), "
|
||||
+ "(:User {name:'Alan'})");
|
||||
|
||||
List<User> nonMatchingUsers = userRepository.findByNameIsNotLike("Je*");
|
||||
assertEquals("The wrong number of users was returned", 1, nonMatchingUsers.size());
|
||||
assertEquals("The wrong user was returned", "Alan", nonMatchingUsers.get(0).getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user