Java Code Examples for org.bson.BsonWriter#writeEndArray()

The following examples show how to use org.bson.BsonWriter#writeEndArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwitchExpression.java    From morphia with Apache License 2.0 6 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartDocument(getOperation());
    writer.writeStartArray("branches");
    for (final Pair branch : branches) {
        writer.writeStartDocument();
        writer.writeName("case");
        branch.caseExpression.encode(mapper, writer, encoderContext);
        writer.writeName("then");
        branch.then.encode(mapper, writer, encoderContext);
        writer.writeEndDocument();
    }
    writer.writeEndArray();
    writeNamedExpression(mapper, writer, "default", defaultCase, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 2
Source File: MathExpression.java    From morphia with Apache License 2.0 6 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeName(getOperation());
    if (operands.size() > 1) {
        writer.writeStartArray();
    }
    for (final Expression operand : operands) {
        if (operand != null) {
            ExpressionCodec.writeUnnamedExpression(mapper, writer, operand, encoderContext);
        } else {
            writer.writeNull();
        }
    }
    if (operands.size() > 1) {
        writer.writeEndArray();
    }
    writer.writeEndDocument();
}
 
Example 3
Source File: PolygonFilter.java    From morphia with Apache License 2.0 6 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) {
    writer.writeStartDocument(field(mapper));
    writer.writeStartDocument("$geoWithin");
    writer.writeStartArray("$polygon");
    for (final Point point : points) {
        writer.writeStartArray();
        for (final Double value : point.getPosition().getValues()) {
            writer.writeDouble(value);
        }
        writer.writeEndArray();
    }
    writer.writeEndArray();
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 4
Source File: LogicalFilter.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) {
    writer.writeStartArray(getFilterName());
    for (final Filter filter : filters) {
        writer.writeStartDocument();
        filter.encode(mapper, writer, context);
        writer.writeEndDocument();
    }
    writer.writeEndArray();
}
 
Example 5
Source File: Accumulator.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeName(getOperation());
    if (expressions.size() > 1) {
        writer.writeStartArray();
    }
    for (final Expression expression : expressions) {
        writeUnnamedExpression(mapper, writer, expression, encoderContext);
    }
    if (expressions.size() > 1) {
        writer.writeEndArray();
    }
    writer.writeEndDocument();
}
 
Example 6
Source File: ArrayIndexExpression.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(getOperation());
    writeUnnamedExpression(mapper, writer, array, encoderContext);
    writeUnnamedExpression(mapper, writer, search, encoderContext);
    writeUnnamedValue(mapper, writer, start, encoderContext);
    writeUnnamedValue(mapper, writer, end, encoderContext);
    writer.writeEndArray();
    writer.writeEndDocument();

}
 
Example 7
Source File: IndexExpression.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(getOperation());
    writeUnnamedExpression(mapper, writer, string, encoderContext);
    writeUnnamedExpression(mapper, writer, substring, encoderContext);
    writeUnnamedValue(mapper, writer, start, encoderContext);
    writeUnnamedValue(mapper, writer, end, encoderContext);
    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 8
Source File: IfNull.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeName(getOperation());
    writer.writeStartArray();
    writeUnnamedExpression(mapper, writer, target, encoderContext);
    writeUnnamedExpression(mapper, writer, replacement, encoderContext);
    writeUnnamedExpression(mapper, writer, document, encoderContext);
    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 9
Source File: RangeExpression.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(getOperation());
    writer.writeInt32(start);
    writer.writeInt32(end);
    if (step != null) {
        writer.writeInt32(step);
    }
    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 10
Source File: AbstractJsonCodec.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
protected void writeArray(BsonWriter writer, String name, Object value, EncoderContext ctx) {
  @SuppressWarnings("unchecked")
  A array = (A) value;

  writer.writeStartArray();
  forEach(array, o -> writeValue(writer, null, o, ctx));
  writer.writeEndArray();
}
 
Example 11
Source File: Filters.java    From morphia with Apache License 2.0 5 votes vote down vote up
/**
 * Performs a modulo operation on the value of a field and selects documents with a specified result.
 *
 * @param field     the field to check
 * @param divisor   the value to divide by
 * @param remainder the remainder to check for
 * @return the filter
 * @query.filter $mod
 */
