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-android Show documentation
Show all versions of abacus-android Show documentation
A general and simple library for Android
/*
* 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.Date;
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.u.Nullable;
import com.landawn.abacus.util.u.Optional;
import com.landawn.abacus.util.u.OptionalBoolean;
import com.landawn.abacus.util.u.OptionalByte;
import com.landawn.abacus.util.u.OptionalChar;
import com.landawn.abacus.util.u.OptionalDouble;
import com.landawn.abacus.util.u.OptionalFloat;
import com.landawn.abacus.util.u.OptionalInt;
import com.landawn.abacus.util.u.OptionalLong;
import com.landawn.abacus.util.u.OptionalShort;
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.DeleteOptions;
import com.mongodb.client.model.InsertManyOptions;
import com.mongodb.client.model.InsertOneOptions;
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 ContinuableFuture exists(final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(objectId);
}
});
}
public ContinuableFuture exists(final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(objectId);
}
});
}
public ContinuableFuture exists(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return collExecutor.exists(filter);
}
});
}
public ContinuableFuture count() {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count();
}
});
}
public ContinuableFuture count(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count(filter);
}
});
}
public ContinuableFuture count(final Bson filter, final CountOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Long call() throws Exception {
return collExecutor.count(filter, options);
}
});
}
public ContinuableFuture> get(final String objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(objectId);
}
});
}
public ContinuableFuture> get(final ObjectId objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(objectId);
}
});
}
public ContinuableFuture> get(final Class targetClass, final String objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(targetClass, objectId);
}
});
}
public ContinuableFuture> get(final Class targetClass, final ObjectId objectId) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(targetClass, objectId);
}
});
}
public ContinuableFuture> get(final Class targetClass, final String objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(targetClass, objectId, selectPropNames);
}
});
}
public ContinuableFuture> get(final Class targetClass, final ObjectId objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.get(targetClass, objectId, selectPropNames);
}
});
}
public ContinuableFuture gett(final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Document call() throws Exception {
return collExecutor.gett(objectId);
}
});
}
public ContinuableFuture gett(final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public Document call() throws Exception {
return collExecutor.gett(objectId);
}
});
}
public ContinuableFuture gett(final Class targetClass, final String objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.gett(targetClass, objectId);
}
});
}
public ContinuableFuture gett(final Class targetClass, final ObjectId objectId) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.gett(targetClass, objectId);
}
});
}
public ContinuableFuture gett(final Class targetClass, final String objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.gett(targetClass, objectId, selectPropNames);
}
});
}
public ContinuableFuture gett(final Class targetClass, final ObjectId objectId, final Collection selectPropNames) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return collExecutor.gett(targetClass, objectId, selectPropNames);
}
});
}
public ContinuableFuture> findFirst(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.findFirst(filter);
}
});
}
public ContinuableFuture> findFirst(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.findFirst(targetClass, filter);
}
});
}
public ContinuableFuture> findFirst(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return collExecutor.findFirst(targetClass, selectPropNames, filter);
}
});
}
public ContinuableFuture> findFirst(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.findFirst(targetClass, selectPropNames, filter, sort);
}
});
}
public ContinuableFuture> findFirst(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.findFirst(targetClass, filter, sort, projection);
}
});
}
public ContinuableFuture> list(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.list(filter);
}
});
}
public ContinuableFuture> list(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.list(targetClass, filter);
}
});
}
public ContinuableFuture> list(final Class targetClass, final Collection selectPropNames, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return collExecutor.list(targetClass, selectPropNames, filter);
}
});
}
public ContinuableFuture> list(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.list(targetClass, selectPropNames, filter, offset, count);
}
});
}
public ContinuableFuture> list(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.list(targetClass, selectPropNames, filter, sort);
}
});
}
public ContinuableFuture> list(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.list(targetClass, selectPropNames, filter, sort, offset, count);
}
});
}
public ContinuableFuture> list(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.list(targetClass, filter, sort, projection);
}
});
}
public ContinuableFuture> list(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.list(targetClass, filter, sort, projection, offset, count);
}
});
}
public ContinuableFuture queryForBoolean(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalBoolean call() throws Exception {
return collExecutor.queryForBoolean(propName, filter);
}
});
}
public ContinuableFuture queryForChar(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalChar call() throws Exception {
return collExecutor.queryForChar(propName, filter);
}
});
}
public ContinuableFuture queryForByte(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalByte call() throws Exception {
return collExecutor.queryForByte(propName, filter);
}
});
}
public ContinuableFuture queryForShort(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalShort call() throws Exception {
return collExecutor.queryForShort(propName, filter);
}
});
}
public ContinuableFuture queryForInt(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalInt call() throws Exception {
return collExecutor.queryForInt(propName, filter);
}
});
}
public ContinuableFuture queryForLong(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalLong call() throws Exception {
return collExecutor.queryForLong(propName, filter);
}
});
}
public ContinuableFuture queryForFloat(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalFloat call() throws Exception {
return collExecutor.queryForFloat(propName, filter);
}
});
}
public ContinuableFuture queryForDouble(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalDouble call() throws Exception {
return collExecutor.queryForDouble(propName, filter);
}
});
}
public ContinuableFuture> queryForString(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return collExecutor.queryForString(propName, filter);
}
});
}
public ContinuableFuture> queryForDate(final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return collExecutor.queryForDate(propName, filter);
}
});
}
public ContinuableFuture> queryForDate(final Class targetClass, final String propName, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return collExecutor.queryForDate(targetClass, propName, filter);
}
});
}
public ContinuableFuture> 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 ContinuableFuture query(final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(filter);
}
});
}
public ContinuableFuture query(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable() {
@Override
public DataSet call() throws Exception {
return collExecutor.query(targetClass, filter);
}
});
}
public ContinuableFuture 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 ContinuableFuture 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 ContinuableFuture 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 ContinuableFuture 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 ContinuableFuture 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 ContinuableFuture 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 ContinuableFuture> stream(final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(filter);
}
});
}
public ContinuableFuture> stream(final Class targetClass, final Bson filter) {
return asyncExecutor.execute(new Callable>() {
@Override
public Stream call() throws Exception {
return collExecutor.stream(targetClass, filter);
}
});
}
public ContinuableFuture> 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 ContinuableFuture> 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 ContinuableFuture> 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 ContinuableFuture> 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 ContinuableFuture> 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 ContinuableFuture> 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 ContinuableFuture insert(final Object obj) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insert(obj);
return null;
}
});
}
public ContinuableFuture insert(final Object obj, final InsertOneOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insert(obj, options);
return null;
}
});
}
public ContinuableFuture insertAll(final Collection> objList) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insertAll(objList);
return null;
}
});
}
public ContinuableFuture insertAll(final Collection> objList, final InsertManyOptions options) {
return asyncExecutor.execute(new Callable() {
@Override
public Void call() throws Exception {
collExecutor.insertAll(objList, options);
return null;
}
});
}
public ContinuableFuture update(final String objectId, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.update(objectId, update);
}
});
}
public ContinuableFuture update(final ObjectId objectId, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.update(objectId, update);
}
});
}
public ContinuableFuture updateOne(final Bson filter, final Object update) {
return asyncExecutor.execute(new Callable() {
@Override
public UpdateResult call() throws Exception {
return collExecutor.updateOne(filter, update);
}
});
}
public ContinuableFuture