private static Document documentOf(String key, Object value) { return new Document(key, value); }
@Override protected void doReadStartDocument() { BsonDocument document; if (currentValue.getBsonType() == BsonType.JAVASCRIPT_WITH_SCOPE) { document = currentValue.asJavaScriptWithScope().getScope(); } else { document = currentValue.asDocument(); } setContext(new Context(getContext(), BsonContextType.DOCUMENT, document)); }
private BsonDocument asCommandResponseDocument() { BsonArray cursorIdArray = new BsonArray(); for (long cursorId : cursors) { cursorIdArray.add(new BsonInt64(cursorId)); } return new BsonDocument("ok", new BsonDouble(1)) .append("cursorsUnknown", cursorIdArray); }
private List<Document> getColumnMetadata(Document doc) { if (!doc.containsKey(FIELDS_KEY)) { return ImmutableList.of(); } return (List<Document>) doc.get(FIELDS_KEY); }
private static Document isNullPredicate() { return documentOf(EXISTS_OP, true).append(EQ_OP, null); }
@Override public BSONObject readObject(final byte[] bytes) { BSONCallback bsonCallback = new BasicBSONCallback(); decode(bytes, bsonCallback); return (BSONObject) bsonCallback.get(); }
@Override public BSONObject readObject(final InputStream in) throws IOException { BSONCallback bsonCallback = new LazyBSONCallback(); decode(in, bsonCallback); return (BSONObject) bsonCallback.get(); }
@Override protected void doReadStartArray() { BsonArray array = currentValue.asArray(); setContext(new Context(getContext(), BsonContextType.ARRAY, array)); }
@Override public void doWriteStartDocument() { BsonContextType contextType = getState() == State.SCOPE_DOCUMENT ? BsonContextType.SCOPE_DOCUMENT : BsonContextType.DOCUMENT; if (getContext() == null || contextType == BsonContextType.SCOPE_DOCUMENT) { bsonCallback.objectStart(); } else { bsonCallback.objectStart(getName()); } setContext(new Context(getContext(), contextType)); }
@Override public void doWriteStartArray() { bsonCallback.arrayStart(getName()); setContext(new Context(getContext(), BsonContextType.ARRAY)); }
@Override protected void doWriteEndArray() { setContext(getContext().getParentContext()); bsonCallback.arrayDone(); }
/** * Construct a new instance. * * @param document the document to write to */ public BsonDocumentWriter(final BsonDocument document) { super(new BsonWriterSettings()); this.document = document; setContext(new Context()); }
public void reset() { super.reset(); BsonDocumentReader.this.currentValue = currentValue; BsonDocumentReader.this.setContext(context); context.reset(); } }