Package org.springframework.data.repository.query.parser

Examples of org.springframework.data.repository.query.parser.PartTree$Subject


  private void assertBindsDistanceToQuery(Point point, Distance distance, Query reference) throws Exception {

    when(converter.convertToMongoType("Dave")).thenReturn("Dave");

    PartTree tree = new PartTree("findByLocationNearAndFirstname",
        org.springframework.data.mongodb.repository.Person.class);
    Method method = PersonRepository.class.getMethod("findByLocationNearAndFirstname", Point.class, Distance.class,
        String.class);
    MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class),
        new MongoMappingContext());
View Full Code Here


   * @see DATAMONGO-770
   */
  @Test
  public void createsQueryWithFindByIgnoreCaseCorrectly() {

    PartTree tree = new PartTree("findByfirstNameIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);

    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").regex("^dave$", "i"))));
  }
View Full Code Here

   * @see DATAMONGO-770
   */
  @Test
  public void createsQueryWithFindByNotIgnoreCaseCorrectly() {

    PartTree tree = new PartTree("findByFirstNameNotIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);

    Query query = creator.createQuery();
    assertThat(query.toString(), is(query(where("firstName").not().regex("^dave$", "i")).toString()));
  }
View Full Code Here

   * (non-Javadoc)
   * @see org.springframework.data.repository.core.support.QueryCreationListener#onCreation(org.springframework.data.repository.query.RepositoryQuery)
   */
  public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();

    for (Part part : tree.getParts()) {
      if (GEOSPATIAL_TYPES.contains(part.getType())) {
        return;
      }
      String property = part.getProperty().toDotPath();
      Direction order = toDirection(sort, property);
View Full Code Here

   * @see DATAMONGO-770
   */
  @Test
  public void createsQueryWithFindByStartingWithIgnoreCaseCorrectly() {

    PartTree tree = new PartTree("findByFirstNameStartingWithIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);

    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").regex("^dave", "i"))));
  }
View Full Code Here

   * @see DATAMONGO-770
   */
  @Test
  public void createsQueryWithFindByEndingWithIgnoreCaseCorrectly() {

    PartTree tree = new PartTree("findByFirstNameEndingWithIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);

    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").regex("dave$", "i"))));
  }
View Full Code Here

   * @see DATAMONGO-770
   */
  @Test
  public void createsQueryWithFindByContainingIgnoreCaseCorrectly() {

    PartTree tree = new PartTree("findByFirstNameContainingIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave"), context);

    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").regex(".*dave.*", "i"))));
  }
View Full Code Here

  public void shouldThrowExceptionForQueryWithFindByIgnoreCaseOnNonStringProperty() {

    expection.expect(IllegalArgumentException.class);
    expection.expectMessage("must be of type String");

    PartTree tree = new PartTree("findByFirstNameAndAgeIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "foo", 42), context);

    creator.createQuery();
  }
View Full Code Here

   * @see DATAMONGO-770
   */
  @Test
  public void shouldOnlyGenerateLikeExpressionsForStringPropertiesIfAllIgnoreCase() {

    PartTree tree = new PartTree("findByFirstNameAndAgeAllIgnoreCase", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave", 42), context);

    Query query = creator.createQuery();
    assertThat(query, is(query(where("firstName").regex("^dave$", "i").and("age").is(42))));
  }
View Full Code Here

   * @see DATAMONGO-566
   */
  @Test
  public void shouldCreateDeleteByQueryCorrectly() {

    PartTree tree = new PartTree("deleteByFirstName", Person.class);
    MongoQueryCreator creator = new MongoQueryCreator(tree, getAccessor(converter, "dave", 42), context);

    Query query = creator.createQuery();

    assertThat(tree.isDelete(), is(true));
    assertThat(query, is(query(where("firstName").is("dave"))));
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.repository.query.parser.PartTree$Subject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.