use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class CommandMonitoringTestHelper method massageActualCommandSucceededEvent.
private static CommandSucceededEvent massageActualCommandSucceededEvent(final CommandSucceededEvent actual) {
BsonDocument response = getWritableCloneOfCommand(actual.getResponse());
// massage numbers that are the wrong BSON type
response.put("ok", new BsonDouble(response.getNumber("ok").doubleValue()));
if (response.containsKey("n")) {
response.put("n", new BsonInt32(response.getNumber("n").intValue()));
}
if (actual.getCommandName().equals("find") || actual.getCommandName().equals("getMore")) {
if (response.containsKey("cursor")) {
if (response.getDocument("cursor").containsKey("id") && !response.getDocument("cursor").getInt64("id").equals(new BsonInt64(0))) {
response.getDocument("cursor").put("id", new BsonInt64(42));
}
}
} else if (actual.getCommandName().equals("killCursors")) {
response.getArray("cursorsUnknown").set(0, new BsonInt64(42));
} else if (isWriteCommand(actual.getCommandName())) {
if (response.containsKey("writeErrors")) {
for (BsonValue bsonValue : response.getArray("writeErrors")) {
BsonDocument cur = bsonValue.asDocument();
BsonDocument newWriteErrorDocument = new BsonDocument().append("index", cur.get("index")).append("code", new BsonInt32(42)).append("errmsg", new BsonString(""));
cur.clear();
cur.putAll(newWriteErrorDocument);
}
}
if (actual.getCommandName().equals("update")) {
response.remove("nModified");
}
}
return new CommandSucceededEvent(actual.getRequestId(), actual.getConnectionDescription(), actual.getCommandName(), response, actual.getElapsedTime(TimeUnit.NANOSECONDS));
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class OperationHelper method cursorDocumentToQueryResult.
private static <T> QueryResult<T> cursorDocumentToQueryResult(final BsonDocument cursorDocument, final ServerAddress serverAddress, final String fieldNameContainingBatch) {
long cursorId = ((BsonInt64) cursorDocument.get("id")).getValue();
MongoNamespace queryResultNamespace = new MongoNamespace(cursorDocument.getString("ns").getValue());
return new QueryResult<T>(queryResultNamespace, BsonDocumentWrapperHelper.<T>toList(cursorDocument, fieldNameContainingBatch), cursorId, serverAddress);
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method executeEstimatedDocumentCount.
public OperationResult executeEstimatedDocumentCount(final BsonDocument operation) {
MongoCollection<BsonDocument> collection = entities.getCollection(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments", new BsonDocument());
EstimatedDocumentCountOptions options = new EstimatedDocumentCountOptions();
for (Map.Entry<String, BsonValue> cur : arguments.entrySet()) {
// noinspection SwitchStatementWithTooFewBranches
switch(cur.getKey()) {
case "maxTimeMS":
options.maxTime(cur.getValue().asNumber().intValue(), TimeUnit.MILLISECONDS);
break;
default:
throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey());
}
}
return resultOf(() -> new BsonInt64(collection.estimatedDocumentCount(options)));
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class GetMoreProtocol method asGetMoreCommandResponseDocument.
private BsonDocument asGetMoreCommandResponseDocument(final QueryResult<T> queryResult, final ResponseBuffers responseBuffers) {
List<ByteBufBsonDocument> rawResultDocuments = Collections.emptyList();
if (responseBuffers.getReplyHeader().getNumberReturned() != 0) {
responseBuffers.reset();
rawResultDocuments = ByteBufBsonDocument.createList(responseBuffers);
}
BsonDocument cursorDocument = new BsonDocument("id", queryResult.getCursor() == null ? new BsonInt64(0) : new BsonInt64(queryResult.getCursor().getId())).append("ns", new BsonString(namespace.getFullName())).append("nextBatch", new BsonArray(rawResultDocuments));
return new BsonDocument("cursor", cursorDocument).append("ok", new BsonDouble(1));
}
use of org.bson.BsonInt64 in project mongo-java-driver by mongodb.
the class IdHoldingBsonWriter method writeInt64.
@Override
public void writeInt64(final String name, final long value) {
setCurrentFieldName(name);
addBsonValue(() -> new BsonInt64(value), () -> getIdBsonWriter().writeInt64(name, value));
super.writeInt64(name, value);
}
Aggregations