com.landawn.abacus.util.AsyncSQLExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abacus-android-jdk7 Show documentation
Show all versions of abacus-android-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.sql.Connection;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import com.landawn.abacus.DataSet;
import com.landawn.abacus.logging.Logger;
import com.landawn.abacus.logging.LoggerFactory;
import com.landawn.abacus.util.SQLExecutor.JdbcSettings;
import com.landawn.abacus.util.SQLExecutor.ResultSetExtractor;
import com.landawn.abacus.util.SQLExecutor.StatementSetter;
import com.landawn.abacus.util.stream.Stream;
/**
* Asynchronous SQLExecutor
.
*
* @since 0.8
*
* @author Haiyang Li
*/
public final class AsyncSQLExecutor {
protected static final Logger logger = LoggerFactory.getLogger(AsyncSQLExecutor.class);
private final SQLExecutor sqlExecutor;
private final AsyncExecutor asyncExecutor;
AsyncSQLExecutor(final SQLExecutor sqlExecutor, final AsyncExecutor asyncExecutor) {
this.sqlExecutor = sqlExecutor;
this.asyncExecutor = asyncExecutor;
}
public SQLExecutor sync() {
return sqlExecutor;
}
AsyncExecutor asyncExecutor() {
return asyncExecutor;
}
@SafeVarargs
public final CompletableFuture insert(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture insert(final String sql, final StatementSetter statementSetter, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(sql, statementSetter, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture insert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture insert(final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(conn, sql, statementSetter, parameters);
}
});
}
/**
* @see SQLExecutor#insert(Connection, String, StatementSetter, JdbcSettings, Object...)
*/
@SafeVarargs
public final CompletableFuture insert(final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.insert(conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
CompletableFuture> batchInsert(final String sql, final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, parametersList);
}
});
}
CompletableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, statementSetter, parametersList);
}
});
}
CompletableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, statementSetter, jdbcSettings, parametersList);
}
});
}
CompletableFuture> batchInsert(final Connection conn, final String sql, final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, parametersList);
}
});
}
CompletableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, statementSetter, parametersList);
}
});
}
CompletableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object[] parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, statementSetter, jdbcSettings, parametersList);
}
});
}
public CompletableFuture> batchInsert(final String sql, final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, parametersList);
}
});
}
public CompletableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, statementSetter, parametersList);
}
});
}
public CompletableFuture> batchInsert(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(sql, statementSetter, jdbcSettings, parametersList);
}
});
}
public CompletableFuture> batchInsert(final Connection conn, final String sql, final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, parametersList);
}
});
}
public CompletableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter,
final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, statementSetter, parametersList);
}
});
}
public CompletableFuture> batchInsert(final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final List> parametersList) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.batchInsert(conn, sql, statementSetter, jdbcSettings, parametersList);
}
});
}
@SafeVarargs
public final CompletableFuture update(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture update(final String sql, final StatementSetter statementSetter, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(sql, statementSetter, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture update(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture update(final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture update(final Connection conn, final String sql, final StatementSetter statementSetter, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(conn, sql, statementSetter, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture update(final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.update(conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
CompletableFuture batchUpdate(final String sql, final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, parametersList);
}
});
}
CompletableFuture batchUpdate(final String sql, final StatementSetter statementSetter, final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, statementSetter, parametersList);
}
});
}
CompletableFuture batchUpdate(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, statementSetter, jdbcSettings, parametersList);
}
});
}
CompletableFuture batchUpdate(final Connection conn, final String sql, final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, parametersList);
}
});
}
CompletableFuture batchUpdate(final Connection conn, final String sql, final StatementSetter statementSetter, final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, statementSetter, parametersList);
}
});
}
CompletableFuture batchUpdate(final Connection conn, final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final Object[] parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, statementSetter, jdbcSettings, parametersList);
}
});
}
public CompletableFuture batchUpdate(final String sql, final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, parametersList);
}
});
}
public CompletableFuture batchUpdate(final String sql, final StatementSetter statementSetter, final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, statementSetter, parametersList);
}
});
}
public CompletableFuture batchUpdate(final String sql, final StatementSetter statementSetter, final JdbcSettings jdbcSettings,
final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(sql, statementSetter, jdbcSettings, parametersList);
}
});
}
public CompletableFuture batchUpdate(final Connection conn, final String sql, final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, parametersList);
}
});
}
public CompletableFuture batchUpdate(final Connection conn, final String sql, final StatementSetter statementSetter,
final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, statementSetter, parametersList);
}
});
}
public CompletableFuture batchUpdate(final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final List> parametersList) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.batchUpdate(conn, sql, statementSetter, jdbcSettings, parametersList);
}
});
}
@SafeVarargs
public final CompletableFuture exists(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return sqlExecutor.exists(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture exists(final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Boolean call() throws Exception {
return sqlExecutor.exists(conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture count(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.count(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture count(final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public Integer call() throws Exception {
return sqlExecutor.count(conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture get(final Class targetClass, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.get(targetClass, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture get(final Class targetClass, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.get(targetClass, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture get(final Class targetClass, final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.get(targetClass, conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture get(final Class targetClass, final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public T call() throws Exception {
return sqlExecutor.get(targetClass, conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> gett(final Class targetClass, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return sqlExecutor.gett(targetClass, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> gett(final Class targetClass, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return sqlExecutor.gett(targetClass, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> gett(final Class targetClass, final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return sqlExecutor.gett(targetClass, conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> gett(final Class targetClass, final Connection conn, final String sql,
final StatementSetter statementSetter, final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Optional call() throws Exception {
return sqlExecutor.gett(targetClass, conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> find(final Class targetClass, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.find(targetClass, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> find(final Class targetClass, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.find(targetClass, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> find(final Class targetClass, final Connection conn, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.find(targetClass, conn, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> find(final Class targetClass, final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.find(targetClass, conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> findAll(final Class targetClass, final String sql, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, sql, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> findAll(final Class targetClass, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, sql, statementSetter, jdbcSettings, parameters);
}
});
}
CompletableFuture> findAll(final Class targetClass, final Connection conn, final String sql, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, conn, sql, jdbcSettings, parameters);
}
});
}
CompletableFuture> findAll(final Class targetClass, final Connection conn, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, conn, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> findAll(final Class targetClass, final List sqls, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, sqls, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> findAll(final Class targetClass, final List sqls, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, sqls, statementSetter, jdbcSettings, parameters);
}
});
}
CompletableFuture> findAll(final Class targetClass, final Connection conn, final List sqls, final JdbcSettings jdbcSettings,
final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, conn, sqls, jdbcSettings, parameters);
}
});
}
CompletableFuture> findAll(final Class targetClass, final Connection conn, final List sqls, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public List call() throws Exception {
return sqlExecutor.findAll(targetClass, conn, sqls, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForBoolean(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalBoolean call() throws Exception {
return sqlExecutor.queryForBoolean(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForChar(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalChar call() throws Exception {
return sqlExecutor.queryForChar(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForByte(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalByte call() throws Exception {
return sqlExecutor.queryForByte(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForShort(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalShort call() throws Exception {
return sqlExecutor.queryForShort(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForInt(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalInt call() throws Exception {
return sqlExecutor.queryForInt(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForLong(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalLong call() throws Exception {
return sqlExecutor.queryForLong(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForFloat(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalFloat call() throws Exception {
return sqlExecutor.queryForFloat(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture queryForDouble(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable() {
@Override
public OptionalDouble call() throws Exception {
return sqlExecutor.queryForDouble(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForString(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return sqlExecutor.queryForString(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForDate(final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return sqlExecutor.queryForDate(sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForDate(final Class targetClass, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return sqlExecutor.queryForDate(targetClass, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForSingleResult(final Class targetClass, final String sql, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return sqlExecutor.queryForSingleResult(targetClass, sql, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForSingleResult(final Class targetClass, final String sql, final StatementSetter statementSetter,
final JdbcSettings jdbcSettings, final Object... parameters) {
return asyncExecutor.execute(new Callable>() {
@Override
public Nullable call() throws Exception {
return sqlExecutor.queryForSingleResult(targetClass, sql, statementSetter, jdbcSettings, parameters);
}
});
}
@SafeVarargs
public final CompletableFuture> queryForSingleResult(final Class targetClass, final Connection conn, final String sql,
final Object... parameters) {
return asyncExecutor.execute(new Callable