com.hundsun.lightdb.unisql.proxy.multijdbc.MultiStatement Maven / Gradle / Ivy
package com.hundsun.lightdb.unisql.proxy.multijdbc;
import com.hundsun.lightdb.unisql.model.UnisqlProperties;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.extern.slf4j.Slf4j;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.List;
/**
* @Author yupeishi
* @Date 2023/10/13
**/
@SuppressFBWarnings({"SQL_INJECTION_JDBC", "RV_RETURN_VALUE_IGNORED"})
@Slf4j
public class MultiStatement implements Statement {
private final Statement delegate;
private final List delegateMulti;
/** 配置参数 */
private final boolean debug = UnisqlProperties.getInstance().isDebug();
public MultiStatement(Statement delegate, List delegateMulti){
this.delegate = delegate;
this.delegateMulti = delegateMulti;
}
public Statement getDelegate() {
return delegate;
}
@Override
public ResultSet executeQuery(String sql) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeQuery(sql);
}
return delegate.executeQuery(sql);
}
@Override
public int executeUpdate(String sql) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
int result = unisqlStatement.executeUpdate(sql);
if(debug){
if (log.isDebugEnabled()) {
log.debug("multi statement executeUpdate result is {}", result);
}
}
}
return delegate.executeUpdate(sql);
}
@Override
public void close() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.close();
}
delegate.close();
}
@Override
public int getMaxFieldSize() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getMaxFieldSize();
}
return delegate.getMaxFieldSize();
}
@Override
public void setMaxFieldSize(int max) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setMaxFieldSize(max);
}
delegate.setMaxFieldSize(max);
}
@Override
public int getMaxRows() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getMaxRows();
}
return delegate.getMaxRows();
}
@Override
public void setMaxRows(int max) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setMaxRows(max);
}
delegate.setMaxRows(max);
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setEscapeProcessing(enable);
}
delegate.setEscapeProcessing(enable);
}
@Override
public int getQueryTimeout() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getQueryTimeout();
}
return delegate.getQueryTimeout();
}
@Override
public void setQueryTimeout(int seconds) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setQueryTimeout(seconds);
}
delegate.setQueryTimeout(seconds);
}
@Override
public void cancel() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.cancel();
}
delegate.cancel();
}
@Override
public SQLWarning getWarnings() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getWarnings();
}
return delegate.getWarnings();
}
@Override
public void clearWarnings() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.clearWarnings();
}
delegate.clearWarnings();
}
@Override
public void setCursorName(String name) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setCursorName(name);
}
delegate.setCursorName(name);
}
@Override
public boolean execute(String sql) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
boolean execute = unisqlStatement.execute(sql);
if(debug){
if (log.isDebugEnabled()) {
log.debug("multi statement execute result is {}", execute);
}
}
}
return delegate.execute(sql);
}
@Override
public ResultSet getResultSet() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getResultSet();
}
return delegate.getResultSet();
}
@Override
public int getUpdateCount() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getUpdateCount();
}
return delegate.getUpdateCount();
}
@Override
public boolean getMoreResults() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getMoreResults();
}
return delegate.getMoreResults();
}
@Override
public void setFetchDirection(int direction) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setFetchDirection(direction);
}
delegate.setFetchDirection(direction);
}
@Override
public int getFetchDirection() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getFetchDirection();
}
return delegate.getFetchDirection();
}
@Override
public void setFetchSize(int rows) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setFetchSize(rows);
}
delegate.setFetchSize(rows);
}
@Override
public int getFetchSize() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getFetchSize();
}
return delegate.getFetchSize();
}
@Override
public int getResultSetConcurrency() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getResultSetConcurrency();
}
return delegate.getResultSetConcurrency();
}
@Override
public int getResultSetType() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getResultSetType();
}
return delegate.getResultSetType();
}
@Override
public void addBatch(String sql) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.addBatch(sql);
}
delegate.addBatch(sql);
}
@Override
public void clearBatch() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.clearBatch();
}
delegate.clearBatch();
}
@Override
public int[] executeBatch() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeBatch();
}
return delegate.executeBatch();
}
@Override
public Connection getConnection() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getConnection();
}
return delegate.getConnection();
}
@Override
public boolean getMoreResults(int current) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getMoreResults(current);
}
return delegate.getMoreResults(current);
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getGeneratedKeys();
}
return delegate.getGeneratedKeys();
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeUpdate(sql, autoGeneratedKeys);
}
return delegate.executeUpdate(sql, autoGeneratedKeys);
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeUpdate(sql, columnIndexes);
}
return delegate.executeUpdate(sql, columnIndexes);
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeUpdate(sql, columnNames);
}
return delegate.executeUpdate(sql, columnNames);
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.execute(sql, autoGeneratedKeys);
}
return delegate.execute(sql, autoGeneratedKeys);
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.execute(sql, columnIndexes);
}
return delegate.execute(sql, columnIndexes);
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.execute(sql, columnNames);
}
return delegate.execute(sql, columnNames);
}
@Override
public int getResultSetHoldability() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getResultSetHoldability();
}
return delegate.getResultSetHoldability();
}
@Override
public boolean isClosed() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.isClosed();
}
return delegate.isClosed();
}
@Override
public void setPoolable(boolean poolable) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setPoolable(poolable);
}
delegate.setPoolable(poolable);
}
@Override
public boolean isPoolable() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.isPoolable();
}
return delegate.isPoolable();
}
@Override
public void closeOnCompletion() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.closeOnCompletion();
}
delegate.closeOnCompletion();
}
@Override
public boolean isCloseOnCompletion() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.isCloseOnCompletion();
}
return delegate.isCloseOnCompletion();
}
@Override
public long getLargeUpdateCount() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getLargeUpdateCount();
}
return delegate.getLargeUpdateCount();
}
@Override
public void setLargeMaxRows(long max) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.setLargeMaxRows(max);
}
delegate.setLargeMaxRows(max);
}
@Override
public long getLargeMaxRows() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.getLargeMaxRows();
}
return delegate.getLargeMaxRows();
}
@Override
public long[] executeLargeBatch() throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeLargeBatch();
}
return delegate.executeLargeBatch();
}
@Override
public long executeLargeUpdate(String sql) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeLargeUpdate(sql);
}
return delegate.executeLargeUpdate(sql);
}
@Override
public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeLargeUpdate(sql, autoGeneratedKeys);
}
return delegate.executeLargeUpdate(sql, autoGeneratedKeys);
}
@Override
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeLargeUpdate(sql, columnIndexes);
}
return delegate.executeLargeUpdate(sql, columnIndexes);
}
@Override
public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.executeLargeUpdate(sql, columnNames);
}
return delegate.executeLargeUpdate(sql, columnNames);
}
@Override
public T unwrap(Class iface) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.unwrap(iface);
}
return delegate.unwrap(iface);
}
@Override
public boolean isWrapperFor(Class> iface) throws SQLException {
for (Statement unisqlStatement : delegateMulti) {
unisqlStatement.isWrapperFor(iface);
}
return delegate.isWrapperFor(iface);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy