4

I have a UserRepository class that extends GraphRepository:

  public interface UserRepository extends GraphRepository<User> {

    @Query("MATCH (User:_User) WHERE User.network = {0} RETURN User")
    Iterable<User> executeFilterTest(String filterValue);

  }

The problem is I don't always know exactly what the 'WHERE' part of the query will have. So I want to be able to send in the WHERE part as a parameter like this:

    @Query("MATCH (User:_User) {0} RETURN User")
    Iterable<User> executeFilterTest(String whereValue);

Is it possible to do something like this? Or can I somehow save the whole Cypher query as a String and then send in the whole String as a parameter?

lulu88
  • 1,694
  • 5
  • 27
  • 41

1 Answers1

1

Try to use custom repository example (please take not that impl method must match to your userRepository not userRepositoryCustom eg: UserRepositoryImpl) :

public interface UserRepository extends GraphRepository<User>, UserRepository {
}

public class UserRepositoryImpl implements UserRepositoryCustom {
    @Autowired Neo4jTemplate template;
    @Override
    public Result<Map<String, Object>> findByCypher(String cypher) {
    return template.query(cypher, null);
    }
}

public interface UserRepositoryCustom {
    Result<Map<String, Object>> findByCypher(String cypher);    
}
Solstice
  • 11
  • 1