package greencode.database;
import greencode.kernel.Console;
import greencode.kernel.GreenCodeConfig;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
public final class DatabaseStatement implements Statement {
private final Statement st;
private final DatabaseConnection connection;
DatabaseStatement(DatabaseConnection connection) throws SQLException {
this.connection = connection;
this.st = connection.getConnection().createStatement();
}
DatabaseStatement(DatabaseConnection connection, int resultSetType, int resultSetConcurrency) throws SQLException {
this.connection = connection;
this.st = connection.getConnection().createStatement(resultSetType, resultSetConcurrency);
}
DatabaseStatement(DatabaseConnection connection, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
this.connection = connection;
this.st = connection.getConnection().createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
}
public ResultSet executeQuery(String sql) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return this.st.executeQuery(sql);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public int executeUpdate(String sql) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.executeUpdate(sql);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public boolean execute(String sql) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.execute(sql);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.executeUpdate(sql, autoGeneratedKeys);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.executeUpdate(sql, columnIndexes);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.executeUpdate(sql, columnNames);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.execute(sql, autoGeneratedKeys);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.execute(sql, columnIndexes);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public boolean execute(String sql, String[] columnNames) throws SQLException {
if (GreenCodeConfig.Server.DataBase.showResultQuery)
Console.log(sql);
try {
return st.execute(sql, columnNames);
} catch (SQLException e) {
this.connection.hasError = true;
throw e;
}
}
public <T> T unwrap(Class<T> iface) throws SQLException {
return st.unwrap(iface);
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return st.isWrapperFor(iface);
}
public void close() throws SQLException {
st.close();
}
public int getMaxFieldSize() throws SQLException {
return st.getMaxFieldSize();
}
public void setMaxFieldSize(int max) throws SQLException {
st.setMaxFieldSize(max);
}
public int getMaxRows() throws SQLException {
return st.getMaxRows();
}
public void setMaxRows(int max) throws SQLException {
st.setMaxRows(max);
}
public void setEscapeProcessing(boolean enable) throws SQLException {
st.setEscapeProcessing(enable);
}
public int getQueryTimeout() throws SQLException {
return st.getQueryTimeout();
}
public void setQueryTimeout(int seconds) throws SQLException {
st.setQueryTimeout(seconds);
}
public void cancel() throws SQLException {
st.cancel();
}
public SQLWarning getWarnings() throws SQLException {
return st.getWarnings();
}
public void clearWarnings() throws SQLException {
st.clearWarnings();
}
public void setCursorName(String name) throws SQLException {
st.setCursorName(name);
}
public ResultSet getResultSet() throws SQLException {
return st.getResultSet();
}
public int getUpdateCount() throws SQLException {
return st.getUpdateCount();
}
public boolean getMoreResults() throws SQLException {
return st.getMoreResults();
}
public void setFetchDirection(int direction) throws SQLException {
st.setFetchDirection(direction);
}
public int getFetchDirection() throws SQLException {
return st.getFetchDirection();
}
public void setFetchSize(int rows) throws SQLException {
st.setFetchSize(rows);
}
public int getFetchSize() throws SQLException {
return st.getFetchSize();
}
public int getResultSetConcurrency() throws SQLException {
return st.getResultSetConcurrency();
}
public int getResultSetType() throws SQLException {
return st.getResultSetType();
}
public void addBatch(String sql) throws SQLException {
st.addBatch(sql);
}
public void clearBatch() throws SQLException {
st.clearBatch();
}
public int[] executeBatch() throws SQLException {
return st.executeBatch();
}
public Connection getConnection() throws SQLException {
return st.getConnection();
}
public boolean getMoreResults(int current) throws SQLException {
return st.getMoreResults();
}
public ResultSet getGeneratedKeys() throws SQLException {
return st.getGeneratedKeys();
}
public int getResultSetHoldability() throws SQLException {
return st.getResultSetConcurrency();
}
public boolean isClosed() throws SQLException {
return st.isClosed();
}
public void setPoolable(boolean poolable) throws SQLException {
st.setPoolable(poolable);
}
public boolean isPoolable() throws SQLException {
return st.isPoolable();
}
public void closeOnCompletion() throws SQLException {
st.isPoolable();
}
public boolean isCloseOnCompletion() throws SQLException {
return st.isCloseOnCompletion();
}
}