public BsonDocument toBson() { return new BsonDocumentBuilder(2) .append(TIMESTAMP_FIELD, timestamp) .append(TERM_FIELD, term) .build(); }
public BsonDocumentBuilder append(DocField field, BsonDocumentBuilder value) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), value.build()); return this; }
public BsonDocumentBuilder appendNumber(NumberField<?> field, Number value) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), toBsonNumber(value)); return this; }
public BsonDocumentBuilder toDescriptiveBson() { BsonDocumentBuilder result = new BsonDocumentBuilder() .append(OPTIME_FIELD, optime) .append(HASH_FIELD, hash) .append(VERSION_FIELD, version.getNumericValue()); if (fromMigrate) { result.append(FROM_MIGRATE_FIELD, true); } return result; }
@Override public BsonDocument marshall() { BsonDocumentBuilder builder = new BsonDocumentBuilder(); marshall(builder); return builder.build(); }
@Override public BsonDocument getBson() { if (bson == null) { try { bson = command.marshallResult(commandReply.get()); } catch (MarshalException ex) { LOGGER.debug("Impossible to marshall a reply for " + command.getCommandName() + " command", ex); bson = new BsonDocumentBuilder(2) .appendUnsafe("errorOn", DefaultBsonValues.newString("marshallable respose")) .appendUnsafe("command", DefaultBsonValues.newString(command.getCommandName())) .build(); } } return bson; }
public BsonDocumentBuilder append(ArrayField field, BsonArray value) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), value); return this; }
private void marshall(BsonDocumentBuilder builder) { builder.append(LAST_OP_FIELD, precedingOpTime); } }
protected void marshall(BsonDocumentBuilder builder) { if (errorDesc == null) { assert error.equals(ErrorCode.OK); builder.appendNull(ERR_FIELD_NAME); } else { builder.append(ERR_FIELD_NAME, errorDesc); builder.append(CODE_FIELD_NAME, error.getErrorCode()); } builder.append(N_FIELD_NAME, getN()); if (replInfo != null) { replInfo.marshall(builder); } if (shardInfo != null) { shardInfo.marshall(builder); } }
@Override public String toString() { BsonDocumentBuilder bson = toDescriptiveBson(); return bson.build().toString(); } }
public void appendAsOldBson(BsonDocumentBuilder builder, String fieldId) { builder.appendUnsafe(fieldId, toOldBson()); }
public <T> BsonDocumentBuilder append(BsonField<T, BsonValue<T>> field, T value, Function<T, BsonValue<T>> translator) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), translator.apply(value)); return this; }
@Override public BsonDocument marshall() { BsonDocumentBuilder builder = new BsonDocumentBuilder(); marshall(builder); builder.append(UPDATE_EXISTING_FIELD_NAME, modified != 0); if (upsertedId != null) { builder.append(UPSERTED_FIELD_NAME, upsertedId); } return builder.build(); }
public BsonDocumentBuilder append(DocField field, BsonDocument value) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), value); return this; }
@Material public BsonDocument toDocument() { BsonDocumentBuilder builder = new BsonDocumentBuilder(3); if (getWType().equals(WType.TEXT)) { builder.append(W_TEXT_FIELD, getWString()); } else { builder.append(W_INT_FIELD, getWInt()); } switch (getSyncMode()) { case FSYNC: builder.append(FSYNC_FIELD, true); break; case JOURNAL: builder.append(JOURNAL_FIELD, true); break; default: } builder.append(TIMEOUT_FIELD, getTimeout()); return builder.build(); }
public BsonDocumentBuilder append(ObjectIdField field, BsonObjectId value) { Preconditions.checkState(!built); if (value == null) { return appendNull(field); } map.put(field.getFieldName(), value); return this; }
} else { if (!bson.containsKey(OK_FIELD.getFieldName())) { bson = new BsonDocumentBuilder(bson) .append(OK_FIELD, MongoConstants.OK) .build(); bson = new BsonDocumentBuilder() .append(ERR_CODE, reply.getErrorCode().getErrorCode()) .append(ERR_MSG_FIELD, reply.getErrorMsg()) .append(OK_FIELD, MongoConstants.KO) .build();