use of org.bson.Document in project zeppelin by apache.
the class MongoNotebookRepo method save.
@Override
public void save(Note note, AuthenticationInfo subject) throws IOException {
Document doc = noteToDocument(note);
coll.replaceOne(eq("_id", note.getId()), doc, new UpdateOptions().upsert(true));
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class GridFSDownloadStreamImpl method checkAndFetchResults.
private void checkAndFetchResults(final int amountRead, final ByteBuffer dst, final SingleResultCallback<Integer> callback) {
if (currentPosition == fileInfo.getLength() || dst.remaining() == 0) {
callback.onResult(amountRead, null);
} else if (hasResultsToProcess()) {
processResults(amountRead, dst, callback);
} else if (cursor == null) {
chunksCollection.find(new Document("files_id", fileInfo.getId()).append("n", new Document("$gte", chunkIndex))).batchSize(batchSize).sort(new Document("n", 1)).batchCursor(new SingleResultCallback<AsyncBatchCursor<Document>>() {
@Override
public void onResult(final AsyncBatchCursor<Document> result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
cursor = result;
checkAndFetchResults(amountRead, dst, callback);
}
}
});
} else {
cursor.next(new SingleResultCallback<List<Document>>() {
@Override
public void onResult(final List<Document> result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else if (result == null || result.isEmpty()) {
callback.onResult(null, chunkNotFound(chunkIndex));
} else {
resultsQueue.addAll(result);
if (batchSize == 1) {
discardCursor();
}
processResults(amountRead, dst, callback);
}
}
});
}
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class GridFSUploadStreamImpl method writeChunk.
private void writeChunk(final SingleResultCallback<Void> callback) {
if (md5 == null) {
callback.onResult(null, new MongoGridFSException("No MD5 message digest available, cannot upload file"));
} else if (bufferOffset > 0) {
chunksCollection.insertOne(new Document("files_id", fileId).append("n", chunkIndex).append("data", getData()), new SingleResultCallback<Void>() {
@Override
public void onResult(final Void result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
md5.update(buffer);
chunkIndex++;
bufferOffset = 0;
callback.onResult(null, null);
}
}
});
} else {
callback.onResult(null, null);
}
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class Fixture method initializeCollection.
public static MongoCollection<Document> initializeCollection(final MongoNamespace namespace) {
MongoDatabase database = getMongoClient().getDatabase(namespace.getDatabaseName());
try {
FutureResultCallback<Document> futureResultCallback = new FutureResultCallback<Document>();
database.runCommand(new Document("drop", namespace.getCollectionName()), futureResultCallback);
futureResultCallback.get(60, SECONDS);
} catch (MongoCommandException e) {
if (!e.getErrorMessage().startsWith("ns not found")) {
throw e;
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
return database.getCollection(namespace.getCollectionName());
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class Fixture method dropDatabase.
public static void dropDatabase(final String name) {
if (name == null) {
return;
}
try {
FutureResultCallback<Document> futureResultCallback = new FutureResultCallback<Document>();
getMongoClient().getDatabase(name).runCommand(new Document("dropDatabase", 1), futureResultCallback);
futureResultCallback.get(60, SECONDS);
} catch (MongoCommandException e) {
if (!e.getErrorMessage().startsWith("ns not found")) {
throw e;
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
Aggregations