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

The following examples show how to use org.bson.BsonWriter#writeEndDocument() . 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: GroupCodec.java    From morphia with Apache License 2.0 6 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Group group, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    GroupId id = group.getId();
    if (id != null) {
        writer.writeName("_id");
        if(id.getDocument() != null) {
            id.getDocument().encode(getMapper(), writer, encoderContext);
        } else {
            id.getField().encode(getMapper(), writer, encoderContext);
        }
    } else {
        writer.writeNull("_id");
    }

    Fields<Group> fields = group.getFields();
    if(fields != null) {
        fields.encode(getMapper(), writer, encoderContext);
    }

    writer.writeEndDocument();
}
 
Example 2
Source File: DateFromParts.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());
    writer.writeStartDocument();

    ExpressionCodec.writeNamedExpression(mapper, writer, "year", year, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "month", month, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "day", day, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "hour", hour, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "minute", minute, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "second", second, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "millisecond", millisecond, encoderContext);

    ExpressionCodec.writeNamedExpression(mapper, writer, "isoWeekYear", isoWeekYear, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "isoWeek", isoWeek, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "isoDayOfWeek", isoDayOfWeek, encoderContext);

    ExpressionCodec.writeNamedExpression(mapper, writer, "timezone", timezone, encoderContext);

    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 3
Source File: NearFilter.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));
    if (isNot()) {
        writer.writeStartDocument("$not");
    }
    writer.writeStartDocument(getFilterName());
    writer.writeName("$geometry");
    writeUnnamedValue(getValue(mapper), mapper, writer, context);
    if (maxDistance != null) {
        writeNamedValue("$maxDistance", maxDistance, mapper, writer, context);
    }
    if (minDistance != null) {
        writeNamedValue("$minDistance", minDistance, mapper, writer, context);
    }
    if (crs != null) {
        writeNamedValue("crs", crs, mapper, writer, context);
    }
    writer.writeEndDocument();
    if (isNot()) {
        writer.writeEndDocument();
    }
    writer.writeEndDocument();
}
 
Example 4
Source File: DateFromString.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.writeStartDocument(getOperation());

    ExpressionCodec.writeNamedExpression(mapper, writer, "dateString", dateString, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "format", format, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "timezone", timeZone, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "onError", onError, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "onNull", onNull, encoderContext);

    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 5
Source File: IamCodec.java    From Shadbot with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void encode(BsonWriter writer, IamBean value, EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeString("message_id", value.getMessageId());
    writer.writeString("role_id", value.getRoleId());
    writer.writeEndDocument();
}
 
Example 6
Source File: MapExpression.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.writeStartDocument(getOperation());
    ExpressionCodec.writeNamedExpression(mapper, writer, "input", input, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "in", in, encoderContext);
    ExpressionCodec.writeNamedValue(mapper, writer, "as", as, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 7
Source File: GeoWithinFilter.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public final void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) {
    writer.writeStartDocument(field(mapper));
    writer.writeStartDocument(getFilterName());
    writer.writeName("$geometry");

    Object shape = getValue();
    Codec codec = mapper.getCodecRegistry().get(shape.getClass());
    codec.encode(writer, shape, context);

    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 8
Source File: ConvertExpression.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.writeStartDocument(getOperation());
    ExpressionCodec.writeNamedExpression(mapper, writer, "input", input, encoderContext);
    ExpressionCodec.writeNamedValue(mapper, writer, "to", to.getName(), encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "onError", onError, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "onNull", onNull, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 9
Source File: ReduceExpression.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.writeStartDocument(getOperation());
    ExpressionCodec.writeNamedExpression(mapper, writer, "input", input, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "initialValue", initial, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "in", in, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 10
Source File: LetExpression.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.writeStartDocument(getOperation());
    writer.writeName("vars");
    variables.encode(mapper, writer, encoderContext);
    ExpressionCodec.writeNamedExpression(mapper, writer, "in", in, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 11
Source File: FacetCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Facet value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    for (final Entry<String, List<Stage>> entry : value.getFields().entrySet()) {
      writeNamedValue(writer, entry.getKey(), entry.getValue(), encoderContext);
    }
    writer.writeEndDocument();
}
 
Example 12
Source File: UnwindCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Unwind value, final EncoderContext encoderContext) {
    if(!value.optionsPresent()) {
        value.getPath().encode(getMapper(), writer, encoderContext);
    } else {
        writer.writeStartDocument();
        writeNamedExpression(getMapper(), writer, "path", value.getPath(), encoderContext);
        writeNamedValue(writer, "includeArrayIndex", value.getIncludeArrayIndex(), encoderContext);
        writeNamedValue(writer, "preserveNullAndEmptyArrays", value.getPreserveNullAndEmptyArrays(), encoderContext);
        writer.writeEndDocument();
    }
}
 
Example 13
Source File: MorphiaMapPropertyCodecProvider.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
public void encode(final BsonWriter writer, final Map<K, V> map, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    for (final Entry<K, V> entry : map.entrySet()) {
        final K key = entry.getKey();
        writer.writeName((String) Conversions.convert(key, String.class));
        if (entry.getValue() == null) {
            writer.writeNull();
        } else {
            codec.encode(writer, entry.getValue(), encoderContext);
        }
    }
    writer.writeEndDocument();
}
 
Example 14
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 15
Source File: TrimExpression.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.writeStartDocument(getOperation());
    writeNamedExpression(mapper, writer, "input", input, encoderContext);
    writeNamedExpression(mapper, writer, "chars", chars, encoderContext);
    writer.writeEndDocument();
    writer.writeEndDocument();
}
 
Example 16
Source File: BucketCodec.java    From morphia with Apache License 2.0 5 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Bucket value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writeNamedExpression(getMapper(), writer, "groupBy", value.getGroupBy(), encoderContext);
    writeNamedValue(writer, "boundaries", value.getBoundaries(), encoderContext);
    writeNamedValue(writer, "default", value.getDefaultValue(), encoderContext);
    DocumentExpression output = value.getOutput();
    if (output != null) {
        output.encode("output", getMapper(), writer, encoderContext);
    }
    writer.writeEndDocument();
}
 
Example 17
Source File: LiteralExpression.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());
    Codec codec = mapper.getCodecRegistry().get(getValue().getClass());
    encoderContext.encodeWithChildContext(codec, writer, getValue());
    writer.writeEndDocument();
}
 
Example 18
Source File: MetaExpression.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeString(getOperation(), "textScore");
    writer.writeEndDocument();
}
 
Example 19
Source File: DocumentExpression.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Override
public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    fields.encode(mapper, writer, encoderContext);
    writer.writeEndDocument();
}
 
Example 20
Source File: SampleCodec.java    From morphia with Apache License 2.0 4 votes vote down vote up
@Override
protected void encodeStage(final BsonWriter writer, final Sample value, final EncoderContext encoderContext) {
    writer.writeStartDocument();
    writer.writeInt64("size", value.getSize());
    writer.writeEndDocument();
}