Package org.springframework.data.mapping

Examples of org.springframework.data.mapping.PropertyPath


  }

  @Test
  public void supportsDotNotationAsWell() {

    PropertyPath propertyPath = PropertyPath.from("bar.userMap.name", Sample.class);

    assertThat(propertyPath, is(notNullValue()));
    assertThat(propertyPath.getSegment(), is("bar"));
    assertThat(propertyPath.getLeafProperty(), is(PropertyPath.from("name", FooBar.class)));
  }
View Full Code Here


  }

  @Test
  public void returnsCorrectIteratorForSingleElement() {

    PropertyPath propertyPath = PropertyPath.from("userName", Foo.class);

    Iterator<PropertyPath> iterator = propertyPath.iterator();
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.next(), is(propertyPath));
    assertThat(iterator.hasNext(), is(false));
  }
View Full Code Here

  }

  @Test
  public void returnsCorrectIteratorForMultipleElement() {

    PropertyPath propertyPath = PropertyPath.from("user.name", Bar.class);

    Iterator<PropertyPath> iterator = propertyPath.iterator();
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.next(), is(propertyPath));
    assertThat(iterator.hasNext(), is(true));
    assertThat(iterator.next(), is(propertyPath.next()));
    assertThat(iterator.hasNext(), is(false));
  }
View Full Code Here

  }

  @Test
  public void samePathsEqual() {

    PropertyPath left = PropertyPath.from("user.name", Bar.class);
    PropertyPath right = PropertyPath.from("user.name", Bar.class);

    PropertyPath shortPath = PropertyPath.from("user", Bar.class);

    assertThat(left, is(right));
    assertThat(right, is(left));
    assertThat(left, is(not(shortPath)));
    assertThat(shortPath, is(not(left)));
View Full Code Here

  }

  @Test
  public void hashCodeTests() {

    PropertyPath left = PropertyPath.from("user.name", Bar.class);
    PropertyPath right = PropertyPath.from("user.name", Bar.class);

    PropertyPath shortPath = PropertyPath.from("user", Bar.class);

    assertThat(left.hashCode(), is(right.hashCode()));
    assertThat(left.hashCode(), is(not(shortPath.hashCode())));
  }
View Full Code Here

   * @see DATACMNS-257
   */
  @Test
  public void findsAllUppercaseProperty() {

    PropertyPath path = PropertyPath.from("UUID", Foo.class);

    assertThat(path, is(notNullValue()));
    assertThat(path.getSegment(), is("UUID"));
  }
View Full Code Here

   * @see DATACMNS-257
   */
  @Test
  public void findsNestedAllUppercaseProperty() {

    PropertyPath path = PropertyPath.from("_fooUUID", Sample2.class);

    assertThat(path, is(notNullValue()));
    assertThat(path.getSegment(), is("_foo"));
    assertThat(path.hasNext(), is(true));
    assertThat(path.next().getSegment(), is("UUID"));
  }
View Full Code Here

  private Order createOrder(String propertySource, Direction direction, Class<?> domainClass) {

    if (null == domainClass) {
      return new Order(direction, StringUtils.uncapitalize(propertySource));
    }
    PropertyPath propertyPath = PropertyPath.from(propertySource, domainClass);
    return new Order(direction, propertyPath.toDotPath());
  }
View Full Code Here

   * @return
   */
  @SuppressWarnings("unchecked")
  private static javax.persistence.criteria.Order toJpaOrder(Order order, Root<?> root, CriteriaBuilder cb) {

    PropertyPath property = PropertyPath.from(order.getProperty(), root.getJavaType());
    Expression<?> expression = toExpressionRecursively(root, property);

    if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) {
      Expression<String> lower = cb.lower((Expression<String>) expression);
      return order.isAscending() ? cb.asc(lower) : cb.desc(lower);
View Full Code Here

   */
  private Expression<?> buildOrderPropertyPathFrom(Order order) {

    Assert.notNull(order, "Order must not be null!");

    PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
    Expression<?> sortPropertyExpression = builder;

    while (path != null) {

      if (!path.hasNext() && order.isIgnoreCase()) {
        // if order is ignore-case we have to treat the last path segment as a String.
        sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
      } else {
        sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
      }

      path = path.next();
    }

    return sortPropertyExpression;
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.mapping.PropertyPath

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.