com.landawn.abacus.util.AsyncMongoCollectionExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-util-all-jdk7 Show documentation
Show all versions of abacus-util-all-jdk7 Show documentation
A general programming library in Java
/*
* Copyright (C) 2015 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus.util;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
import com.landawn.abacus.DataSet;
import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.util.stream.Stream;
import com.mongodb.bulk.BulkWriteResult;
import com.mongodb.client.model.BulkWriteOptions;
import com.mongodb.client.model.CountOptions;
import com.mongodb.client.model.InsertManyOptions;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.WriteModel;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
/**
* Asynchronous MongoCollectionExecutor
.
*
* @since 0.8
*
* @author Haiyang Li
*/
public final class AsyncMongoCollectionExecutor {
private final MongoCollectionExecutor collExecutor;
private final AsyncExecutor asyncExecutor;
AsyncMongoCollectionExecutor(final MongoCollectionExecutor collExecutor, final AsyncExecutor asyncExecutor) {
this.collExecutor = collExecutor;
this.asyncExecutor = asyncExecutor;
}
public MongoCollectionExecutor sync() {
return collExecutor;
}
public CompletableFuture exists(final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(objectId);
}
});
}
public CompletableFuture exists(final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(objectId);
}
});
}
public CompletableFuture exists(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(filter);
}
});
}
public CompletableFuture count() {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count();
}
});
}
public CompletableFuture count(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count(filter);
}
});
}
public CompletableFuture count(final Bson filter, final CountOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count(filter, options);
}
});
}
public CompletableFuture get(final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Document call() throws Exception {
return collExecutor.get(objectId);
}
});
}
public CompletableFuture get(final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Document call() throws Exception {
return collExecutor.get(objectId);
}
});
}
public CompletableFuture get(final Class targetClass, final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.get(targetClass, objectId);
}
});
}
public CompletableFuture get(final Class targetClass, final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.get(targetClass, objectId);
}
});
}
public CompletableFuture get(final Class targetClass, final String objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.get(targetClass, objectId, selectPropNames);
}
});
}
public CompletableFuture get(final Class targetClass, final ObjectId objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.get(targetClass, objectId, selectPropNames);
}
});
}
public CompletableFuture> gett(final String objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(objectId);
}
});
}
public CompletableFuture> gett(final ObjectId objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(objectId);
}
});
}
public CompletableFuture> gett(final Class targetClass, final String objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(targetClass, objectId);
}
});
}
public CompletableFuture> gett(final Class targetClass, final ObjectId objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(targetClass, objectId);
}
});
}
public CompletableFuture> gett(final Class targetClass, final String objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(targetClass, objectId, selectPropNames);
}
});
}
public CompletableFuture> gett(final Class targetClass, final ObjectId objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.gett(targetClass, objectId, selectPropNames);
}
});
}
public CompletableFuture> queryForSingleResult(final Class targetClass, final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return collExecutor.queryForSingleResult(targetClass, propName, filter);
}
});
}
public CompletableFuture> queryForEntity(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.queryForEntity(filter);
}
});
}
public CompletableFuture> queryForEntity(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.queryForEntity(targetClass, filter);
}
});
}
public CompletableFuture> queryForEntity(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.queryForEntity(targetClass, selectPropNames, filter);
}
});
}
public CompletableFuture> queryForEntity(final Class targetClass, final Collection selectPropNames, final Bson filter,
final Bson sort) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.queryForEntity(targetClass, selectPropNames, filter, sort);
}
});
}
public CompletableFuture> queryForEntity(final Class targetClass, final Bson filter, final Bson sort, final Bson projection) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.queryForEntity(targetClass, filter, sort, projection);
}
});
}
public CompletableFuture> find(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(filter);
}
});
}
public CompletableFuture> find(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, filter);
}
});
}
public CompletableFuture> find(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, selectPropNames, filter);
}
});
}
public CompletableFuture> find(final Class targetClass, final Collection selectPropNames, final Bson filter, final int offset,
final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, selectPropNames, filter, offset, count);
}
});
}
public CompletableFuture> find(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, selectPropNames, filter, sort);
}
});
}
public CompletableFuture> find(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort,
final int offset, final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, selectPropNames, filter, sort, offset, count);
}
});
}
public CompletableFuture> find(final Class targetClass, final Bson filter, final Bson sort, final Bson projection) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, filter, sort, projection);
}
});
}
public CompletableFuture> find(final Class targetClass, final Bson filter, final Bson sort, final Bson projection, final int offset,
final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.find(targetClass, filter, sort, projection, offset, count);
}
});
}
public CompletableFuture query(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(filter);
}
});
}
public CompletableFuture query(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, filter);
}
});
}
public CompletableFuture query(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, selectPropNames, filter);
}
});
}
public CompletableFuture query(final Class targetClass, final Collection selectPropNames, final Bson filter, final int offset,
final int count) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, selectPropNames, filter, offset, count);
}
});
}
public CompletableFuture query(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, selectPropNames, filter, sort);
}
});
}
public CompletableFuture query(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort,
final int offset, final int count) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, selectPropNames, filter, sort, offset, count);
}
});
}
public CompletableFuture query(final Class targetClass, final Bson filter, final Bson sort, final Bson projection) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, filter, sort, projection);
}
});
}
public CompletableFuture query(final Class targetClass, final Bson filter, final Bson sort, final Bson projection, final int offset,
final int count) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, filter, sort, projection, offset, count);
}
});
}
public CompletableFuture> stream(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(filter);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, filter);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, selectPropNames, filter);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Collection selectPropNames, final Bson filter, final int offset,
final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, selectPropNames, filter, offset, count);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, selectPropNames, filter, sort);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Collection selectPropNames, final Bson filter, final Bson sort,
final int offset, final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, selectPropNames, filter, sort, offset, count);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Bson filter, final Bson sort, final Bson projection) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, filter, sort, projection);
}
});
}
public CompletableFuture> stream(final Class targetClass, final Bson filter, final Bson sort, final Bson projection, final int offset,
final int count) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, filter, sort, projection, offset, count);
}
});
}
public CompletableFuture insert(final Object obj) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insert(obj);
return null;
}
});
}
public CompletableFuture insert(final Collection> objList) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insert(objList);
return null;
}
});
}
public CompletableFuture insert(final Collection> objList, final InsertManyOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insert(objList, options);
return null;
}
});
}
public CompletableFuture update(final String objectId, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.update(objectId, update);
}
});
}
public CompletableFuture update(final ObjectId objectId, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.update(objectId, update);
}
});
}
public CompletableFuture updateOne(final Bson filter, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.updateOne(filter, update);
}
});
}
public CompletableFuture updateOne(final Bson filter, final Object update, final UpdateOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.updateOne(filter, update, options);
}
});
}
public CompletableFuture updateAll(final Bson filter, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.updateAll(filter, update);
}
});
}
public CompletableFuture updateAll(final Bson filter, final Object update, final UpdateOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.updateAll(filter, update, options);
}
});
}
public CompletableFuture replace(final String objectId, final Object replacement) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.replace(objectId, replacement);
}
});
}
public CompletableFuture replace(final ObjectId objectId, final Object replacement) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.replace(objectId, replacement);
}
});
}
public CompletableFuture replaceOne(final Bson filter, final Object replacement) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.replaceOne(filter, replacement);
}
});
}
public CompletableFuture replaceOne(final Bson filter, final Object replacement, final UpdateOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.replaceOne(filter, replacement, options);
}
});
}
public CompletableFuture delete(final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public DeleteResult call() throws Exception {
return collExecutor.delete(objectId);
}
});
}
public CompletableFuture delete(final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public DeleteResult call() throws Exception {
return collExecutor.delete(objectId);
}
});
}
public CompletableFuture deleteOne(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DeleteResult call() throws Exception {
return collExecutor.deleteOne(filter);
}
});
}
public CompletableFuture deleteAll(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DeleteResult call() throws Exception {
return collExecutor.deleteAll(filter);
}
});
}
public CompletableFuture bulkInsert(final Collection> entities) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return collExecutor.bulkInsert(entities);
}
});
}
public CompletableFuture bulkInsert(final Collection> entities, final BulkWriteOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return collExecutor.bulkInsert(entities, options);
}
});
}
public CompletableFuture bulkWrite(final List extends WriteModel extends Document>> requests) {
return asyncExecutor.execute(new Callable() {
@Override
public BulkWriteResult call() throws Exception {
return collExecutor.bulkWrite(requests);
}
});
}
public CompletableFuture