Package org.springframework.data.mongodb.core.aggregation.ExposedFields

Examples of org.springframework.data.mongodb.core.aggregation.ExposedFields.FieldReference


    BasicDBObject object = new BasicDBObject();

    for (Order order : sort) {

      // Check reference
      FieldReference reference = context.getReference(order.getProperty());
      object.put(reference.getRaw(), order.isAscending() ? 1 : -1);
    }

    return new BasicDBObject("$sort", object);
  }
View Full Code Here


    if (exposedField != null) {

      if (field != null) {
        // we return a FieldReference to the given field directly to make sure that we reference the proper alias here.
        return new FieldReference(new ExposedField(field, exposedField.isSynthetic()));
      }

      return new FieldReference(exposedField);
    }

    if (name.contains(".")) {

      // for nested field references we only check that the root field exists.
      ExposedField rootField = exposedFields.getField(name.split("\\.")[0]);

      if (rootField != null) {

        // We have to synthetic to true, in order to render the field-name as is.
        return new FieldReference(new ExposedField(name, true));
      }
    }

    throw new IllegalArgumentException(String.format("Invalid reference '%s'!", name));
  }
View Full Code Here

     * (non-Javadoc)
     * @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getReference(org.springframework.data.mongodb.core.aggregation.ExposedFields.AvailableField)
     */
    @Override
    public FieldReference getReference(Field field) {
      return new FieldReference(new ExposedField(field, true));
    }
View Full Code Here

     * (non-Javadoc)
     * @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getReference(java.lang.String)
     */
    @Override
    public FieldReference getReference(String name) {
      return new FieldReference(new ExposedField(new AggregationField(name), true));
    }
View Full Code Here

    PersistentPropertyPath<MongoPersistentProperty> propertyPath = mappingContext.getPersistentPropertyPath(
        field.getTarget(), type);
    Field mappedField = field(propertyPath.getLeafProperty().getName(),
        propertyPath.toDotPath(MongoPersistentProperty.PropertyToFieldNameConverter.INSTANCE));

    return new FieldReference(new ExposedField(mappedField, true));
  }
View Full Code Here

      operationObject.put(Fields.UNDERSCORE_ID, null);

    } else if (idFields.exposesSingleNonSyntheticFieldOnly()) {

      FieldReference reference = context.getReference(idFields.iterator().next());
      operationObject.put(Fields.UNDERSCORE_ID, reference.toString());

    } else {

      BasicDBObject inner = new BasicDBObject();

      for (ExposedField field : idFields) {
        FieldReference reference = context.getReference(field);
        inner.put(field.getName(), reference.toString());
      }

      operationObject.put(Fields.UNDERSCORE_ID, inner);
    }
View Full Code Here

   */
  @Test
  public void aliasesIdFieldCorrectly() {

    AggregationOperationContext context = getContext(Foo.class);
    assertThat(context.getReference("id"), is(new FieldReference(new ExposedField(Fields.field("id", "_id"), true))));
  }
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.aggregation.ExposedFields.FieldReference

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.