public default Optional<BsonValue> getOptional(String key) { return Optional.ofNullable(get(key)); }
@Override public UnmodifiableIterator<DocEntry<?>> iterator() { return Iterators.unmodifiableIterator( Iterators.transform(wrapped.iterator(), ENTRY_TRANSLATE_FUNCTION)); }
public static boolean containsField(BsonDocument doc, BsonField<?, ?> field) { return doc.containsKey(field.getFieldName()); }
@Override public LibraryEntry find(BsonDocument requestDocument) { if (requestDocument.isEmpty()) { return null; } String commandAlias = requestDocument.getFirstEntry().getKey(); String key = commandAlias.toLowerCase(Locale.ENGLISH); Command<?, ?> command = commandMap.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; }
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);
@Override @SuppressFBWarnings("BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS") public boolean equals(Object obj) { if (!generalEquals(obj)) { return false; } UpdateOplogOperation other = (UpdateOplogOperation) obj; return other.getFilter().equals(this.getFilter()) && other.getModification().equals(this.getModification()); }
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 void writeInto(ByteBuf byteBuf, BsonDocument doc) { doc.accept(VISITOR, byteBuf); }
public default Optional<Entry<?>> getOptionalEntry(String key) { return Optional.ofNullable(getEntry(key)); }
@Override @SuppressFBWarnings("BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS") public boolean equals(Object obj) { if (!generalEquals(obj)) { return false; } DeleteOplogOperation other = (DeleteOplogOperation) obj; return other.isJustOne() == this.isJustOne() && other.filter.equals(this.filter); }
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 Void visit(BsonJavaScriptWithScope value, ByteBuf arg) { final int codeWsStart = arg.writerIndex(); arg.writeInt(0); // reserve space for code_w_s size writeString(arg, value.getJavaScript()); value.getScope().accept(VISITOR, arg); final int codeWsEnds = arg.writerIndex(); arg.writerIndex(codeWsStart).writeInt(codeWsEnds - codeWsStart).writerIndex(codeWsEnds); return null; }
@Nullable public static BsonNumber<?> getNumeric(BsonDocument doc, String fieldId, BsonNumber defaultValue) throws TypesMismatchException { Entry<?> entry = doc.getEntry(fieldId); if (entry == null) { return defaultValue; } return getNumeric(entry, fieldId); }
@Nonnull public static BsonValue getValue(BsonDocument doc, String fieldId) throws NoSuchKeyException { BsonValue object = doc.get(fieldId); if (object == null) { throw new NoSuchKeyException(fieldId); } return object; }