com.noenv.wiremongo.WireMongoClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-wiremongo Show documentation
Show all versions of vertx-wiremongo Show documentation
Lightweight mongo mocking for Vert.x
package com.noenv.wiremongo;
import com.mongodb.client.model.changestream.ChangeStreamDocument;
import com.noenv.wiremongo.command.Command;
import com.noenv.wiremongo.command.CountCommand;
import com.noenv.wiremongo.command.CountWithOptionsCommand;
import com.noenv.wiremongo.command.RunCommandCommand;
import com.noenv.wiremongo.command.aggregate.AggregateBaseCommand;
import com.noenv.wiremongo.command.aggregate.AggregateWithOptionsCommand;
import com.noenv.wiremongo.command.bulkwrite.BulkWriteBaseCommand;
import com.noenv.wiremongo.command.bulkwrite.BulkWriteWithOptionsCommand;
import com.noenv.wiremongo.command.collection.CreateCollectionCommand;
import com.noenv.wiremongo.command.collection.CreateCollectionWithOptionsCommand;
import com.noenv.wiremongo.command.collection.DropCollectionCommand;
import com.noenv.wiremongo.command.collection.GetCollectionsCommand;
import com.noenv.wiremongo.command.distinct.DistinctBatchBaseCommand;
import com.noenv.wiremongo.command.distinct.DistinctBatchWithQueryCommand;
import com.noenv.wiremongo.command.distinct.DistinctCommand;
import com.noenv.wiremongo.command.distinct.DistinctWithQueryCommand;
import com.noenv.wiremongo.command.find.*;
import com.noenv.wiremongo.command.index.*;
import com.noenv.wiremongo.command.insert.InsertBaseCommand;
import com.noenv.wiremongo.command.insert.InsertWithOptionsCommand;
import com.noenv.wiremongo.command.remove.RemoveDocumentBaseCommand;
import com.noenv.wiremongo.command.remove.RemoveDocumentWithOptionsCommand;
import com.noenv.wiremongo.command.remove.RemoveDocumentsBaseCommand;
import com.noenv.wiremongo.command.remove.RemoveDocumentsWithOptionsCommand;
import com.noenv.wiremongo.command.replace.ReplaceDocumentsBaseCommand;
import com.noenv.wiremongo.command.replace.ReplaceDocumentsWithOptionsCommand;
import com.noenv.wiremongo.command.save.SaveBaseCommand;
import com.noenv.wiremongo.command.save.SaveWithOptionsCommand;
import com.noenv.wiremongo.command.update.UpdateCollectionBaseCommand;
import com.noenv.wiremongo.command.update.UpdateCollectionWithOptionsCommand;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.core.streams.ReadStream;
import io.vertx.ext.mongo.*;
import java.util.List;
public class WireMongoClient implements MongoClient {
public static final String NOT_IMPLEMENTED = "not implemented";
private static WireMongoClient instance;
private WireMongo wireMongo;
private WireMongoClient() {
}
public WireMongo getWireMongo() {
return wireMongo;
}
WireMongoClient setWireMongo(WireMongo wireMongo) {
this.wireMongo = wireMongo;
return this;
}
private Future call(U request) {
return wireMongo.call(request);
}
private ReadStream callStream(Command request) {
return wireMongo.callStream(request);
}
@Override
public MongoClient save(String collection, JsonObject document, Handler> handler) {
save(collection, document).onComplete(handler);
return this;
}
@Override
public Future save(String collection, JsonObject document) {
return call(new SaveBaseCommand(collection, document));
}
@Override
public MongoClient saveWithOptions(String collection, JsonObject document, @Nullable WriteOption writeOption, Handler> handler) {
saveWithOptions(collection, document, writeOption).onComplete(handler);
return this;
}
@Override
public Future saveWithOptions(String collection, JsonObject document, @Nullable WriteOption writeOption) {
return call(new SaveWithOptionsCommand(collection, document, writeOption));
}
@Override
public MongoClient insert(String collection, JsonObject document, Handler> handler) {
insert(collection, document).onComplete(handler);
return this;
}
@Override
public Future insert(String collection, JsonObject document) {
return call(new InsertBaseCommand(collection, document));
}
@Override
public MongoClient insertWithOptions(String collection, JsonObject document, @Nullable WriteOption writeOption, Handler> handler) {
insertWithOptions(collection, document, writeOption).onComplete(handler);
return this;
}
@Override
public Future insertWithOptions(String collection, JsonObject document, @Nullable WriteOption writeOption) {
return call(new InsertWithOptionsCommand(collection, document, writeOption));
}
@Override
public MongoClient updateCollection(String collection, JsonObject query, JsonObject update, Handler> handler) {
updateCollection(collection, query, update).onComplete(handler);
return this;
}
@Override
public Future updateCollection(String collection, JsonObject query, JsonObject update) {
return call(new UpdateCollectionBaseCommand<>(collection, query, update));
}
@Override
public MongoClient updateCollection(String collection, JsonObject query, JsonArray update, Handler> handler) {
updateCollection(collection, query, update).onComplete(handler);
return this;
}
@Override
public Future updateCollection(String collection, JsonObject query, JsonArray update) {
return call(new UpdateCollectionBaseCommand<>("updateCollectionAggregationPipeline", collection, query, update));
}
@Override
public MongoClient updateCollectionWithOptions(String collection, JsonObject query, JsonObject update, UpdateOptions options, Handler> handler) {
updateCollectionWithOptions(collection, query, update, options).onComplete(handler);
return this;
}
@Override
public Future updateCollectionWithOptions(String collection, JsonObject query, JsonObject update, UpdateOptions options) {
return call(new UpdateCollectionWithOptionsCommand<>(collection, query, update, options));
}
@Override
public MongoClient updateCollectionWithOptions(String collection, JsonObject query, JsonArray update, UpdateOptions options, Handler> handler) {
updateCollectionWithOptions(collection, query, update, options).onComplete(handler);
return this;
}
@Override
public Future updateCollectionWithOptions(String collection, JsonObject query, JsonArray update, UpdateOptions options) {
return call(new UpdateCollectionWithOptionsCommand<>("updateCollectionWithOptionsAggregationPipeline", collection, query, update, options));
}
@Override
public MongoClient replaceDocuments(String collection, JsonObject query, JsonObject replace, Handler> handler) {
replaceDocuments(collection, query, replace).onComplete(handler);
return this;
}
@Override
public Future replaceDocuments(String collection, JsonObject query, JsonObject replace) {
return call(new ReplaceDocumentsBaseCommand(collection, query, replace));
}
@Override
public MongoClient replaceDocumentsWithOptions(String collection, JsonObject query, JsonObject replace, UpdateOptions options, Handler> handler) {
replaceDocumentsWithOptions(collection, query, replace, options).onComplete(handler);
return this;
}
@Override
public Future replaceDocumentsWithOptions(String collection, JsonObject query, JsonObject replace, UpdateOptions options) {
return call(new ReplaceDocumentsWithOptionsCommand(collection, query, replace, options));
}
@Override
public MongoClient bulkWrite(String collection, List operations, Handler> handler) {
bulkWrite(collection, operations).onComplete(handler);
return this;
}
@Override
public Future bulkWrite(String collection, List operations) {
return call(new BulkWriteBaseCommand(collection, operations));
}
@Override
public MongoClient bulkWriteWithOptions(String collection, List operations, BulkWriteOptions bulkWriteOptions, Handler> handler) {
bulkWriteWithOptions(collection, operations, bulkWriteOptions).onComplete(handler);
return this;
}
@Override
public Future bulkWriteWithOptions(String collection, List operations, BulkWriteOptions bulkWriteOptions) {
return call(new BulkWriteWithOptionsCommand(collection, operations, bulkWriteOptions));
}
@Override
public MongoClient find(String collection, JsonObject query, Handler>> handler) {
find(collection, query).onComplete(handler);
return this;
}
@Override
public Future> find(String collection, JsonObject query) {
return call(new FindBaseCommand(collection, query));
}
@Override
public ReadStream findBatch(String collection, JsonObject query) {
return callStream(new FindBatchBaseCommand(collection, query));
}
@Override
public MongoClient findWithOptions(String collection, JsonObject query, FindOptions options, Handler>> handler) {
findWithOptions(collection, query, options).onComplete(handler);
return this;
}
@Override
public Future> findWithOptions(String collection, JsonObject query, FindOptions options) {
return call(new FindWithOptionsCommand(collection, query, options));
}
@Override
public ReadStream findBatchWithOptions(String collection, JsonObject query, FindOptions options) {
return callStream(new FindBatchWithOptionsCommand(collection, query, options));
}
@Override
public MongoClient findOne(String collection, JsonObject query, @Nullable JsonObject fields, Handler> handler) {
findOne(collection, query, fields).onComplete(handler);
return this;
}
@Override
public Future findOne(String collection, JsonObject query, @Nullable JsonObject fields) {
return call(new FindOneCommand(collection, query, fields));
}
@Override
public MongoClient findOneAndUpdate(String collection, JsonObject query, JsonObject update, Handler> handler) {
findOneAndUpdate(collection, query, update).onComplete(handler);
return this;
}
@Override
public Future findOneAndUpdate(String collection, JsonObject query, JsonObject update) {
return call(new FindOneAndUpdateBaseCommand(collection, query, update));
}
@Override
public MongoClient findOneAndUpdateWithOptions(String collection, JsonObject query, JsonObject update, FindOptions findOptions, UpdateOptions updateOptions, Handler> handler) {
findOneAndUpdateWithOptions(collection, query, update, findOptions, updateOptions).onComplete(handler);
return this;
}
@Override
public Future findOneAndUpdateWithOptions(String collection, JsonObject query, JsonObject update, FindOptions findOptions, UpdateOptions updateOptions) {
return call(new FindOneAndUpdateWithOptionsCommand(collection, query, update, findOptions, updateOptions));
}
@Override
public MongoClient findOneAndReplace(String collection, JsonObject query, JsonObject replace, Handler> handler) {
findOneAndReplace(collection, query, replace).onComplete(handler);
return this;
}
@Override
public Future findOneAndReplace(String collection, JsonObject query, JsonObject replace) {
return call(new FindOneAndReplaceBaseCommand(collection, query, replace));
}
@Override
public MongoClient findOneAndReplaceWithOptions(String collection, JsonObject query, JsonObject replace, FindOptions findOptions, UpdateOptions updateOptions, Handler> handler) {
findOneAndReplaceWithOptions(collection, query, replace, findOptions, updateOptions).onComplete(handler);
return this;
}
@Override
public Future findOneAndReplaceWithOptions(String collection, JsonObject query, JsonObject replace, FindOptions findOptions, UpdateOptions updateOptions) {
return call(new FindOneAndReplaceWithOptionsCommand(collection, query, replace, findOptions, updateOptions));
}
@Override
public MongoClient findOneAndDelete(String collection, JsonObject query, Handler> resultHandler) {
findOneAndDelete(collection, query).onComplete(resultHandler);
return this;
}
@Override
public Future findOneAndDelete(String collection, JsonObject query) {
return call(new FindOneAndDeleteBaseCommand(collection, query));
}
@Override
public MongoClient findOneAndDeleteWithOptions(String collection, JsonObject query, FindOptions findOptions, Handler> handler) {
findOneAndDeleteWithOptions(collection, query, findOptions).onComplete(handler);
return this;
}
@Override
public Future findOneAndDeleteWithOptions(String collection, JsonObject query, FindOptions findOptions) {
return call(new FindOneAndDeleteWithOptionsCommand(collection, query, findOptions));
}
@Override
public MongoClient count(String collection, JsonObject query, Handler> handler) {
count(collection, query).onComplete(handler);
return this;
}
@Override
public Future count(String collection, JsonObject query) {
return call(new CountCommand(collection, query));
}
@Override
public MongoClient countWithOptions(String collection, JsonObject query, CountOptions countOptions, Handler> handler) {
countWithOptions(collection, query, countOptions).onComplete(handler);
return this;
}
@Override
public Future countWithOptions(String collection, JsonObject query, CountOptions countOptions) {
return call(new CountWithOptionsCommand(collection, query, countOptions));
}
@Override
public MongoClient removeDocuments(String collection, JsonObject query, Handler> handler) {
removeDocuments(collection, query).onComplete(handler);
return this;
}
@Override
public Future removeDocuments(String collection, JsonObject query) {
return call(new RemoveDocumentsBaseCommand(collection, query));
}
@Override
public MongoClient removeDocumentsWithOptions(String collection, JsonObject query, @Nullable WriteOption writeOption, Handler> handler) {
removeDocumentsWithOptions(collection, query, writeOption).onComplete(handler);
return this;
}
@Override
public Future removeDocumentsWithOptions(String collection, JsonObject query, @Nullable WriteOption writeOption) {
return call(new RemoveDocumentsWithOptionsCommand(collection, query, writeOption));
}
@Override
public MongoClient removeDocument(String collection, JsonObject query, Handler> handler) {
removeDocument(collection, query).onComplete(handler);
return this;
}
@Override
public Future removeDocument(String collection, JsonObject query) {
return call(new RemoveDocumentBaseCommand(collection, query));
}
@Override
public MongoClient removeDocumentWithOptions(String collection, JsonObject query, @Nullable WriteOption writeOption, Handler> handler) {
removeDocumentWithOptions(collection, query, writeOption).onComplete(handler);
return this;
}
@Override
public Future removeDocumentWithOptions(String collection, JsonObject query, @Nullable WriteOption writeOption) {
return call(new RemoveDocumentWithOptionsCommand(collection, query, writeOption));
}
@Override
public MongoClient createCollection(String collection, Handler> handler) {
createCollection(collection).onComplete(handler);
return this;
}
@Override
public MongoClient createCollectionWithOptions(String collection, CreateCollectionOptions createCollectionOptions, Handler> handler) {
createCollectionWithOptions(collection, createCollectionOptions).onComplete(handler);
return this;
}
@Override
public Future createCollection(String collection) {
return call(new CreateCollectionCommand(collection));
}
@Override
public Future createCollectionWithOptions(String collection, CreateCollectionOptions createCollectionOptions) {
return call(new CreateCollectionWithOptionsCommand(collection, createCollectionOptions));
}
@Override
public MongoClient getCollections(Handler>> handler) {
getCollections().onComplete(handler);
return this;
}
@Override
public Future> getCollections() {
return call(new GetCollectionsCommand());
}
@Override
public MongoClient dropCollection(String collection, Handler> handler) {
dropCollection(collection).onComplete(handler);
return this;
}
@Override
public Future dropCollection(String collection) {
return call(new DropCollectionCommand(collection));
}
@Override
public MongoClient createIndex(String collection, JsonObject key, Handler> handler) {
createIndex(collection, key).onComplete(handler);
return this;
}
@Override
public Future createIndex(String collection, JsonObject key) {
return call(new CreateIndexBaseCommand(collection, key));
}
@Override
public MongoClient createIndexWithOptions(String collection, JsonObject key, IndexOptions options, Handler> handler) {
createIndexWithOptions(collection, key, options).onComplete(handler);
return this;
}
@Override
public Future createIndexWithOptions(String collection, JsonObject key, IndexOptions options) {
return call(new CreateIndexWithOptionsCommand(collection, key, options));
}
@Override
public MongoClient createIndexes(String s, List list, Handler> handler) {
createIndexes(s, list).onComplete(handler);
return this;
}
@Override
public Future createIndexes(String collection, List indexModels) {
return call(new CreateIndexesCommand(collection, indexModels));
}
@Override
public MongoClient listIndexes(String collection, Handler> handler) {
listIndexes(collection).onComplete(handler);
return this;
}
@Override
public Future listIndexes(String collection) {
return call(new ListIndexesCommand(collection));
}
@Override
public MongoClient dropIndex(String collection, String indexName, Handler> handler) {
dropIndex(collection, indexName).onComplete(handler);
return this;
}
@Override
public Future dropIndex(String collection, String indexName) {
return call(new DropIndexCommand(collection, indexName));
}
@Override
public MongoClient runCommand(String commandName, JsonObject command, Handler> handler) {
runCommand(commandName, command).onComplete(handler);
return this;
}
@Override
public Future runCommand(String commandName, JsonObject command) {
return call(new RunCommandCommand(commandName, command));
}
@Override
public MongoClient distinct(String collection, String fieldName, String resultClassname, Handler> handler) {
distinct(collection, fieldName, resultClassname).onComplete(handler);
return this;
}
@Override
public MongoClient distinct(String collection, String fieldName, String resultClassname, DistinctOptions distinctOptions, Handler> handler) {
distinct(collection, fieldName, resultClassname, distinctOptions).onComplete(handler);
return this;
}
@Override
public Future distinct(String collection, String fieldName, String resultClassname) {
return call(new DistinctCommand(collection, fieldName, resultClassname));
}
@Override
public Future distinct(String collection, String fieldName, String resultClassname, DistinctOptions distinctOptions) {
return call(new DistinctCommand(collection, fieldName, resultClassname, distinctOptions));
}
@Override
public MongoClient distinctWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, Handler> handler) {
distinctWithQuery(collection, fieldName, resultClassname, query).onComplete(handler);
return this;
}
@Override
public MongoClient distinctWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, DistinctOptions distinctOptions, Handler> handler) {
distinctWithQuery(collection, fieldName, resultClassname, query, distinctOptions).onComplete(handler);
return this;
}
@Override
public Future distinctWithQuery(String collection, String fieldName, String resultClassname, JsonObject query) {
return call(new DistinctWithQueryCommand(collection, fieldName, resultClassname, query));
}
@Override
public Future distinctWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, DistinctOptions distinctOptions) {
return call(new DistinctWithQueryCommand(collection, fieldName, resultClassname, query, distinctOptions));
}
@Override
public ReadStream distinctBatch(String collection, String fieldName, String resultClassname) {
return callStream(new DistinctBatchBaseCommand(collection, fieldName, resultClassname));
}
@Override
public ReadStream distinctBatch(String collection, String fieldName, String resultClassname, DistinctOptions distinctOptions) {
return callStream(new DistinctBatchBaseCommand(collection, fieldName, resultClassname, distinctOptions));
}
@Override
public ReadStream distinctBatchWithQuery(String collection, String fieldName, String resultClassname, JsonObject query) {
return callStream(new DistinctBatchWithQueryCommand(collection, fieldName, resultClassname, query));
}
@Override
public ReadStream distinctBatchWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, DistinctOptions options) {
return callStream(new DistinctBatchWithQueryCommand(collection, fieldName, resultClassname, query, options));
}
@Override
public ReadStream distinctBatchWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, int batchSize) {
return callStream(new DistinctBatchWithQueryCommand(collection, fieldName, resultClassname, query, batchSize));
}
@Override
public ReadStream distinctBatchWithQuery(String collection, String fieldName, String resultClassname, JsonObject query, int batchSize, DistinctOptions options) {
return callStream(new DistinctBatchWithQueryCommand(collection, fieldName, resultClassname, query, batchSize, options));
}
@Override
public ReadStream aggregate(String collection, JsonArray pipeline) {
return callStream(new AggregateBaseCommand(collection, pipeline));
}
@Override
public ReadStream aggregateWithOptions(String collection, JsonArray pipeline, AggregateOptions options) {
return callStream(new AggregateWithOptionsCommand(collection, pipeline, options));
}
@Override
public MongoClient createDefaultGridFsBucketService(Handler> handler) {
createDefaultGridFsBucketService().onComplete(handler);
return this;
}
@Override
public Future createDefaultGridFsBucketService() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
@Override
public MongoClient createGridFsBucketService(String s, Handler> handler) {
createGridFsBucketService(s).onComplete(handler);
return this;
}
@Override
public Future createGridFsBucketService(String s) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
@Override
public ReadStream> watch(String s, JsonArray jsonArray, boolean b, int i) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED);
}
@Override
public void close(Handler> handler) {
close().onComplete(handler);
}
@Override
public Future close() {
return Future.succeededFuture();
}
public static synchronized WireMongoClient createShared(Vertx vertx, JsonObject config, String dataSource) {
if (instance == null) {
instance = new WireMongoClient();
}
return instance;
}
}