public static Filter mod(final String field, final long divisor, final long remainder) {
    return new Filter("$mod", field, null) {
        @Override
        public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) {
            writer.writeStartDocument(field(mapper));
            writer.writeName(getFilterName());
            writer.writeStartArray();
            writeUnnamedValue(divisor, mapper, writer, context);
            writeUnnamedValue(remainder, mapper, writer, context);
            writer.writeEndArray();
            writer.writeEndDocument();
        }
    };
}
 
Example 12
Source File: SliceExpression.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(getOperation());
    writeUnnamedExpression(mapper, writer, array, encoderContext);
    if (position != null) {
        writer.writeInt32(position);
    }
    writer.writeInt32(size);
    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 13
Source File: CenterCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
private void encodePosition(final BsonWriter writer, final Position value) {
    writer.writeStartArray();

    for (double number : value.getValues()) {
        writer.writeDouble(number);
    }

    writer.writeEndArray();
}
 
Example 14
Source File: CenterCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final BsonWriter writer, final dev.morphia.query.Shape.Center value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(value.getGeometry());

    encodePosition(writer, value.getCenter().getPosition());
    writer.writeDouble(value.getRadius());

    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 15
Source File: CollectionCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final BsonWriter writer, final Collection<T> collection, final EncoderContext encoderContext) {
    writer.writeStartArray();
    for (final T value : collection) {
        if (value == null) {
            writer.writeNull();
        } else {
            codec.encode(writer, value, encoderContext);
        }
    }
    writer.writeEndArray();
}
 
Example 16
Source File: ShapeCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
private void encodePosition(final BsonWriter writer, final Position value) {
    writer.writeStartArray();

    for (double number : value.getValues()) {
        writer.writeDouble(number);
    }

    writer.writeEndArray();
}
 
Example 17
Source File: ShapeCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final BsonWriter writer, final dev.morphia.query.Shape value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeStartArray(value.getGeometry());
    for (final Point point : value.getPoints()) {
        encodePosition(writer, point.getCoordinates());
    }
    writer.writeEndArray();
    writer.writeEndDocument();
}
 
Example 18
Source File: ArrayCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void encode(final BsonWriter writer, final Object value, final EncoderContext encoderContext) {
    writer.writeStartArray();
    int length = Array.getLength(value);
    for (int i = 0; i < length; i++) {
        Object element = Array.get(value, i);
        Codec codec = mapper.getCodecRegistry().get(element.getClass());
        codec.encode(writer, element, encoderContext);
    }
    writer.writeEndArray();
}
 
Example 19
Source File: TypedArrayCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final BsonWriter writer, final Object value, final EncoderContext encoderContext) {
    writer.writeStartArray();
    int length = Array.getLength(value);
    for (int i = 0; i < length; i++) {
        getCodec().encode(writer, Array.get(value, i), encoderContext);
    }
    writer.writeEndArray();
}
 
Example 20
Source File: MergeCodec.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Merge value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    String collection;
    String database = null;
    if(value.getType() != null) {
        collection = getMapper().getMappedClass(value.getType()).getCollectionName();
    } else {
        collection = value.getCollection();
        database = value.getDatabase();
    }

    if(database == null) {
        writer.writeString("into", collection);
    } else {
        writer.writeStartDocument("into");
        writer.writeString("db", database);
        writer.writeString("coll", collection);
        writer.writeEndDocument();
    }

    List<String> on = value.getOn();
    if(on != null) {
        if(on.size() == 1) {
            writer.writeString("on", on.get(0));
        } else {
            writer.writeStartArray("on");
            for (final String name : on) {
                writer.writeString(name);
            }
            writer.writeEndArray();
        }
    }
    Map<String, Expression> variables = value.getVariables();
    if(variables != null) {
        writer.writeStartDocument("let");
        for (final Entry<String, Expression> entry : variables.entrySet()) {
            writer.writeName(entry.getKey());
            entry.getValue().encode(getMapper(), writer, encoderContext);
        }
        writer.writeEndDocument();
    }
    writeEnum(writer, "whenMatched", value.getWhenMatched(), encoderContext);
    List<Stage> pipeline = value.getWhenMatchedPipeline();
    if(pipeline != null) {
        writer.writeName("whenMatched");
        Codec codec = getCodecRegistry().get(pipeline.getClass());
        encoderContext.encodeWithChildContext(codec, writer, pipeline);
    }
    writeEnum(writer, "whenNotMatched", value.getWhenNotMatched(), encoderContext);
    writer.writeEndDocument();
}