public default Optional<BsonValue> getOptional(String key) { return Optional.ofNullable(get(key)); }
public static boolean containsField(BsonDocument doc, BsonField<?, ?> field) { return doc.containsKey(field.getFieldName()); }
@Override public UnmodifiableIterator<DocEntry<?>> iterator() { return Iterators.unmodifiableIterator( Iterators.transform(wrapped.iterator(), ENTRY_TRANSLATE_FUNCTION) ); }
@Override public LibraryEntry find(BsonDocument requestDocument) { if (requestDocument.isEmpty()) { return null; } String commandAlias = requestDocument.getFirstEntry().getKey(); String key = commandAlias.toLowerCase(Locale.ENGLISH); Command<?, ?> command = commandsMap.get(key); if (command == null) { return null; } return new PojoLibraryEntry(commandAlias, command); }
@Nullable public static Entry<?> getEntry(BsonDocument doc, String fieldId, Entry<?> defaultValue) { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return entry; }
Command command = libraryEntry.getCommand(); if (command == null) { if (document.isEmpty()) { throw new CommandNotFoundException("Empty document query"); String firstKey = document.iterator().next().getKey(); throw new CommandNotFoundException(firstKey); bson = DefaultBsonValues.EMPTY_DOC; } else { if (!bson.containsKey(OK_FIELD.getFieldName())) { bson = new BsonDocumentBuilder(bson) .append(OK_FIELD, MongoConstants.OK)
@Override public int compareTo(BsonValue<?> obj) { if (obj == this) { return 0; } int diff = BsonTypeComparator.INSTANCE.compare(getType(), obj.getType()); if (diff != 0) { return 0; } assert obj.isDocument(); BsonDocument other = obj.asDocument(); // TODO: Check how MongoDB compares documents! diff = this.size() - other.size(); if (diff != 0) { return diff; } Iterator<Entry<?>> myIt = this.iterator(); Iterator<Entry<?>> otherIt = other.iterator(); while (myIt.hasNext() && otherIt.hasNext()) { diff = myIt.next().getValue().compareTo(otherIt.next().getValue()); if (diff != 0) { return diff; } } assert !myIt.hasNext() : "the other document has more entries than ourself!"; assert !otherIt.hasNext() : "the other document has less entries than ourself!"; return 0; }
public static WriteConcern fromDocument(@Nonnull BsonDocument doc) throws FailedToParseException { if (doc.isEmpty()) { throw new FailedToParseException("write concern object cannot be empty"); timeout = 0; } catch (TypesMismatchException ex) { LOGGER.warn("Unexpected write concern timeout '{}'. Using the default value", doc.get( "timeout")); timeout = 0; BsonValue<?> wValue = doc.get("w"); if (wValue == null) { return new IntWriteConcern(syncMode, timeout, 1);
public BsonDocumentBuilder(BsonDocument doc) { this.map = new LinkedHashMap<>(doc.size()); for (Entry<?> entry : doc) { map.put(entry.getKey(), entry.getValue()); } built = false; }
@Override public DocEntry<?> getFirstEntry() throws NoSuchElementException { return ENTRY_TRANSLATE_FUNCTION.apply(wrapped.getFirstEntry()); }
public static WriteConcern fromDocument(@Nullable BsonDocument doc, WriteConcern defaultValue) { if (doc == null || doc.isEmpty()) { return defaultValue; } try { return fromDocument(doc); } catch (FailedToParseException ex) { return defaultValue; } }
public default Optional<Entry<?>> getOptionalEntry(String key) { return Optional.ofNullable(getEntry(key)); }
public static KVDocument toEagerDocument(BsonDocument doc) { LinkedHashMap<String, KVValue<?>> map = new LinkedHashMap<>(doc.size()); for (Entry<?> entry : doc) { map.put(entry.getKey(), MongoWPConverter.translate(entry.getValue())); } return new MapKVDocument(map); }
@Nonnull public A unmarshallArg(@Nonnull BsonDocument requestDoc, String aliasedAs) throws MongoException;
@Override public KVValue<?> get(String key) { BsonValue<?> bsonValue = wrapped.get(key); return MongoWPConverter.translate(bsonValue); }
@Nullable public static Instant getInstant(BsonDocument doc, String fieldId, Instant defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getInstant(entry, fieldId); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof BsonDocument)) { return false; } return Iterators.elementsEqual(this.iterator(), ((BsonDocument) obj) .iterator()); }
BsonDocument doc = docReader.readDocument(OFFHEAP_VALUES, docByteBuf); if (doc.containsKey("$query")) {
public Optional<String> getCommandName() { return Optional.ofNullable(getRequest().getFirstEntry().getKey()); }
@Override public BsonValue<?> getDocId() { return getDocToInsert().get("_id"); }