private void addReadConcernDocument(final List<BsonElement> extraElements, final SessionContext sessionContext) { BsonDocument readConcernDocument = getReadConcernDocument(sessionContext); if (!readConcernDocument.isEmpty()) { extraElements.add(new BsonElement("readConcern", readConcernDocument)); } }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } BsonElement that = (BsonElement) o; if (getName() != null ? !getName().equals(that.getName()) : that.getName() != null) { return false; } if (getValue() != null ? !getValue().equals(that.getValue()) : that.getValue() != null) { return false; } return true; }
private List<BsonElement> getExtraElements(final SessionContext sessionContext) { List<BsonElement> extraElements = new ArrayList<BsonElement>(); extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName()))); if (sessionContext.getClusterTime() != null) { extraElements.add(new BsonElement("$clusterTime", sessionContext.getClusterTime())); } if (sessionContext.hasSession() && responseExpected) { extraElements.add(new BsonElement("lsid", sessionContext.getSessionId())); } boolean firstMessageInTransaction = sessionContext.notifyMessageSent(); if (sessionContext.hasActiveTransaction()) { checkServerVersionForTransactionSupport(); extraElements.add(new BsonElement("txnNumber", new BsonInt64(sessionContext.getTransactionNumber()))); if (firstMessageInTransaction) { extraElements.add(new BsonElement("startTransaction", BsonBoolean.TRUE)); addReadConcernDocument(extraElements, sessionContext); } extraElements.add(new BsonElement("autocommit", BsonBoolean.FALSE)); } if (readPreference != null) { if (!readPreference.equals(primary())) { extraElements.add(new BsonElement("$readPreference", readPreference.toDocument())); } else if (isDirectConnectionToNonShardRouter()) { extraElements.add(new BsonElement("$readPreference", primaryPreferred().toDocument())); } } return extraElements; }
@Override public BsonDocument decode(final BsonReader reader, final DecoderContext decoderContext) { List<BsonElement> keyValuePairs = new ArrayList<BsonElement>(); reader.readStartDocument(); while (reader.readBsonType() != BsonType.END_OF_DOCUMENT) { String fieldName = reader.readName(); keyValuePairs.add(new BsonElement(fieldName, readValue(reader, decoderContext))); } reader.readEndDocument(); return new BsonDocument(keyValuePairs); }
public <V> Builder write(Key<? extends V> key, String fieldName, Function<? super V, BsonValue> serialiser) { Function<? extends V, BsonElement> keyValueWriter = (V value) -> new BsonElement(fieldName, serialiser.apply(value)); serialiserMap.put(key, keyValueWriter); return this; }
/** * Pipe a list of extra element to this writer * * @param extraElements the extra elements */ protected void pipeExtraElements(final List<BsonElement> extraElements) { notNull("extraElements", extraElements); for (BsonElement cur : extraElements) { writeName(cur.getName()); pipeValue(cur.getValue()); } }
private void addReadConcernDocument(final List<BsonElement> extraElements, final SessionContext sessionContext) { BsonDocument readConcernDocument = getReadConcernDocument(sessionContext); if (!readConcernDocument.isEmpty()) { extraElements.add(new BsonElement("readConcern", readConcernDocument)); } }
private List<BsonElement> getExtraElements(final SessionContext sessionContext) { List<BsonElement> extraElements = new ArrayList<BsonElement>(); extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName()))); if (sessionContext.getClusterTime() != null) { extraElements.add(new BsonElement("$clusterTime", sessionContext.getClusterTime())); } if (sessionContext.hasSession() && responseExpected) { extraElements.add(new BsonElement("lsid", sessionContext.getSessionId())); } boolean firstMessageInTransaction = sessionContext.notifyMessageSent(); if (sessionContext.hasActiveTransaction()) { checkServerVersionForTransactionSupport(); extraElements.add(new BsonElement("txnNumber", new BsonInt64(sessionContext.getTransactionNumber()))); if (firstMessageInTransaction) { extraElements.add(new BsonElement("startTransaction", BsonBoolean.TRUE)); addReadConcernDocument(extraElements, sessionContext); } extraElements.add(new BsonElement("autocommit", BsonBoolean.FALSE)); } if (readPreference != null) { if (!readPreference.equals(primary())) { extraElements.add(new BsonElement("$readPreference", readPreference.toDocument())); } else if (isDirectConnectionToNonShardRouter()) { extraElements.add(new BsonElement("$readPreference", primaryPreferred().toDocument())); } } return extraElements; }