Java Code Examples for org.bson.BsonWriter#writeString()
The following examples show how to use
org.bson.BsonWriter#writeString() .
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: EntityEncoder.java From morphia with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void encodeEntity(final BsonWriter writer, final T value, final EncoderContext encoderContext) { if (areEquivalentTypes(value.getClass(), morphiaCodec.getEntityModel().getType())) { writer.writeStartDocument(); FieldModel<?> idModel = morphiaCodec.getEntityModel().getIdModel(); encodeIdProperty(writer, value, encoderContext, idModel); if (morphiaCodec.getEntityModel().useDiscriminator()) { writer.writeString(morphiaCodec.getEntityModel().getDiscriminatorKey(), morphiaCodec.getEntityModel().getDiscriminator()); } for (FieldModel<?> fieldModel : morphiaCodec.getEntityModel().getFieldModels()) { if (fieldModel.equals(idModel)) { continue; } encodeProperty(writer, value, encoderContext, fieldModel); } writer.writeEndDocument(); } else { morphiaCodec.getRegistry().get((Class<T>) value.getClass()) .encode(writer, value, encoderContext); } }
Example 2
Source File: IamCodec.java From Shadbot with GNU General Public License v3.0 | 5 votes |
@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 3
Source File: Filters.java From morphia with Apache License 2.0 | 5 votes |
/** * Matches documents that satisfy a JavaScript expression. * * @param val the value to check * @return the filter * @query.filter $where */ public static Filter where(final String val) { return new Filter("$where", null, val) { @Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext context) { writer.writeName(getFilterName()); String value = getValue(mapper).toString().trim(); if (!value.startsWith("function()")) { value = format("function() { %s }", value); } writer.writeString(value); } }; }
Example 4
Source File: LookupCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override protected void encodeStage(final BsonWriter writer, final Lookup value, final EncoderContext encoderContext) { writer.writeStartDocument(); if(value.getFrom() != null) { writeNamedValue(writer, "from", value.getFrom(), encoderContext); } else { MongoCollection collection = getMapper().getCollection(value.getFromType()); writer.writeString("from", collection.getNamespace().getCollectionName()); } writer.writeString("localField", value.getLocalField()); writer.writeString("foreignField", value.getForeignField()); writer.writeString("as", value.getAs()); writer.writeEndDocument(); }
Example 5
Source File: URICodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final URI value, final EncoderContext encoderContext) { try { writer.writeString(value.toURL().toExternalForm()); } catch (MalformedURLException e) { throw new BSONException("Could not serialize the URI: " + value); } }
Example 6
Source File: OutCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected void encodeStage(final BsonWriter writer, final Out value, final EncoderContext encoderContext) { if(value.getType() != null) { writer.writeString(getMapper().getCollection(value.getType()).getNamespace().getCollectionName()); } else { writer.writeString(value.getCollection()); } }
Example 7
Source File: GraphLookupCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") protected void encodeStage(final BsonWriter writer, final GraphLookup value, final EncoderContext encoderContext) { writer.writeStartDocument(); if(value.getFrom() != null) { writeNamedValue(writer, "from", value.getFrom(), encoderContext); } else { MongoCollection collection = getMapper().getCollection(value.getFromType()); writer.writeString("from", collection.getNamespace().getCollectionName()); } writeNamedExpression(getMapper(), writer, "startWith", value.getStartWith(), encoderContext); writeNamedValue(writer, "connectFromField", value.getConnectFromField(), encoderContext); writeNamedValue(writer, "connectToField", value.getConnectToField(), encoderContext); writeNamedValue(writer, "as", value.getAs(), encoderContext); writeNamedValue(writer, "maxDepth", value.getMaxDepth(), encoderContext); writeNamedValue(writer, "depthField", value.getDepthField(), encoderContext); Filter[] restriction = value.getRestriction(); if (restriction != null) { writer.writeStartDocument("restrictSearchWithMatch"); for (final Filter filter : restriction) { filter.encode(getMapper(), writer, encoderContext); } writer.writeEndDocument(); } writer.writeEndDocument(); }
Example 8
Source File: LocaleCodec.java From morphia with Apache License 2.0 | 5 votes |
@Override public void encode(final BsonWriter writer, final Locale value, final EncoderContext encoderContext) { if (value == null) { writer.writeNull(); } else { writer.writeString(value.toString()); } }
Example 9
Source File: MergeCodec.java From morphia with Apache License 2.0 | 4 votes |
private void writeEnum(final BsonWriter writer, final String name, final Enum value, final EncoderContext encoderContext) { if (value != null) { writer.writeString(name, value.name().toLowerCase()); } }
Example 10
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 11
Source File: Sort.java From morphia with Apache License 2.0 | 4 votes |
@Override public void encode(final BsonWriter writer) { writer.writeStartDocument(); writer.writeString("$meta", "textScore"); writer.writeEndDocument(); }
Example 12
Source File: MongoDb3LevelCodec.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public void encode(final BsonWriter writer, final Level level, final EncoderContext encoderContext) { writer.writeString(level.name()); }
Example 13
Source File: EnumCodec.java From morphia with Apache License 2.0 | 4 votes |
@Override public void encode(final BsonWriter writer, final T value, final EncoderContext encoderContext) { writer.writeString(value.name()); }
Example 14
Source File: CountCodec.java From morphia with Apache License 2.0 | 4 votes |
@Override protected void encodeStage(final BsonWriter writer, final Count value, final EncoderContext encoderContext) { writer.writeString(value.getName()); }
Example 15
Source File: MetaExpression.java From morphia with Apache License 2.0 | 4 votes |
@Override public void encode(final Mapper mapper, final BsonWriter writer, final EncoderContext encoderContext) { writer.writeStartDocument(); writer.writeString(getOperation(), "textScore"); writer.writeEndDocument(); }
Example 16
Source File: BigDecimalCodec.java From mongo-mapper with Apache License 2.0 | 4 votes |
@Override public void encode(BsonWriter bsonWriter, BigDecimal bigDecimal, EncoderContext encoderContext) { bsonWriter.writeString(bigDecimal.toPlainString()); }
Example 17
Source File: MongoDb4LevelCodec.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public void encode(final BsonWriter writer, final Level level, final EncoderContext encoderContext) { writer.writeString(level.name()); }
Example 18
Source File: CustomLongCodec.java From mongolastic with MIT License | 4 votes |
@Override public void encode(final BsonWriter writer, final Long value, final EncoderContext encoderContext) { writer.writeString(value.toString()); }
Example 19
Source File: PersistenceModule.java From EDDI with Apache License 2.0 | 4 votes |
@Override public void encode(BsonWriter writer, URI value, EncoderContext encoderContext) { writer.writeString(value.toString()); }
Example 20
Source File: SnowflakeCodec.java From Shadbot with GNU General Public License v3.0 | 4 votes |
@Override public void encode(BsonWriter writer, Snowflake value, EncoderContext encoderContext) { writer.writeString(value.asString()); }