use of org.bson.BsonObjectId in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method uploadFromStream.
@Override
public void uploadFromStream(final String filename, final AsyncInputStream source, final GridFSUploadOptions options, final SingleResultCallback<ObjectId> callback) {
final BsonObjectId id = new BsonObjectId();
uploadFromStream(id, filename, source, options, new SingleResultCallback<Void>() {
@Override
public void onResult(final Void result, final Throwable t) {
if (t != null) {
callback.onResult(null, t);
} else {
callback.onResult(id.getValue(), null);
}
}
});
}
use of org.bson.BsonObjectId in project mongo-java-driver by mongodb.
the class GridFSTest method doDelete.
private void doDelete(final BsonDocument arguments, final BsonDocument assertion) {
Throwable error = null;
try {
gridFSBucket.delete(arguments.getObjectId("id").getValue());
} catch (MongoGridFSException e) {
error = e;
}
if (assertion.containsKey("error")) {
assertNotNull("Should have thrown an exception", error);
} else {
assertNull("Should not have thrown an exception", error);
for (BsonValue rawDataItem : assertion.getArray("data")) {
BsonDocument dataItem = rawDataItem.asDocument();
for (BsonValue deletedItem : dataItem.getArray("deletes", new BsonArray())) {
String delete = dataItem.getString("delete", new BsonString("none")).getValue();
BsonObjectId id = new BsonObjectId(new ObjectId());
if (delete.equals("expected.files")) {
id = deletedItem.asDocument().getDocument("q").getObjectId("_id");
} else if (delete.equals("expected.chunks")) {
id = deletedItem.asDocument().getDocument("q").getObjectId("files_id");
}
assertEquals(filesCollection.count(new BsonDocument("_id", id)), 0);
assertEquals(chunksCollection.count(new BsonDocument("files_id", id)), 0);
}
}
}
}
use of org.bson.BsonObjectId in project core-ng-project by neowu.
the class EntityCodecTest method getDocumentId.
@Test
void getDocumentId() {
TestEntity entity = new TestEntity();
entity.id = new ObjectId();
assertEquals(new BsonObjectId(entity.id), entityCodec.getDocumentId(entity));
}
use of org.bson.BsonObjectId in project drill by axbaretto.
the class TestBsonRecordReader method testObjectIdType.
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
use of org.bson.BsonObjectId in project drill by apache.
the class TestBsonRecordReader method testObjectIdType.
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertArrayEquals(value.getValue().toByteArray(), readByteArray);
}
Aggregations