Java Code Examples for org.bson.BsonWriter#writeName()
The following examples show how to use
org.bson.BsonWriter#writeName() .
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: NearFilter.java From morphia with Apache License 2.0 | 6 votes |
@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 2
Source File: DateFromParts.java From morphia with Apache License 2.0 | 6 votes |
@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: EntityEncoder.java From morphia with Apache License 2.0 | 6 votes |
private <S> void encodeValue(final BsonWriter writer, final EncoderContext encoderContext, final FieldModel<S> model, final S propertyValue) { if (model.shouldSerialize(propertyValue)) { writer.writeName(model.getMappedName()); if (propertyValue == null) { writer.writeNull(); } else { try { encoderContext.encodeWithChildContext(model.getCachedCodec(), writer, propertyValue); } catch (CodecConfigurationException e) { throw new CodecConfigurationException(String.format("Failed to encode '%s'. Encoding '%s' errored with: %s", morphiaCodec.getEntityModel().getName(), model.getMappedName(), e.getMessage()), e); } } } }
Example 4
Source File: LiteralExpression.java From morphia with Apache License 2.0 | 5 votes |
@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 5
Source File: ExpressionCodec.java From morphia with Apache License 2.0 | 5 votes |
/** * @param mapper * @param writer * @param name * @param value * @param encoderContext * @morphia.internal */ public static void writeNamedValue(final Mapper mapper, final BsonWriter writer, final String name, final Object value, final EncoderContext encoderContext) { if (value != null) { writer.writeName(name); Codec codec = mapper.getCodecRegistry().get(value.getClass()); encoderContext.encodeWithChildContext(codec, writer, value); } }
Example 6
Source File: ReplaceRootCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override protected void encodeStage(final BsonWriter writer, final ReplaceRoot replace, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName("newRoot"); if(replace.getValue() != null) { replace.getValue().encode(getMapper(), writer, encoderContext); } else { replace.getDocument().encode(getMapper(), writer, encoderContext); } writer.writeEndDocument(); }
Example 7
Source File: StageCodec.java From morphia with Apache License 2.0 | 5 votes |
protected void writeNamedValue(final BsonWriter writer, final String name, final Object value, final EncoderContext encoderContext) { if (value != null) { writer.writeName(name); Codec codec = getCodecRegistry().get(value.getClass()); encoderContext.encodeWithChildContext(codec, writer, value); } }
Example 8
Source File: StageCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public final void encode(final BsonWriter writer, final T value, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName(value.getStageName()); encodeStage(writer, value, encoderContext); writer.writeEndDocument(); }
Example 9
Source File: GeoIntersectsFilter.java From morphia with Apache License 2.0 | 5 votes |
@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); writer.writeEndDocument(); if (isNot()) { writer.writeEndDocument(); } writer.writeEndDocument(); }
Example 10
Source File: IsoDates.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName(getOperation()); writer.writeStartDocument(); ExpressionCodec.writeNamedExpression(mapper, writer, "date", date, encoderContext); ExpressionCodec.writeNamedExpression(mapper, writer, "timezone", timezone, encoderContext); writer.writeEndDocument(); writer.writeEndDocument(); }
Example 11
Source File: Filters.java From morphia with Apache License 2.0 | 5 votes |
/** * 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: Filters.java From morphia with Apache License 2.0 | 5 votes |
/** * Allows use of aggregation expressions within the query language. * * @param expression the expression to evaluate * @return the filter * @query.filter $expr */ public static Filter expr(final Expression expression) { return new Filter("$expr", null, expression) { @Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) { writer.writeName("$expr"); getValue().encode(mapper, writer, context); } @Override protected Expression getValue() { return (Expression) super.getValue(); } }; }
Example 13
Source File: Filters.java From morphia with Apache License 2.0 | 5 votes |
/** * Matches documents that have the specified field. * * @param field the field to check * @return the filter * @query.filter $exists */ public static Filter exists(final String field) { return new Filter("$exists", field, null) { @Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) { writer.writeStartDocument(field(mapper)); writer.writeName(getFilterName()); writer.writeBoolean(!isNot()); writer.writeEndDocument(); } }; }
Example 14
Source File: Filters.java From morphia with Apache License 2.0 | 5 votes |
/** * Specifies equality condition. The $eq operator matches documents where the value of a field equals the specified value. * * @param field the field to check * @param val the value to check * @return the filter * @query.filter $eq */ public static Filter eq(final String field, final Object val) { return new Filter("$eq", field, val) { @Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) { writer.writeName(field(mapper)); writeUnnamedValue(getValue(mapper), mapper, writer, context); } }; }
Example 15
Source File: DateToParts.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName(getOperation()); writer.writeStartDocument(); ExpressionCodec.writeNamedExpression(mapper, writer, "date", date, encoderContext); ExpressionCodec.writeNamedExpression(mapper, writer, "timezone", timeZone, encoderContext); ExpressionCodec.writeNamedValue(mapper, writer, "iso8601", iso8601, encoderContext); writer.writeEndDocument(); writer.writeEndDocument(); }
Example 16
Source File: Filter.java From morphia with Apache License 2.0 | 5 votes |
/** * @param mapper the mapper * @param writer the writer * @param context the context * @morphia.internal */ public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) { writer.writeStartDocument(field(mapper)); if (not) { writer.writeStartDocument("$not"); } writer.writeName(filterName); writeUnnamedValue(getValue(mapper), mapper, writer, context); if (not) { writer.writeEndDocument(); } writer.writeEndDocument(); }
Example 17
Source File: LetExpression.java From morphia with Apache License 2.0 | 5 votes |
@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 18
Source File: Push.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeName(getOperation()); if (field != null) { field.encode(mapper, writer, encoderContext); } else if(document != null) { document.encode(mapper, writer, encoderContext); } writer.writeEndDocument(); }
Example 19
Source File: MergeCodec.java From morphia with Apache License 2.0 | 4 votes |
@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(); }
Example 20
Source File: ProjectionCodec.java From morphia with Apache License 2.0 | 4 votes |
private void write(final BsonWriter writer, final PipelineField field, final EncoderContext encoderContext) { writer.writeName(field.getName()); Class aClass = field.getValue().getClass(); Codec codec = getCodecRegistry().get(aClass); encoderContext.encodeWithChildContext(codec, writer, field.getValue()); }