diff --git a/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java b/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java index 6ed4f69bc5..6482852584 100644 --- a/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java +++ b/src/main/java/com/alibaba/druid/filter/FilterChainImpl.java @@ -1,4537 +1,4537 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.filter; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.Driver; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLClientInfoException; -import java.sql.SQLException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Savepoint; -import java.sql.Statement; -import java.sql.Struct; -import java.sql.Wrapper; -import java.util.Calendar; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.pool.DruidPooledConnection; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; -import com.alibaba.druid.proxy.jdbc.ClobProxy; -import com.alibaba.druid.proxy.jdbc.ClobProxyImpl; -import com.alibaba.druid.proxy.jdbc.ConnectionProxy; -import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; -import com.alibaba.druid.proxy.jdbc.DataSourceProxy; -import com.alibaba.druid.proxy.jdbc.NClobProxy; -import com.alibaba.druid.proxy.jdbc.NClobProxyImpl; -import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; -import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl; -import com.alibaba.druid.proxy.jdbc.ResultSetProxy; -import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl; -import com.alibaba.druid.proxy.jdbc.StatementProxy; -import com.alibaba.druid.proxy.jdbc.StatementProxyImpl; - -/** - * @author wenshao - */ -public class FilterChainImpl implements FilterChain { - - protected int pos = 0; - - private final DataSourceProxy dataSource; - - private final int filterSize; - - public FilterChainImpl(DataSourceProxy dataSource){ - this.dataSource = dataSource; - this.filterSize = getFilters().size(); - } - - public FilterChainImpl(DataSourceProxy dataSource, int pos){ - this.dataSource = dataSource; - this.pos = pos; - this.filterSize = getFilters().size(); - } - - public int getFilterSize() { - return filterSize; - } - - public void reset() { - pos = 0; - } - - @Override - public FilterChain cloneChain() { - return new FilterChainImpl(dataSource, pos); - } - - public DataSourceProxy getDataSource() { - return dataSource; - } - - @Override - public boolean isWrapperFor(Wrapper wrapper, Class iface) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().isWrapperFor(this, wrapper, iface); - } - - // // if driver is for jdbc 3.0 - if (iface.isInstance(wrapper)) { - return true; - } - - return wrapper.isWrapperFor(iface); - } - - @SuppressWarnings("unchecked") - @Override - public T unwrap(Wrapper wrapper, Class iface) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().unwrap(this, wrapper, iface); - } - - if (iface == null) { - return null; - } - - // if driver is for jdbc 3.0 - if (iface.isAssignableFrom(wrapper.getClass())) { - return (T) wrapper; - } - - return wrapper.unwrap(iface); - } - - public ConnectionProxy connection_connect(Properties info) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_connect(this, info); - } - - Driver driver = dataSource.getRawDriver(); - String url = dataSource.getRawJdbcUrl(); - - Connection nativeConnection = driver.connect(url, info); - return wrap(nativeConnection, info); - } - - @Override - public void connection_clearWarnings(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_clearWarnings(this, connection); - return; - } - - connection.getRawObject().clearWarnings(); - } - - @Override - public void connection_close(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_close(this, connection); - return; - } - - connection.getRawObject().close(); - connection.getAttributes().clear(); - } - - @Override - public void connection_commit(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_commit(this, connection); - return; - } - - connection.getRawObject().commit(); - } - - @Override - public Array connection_createArrayOf(ConnectionProxy connection, String typeName, Object[] elements) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createArrayOf(this, connection, typeName, elements); - } - - return connection.getRawObject().createArrayOf(typeName, elements); - - } - - @Override - public Blob connection_createBlob(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createBlob(this, connection); - } - - return connection.getRawObject().createBlob(); - } - - @Override - public Clob connection_createClob(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createClob(this, connection); - } - - Clob clob = connection.getRawObject().createClob(); - - return wrap(connection, clob); - } - - @Override - public NClob connection_createNClob(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createNClob(this, connection); - } - - NClob nclob = connection.getRawObject().createNClob(); - - return wrap(connection, nclob); - } - - @Override - public SQLXML connection_createSQLXML(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createSQLXML(this, connection); - } - - return connection.getRawObject().createSQLXML(); - } - - @Override - public StatementProxy connection_createStatement(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createStatement(this, connection); - } - - Statement statement = connection.getRawObject().createStatement(); - return wrap(connection, statement); - } - - @Override - public StatementProxy connection_createStatement(ConnectionProxy connection, int resultSetType, - int resultSetConcurrency) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createStatement(this, connection, resultSetType, resultSetConcurrency); - } - - Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency); - return wrap(connection, statement); - } - - @Override - public StatementProxy connection_createStatement(ConnectionProxy connection, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createStatement(this, connection, resultSetType, resultSetConcurrency, - resultSetHoldability); - } - - Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency, - resultSetHoldability); - return wrap(connection, statement); - } - - @Override - public Struct connection_createStruct(ConnectionProxy connection, String typeName, Object[] attributes) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_createStruct(this, connection, typeName, attributes); - } - - return connection.getRawObject().createStruct(typeName, attributes); - } - - @Override - public boolean connection_getAutoCommit(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getAutoCommit(this, connection); - } - - return connection.getRawObject().getAutoCommit(); - } - - @Override - public String connection_getCatalog(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getCatalog(this, connection); - } - - return connection.getRawObject().getCatalog(); - } - - @Override - public Properties connection_getClientInfo(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getClientInfo(this, connection); - } - - return connection.getRawObject().getClientInfo(); - } - - @Override - public String connection_getClientInfo(ConnectionProxy connection, String name) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getClientInfo(this, connection, name); - } - - return connection.getRawObject().getClientInfo(name); - } - - public List getFilters() { - return dataSource.getProxyFilters(); - } - - @Override - public int connection_getHoldability(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getHoldability(this, connection); - } - - return connection.getRawObject().getHoldability(); - } - - @Override - public DatabaseMetaData connection_getMetaData(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getMetaData(this, connection); - } - - // DatabaseMetaData - - DatabaseMetaData rawDatabaseMetaData = connection.getRawObject().getMetaData(); - - return rawDatabaseMetaData; - } - - @Override - public int connection_getTransactionIsolation(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getTransactionIsolation(this, connection); - } - - return connection.getRawObject().getTransactionIsolation(); - } - - @Override - public Map> connection_getTypeMap(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getTypeMap(this, connection); - } - - return connection.getRawObject().getTypeMap(); - } - - @Override - public SQLWarning connection_getWarnings(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_getWarnings(this, connection); - } - - return connection.getRawObject().getWarnings(); - } - - @Override - public boolean connection_isClosed(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_isClosed(this, connection); - } - - return connection.getRawObject().isClosed(); - } - - @Override - public boolean connection_isReadOnly(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_isReadOnly(this, connection); - } - - return connection.getRawObject().isReadOnly(); - } - - @Override - public boolean connection_isValid(ConnectionProxy connection, int timeout) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_isValid(this, connection, timeout); - } - - return connection.getRawObject().isValid(timeout); - } - - @Override - public String connection_nativeSQL(ConnectionProxy connection, String sql) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_nativeSQL(this, connection, sql); - } - - return connection.getRawObject().nativeSQL(sql); - } - - private Filter nextFilter() { - Filter filter = getFilters().get(pos++); - return filter; - } - - @Override - public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareCall(this, connection, sql); - } - - CallableStatement statement = connection.getRawObject().prepareCall(sql); - return wrap(connection, statement, sql); - } - - @Override - public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql, int resultSetType, - int resultSetConcurrency) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareCall(this, connection, sql, resultSetType, resultSetConcurrency); - } - - CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency); - return wrap(connection, statement, sql); - } - - @Override - public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareCall(this, connection, sql, resultSetType, resultSetConcurrency, - resultSetHoldability); - } - - CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency, - resultSetHoldability); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, - int autoGeneratedKeys) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql, autoGeneratedKeys); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql, autoGeneratedKeys); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql, resultSetType, resultSetConcurrency); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType, - resultSetConcurrency); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql, resultSetType, resultSetConcurrency, - resultSetHoldability); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType, - resultSetConcurrency, - resultSetHoldability); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, - int[] columnIndexes) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql, columnIndexes); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnIndexes); - return wrap(connection, statement, sql); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, - String[] columnNames) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_prepareStatement(this, connection, sql, columnNames); - } - - PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnNames); - return wrap(connection, statement, sql); - } - - @Override - public void connection_releaseSavepoint(ConnectionProxy connection, Savepoint savepoint) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_releaseSavepoint(this, connection, savepoint); - return; - } - - connection.getRawObject().releaseSavepoint(savepoint); - } - - @Override - public void connection_rollback(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_rollback(this, connection); - return; - } - - connection.getRawObject().rollback(); - } - - @Override - public void connection_rollback(ConnectionProxy connection, Savepoint savepoint) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_rollback(this, connection, savepoint); - return; - } - - connection.getRawObject().rollback(savepoint); - } - - @Override - public void connection_setAutoCommit(ConnectionProxy connection, boolean autoCommit) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setAutoCommit(this, connection, autoCommit); - return; - } - - connection.getRawObject().setAutoCommit(autoCommit); - } - - @Override - public void connection_setCatalog(ConnectionProxy connection, String catalog) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setCatalog(this, connection, catalog); - return; - } - - connection.getRawObject().setCatalog(catalog); - } - - @Override - public void connection_setClientInfo(ConnectionProxy connection, Properties properties) - throws SQLClientInfoException { - if (this.pos < filterSize) { - nextFilter().connection_setClientInfo(this, connection, properties); - return; - } - - connection.getRawObject().setClientInfo(properties); - } - - @Override - public void connection_setClientInfo(ConnectionProxy connection, String name, String value) - throws SQLClientInfoException { - if (this.pos < filterSize) { - nextFilter().connection_setClientInfo(this, connection, name, value); - return; - } - - connection.getRawObject().setClientInfo(name, value); - } - - @Override - public void connection_setHoldability(ConnectionProxy connection, int holdability) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setHoldability(this, connection, holdability); - return; - } - - connection.getRawObject().setHoldability(holdability); - } - - @Override - public void connection_setReadOnly(ConnectionProxy connection, boolean readOnly) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setReadOnly(this, connection, readOnly); - return; - } - - connection.getRawObject().setReadOnly(readOnly); - } - - @Override - public Savepoint connection_setSavepoint(ConnectionProxy connection) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_setSavepoint(this, connection); - } - - return connection.getRawObject().setSavepoint(); - } - - @Override - public Savepoint connection_setSavepoint(ConnectionProxy connection, String name) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().connection_setSavepoint(this, connection, name); - } - - return connection.getRawObject().setSavepoint(name); - } - - @Override - public void connection_setTransactionIsolation(ConnectionProxy connection, int level) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setTransactionIsolation(this, connection, level); - return; - } - - connection.getRawObject().setTransactionIsolation(level); - } - - @Override - public void connection_setTypeMap(ConnectionProxy connection, Map> map) throws SQLException { - if (this.pos < filterSize) { - nextFilter().connection_setTypeMap(this, connection, map); - return; - } - - connection.getRawObject().setTypeMap(map); - } - - // /////////////////////////////////////// - - @Override - public boolean resultSet_next(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_next(this, resultSet); - } - - return resultSet.getResultSetRaw().next(); - } - - @Override - public void resultSet_close(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_close(this, resultSet); - return; - } - resultSet.getResultSetRaw().close(); - resultSet.getAttributes().clear(); - } - - @Override - public boolean resultSet_wasNull(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_wasNull(this, resultSet); - } - return resultSet.getResultSetRaw().wasNull(); - } - - @Override - public String resultSet_getString(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getString(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getString(columnIndex); - } - - @Override - public boolean resultSet_getBoolean(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBoolean(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getBoolean(columnIndex); - } - - @Override - public byte resultSet_getByte(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getByte(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getByte(columnIndex); - } - - @Override - public short resultSet_getShort(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getShort(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getShort(columnIndex); - } - - @Override - public int resultSet_getInt(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getInt(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getInt(columnIndex); - } - - @Override - public long resultSet_getLong(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getLong(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getLong(columnIndex); - } - - @Override - public float resultSet_getFloat(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getFloat(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getFloat(columnIndex); - } - - @Override - public double resultSet_getDouble(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDouble(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getDouble(columnIndex); - } - - @SuppressWarnings("deprecation") - @Override - public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, int columnIndex, int scale) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBigDecimal(this, resultSet, columnIndex, scale); - } - return resultSet.getResultSetRaw().getBigDecimal(columnIndex, scale); - } - - @Override - public byte[] resultSet_getBytes(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBytes(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getBytes(columnIndex); - } - - @Override - public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDate(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getDate(columnIndex); - } - - @Override - public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTime(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getTime(columnIndex); - } - - @Override - public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTimestamp(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getTimestamp(columnIndex); - } - - @Override - public java.io.InputStream resultSet_getAsciiStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getAsciiStream(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getAsciiStream(columnIndex); - } - - @SuppressWarnings("deprecation") - @Override - public java.io.InputStream resultSet_getUnicodeStream(ResultSetProxy resultSet, int columnIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getUnicodeStream(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getUnicodeStream(columnIndex); - } - - @Override - public java.io.InputStream resultSet_getBinaryStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBinaryStream(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getBinaryStream(columnIndex); - } - - @Override - public String resultSet_getString(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getString(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getString(columnLabel); - } - - @Override - public boolean resultSet_getBoolean(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBoolean(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getBoolean(columnLabel); - } - - @Override - public byte resultSet_getByte(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getByte(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getByte(columnLabel); - } - - @Override - public short resultSet_getShort(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getShort(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getShort(columnLabel); - } - - @Override - public int resultSet_getInt(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getInt(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getInt(columnLabel); - } - - @Override - public long resultSet_getLong(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getLong(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getLong(columnLabel); - } - - @Override - public float resultSet_getFloat(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getFloat(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getFloat(columnLabel); - } - - @Override - public double resultSet_getDouble(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDouble(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getDouble(columnLabel); - } - - @SuppressWarnings("deprecation") - @Override - public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, String columnLabel, int scale) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBigDecimal(this, resultSet, columnLabel, scale); - } - return resultSet.getResultSetRaw().getBigDecimal(columnLabel, scale); - } - - @Override - public byte[] resultSet_getBytes(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBytes(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getBytes(columnLabel); - } - - @Override - public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDate(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getDate(columnLabel); - } - - @Override - public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTime(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getTime(columnLabel); - } - - @Override - public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTimestamp(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getTimestamp(columnLabel); - } - - @Override - public java.io.InputStream resultSet_getAsciiStream(ResultSetProxy resultSet, String columnLabel) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getAsciiStream(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getAsciiStream(columnLabel); - } - - @SuppressWarnings("deprecation") - @Override - public java.io.InputStream resultSet_getUnicodeStream(ResultSetProxy resultSet, String columnLabel) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getUnicodeStream(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getUnicodeStream(columnLabel); - } - - @Override - public java.io.InputStream resultSet_getBinaryStream(ResultSetProxy resultSet, String columnLabel) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBinaryStream(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getBinaryStream(columnLabel); - } - - @Override - public SQLWarning resultSet_getWarnings(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getWarnings(this, resultSet); - } - return resultSet.getResultSetRaw().getWarnings(); - } - - @Override - public void resultSet_clearWarnings(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_clearWarnings(this, resultSet); - return; - } - resultSet.getResultSetRaw().clearWarnings(); - } - - @Override - public String resultSet_getCursorName(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getCursorName(this, resultSet); - } - return resultSet.getResultSetRaw().getCursorName(); - } - - @Override - public ResultSetMetaData resultSet_getMetaData(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getMetaData(this, resultSet); - } - return resultSet.getResultSetRaw().getMetaData(); - } - - @Override - public Object resultSet_getObject(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getObject(this, resultSet, columnIndex); - } - - Object obj = resultSet.getResultSetRaw().getObject(columnIndex); - - if (obj instanceof ResultSet) { - return wrap(resultSet.getStatementProxy(), (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(resultSet.getStatementProxy(), (Clob) obj); - } - - return obj; - } - - @Override - public Object resultSet_getObject(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getObject(this, resultSet, columnLabel); - } - - Object obj = resultSet.getResultSetRaw().getObject(columnLabel); - - if (obj instanceof ResultSet) { - return wrap(resultSet.getStatementProxy(), (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(resultSet.getStatementProxy(), (Clob) obj); - } - - return obj; - } - - @Override - public int resultSet_findColumn(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_findColumn(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().findColumn(columnLabel); - } - - @Override - public java.io.Reader resultSet_getCharacterStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getCharacterStream(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getCharacterStream(columnIndex); - } - - @Override - public java.io.Reader resultSet_getCharacterStream(ResultSetProxy resultSet, String columnLabel) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getCharacterStream(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getCharacterStream(columnLabel); - } - - @Override - public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBigDecimal(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getBigDecimal(columnIndex); - } - - @Override - public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBigDecimal(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getBigDecimal(columnLabel); - } - - @Override - public boolean resultSet_isBeforeFirst(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_isBeforeFirst(this, resultSet); - } - return resultSet.getResultSetRaw().isBeforeFirst(); - } - - @Override - public boolean resultSet_isAfterLast(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_isAfterLast(this, resultSet); - } - return resultSet.getResultSetRaw().isAfterLast(); - } - - @Override - public boolean resultSet_isFirst(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_isFirst(this, resultSet); - } - return resultSet.getResultSetRaw().isFirst(); - } - - @Override - public boolean resultSet_isLast(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_isLast(this, resultSet); - } - return resultSet.getResultSetRaw().isLast(); - } - - @Override - public void resultSet_beforeFirst(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_beforeFirst(this, resultSet); - return; - } - resultSet.getResultSetRaw().beforeFirst(); - } - - @Override - public void resultSet_afterLast(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_afterLast(this, resultSet); - return; - } - resultSet.getResultSetRaw().afterLast(); - } - - @Override - public boolean resultSet_first(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_first(this, resultSet); - } - return resultSet.getResultSetRaw().first(); - } - - @Override - public boolean resultSet_last(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_last(this, resultSet); - } - return resultSet.getResultSetRaw().last(); - } - - @Override - public int resultSet_getRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getRow(this, resultSet); - } - return resultSet.getResultSetRaw().getRow(); - } - - @Override - public boolean resultSet_absolute(ResultSetProxy resultSet, int row) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_absolute(this, resultSet, row); - } - return resultSet.getResultSetRaw().absolute(row); - } - - @Override - public boolean resultSet_relative(ResultSetProxy resultSet, int rows) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_relative(this, resultSet, rows); - } - return resultSet.getResultSetRaw().relative(rows); - } - - @Override - public boolean resultSet_previous(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_previous(this, resultSet); - } - return resultSet.getResultSetRaw().previous(); - } - - @Override - public void resultSet_setFetchDirection(ResultSetProxy resultSet, int direction) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_setFetchDirection(this, resultSet, direction); - return; - } - resultSet.getResultSetRaw().setFetchDirection(direction); - } - - @Override - public int resultSet_getFetchDirection(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getFetchDirection(this, resultSet); - } - return resultSet.getResultSetRaw().getFetchDirection(); - } - - @Override - public void resultSet_setFetchSize(ResultSetProxy resultSet, int rows) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_setFetchSize(this, resultSet, rows); - return; - } - resultSet.getResultSetRaw().setFetchSize(rows); - } - - @Override - public int resultSet_getFetchSize(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getFetchSize(this, resultSet); - } - return resultSet.getResultSetRaw().getFetchSize(); - } - - @Override - public int resultSet_getType(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getType(this, resultSet); - } - return resultSet.getResultSetRaw().getType(); - } - - @Override - public int resultSet_getConcurrency(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getConcurrency(this, resultSet); - } - return resultSet.getResultSetRaw().getConcurrency(); - } - - @Override - public boolean resultSet_rowUpdated(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_rowUpdated(this, resultSet); - } - return resultSet.getResultSetRaw().rowUpdated(); - } - - @Override - public boolean resultSet_rowInserted(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_rowInserted(this, resultSet); - } - return resultSet.getResultSetRaw().rowInserted(); - } - - @Override - public boolean resultSet_rowDeleted(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_rowDeleted(this, resultSet); - } - return resultSet.getResultSetRaw().rowDeleted(); - } - - @Override - public void resultSet_updateNull(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNull(this, resultSet, columnIndex); - return; - } - resultSet.getResultSetRaw().updateNull(columnIndex); - } - - @Override - public void resultSet_updateBoolean(ResultSetProxy resultSet, int columnIndex, boolean x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBoolean(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateBoolean(columnIndex, x); - } - - @Override - public void resultSet_updateByte(ResultSetProxy resultSet, int columnIndex, byte x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateByte(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateByte(columnIndex, x); - } - - @Override - public void resultSet_updateShort(ResultSetProxy resultSet, int columnIndex, short x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateShort(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateShort(columnIndex, x); - } - - @Override - public void resultSet_updateInt(ResultSetProxy resultSet, int columnIndex, int x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateInt(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateInt(columnIndex, x); - } - - @Override - public void resultSet_updateLong(ResultSetProxy resultSet, int columnIndex, long x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateLong(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateLong(columnIndex, x); - } - - @Override - public void resultSet_updateFloat(ResultSetProxy resultSet, int columnIndex, float x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateFloat(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateFloat(columnIndex, x); - } - - @Override - public void resultSet_updateDouble(ResultSetProxy resultSet, int columnIndex, double x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateDouble(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateDouble(columnIndex, x); - } - - @Override - public void resultSet_updateBigDecimal(ResultSetProxy resultSet, int columnIndex, BigDecimal x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBigDecimal(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateBigDecimal(columnIndex, x); - } - - @Override - public void resultSet_updateString(ResultSetProxy resultSet, int columnIndex, String x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateString(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateString(columnIndex, x); - } - - @Override - public void resultSet_updateBytes(ResultSetProxy resultSet, int columnIndex, byte[] x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBytes(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateBytes(columnIndex, x); - } - - @Override - public void resultSet_updateDate(ResultSetProxy resultSet, int columnIndex, java.sql.Date x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateDate(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateDate(columnIndex, x); - } - - @Override - public void resultSet_updateTime(ResultSetProxy resultSet, int columnIndex, java.sql.Time x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateTime(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateTime(columnIndex, x); - } - - @Override - public void resultSet_updateTimestamp(ResultSetProxy resultSet, int columnIndex, java.sql.Timestamp x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateTimestamp(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateTimestamp(columnIndex, x); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, int length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, - int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, int length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateObject(ResultSetProxy resultSet, int columnIndex, Object x, int scaleOrLength) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateObject(this, resultSet, columnIndex, x, scaleOrLength); - return; - } - resultSet.getResultSetRaw().updateObject(columnIndex, x, scaleOrLength); - } - - @Override - public void resultSet_updateObject(ResultSetProxy resultSet, int columnIndex, Object x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateObject(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateObject(columnIndex, x); - } - - @Override - public void resultSet_updateNull(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNull(this, resultSet, columnLabel); - return; - } - resultSet.getResultSetRaw().updateNull(columnLabel); - } - - @Override - public void resultSet_updateBoolean(ResultSetProxy resultSet, String columnLabel, boolean x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBoolean(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateBoolean(columnLabel, x); - } - - @Override - public void resultSet_updateByte(ResultSetProxy resultSet, String columnLabel, byte x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateByte(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateByte(columnLabel, x); - } - - @Override - public void resultSet_updateShort(ResultSetProxy resultSet, String columnLabel, short x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateShort(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateShort(columnLabel, x); - } - - @Override - public void resultSet_updateInt(ResultSetProxy resultSet, String columnLabel, int x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateInt(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateInt(columnLabel, x); - } - - @Override - public void resultSet_updateLong(ResultSetProxy resultSet, String columnLabel, long x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateLong(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateLong(columnLabel, x); - } - - @Override - public void resultSet_updateFloat(ResultSetProxy resultSet, String columnLabel, float x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateFloat(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateFloat(columnLabel, x); - } - - @Override - public void resultSet_updateDouble(ResultSetProxy resultSet, String columnLabel, double x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateDouble(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateDouble(columnLabel, x); - } - - @Override - public void resultSet_updateBigDecimal(ResultSetProxy resultSet, String columnLabel, BigDecimal x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBigDecimal(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateBigDecimal(columnLabel, x); - } - - @Override - public void resultSet_updateString(ResultSetProxy resultSet, String columnLabel, String x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateString(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateString(columnLabel, x); - } - - @Override - public void resultSet_updateBytes(ResultSetProxy resultSet, String columnLabel, byte x[]) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBytes(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateBytes(columnLabel, x); - } - - @Override - public void resultSet_updateDate(ResultSetProxy resultSet, String columnLabel, java.sql.Date x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateDate(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateDate(columnLabel, x); - } - - @Override - public void resultSet_updateTime(ResultSetProxy resultSet, String columnLabel, java.sql.Time x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateTime(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateTime(columnLabel, x); - } - - @Override - public void resultSet_updateTimestamp(ResultSetProxy resultSet, String columnLabel, java.sql.Timestamp x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateTimestamp(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateTimestamp(columnLabel, x); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, - int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x, length); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x, length); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, - int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x, length); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x, length); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, - int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader, length); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader, length); - } - - @Override - public void resultSet_updateObject(ResultSetProxy resultSet, String columnLabel, Object x, int scaleOrLength) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateObject(this, resultSet, columnLabel, x, scaleOrLength); - return; - } - resultSet.getResultSetRaw().updateObject(columnLabel, x, scaleOrLength); - } - - @Override - public void resultSet_updateObject(ResultSetProxy resultSet, String columnLabel, Object x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateObject(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateObject(columnLabel, x); - } - - @Override - public void resultSet_insertRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_insertRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().insertRow(); - } - - @Override - public void resultSet_updateRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().updateRow(); - } - - @Override - public void resultSet_deleteRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_deleteRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().deleteRow(); - } - - @Override - public void resultSet_refreshRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_refreshRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().refreshRow(); - } - - @Override - public void resultSet_cancelRowUpdates(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_cancelRowUpdates(this, resultSet); - return; - } - resultSet.getResultSetRaw().cancelRowUpdates(); - } - - @Override - public void resultSet_moveToInsertRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_moveToInsertRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().moveToInsertRow(); - } - - @Override - public void resultSet_moveToCurrentRow(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_moveToCurrentRow(this, resultSet); - return; - } - resultSet.getResultSetRaw().moveToCurrentRow(); - } - - @Override - public Statement resultSet_getStatement(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getStatement(this, resultSet); - } - return resultSet.getResultSetRaw().getStatement(); - } - - @Override - public Object resultSet_getObject(ResultSetProxy resultSet, int columnIndex, java.util.Map> map) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getObject(this, resultSet, columnIndex, map); - } - - Object obj = resultSet.getResultSetRaw().getObject(columnIndex, map); - - if (obj instanceof ResultSet) { - return wrap(resultSet.getStatementProxy(), (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(resultSet.getStatementProxy(), (Clob) obj); - } - - return obj; - } - - @Override - public Ref resultSet_getRef(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getRef(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getRef(columnIndex); - } - - @Override - public Blob resultSet_getBlob(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBlob(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getBlob(columnIndex); - } - - @Override - public Clob resultSet_getClob(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getClob(this, resultSet, columnIndex); - } - - Clob clob = resultSet.getResultSetRaw().getClob(columnIndex); - - return wrap(resultSet.getStatementProxy(), clob); - } - - @Override - public Array resultSet_getArray(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getArray(this, resultSet, columnIndex); - } - - Array rawArray = resultSet.getResultSetRaw().getArray(columnIndex); - - return rawArray; - } - - @Override - public Object resultSet_getObject(ResultSetProxy resultSet, String columnLabel, java.util.Map> map) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getObject(this, resultSet, columnLabel, map); - } - - Object obj = resultSet.getResultSetRaw().getObject(columnLabel, map); - - if (obj instanceof ResultSet) { - return wrap(resultSet.getStatementProxy(), (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(resultSet.getStatementProxy(), (Clob) obj); - } - - return obj; - } - - @Override - public Ref resultSet_getRef(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getRef(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getRef(columnLabel); - } - - @Override - public Blob resultSet_getBlob(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getBlob(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getBlob(columnLabel); - } - - @Override - public Clob resultSet_getClob(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getClob(this, resultSet, columnLabel); - } - - Clob clob = resultSet.getResultSetRaw().getClob(columnLabel); - - return wrap(resultSet.getStatementProxy(), clob); - } - - @Override - public Array resultSet_getArray(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getArray(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getArray(columnLabel); - } - - @Override - public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, int columnIndex, Calendar cal) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDate(this, resultSet, columnIndex, cal); - } - return resultSet.getResultSetRaw().getDate(columnIndex, cal); - } - - @Override - public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, String columnLabel, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getDate(this, resultSet, columnLabel, cal); - } - return resultSet.getResultSetRaw().getDate(columnLabel, cal); - } - - @Override - public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, int columnIndex, Calendar cal) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTime(this, resultSet, columnIndex, cal); - } - return resultSet.getResultSetRaw().getTime(columnIndex, cal); - } - - @Override - public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, String columnLabel, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTime(this, resultSet, columnLabel, cal); - } - return resultSet.getResultSetRaw().getTime(columnLabel, cal); - } - - @Override - public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, int columnIndex, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTimestamp(this, resultSet, columnIndex, cal); - } - return resultSet.getResultSetRaw().getTimestamp(columnIndex, cal); - } - - @Override - public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, String columnLabel, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getTimestamp(this, resultSet, columnLabel, cal); - } - return resultSet.getResultSetRaw().getTimestamp(columnLabel, cal); - } - - @Override - public java.net.URL resultSet_getURL(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getURL(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getURL(columnIndex); - } - - @Override - public java.net.URL resultSet_getURL(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getURL(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getURL(columnLabel); - } - - @Override - public void resultSet_updateRef(ResultSetProxy resultSet, int columnIndex, java.sql.Ref x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateRef(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateRef(columnIndex, x); - } - - @Override - public void resultSet_updateRef(ResultSetProxy resultSet, String columnLabel, java.sql.Ref x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateRef(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateRef(columnLabel, x); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, java.sql.Blob x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateBlob(columnIndex, x); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, java.sql.Blob x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateBlob(columnLabel, x); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, java.sql.Clob x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateClob(columnIndex, x); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, java.sql.Clob x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateClob(columnLabel, x); - } - - @Override - public void resultSet_updateArray(ResultSetProxy resultSet, int columnIndex, java.sql.Array x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateArray(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateArray(columnIndex, x); - } - - @Override - public void resultSet_updateArray(ResultSetProxy resultSet, String columnLabel, java.sql.Array x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateArray(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateArray(columnLabel, x); - } - - @Override - public RowId resultSet_getRowId(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getRowId(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getRowId(columnIndex); - } - - @Override - public RowId resultSet_getRowId(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getRowId(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getRowId(columnLabel); - } - - @Override - public void resultSet_updateRowId(ResultSetProxy resultSet, int columnIndex, RowId x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateRowId(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateRowId(columnIndex, x); - } - - @Override - public void resultSet_updateRowId(ResultSetProxy resultSet, String columnLabel, RowId x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateRowId(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateRowId(columnLabel, x); - } - - @Override - public int resultSet_getHoldability(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getHoldability(this, resultSet); - } - return resultSet.getResultSetRaw().getHoldability(); - } - - @Override - public boolean resultSet_isClosed(ResultSetProxy resultSet) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_isClosed(this, resultSet); - } - return resultSet.getResultSetRaw().isClosed(); - } - - @Override - public void resultSet_updateNString(ResultSetProxy resultSet, int columnIndex, String nString) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNString(this, resultSet, columnIndex, nString); - return; - } - resultSet.getResultSetRaw().updateNString(columnIndex, nString); - } - - @Override - public void resultSet_updateNString(ResultSetProxy resultSet, String columnLabel, String nString) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNString(this, resultSet, columnLabel, nString); - return; - } - resultSet.getResultSetRaw().updateNString(columnLabel, nString); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, NClob nClob) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, nClob); - return; - } - resultSet.getResultSetRaw().updateNClob(columnIndex, nClob); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, NClob nClob) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, nClob); - return; - } - resultSet.getResultSetRaw().updateNClob(columnLabel, nClob); - } - - @Override - public NClob resultSet_getNClob(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNClob(this, resultSet, columnIndex); - } - - NClob nclob = resultSet.getResultSetRaw().getNClob(columnIndex); - - return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); - } - - @Override - public NClob resultSet_getNClob(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNClob(this, resultSet, columnLabel); - } - - NClob nclob = resultSet.getResultSetRaw().getNClob(columnLabel); - - return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); - } - - @Override - public SQLXML resultSet_getSQLXML(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getSQLXML(this, resultSet, columnIndex); - } - - return resultSet.getResultSetRaw().getSQLXML(columnIndex); - } - - @Override - public SQLXML resultSet_getSQLXML(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getSQLXML(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getSQLXML(columnLabel); - } - - @Override - public void resultSet_updateSQLXML(ResultSetProxy resultSet, int columnIndex, SQLXML xmlObject) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateSQLXML(this, resultSet, columnIndex, xmlObject); - return; - } - resultSet.getResultSetRaw().updateSQLXML(columnIndex, xmlObject); - } - - @Override - public void resultSet_updateSQLXML(ResultSetProxy resultSet, String columnLabel, SQLXML xmlObject) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateSQLXML(this, resultSet, columnLabel, xmlObject); - return; - } - resultSet.getResultSetRaw().updateSQLXML(columnLabel, xmlObject); - } - - @Override - public String resultSet_getNString(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNString(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getNString(columnIndex); - } - - @Override - public String resultSet_getNString(ResultSetProxy resultSet, String columnLabel) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNString(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getNString(columnLabel); - } - - @Override - public java.io.Reader resultSet_getNCharacterStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNCharacterStream(this, resultSet, columnIndex); - } - return resultSet.getResultSetRaw().getNCharacterStream(columnIndex); - } - - @Override - public java.io.Reader resultSet_getNCharacterStream(ResultSetProxy resultSet, String columnLabel) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().resultSet_getNCharacterStream(this, resultSet, columnLabel); - } - return resultSet.getResultSetRaw().getNCharacterStream(columnLabel); - } - - @Override - public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateNCharacterStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnLabel, reader, length); - return; - } - resultSet.getResultSetRaw().updateNCharacterStream(columnLabel, reader, length); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x, length); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x, length); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x, length); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x, length); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x, length); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x, length); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader, length); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader, length); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, InputStream inputStream, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, inputStream, length); - return; - } - resultSet.getResultSetRaw().updateBlob(columnIndex, inputStream, length); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, InputStream inputStream, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, inputStream, length); - return; - } - resultSet.getResultSetRaw().updateBlob(columnLabel, inputStream, length); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, Reader reader, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnIndex, reader, length); - return; - } - resultSet.getResultSetRaw().updateClob(columnIndex, reader, length); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, Reader reader, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnLabel, reader, length); - return; - } - resultSet.getResultSetRaw().updateClob(columnLabel, reader, length); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, Reader reader, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, reader, length); - return; - } - resultSet.getResultSetRaw().updateNClob(columnIndex, reader, length); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, Reader reader, long length) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, reader, length); - return; - } - resultSet.getResultSetRaw().updateNClob(columnLabel, reader, length); - } - - @Override - public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateNCharacterStream(columnIndex, x); - } - - @Override - public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnLabel, reader); - return; - } - resultSet.getResultSetRaw().updateNCharacterStream(columnLabel, reader); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x); - } - - @Override - public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x); - } - - @Override - public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x); - return; - } - resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x); - } - - @Override - public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader); - return; - } - resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, InputStream inputStream) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, inputStream); - return; - } - resultSet.getResultSetRaw().updateBlob(columnIndex, inputStream); - } - - @Override - public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, InputStream inputStream) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, inputStream); - return; - } - resultSet.getResultSetRaw().updateBlob(columnLabel, inputStream); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnIndex, reader); - return; - } - resultSet.getResultSetRaw().updateClob(columnIndex, reader); - } - - @Override - public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateClob(this, resultSet, columnLabel, reader); - return; - } - resultSet.getResultSetRaw().updateClob(columnLabel, reader); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, reader); - return; - } - resultSet.getResultSetRaw().updateNClob(columnIndex, reader); - } - - @Override - public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, reader); - return; - } - resultSet.getResultSetRaw().updateNClob(columnLabel, reader); - } - - // //////////////////////////////////////// statement - @Override - public ResultSetProxy statement_executeQuery(StatementProxy statement, String sql) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeQuery(this, statement, sql); - } - - ResultSet resultSet = statement.getRawObject().executeQuery(sql); - - if (resultSet == null) { - return null; - } - - return wrap(statement, resultSet); - } - - @Override - public int statement_executeUpdate(StatementProxy statement, String sql) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeUpdate(this, statement, sql); - } - return statement.getRawObject().executeUpdate(sql); - } - - @Override - public void statement_close(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_close(this, statement); - return; - } - statement.getRawObject().close(); - } - - @Override - public int statement_getMaxFieldSize(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getMaxFieldSize(this, statement); - } - return statement.getRawObject().getMaxFieldSize(); - } - - @Override - public void statement_setMaxFieldSize(StatementProxy statement, int max) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setMaxFieldSize(this, statement, max); - return; - } - statement.getRawObject().setMaxFieldSize(max); - } - - @Override - public int statement_getMaxRows(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getMaxRows(this, statement); - } - return statement.getRawObject().getMaxRows(); - } - - @Override - public void statement_setMaxRows(StatementProxy statement, int max) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setMaxRows(this, statement, max); - return; - } - statement.getRawObject().setMaxRows(max); - } - - @Override - public void statement_setEscapeProcessing(StatementProxy statement, boolean enable) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setEscapeProcessing(this, statement, enable); - return; - } - statement.getRawObject().setEscapeProcessing(enable); - } - - @Override - public int statement_getQueryTimeout(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getQueryTimeout(this, statement); - } - return statement.getRawObject().getQueryTimeout(); - } - - @Override - public void statement_setQueryTimeout(StatementProxy statement, int seconds) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setQueryTimeout(this, statement, seconds); - return; - } - statement.getRawObject().setQueryTimeout(seconds); - } - - @Override - public void statement_cancel(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_cancel(this, statement); - return; - } - statement.getRawObject().cancel(); - } - - @Override - public SQLWarning statement_getWarnings(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getWarnings(this, statement); - } - return statement.getRawObject().getWarnings(); - } - - @Override - public void statement_clearWarnings(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_clearWarnings(this, statement); - return; - } - statement.getRawObject().clearWarnings(); - } - - @Override - public void statement_setCursorName(StatementProxy statement, String name) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setCursorName(this, statement, name); - return; - } - statement.getRawObject().setCursorName(name); - } - - @Override - public boolean statement_execute(StatementProxy statement, String sql) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_execute(this, statement, sql); - } - return statement.getRawObject().execute(sql); - } - - @Override - public ResultSetProxy statement_getResultSet(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getResultSet(this, statement); - } - - ResultSet resultSet = statement.getRawObject().getResultSet(); - - if (resultSet == null) { - return null; - } - - return wrap(statement, resultSet); - } - - @Override - public int statement_getUpdateCount(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getUpdateCount(this, statement); - } - return statement.getRawObject().getUpdateCount(); - } - - @Override - public boolean statement_getMoreResults(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getMoreResults(this, statement); - } - return statement.getRawObject().getMoreResults(); - } - - @Override - public void statement_setFetchDirection(StatementProxy statement, int direction) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setFetchDirection(this, statement, direction); - return; - } - statement.getRawObject().setFetchDirection(direction); - } - - @Override - public int statement_getFetchDirection(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getFetchDirection(this, statement); - } - return statement.getRawObject().getFetchDirection(); - } - - @Override - public void statement_setFetchSize(StatementProxy statement, int rows) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setFetchSize(this, statement, rows); - return; - } - statement.getRawObject().setFetchSize(rows); - } - - @Override - public int statement_getFetchSize(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getFetchSize(this, statement); - } - return statement.getRawObject().getFetchSize(); - } - - @Override - public int statement_getResultSetConcurrency(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getResultSetConcurrency(this, statement); - } - return statement.getRawObject().getResultSetConcurrency(); - } - - @Override - public int statement_getResultSetType(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getResultSetType(this, statement); - } - return statement.getRawObject().getResultSetType(); - } - - @Override - public void statement_addBatch(StatementProxy statement, String sql) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_addBatch(this, statement, sql); - return; - } - statement.getRawObject().addBatch(sql); - } - - @Override - public void statement_clearBatch(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_clearBatch(this, statement); - return; - } - statement.getRawObject().clearBatch(); - } - - @Override - public int[] statement_executeBatch(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeBatch(this, statement); - } - return statement.getRawObject().executeBatch(); - } - - @Override - public Connection statement_getConnection(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getConnection(this, statement); - } - return statement.getRawObject().getConnection(); - } - - @Override - public boolean statement_getMoreResults(StatementProxy statement, int current) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getMoreResults(this, statement, current); - } - return statement.getRawObject().getMoreResults(current); - } - - @Override - public ResultSetProxy statement_getGeneratedKeys(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getGeneratedKeys(this, statement); - } - - ResultSet resultSet = statement.getRawObject().getGeneratedKeys(); - return wrap(statement, resultSet); - } - - @Override - public int statement_executeUpdate(StatementProxy statement, String sql, int autoGeneratedKeys) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeUpdate(this, statement, sql, autoGeneratedKeys); - } - return statement.getRawObject().executeUpdate(sql, autoGeneratedKeys); - } - - @Override - public int statement_executeUpdate(StatementProxy statement, String sql, int columnIndexes[]) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeUpdate(this, statement, sql, columnIndexes); - } - return statement.getRawObject().executeUpdate(sql, columnIndexes); - } - - @Override - public int statement_executeUpdate(StatementProxy statement, String sql, String columnNames[]) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_executeUpdate(this, statement, sql, columnNames); - } - return statement.getRawObject().executeUpdate(sql, columnNames); - } - - @Override - public boolean statement_execute(StatementProxy statement, String sql, int autoGeneratedKeys) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_execute(this, statement, sql, autoGeneratedKeys); - } - return statement.getRawObject().execute(sql, autoGeneratedKeys); - } - - @Override - public boolean statement_execute(StatementProxy statement, String sql, int columnIndexes[]) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_execute(this, statement, sql, columnIndexes); - } - return statement.getRawObject().execute(sql, columnIndexes); - } - - @Override - public boolean statement_execute(StatementProxy statement, String sql, String columnNames[]) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_execute(this, statement, sql, columnNames); - } - return statement.getRawObject().execute(sql, columnNames); - } - - @Override - public int statement_getResultSetHoldability(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_getResultSetHoldability(this, statement); - } - return statement.getRawObject().getResultSetHoldability(); - } - - @Override - public boolean statement_isClosed(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_isClosed(this, statement); - } - return statement.getRawObject().isClosed(); - } - - @Override - public void statement_setPoolable(StatementProxy statement, boolean poolable) throws SQLException { - if (this.pos < filterSize) { - nextFilter().statement_setPoolable(this, statement, poolable); - return; - } - statement.getRawObject().setPoolable(poolable); - } - - @Override - public boolean statement_isPoolable(StatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().statement_isPoolable(this, statement); - } - return statement.getRawObject().isPoolable(); - } - - // //////////////// - - @Override - public ResultSetProxy preparedStatement_executeQuery(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().preparedStatement_executeQuery(this, statement); - } - - ResultSet resultSet = statement.getRawObject().executeQuery(); - return wrap(statement, resultSet); - } - - @Override - public int preparedStatement_executeUpdate(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().preparedStatement_executeUpdate(this, statement); - } - return statement.getRawObject().executeUpdate(); - } - - @Override - public void preparedStatement_setNull(PreparedStatementProxy statement, int parameterIndex, int sqlType) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNull(this, statement, parameterIndex, sqlType); - return; - } - statement.getRawObject().setNull(parameterIndex, sqlType); - } - - @Override - public void preparedStatement_setBoolean(PreparedStatementProxy statement, int parameterIndex, boolean x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBoolean(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setBoolean(parameterIndex, x); - } - - @Override - public void preparedStatement_setByte(PreparedStatementProxy statement, int parameterIndex, byte x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setByte(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setByte(parameterIndex, x); - } - - @Override - public void preparedStatement_setShort(PreparedStatementProxy statement, int parameterIndex, short x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setShort(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setShort(parameterIndex, x); - } - - @Override - public void preparedStatement_setInt(PreparedStatementProxy statement, int parameterIndex, int x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setInt(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setInt(parameterIndex, x); - } - - @Override - public void preparedStatement_setLong(PreparedStatementProxy statement, int parameterIndex, long x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setLong(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setLong(parameterIndex, x); - } - - @Override - public void preparedStatement_setFloat(PreparedStatementProxy statement, int parameterIndex, float x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setFloat(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setFloat(parameterIndex, x); - } - - @Override - public void preparedStatement_setDouble(PreparedStatementProxy statement, int parameterIndex, double x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setDouble(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setDouble(parameterIndex, x); - } - - @Override - public void preparedStatement_setBigDecimal(PreparedStatementProxy statement, int parameterIndex, BigDecimal x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBigDecimal(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setBigDecimal(parameterIndex, x); - } - - @Override - public void preparedStatement_setString(PreparedStatementProxy statement, int parameterIndex, String x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setString(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setString(parameterIndex, x); - } - - @Override - public void preparedStatement_setBytes(PreparedStatementProxy statement, int parameterIndex, byte x[]) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBytes(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setBytes(parameterIndex, x); - } - - @Override - public void preparedStatement_setDate(PreparedStatementProxy statement, int parameterIndex, java.sql.Date x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setDate(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setDate(parameterIndex, x); - } - - @Override - public void preparedStatement_setTime(PreparedStatementProxy statement, int parameterIndex, java.sql.Time x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setTime(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setTime(parameterIndex, x); - } - - @Override - public void preparedStatement_setTimestamp(PreparedStatementProxy statement, int parameterIndex, - java.sql.Timestamp x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setTimestamp(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setTimestamp(parameterIndex, x); - } - - @Override - public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x, length); - return; - } - statement.getRawObject().setAsciiStream(parameterIndex, x, length); - } - - @SuppressWarnings("deprecation") - @Override - public void preparedStatement_setUnicodeStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setUnicodeStream(this, statement, parameterIndex, x, length); - return; - } - statement.getRawObject().setUnicodeStream(parameterIndex, x, length); - } - - @Override - public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x, length); - return; - } - statement.getRawObject().setBinaryStream(parameterIndex, x, length); - } - - @Override - public void preparedStatement_clearParameters(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_clearParameters(this, statement); - return; - } - statement.getRawObject().clearParameters(); - } - - @Override - public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x, - int targetSqlType) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x, targetSqlType); - return; - } - statement.getRawObject().setObject(parameterIndex, x, targetSqlType); - } - - @Override - public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setObject(parameterIndex, x); - } - - @Override - public boolean preparedStatement_execute(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().preparedStatement_execute(this, statement); - } - return statement.getRawObject().execute(); - } - - @Override - public void preparedStatement_addBatch(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_addBatch(this, statement); - return; - } - statement.getRawObject().addBatch(); - } - - @Override - public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, - java.io.Reader reader, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader, length); - return; - } - statement.getRawObject().setCharacterStream(parameterIndex, reader, length); - } - - @Override - public void preparedStatement_setRef(PreparedStatementProxy statement, int parameterIndex, Ref x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setRef(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setRef(parameterIndex, x); - } - - @Override - public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, Blob x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setBlob(parameterIndex, x); - } - - @Override - public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Clob x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setClob(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setClob(parameterIndex, x); - } - - @Override - public void preparedStatement_setArray(PreparedStatementProxy statement, int parameterIndex, Array x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setArray(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setArray(parameterIndex, x); - } - - @Override - public ResultSetMetaData preparedStatement_getMetaData(PreparedStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().preparedStatement_getMetaData(this, statement); - } - return statement.getRawObject().getMetaData(); - } - - @Override - public void preparedStatement_setDate(PreparedStatementProxy statement, int parameterIndex, java.sql.Date x, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setDate(this, statement, parameterIndex, x, cal); - return; - } - statement.getRawObject().setDate(parameterIndex, x, cal); - } - - @Override - public void preparedStatement_setTime(PreparedStatementProxy statement, int parameterIndex, java.sql.Time x, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setTime(this, statement, parameterIndex, x, cal); - return; - } - statement.getRawObject().setTime(parameterIndex, x, cal); - } - - @Override - public void preparedStatement_setTimestamp(PreparedStatementProxy statement, int parameterIndex, - java.sql.Timestamp x, Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setTimestamp(this, statement, parameterIndex, x, cal); - return; - } - statement.getRawObject().setTimestamp(parameterIndex, x, cal); - } - - @Override - public void preparedStatement_setNull(PreparedStatementProxy statement, int parameterIndex, int sqlType, - String typeName) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNull(this, statement, parameterIndex, sqlType, typeName); - return; - } - statement.getRawObject().setNull(parameterIndex, sqlType, typeName); - } - - @Override - public void preparedStatement_setURL(PreparedStatementProxy statement, int parameterIndex, java.net.URL x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setURL(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setURL(parameterIndex, x); - } - - @Override - public ParameterMetaData preparedStatement_getParameterMetaData(PreparedStatementProxy statement) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().preparedStatement_getParameterMetaData(this, statement); - } - return statement.getRawObject().getParameterMetaData(); - } - - @Override - public void preparedStatement_setRowId(PreparedStatementProxy statement, int parameterIndex, RowId x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setRowId(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setRowId(parameterIndex, x); - } - - @Override - public void preparedStatement_setNString(PreparedStatementProxy statement, int parameterIndex, String value) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNString(this, statement, parameterIndex, value); - return; - } - statement.getRawObject().setNString(parameterIndex, value); - } - - @Override - public void preparedStatement_setNCharacterStream(PreparedStatementProxy statement, int parameterIndex, - Reader value, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNCharacterStream(this, statement, parameterIndex, value, length); - return; - } - statement.getRawObject().setNCharacterStream(parameterIndex, value, length); - } - - @Override - public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, NClob value) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, value); - return; - } - statement.getRawObject().setNClob(parameterIndex, value); - } - - @Override - public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setClob(this, statement, parameterIndex, reader, length); - return; - } - statement.getRawObject().setClob(parameterIndex, reader, length); - } - - @Override - public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, - InputStream inputStream, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, inputStream, length); - return; - } - statement.getRawObject().setBlob(parameterIndex, inputStream, length); - } - - @Override - public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, reader, length); - return; - } - statement.getRawObject().setNClob(parameterIndex, reader, length); - } - - @Override - public void preparedStatement_setSQLXML(PreparedStatementProxy statement, int parameterIndex, SQLXML xmlObject) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setSQLXML(this, statement, parameterIndex, xmlObject); - return; - } - statement.getRawObject().setSQLXML(parameterIndex, xmlObject); - } - - @Override - public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x, - int targetSqlType, int scaleOrLength) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x, targetSqlType, scaleOrLength); - return; - } - statement.getRawObject().setObject(parameterIndex, x, targetSqlType, scaleOrLength); - } - - @Override - public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x, length); - return; - } - statement.getRawObject().setAsciiStream(parameterIndex, x, length); - } - - @Override - public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x, length); - return; - } - statement.getRawObject().setBinaryStream(parameterIndex, x, length); - } - - @Override - public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, - java.io.Reader reader, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader, length); - return; - } - statement.getRawObject().setCharacterStream(parameterIndex, reader, length); - } - - @Override - public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setAsciiStream(parameterIndex, x); - } - - @Override - public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, - java.io.InputStream x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x); - return; - } - statement.getRawObject().setBinaryStream(parameterIndex, x); - } - - @Override - public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, - java.io.Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader); - return; - } - statement.getRawObject().setCharacterStream(parameterIndex, reader); - } - - @Override - public void preparedStatement_setNCharacterStream(PreparedStatementProxy statement, int parameterIndex, Reader value) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNCharacterStream(this, statement, parameterIndex, value); - return; - } - statement.getRawObject().setNCharacterStream(parameterIndex, value); - } - - @Override - public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setClob(this, statement, parameterIndex, reader); - return; - } - statement.getRawObject().setClob(parameterIndex, reader); - } - - @Override - public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, InputStream inputStream) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, inputStream); - return; - } - statement.getRawObject().setBlob(parameterIndex, inputStream); - } - - @Override - public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, reader); - return; - } - statement.getRawObject().setNClob(parameterIndex, reader); - } - - // ///////////////////////////////////// - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, int sqlType) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType); - return; - } - statement.getRawObject().registerOutParameter(parameterIndex, sqlType); - } - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, - int sqlType, int scale) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType, scale); - return; - } - statement.getRawObject().registerOutParameter(parameterIndex, sqlType, scale); - } - - @Override - public boolean callableStatement_wasNull(CallableStatementProxy statement) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_wasNull(this, statement); - } - return statement.getRawObject().wasNull(); - } - - @Override - public String callableStatement_getString(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getString(this, statement, parameterIndex); - } - return statement.getRawObject().getString(parameterIndex); - } - - @Override - public boolean callableStatement_getBoolean(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBoolean(this, statement, parameterIndex); - } - return statement.getRawObject().getBoolean(parameterIndex); - } - - @Override - public byte callableStatement_getByte(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getByte(this, statement, parameterIndex); - } - return statement.getRawObject().getByte(parameterIndex); - } - - @Override - public short callableStatement_getShort(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getShort(this, statement, parameterIndex); - } - return statement.getRawObject().getShort(parameterIndex); - } - - @Override - public int callableStatement_getInt(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getInt(this, statement, parameterIndex); - } - return statement.getRawObject().getInt(parameterIndex); - } - - @Override - public long callableStatement_getLong(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getLong(this, statement, parameterIndex); - } - return statement.getRawObject().getLong(parameterIndex); - } - - @Override - public float callableStatement_getFloat(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getFloat(this, statement, parameterIndex); - } - return statement.getRawObject().getFloat(parameterIndex); - } - - @Override - public double callableStatement_getDouble(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDouble(this, statement, parameterIndex); - } - return statement.getRawObject().getDouble(parameterIndex); - } - - @SuppressWarnings("deprecation") - @Override - public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, int parameterIndex, int scale) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBigDecimal(this, statement, parameterIndex, scale); - } - return statement.getRawObject().getBigDecimal(parameterIndex, scale); - } - - @Override - public byte[] callableStatement_getBytes(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBytes(this, statement, parameterIndex); - } - return statement.getRawObject().getBytes(parameterIndex); - } - - @Override - public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDate(this, statement, parameterIndex); - } - return statement.getRawObject().getDate(parameterIndex); - } - - @Override - public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTime(this, statement, parameterIndex); - } - return statement.getRawObject().getTime(parameterIndex); - } - - @Override - public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTimestamp(this, statement, parameterIndex); - } - return statement.getRawObject().getTimestamp(parameterIndex); - } - - @Override - public Object callableStatement_getObject(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getObject(this, statement, parameterIndex); - } - - Object obj = statement.getRawObject().getObject(parameterIndex); - - if (obj instanceof ResultSet) { - return wrap(statement, (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(statement, (Clob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(CallableStatementProxy statement, int parameterIndex, - java.util.Map> map) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getObject(this, statement, parameterIndex, map); - } - - Object obj = statement.getRawObject().getObject(parameterIndex, map); - - if (obj instanceof ResultSet) { - return wrap(statement, (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(statement, (Clob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getObject(this, statement, parameterName); - } - - Object obj = statement.getRawObject().getObject(parameterName); - - if (obj instanceof ResultSet) { - return wrap(statement, (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(statement, (Clob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName, - java.util.Map> map) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getObject(this, statement, parameterName, map); - } - - Object obj = statement.getRawObject().getObject(parameterName, map); - - if (obj instanceof ResultSet) { - return wrap(statement, (ResultSet) obj); - } - - if (obj instanceof Clob) { - return wrap(statement, (Clob) obj); - } - - return obj; - } - - @Override - public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBigDecimal(this, statement, parameterIndex); - } - return statement.getRawObject().getBigDecimal(parameterIndex); - } - - @Override - public Ref callableStatement_getRef(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getRef(this, statement, parameterIndex); - } - return statement.getRawObject().getRef(parameterIndex); - } - - @Override - public Blob callableStatement_getBlob(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBlob(this, statement, parameterIndex); - } - return statement.getRawObject().getBlob(parameterIndex); - } - - @Override - public Clob callableStatement_getClob(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getClob(this, statement, parameterIndex); - } - - Clob clob = statement.getRawObject().getClob(parameterIndex); - - return wrap(statement, clob); - } - - @Override - public Array callableStatement_getArray(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getArray(this, statement, parameterIndex); - } - return statement.getRawObject().getArray(parameterIndex); - } - - @Override - public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, int parameterIndex, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDate(this, statement, parameterIndex, cal); - } - return statement.getRawObject().getDate(parameterIndex, cal); - } - - @Override - public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, int parameterIndex, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTime(this, statement, parameterIndex, cal); - } - return statement.getRawObject().getTime(parameterIndex, cal); - } - - @Override - public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, int parameterIndex, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTimestamp(this, statement, parameterIndex, cal); - } - return statement.getRawObject().getTimestamp(parameterIndex, cal); - } - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, - int sqlType, String typeName) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType, typeName); - return; - } - statement.getRawObject().registerOutParameter(parameterIndex, sqlType, typeName); - } - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, - int sqlType) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType); - return; - } - statement.getRawObject().registerOutParameter(parameterName, sqlType); - } - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, - int sqlType, int scale) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType, scale); - return; - } - statement.getRawObject().registerOutParameter(parameterName, sqlType, scale); - } - - @Override - public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, - int sqlType, String typeName) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType, typeName); - return; - } - statement.getRawObject().registerOutParameter(parameterName, sqlType, typeName); - } - - @Override - public java.net.URL callableStatement_getURL(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getURL(this, statement, parameterIndex); - } - return statement.getRawObject().getURL(parameterIndex); - } - - @Override - public void callableStatement_setURL(CallableStatementProxy statement, String parameterName, java.net.URL val) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setURL(this, statement, parameterName, val); - return; - } - statement.getRawObject().setURL(parameterName, val); - } - - @Override - public void callableStatement_setNull(CallableStatementProxy statement, String parameterName, int sqlType) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNull(this, statement, parameterName, sqlType); - return; - } - statement.getRawObject().setNull(parameterName, sqlType); - } - - @Override - public void callableStatement_setBoolean(CallableStatementProxy statement, String parameterName, boolean x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBoolean(this, statement, parameterName, x); - return; - } - statement.getRawObject().setBoolean(parameterName, x); - } - - @Override - public void callableStatement_setByte(CallableStatementProxy statement, String parameterName, byte x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setByte(this, statement, parameterName, x); - } - statement.getRawObject().setByte(parameterName, x); - } - - @Override - public void callableStatement_setShort(CallableStatementProxy statement, String parameterName, short x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setShort(this, statement, parameterName, x); - return; - } - statement.getRawObject().setShort(parameterName, x); - } - - @Override - public void callableStatement_setInt(CallableStatementProxy statement, String parameterName, int x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setInt(this, statement, parameterName, x); - return; - } - statement.getRawObject().setInt(parameterName, x); - } - - @Override - public void callableStatement_setLong(CallableStatementProxy statement, String parameterName, long x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setLong(this, statement, parameterName, x); - return; - } - statement.getRawObject().setLong(parameterName, x); - } - - @Override - public void callableStatement_setFloat(CallableStatementProxy statement, String parameterName, float x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setFloat(this, statement, parameterName, x); - return; - } - statement.getRawObject().setFloat(parameterName, x); - } - - @Override - public void callableStatement_setDouble(CallableStatementProxy statement, String parameterName, double x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setDouble(this, statement, parameterName, x); - return; - } - statement.getRawObject().setDouble(parameterName, x); - } - - @Override - public void callableStatement_setBigDecimal(CallableStatementProxy statement, String parameterName, BigDecimal x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBigDecimal(this, statement, parameterName, x); - return; - } - statement.getRawObject().setBigDecimal(parameterName, x); - } - - @Override - public void callableStatement_setString(CallableStatementProxy statement, String parameterName, String x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setString(this, statement, parameterName, x); - return; - } - statement.getRawObject().setString(parameterName, x); - } - - @Override - public void callableStatement_setBytes(CallableStatementProxy statement, String parameterName, byte x[]) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBytes(this, statement, parameterName, x); - return; - } - statement.getRawObject().setBytes(parameterName, x); - } - - @Override - public void callableStatement_setDate(CallableStatementProxy statement, String parameterName, java.sql.Date x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setDate(this, statement, parameterName, x); - return; - } - statement.getRawObject().setDate(parameterName, x); - } - - @Override - public void callableStatement_setTime(CallableStatementProxy statement, String parameterName, java.sql.Time x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setTime(this, statement, parameterName, x); - return; - } - statement.getRawObject().setTime(parameterName, x); - } - - @Override - public void callableStatement_setTimestamp(CallableStatementProxy statement, String parameterName, - java.sql.Timestamp x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setTimestamp(this, statement, parameterName, x); - return; - } - statement.getRawObject().setTimestamp(parameterName, x); - } - - @Override - public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x, length); - return; - } - statement.getRawObject().setAsciiStream(parameterName, x, length); - } - - @Override - public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x, length); - return; - } - statement.getRawObject().setBinaryStream(parameterName, x, length); - } - - @Override - public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, - int targetSqlType, int scale) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType, scale); - return; - } - statement.getRawObject().setObject(parameterName, x, targetSqlType, scale); - } - - @Override - public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, - int targetSqlType) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType); - return; - } - statement.getRawObject().setObject(parameterName, x, targetSqlType); - } - - @Override - public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setObject(this, statement, parameterName, x); - return; - } - statement.getRawObject().setObject(parameterName, x); - } - - @Override - public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, - java.io.Reader reader, int length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader, length); - return; - } - statement.getRawObject().setCharacterStream(parameterName, reader, length); - } - - @Override - public void callableStatement_setDate(CallableStatementProxy statement, String parameterName, java.sql.Date x, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setDate(this, statement, parameterName, x, cal); - return; - } - statement.getRawObject().setDate(parameterName, x, cal); - } - - @Override - public void callableStatement_setTime(CallableStatementProxy statement, String parameterName, java.sql.Time x, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setTime(this, statement, parameterName, x, cal); - return; - } - statement.getRawObject().setTime(parameterName, x, cal); - } - - @Override - public void callableStatement_setTimestamp(CallableStatementProxy statement, String parameterName, - java.sql.Timestamp x, Calendar cal) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setTimestamp(this, statement, parameterName, x, cal); - return; - } - statement.getRawObject().setTimestamp(parameterName, x, cal); - } - - @Override - public void callableStatement_setNull(CallableStatementProxy statement, String parameterName, int sqlType, - String typeName) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNull(this, statement, parameterName, sqlType, typeName); - return; - } - statement.getRawObject().setNull(parameterName, sqlType, typeName); - } - - @Override - public String callableStatement_getString(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getString(this, statement, parameterName); - } - return statement.getRawObject().getString(parameterName); - } - - @Override - public boolean callableStatement_getBoolean(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBoolean(this, statement, parameterName); - } - return statement.getRawObject().getBoolean(parameterName); - } - - @Override - public byte callableStatement_getByte(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getByte(this, statement, parameterName); - } - return statement.getRawObject().getByte(parameterName); - } - - @Override - public short callableStatement_getShort(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getShort(this, statement, parameterName); - } - return statement.getRawObject().getShort(parameterName); - } - - @Override - public int callableStatement_getInt(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getInt(this, statement, parameterName); - } - return statement.getRawObject().getInt(parameterName); - } - - @Override - public long callableStatement_getLong(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getLong(this, statement, parameterName); - } - return statement.getRawObject().getLong(parameterName); - } - - @Override - public float callableStatement_getFloat(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getFloat(this, statement, parameterName); - } - return statement.getRawObject().getFloat(parameterName); - } - - @Override - public double callableStatement_getDouble(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDouble(this, statement, parameterName); - } - return statement.getRawObject().getDouble(parameterName); - } - - @Override - public byte[] callableStatement_getBytes(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBytes(this, statement, parameterName); - } - return statement.getRawObject().getBytes(parameterName); - } - - @Override - public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDate(this, statement, parameterName); - } - return statement.getRawObject().getDate(parameterName); - } - - @Override - public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTime(this, statement, parameterName); - } - return statement.getRawObject().getTime(parameterName); - } - - @Override - public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTimestamp(this, statement, parameterName); - } - return statement.getRawObject().getTimestamp(parameterName); - } - - @Override - public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBigDecimal(this, statement, parameterName); - } - return statement.getRawObject().getBigDecimal(parameterName); - } - - @Override - public Ref callableStatement_getRef(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getRef(this, statement, parameterName); - } - return statement.getRawObject().getRef(parameterName); - } - - @Override - public Blob callableStatement_getBlob(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getBlob(this, statement, parameterName); - } - return statement.getRawObject().getBlob(parameterName); - } - - @Override - public Clob callableStatement_getClob(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getClob(this, statement, parameterName); - } - - Clob clob = statement.getRawObject().getClob(parameterName); - - return wrap(statement, clob); - } - - @Override - public Array callableStatement_getArray(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getArray(this, statement, parameterName); - } - return statement.getRawObject().getArray(parameterName); - } - - @Override - public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, String parameterName, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getDate(this, statement, parameterName, cal); - } - return statement.getRawObject().getDate(parameterName, cal); - } - - @Override - public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, String parameterName, Calendar cal) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTime(this, statement, parameterName, cal); - } - return statement.getRawObject().getTime(parameterName, cal); - } - - @Override - public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, String parameterName, - Calendar cal) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getTimestamp(this, statement, parameterName, cal); - } - return statement.getRawObject().getTimestamp(parameterName, cal); - } - - @Override - public java.net.URL callableStatement_getURL(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getURL(this, statement, parameterName); - } - return statement.getRawObject().getURL(parameterName); - } - - @Override - public RowId callableStatement_getRowId(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getRowId(this, statement, parameterIndex); - } - return statement.getRawObject().getRowId(parameterIndex); - } - - @Override - public RowId callableStatement_getRowId(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getRowId(this, statement, parameterName); - } - return statement.getRawObject().getRowId(parameterName); - } - - @Override - public void callableStatement_setRowId(CallableStatementProxy statement, String parameterName, RowId x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setRowId(this, statement, parameterName, x); - return; - } - statement.getRawObject().setRowId(parameterName, x); - } - - @Override - public void callableStatement_setNString(CallableStatementProxy statement, String parameterName, String value) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNString(this, statement, parameterName, value); - return; - } - statement.getRawObject().setNString(parameterName, value); - } - - @Override - public void callableStatement_setNCharacterStream(CallableStatementProxy statement, String parameterName, - Reader value, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNCharacterStream(this, statement, parameterName, value, length); - return; - } - statement.getRawObject().setNCharacterStream(parameterName, value, length); - } - - @Override - public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, NClob value) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNClob(this, statement, parameterName, value); - return; - } - statement.getRawObject().setNClob(parameterName, value); - } - - @Override - public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setClob(this, statement, parameterName, reader, length); - return; - } - statement.getRawObject().setClob(parameterName, reader, length); - } - - @Override - public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, - InputStream inputStream, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBlob(this, statement, parameterName, inputStream, length); - return; - } - statement.getRawObject().setBlob(parameterName, inputStream, length); - } - - @Override - public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, Reader reader, - long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNClob(this, statement, parameterName, reader, length); - return; - } - statement.getRawObject().setNClob(parameterName, reader, length); - } - - @Override - public NClob callableStatement_getNClob(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNClob(this, statement, parameterIndex); - } - - NClob nclob = statement.getRawObject().getNClob(parameterIndex); - - return wrap(statement.getConnectionProxy(), nclob); - } - - @Override - public NClob callableStatement_getNClob(CallableStatementProxy statement, String parameterName) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNClob(this, statement, parameterName); - } - - NClob nclob = statement.getRawObject().getNClob(parameterName); - - return wrap(statement.getConnectionProxy(), nclob); - } - - @Override - public void callableStatement_setSQLXML(CallableStatementProxy statement, String parameterName, SQLXML xmlObject) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setSQLXML(this, statement, parameterName, xmlObject); - return; - } - statement.getRawObject().setSQLXML(parameterName, xmlObject); - } - - @Override - public SQLXML callableStatement_getSQLXML(CallableStatementProxy statement, int parameterIndex) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getSQLXML(this, statement, parameterIndex); - } - return statement.getRawObject().getSQLXML(parameterIndex); - } - - @Override - public SQLXML callableStatement_getSQLXML(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getSQLXML(this, statement, parameterName); - } - return statement.getRawObject().getSQLXML(parameterName); - } - - @Override - public String callableStatement_getNString(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNString(this, statement, parameterIndex); - } - return statement.getRawObject().getNString(parameterIndex); - } - - @Override - public String callableStatement_getNString(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNString(this, statement, parameterName); - } - return statement.getRawObject().getNString(parameterName); - } - - @Override - public java.io.Reader callableStatement_getNCharacterStream(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNCharacterStream(this, statement, parameterIndex); - } - return statement.getRawObject().getNCharacterStream(parameterIndex); - } - - @Override - public java.io.Reader callableStatement_getNCharacterStream(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getNCharacterStream(this, statement, parameterName); - } - return statement.getRawObject().getNCharacterStream(parameterName); - } - - @Override - public java.io.Reader callableStatement_getCharacterStream(CallableStatementProxy statement, int parameterIndex) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getCharacterStream(this, statement, parameterIndex); - } - return statement.getRawObject().getCharacterStream(parameterIndex); - } - - @Override - public java.io.Reader callableStatement_getCharacterStream(CallableStatementProxy statement, String parameterName) - throws SQLException { - if (this.pos < filterSize) { - return nextFilter().callableStatement_getCharacterStream(this, statement, parameterName); - } - return statement.getRawObject().getCharacterStream(parameterName); - } - - @Override - public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, Blob x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBlob(this, statement, parameterName, x); - return; - } - statement.getRawObject().setBlob(parameterName, x); - } - - @Override - public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Clob x) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setClob(this, statement, parameterName, x); - return; - } - statement.getRawObject().setClob(parameterName, x); - } - - @Override - public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x, length); - return; - } - statement.getRawObject().setAsciiStream(parameterName, x, length); - } - - @Override - public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x, length); - return; - } - statement.getRawObject().setBinaryStream(parameterName, x, length); - } - - @Override - public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, - java.io.Reader reader, long length) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader, length); - return; - } - statement.getRawObject().setCharacterStream(parameterName, reader, length); - } - - @Override - public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x); - return; - } - statement.getRawObject().setAsciiStream(parameterName, x); - } - - @Override - public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, - java.io.InputStream x) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x); - return; - } - statement.getRawObject().setBinaryStream(parameterName, x); - } - - @Override - public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, - java.io.Reader reader) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader); - return; - } - statement.getRawObject().setCharacterStream(parameterName, reader); - } - - @Override - public void callableStatement_setNCharacterStream(CallableStatementProxy statement, String parameterName, - Reader value) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNCharacterStream(this, statement, parameterName, value); - return; - } - statement.getRawObject().setNCharacterStream(parameterName, value); - } - - @Override - public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setClob(this, statement, parameterName, reader); - return; - } - statement.getRawObject().setClob(parameterName, reader); - } - - @Override - public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, - InputStream inputStream) throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setBlob(this, statement, parameterName, inputStream); - return; - } - statement.getRawObject().setBlob(parameterName, inputStream); - } - - @Override - public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, Reader reader) - throws SQLException { - if (this.pos < filterSize) { - nextFilter().callableStatement_setNClob(this, statement, parameterName, reader); - return; - } - statement.getRawObject().setNClob(parameterName, reader); - } - - @Override - public long clob_length(ClobProxy clob) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_length(this, clob); - } - return clob.getRawClob().length(); - } - - @Override - public String clob_getSubString(ClobProxy clob, long pos, int length) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_getSubString(this, clob, pos, length); - } - return clob.getRawClob().getSubString(pos, length); - } - - @Override - public java.io.Reader clob_getCharacterStream(ClobProxy clob) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_getCharacterStream(this, clob); - } - return clob.getRawClob().getCharacterStream(); - } - - @Override - public java.io.InputStream clob_getAsciiStream(ClobProxy clob) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_getAsciiStream(this, clob); - } - return clob.getRawClob().getAsciiStream(); - } - - @Override - public long clob_position(ClobProxy clob, String searchstr, long start) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_position(this, clob, searchstr, start); - } - return clob.getRawClob().position(searchstr, start); - } - - @Override - public long clob_position(ClobProxy clob, Clob searchstr, long start) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_position(this, clob, searchstr, start); - } - return clob.getRawClob().position(searchstr, start); - } - - @Override - public int clob_setString(ClobProxy clob, long pos, String str) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_setString(this, clob, pos, str); - } - return clob.getRawClob().setString(pos, str); - } - - @Override - public int clob_setString(ClobProxy clob, long pos, String str, int offset, int len) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_setString(this, clob, pos, str, offset, len); - } - return clob.getRawClob().setString(pos, str, offset, len); - } - - @Override - public java.io.OutputStream clob_setAsciiStream(ClobProxy clob, long pos) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_setAsciiStream(this, clob, pos); - } - return clob.getRawClob().setAsciiStream(pos); - } - - @Override - public java.io.Writer clob_setCharacterStream(ClobProxy clob, long pos) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_setCharacterStream(this, clob, pos); - } - return clob.getRawClob().setCharacterStream(pos); - } - - @Override - public void clob_truncate(ClobProxy clob, long len) throws SQLException { - if (this.pos < filterSize) { - nextFilter().clob_truncate(this, clob, len); - return; - } - clob.getRawClob().truncate(len); - } - - @Override - public void clob_free(ClobProxy clob) throws SQLException { - if (this.pos < filterSize) { - nextFilter().clob_free(this, clob); - return; - } - clob.getRawClob().free(); - } - - @Override - public Reader clob_getCharacterStream(ClobProxy clob, long pos, long length) throws SQLException { - if (this.pos < filterSize) { - return nextFilter().clob_getCharacterStream(this, clob, pos, length); - } - return clob.getRawClob().getCharacterStream(pos, length); - } - - // //////////// - - public ConnectionProxy wrap(Connection connection, Properties info) { - if (connection == null) { - return null; - } - - return new ConnectionProxyImpl(dataSource, connection, info, dataSource.createConnectionId()); - } - - public StatementProxy wrap(ConnectionProxy connection, Statement statement) { - if (statement == null) { - return null; - } - - return new StatementProxyImpl(connection, statement, dataSource.createStatementId()); - } - - public PreparedStatementProxy wrap(ConnectionProxy connection, PreparedStatement statement, String sql) { - if (statement == null) { - return null; - } - - return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId()); - } - - public CallableStatementProxy wrap(ConnectionProxy connection, CallableStatement statement, String sql) { - if (statement == null) { - return null; - } - - return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId()); - } - - public ResultSetProxy wrap(StatementProxy statement, ResultSet resultSet) { - if (resultSet == null) { - return null; - } - - return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(), - statement.getLastExecuteSql()); - } - - public ClobProxy wrap(ConnectionProxy conn, Clob clob) { - if (clob == null) { - return null; - } - - if (clob instanceof NClob) { - return wrap(conn, (NClob) clob); - } - - return new ClobProxyImpl(dataSource, conn, clob); - } - - public NClobProxy wrap(ConnectionProxy conn, NClob clob) { - if (clob == null) { - return null; - } - - return new NClobProxyImpl(dataSource, conn, clob); - } - - public ClobProxy wrap(StatementProxy stmt, Clob clob) { - if (clob == null) { - return null; - } - - if (clob instanceof NClob) { - return wrap(stmt, (NClob) clob); - } - - return new ClobProxyImpl(dataSource, stmt.getConnectionProxy(), clob); - } - - public NClobProxy wrap(StatementProxy stmt, NClob nclob) { - if (nclob == null) { - return null; - } - - return new NClobProxyImpl(dataSource, stmt.getConnectionProxy(), nclob); - } - - @Override - public void dataSource_recycle(DruidPooledConnection connection) throws SQLException { - if (this.pos < filterSize) { - nextFilter().dataSource_releaseConnection(this, connection); - return; - } - - connection.recycle(); - } - - @Override - public DruidPooledConnection dataSource_connect(DruidDataSource dataSource, long maxWaitMillis) throws SQLException { - if (this.pos < filterSize) { - DruidPooledConnection conn = nextFilter().dataSource_getConnection(this, dataSource, maxWaitMillis); - return conn; - } - - return dataSource.getConnectionDirect(maxWaitMillis); - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.filter; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.Driver; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.Statement; +import java.sql.Struct; +import java.sql.Wrapper; +import java.util.Calendar; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.pool.DruidPooledConnection; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; +import com.alibaba.druid.proxy.jdbc.ClobProxy; +import com.alibaba.druid.proxy.jdbc.ClobProxyImpl; +import com.alibaba.druid.proxy.jdbc.ConnectionProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; +import com.alibaba.druid.proxy.jdbc.DataSourceProxy; +import com.alibaba.druid.proxy.jdbc.NClobProxy; +import com.alibaba.druid.proxy.jdbc.NClobProxyImpl; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl; +import com.alibaba.druid.proxy.jdbc.ResultSetProxy; +import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl; +import com.alibaba.druid.proxy.jdbc.StatementProxy; +import com.alibaba.druid.proxy.jdbc.StatementProxyImpl; + +/** + * @author wenshao + */ +public class FilterChainImpl implements FilterChain { + + protected int pos = 0; + + private final DataSourceProxy dataSource; + + private final int filterSize; + + public FilterChainImpl(DataSourceProxy dataSource){ + this.dataSource = dataSource; + this.filterSize = getFilters().size(); + } + + public FilterChainImpl(DataSourceProxy dataSource, int pos){ + this.dataSource = dataSource; + this.pos = pos; + this.filterSize = getFilters().size(); + } + + public int getFilterSize() { + return filterSize; + } + + public void reset() { + pos = 0; + } + + @Override + public FilterChain cloneChain() { + return new FilterChainImpl(dataSource, pos); + } + + public DataSourceProxy getDataSource() { + return dataSource; + } + + @Override + public boolean isWrapperFor(Wrapper wrapper, Class iface) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().isWrapperFor(this, wrapper, iface); + } + + // // if driver is for jdbc 3.0 + if (iface.isInstance(wrapper)) { + return true; + } + + return wrapper.isWrapperFor(iface); + } + + @SuppressWarnings("unchecked") + @Override + public T unwrap(Wrapper wrapper, Class iface) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().unwrap(this, wrapper, iface); + } + + if (iface == null) { + return null; + } + + // if driver is for jdbc 3.0 + if (iface.isAssignableFrom(wrapper.getClass())) { + return (T) wrapper; + } + + return wrapper.unwrap(iface); + } + + public ConnectionProxy connection_connect(Properties info) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_connect(this, info); + } + + Driver driver = dataSource.getRawDriver(); + String url = dataSource.getRawJdbcUrl(); + + Connection nativeConnection = driver.connect(url, info); + return wrap(nativeConnection, info); + } + + @Override + public void connection_clearWarnings(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_clearWarnings(this, connection); + return; + } + + connection.getRawObject().clearWarnings(); + } + + @Override + public void connection_close(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_close(this, connection); + return; + } + + connection.getRawObject().close(); + connection.clearAttributes(); + } + + @Override + public void connection_commit(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_commit(this, connection); + return; + } + + connection.getRawObject().commit(); + } + + @Override + public Array connection_createArrayOf(ConnectionProxy connection, String typeName, Object[] elements) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createArrayOf(this, connection, typeName, elements); + } + + return connection.getRawObject().createArrayOf(typeName, elements); + + } + + @Override + public Blob connection_createBlob(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createBlob(this, connection); + } + + return connection.getRawObject().createBlob(); + } + + @Override + public Clob connection_createClob(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createClob(this, connection); + } + + Clob clob = connection.getRawObject().createClob(); + + return wrap(connection, clob); + } + + @Override + public NClob connection_createNClob(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createNClob(this, connection); + } + + NClob nclob = connection.getRawObject().createNClob(); + + return wrap(connection, nclob); + } + + @Override + public SQLXML connection_createSQLXML(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createSQLXML(this, connection); + } + + return connection.getRawObject().createSQLXML(); + } + + @Override + public StatementProxy connection_createStatement(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createStatement(this, connection); + } + + Statement statement = connection.getRawObject().createStatement(); + return wrap(connection, statement); + } + + @Override + public StatementProxy connection_createStatement(ConnectionProxy connection, int resultSetType, + int resultSetConcurrency) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createStatement(this, connection, resultSetType, resultSetConcurrency); + } + + Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency); + return wrap(connection, statement); + } + + @Override + public StatementProxy connection_createStatement(ConnectionProxy connection, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createStatement(this, connection, resultSetType, resultSetConcurrency, + resultSetHoldability); + } + + Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency, + resultSetHoldability); + return wrap(connection, statement); + } + + @Override + public Struct connection_createStruct(ConnectionProxy connection, String typeName, Object[] attributes) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_createStruct(this, connection, typeName, attributes); + } + + return connection.getRawObject().createStruct(typeName, attributes); + } + + @Override + public boolean connection_getAutoCommit(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getAutoCommit(this, connection); + } + + return connection.getRawObject().getAutoCommit(); + } + + @Override + public String connection_getCatalog(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getCatalog(this, connection); + } + + return connection.getRawObject().getCatalog(); + } + + @Override + public Properties connection_getClientInfo(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getClientInfo(this, connection); + } + + return connection.getRawObject().getClientInfo(); + } + + @Override + public String connection_getClientInfo(ConnectionProxy connection, String name) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getClientInfo(this, connection, name); + } + + return connection.getRawObject().getClientInfo(name); + } + + public List getFilters() { + return dataSource.getProxyFilters(); + } + + @Override + public int connection_getHoldability(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getHoldability(this, connection); + } + + return connection.getRawObject().getHoldability(); + } + + @Override + public DatabaseMetaData connection_getMetaData(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getMetaData(this, connection); + } + + // DatabaseMetaData + + DatabaseMetaData rawDatabaseMetaData = connection.getRawObject().getMetaData(); + + return rawDatabaseMetaData; + } + + @Override + public int connection_getTransactionIsolation(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getTransactionIsolation(this, connection); + } + + return connection.getRawObject().getTransactionIsolation(); + } + + @Override + public Map> connection_getTypeMap(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getTypeMap(this, connection); + } + + return connection.getRawObject().getTypeMap(); + } + + @Override + public SQLWarning connection_getWarnings(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_getWarnings(this, connection); + } + + return connection.getRawObject().getWarnings(); + } + + @Override + public boolean connection_isClosed(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_isClosed(this, connection); + } + + return connection.getRawObject().isClosed(); + } + + @Override + public boolean connection_isReadOnly(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_isReadOnly(this, connection); + } + + return connection.getRawObject().isReadOnly(); + } + + @Override + public boolean connection_isValid(ConnectionProxy connection, int timeout) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_isValid(this, connection, timeout); + } + + return connection.getRawObject().isValid(timeout); + } + + @Override + public String connection_nativeSQL(ConnectionProxy connection, String sql) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_nativeSQL(this, connection, sql); + } + + return connection.getRawObject().nativeSQL(sql); + } + + private Filter nextFilter() { + Filter filter = getFilters().get(pos++); + return filter; + } + + @Override + public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareCall(this, connection, sql); + } + + CallableStatement statement = connection.getRawObject().prepareCall(sql); + return wrap(connection, statement, sql); + } + + @Override + public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql, int resultSetType, + int resultSetConcurrency) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareCall(this, connection, sql, resultSetType, resultSetConcurrency); + } + + CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency); + return wrap(connection, statement, sql); + } + + @Override + public CallableStatementProxy connection_prepareCall(ConnectionProxy connection, String sql, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareCall(this, connection, sql, resultSetType, resultSetConcurrency, + resultSetHoldability); + } + + CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency, + resultSetHoldability); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, + int autoGeneratedKeys) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql, autoGeneratedKeys); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql, autoGeneratedKeys); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql, resultSetType, resultSetConcurrency); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType, + resultSetConcurrency); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql, resultSetType, resultSetConcurrency, + resultSetHoldability); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType, + resultSetConcurrency, + resultSetHoldability); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, + int[] columnIndexes) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql, columnIndexes); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnIndexes); + return wrap(connection, statement, sql); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(ConnectionProxy connection, String sql, + String[] columnNames) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_prepareStatement(this, connection, sql, columnNames); + } + + PreparedStatement statement = connection.getRawObject().prepareStatement(sql, columnNames); + return wrap(connection, statement, sql); + } + + @Override + public void connection_releaseSavepoint(ConnectionProxy connection, Savepoint savepoint) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_releaseSavepoint(this, connection, savepoint); + return; + } + + connection.getRawObject().releaseSavepoint(savepoint); + } + + @Override + public void connection_rollback(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_rollback(this, connection); + return; + } + + connection.getRawObject().rollback(); + } + + @Override + public void connection_rollback(ConnectionProxy connection, Savepoint savepoint) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_rollback(this, connection, savepoint); + return; + } + + connection.getRawObject().rollback(savepoint); + } + + @Override + public void connection_setAutoCommit(ConnectionProxy connection, boolean autoCommit) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setAutoCommit(this, connection, autoCommit); + return; + } + + connection.getRawObject().setAutoCommit(autoCommit); + } + + @Override + public void connection_setCatalog(ConnectionProxy connection, String catalog) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setCatalog(this, connection, catalog); + return; + } + + connection.getRawObject().setCatalog(catalog); + } + + @Override + public void connection_setClientInfo(ConnectionProxy connection, Properties properties) + throws SQLClientInfoException { + if (this.pos < filterSize) { + nextFilter().connection_setClientInfo(this, connection, properties); + return; + } + + connection.getRawObject().setClientInfo(properties); + } + + @Override + public void connection_setClientInfo(ConnectionProxy connection, String name, String value) + throws SQLClientInfoException { + if (this.pos < filterSize) { + nextFilter().connection_setClientInfo(this, connection, name, value); + return; + } + + connection.getRawObject().setClientInfo(name, value); + } + + @Override + public void connection_setHoldability(ConnectionProxy connection, int holdability) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setHoldability(this, connection, holdability); + return; + } + + connection.getRawObject().setHoldability(holdability); + } + + @Override + public void connection_setReadOnly(ConnectionProxy connection, boolean readOnly) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setReadOnly(this, connection, readOnly); + return; + } + + connection.getRawObject().setReadOnly(readOnly); + } + + @Override + public Savepoint connection_setSavepoint(ConnectionProxy connection) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_setSavepoint(this, connection); + } + + return connection.getRawObject().setSavepoint(); + } + + @Override + public Savepoint connection_setSavepoint(ConnectionProxy connection, String name) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().connection_setSavepoint(this, connection, name); + } + + return connection.getRawObject().setSavepoint(name); + } + + @Override + public void connection_setTransactionIsolation(ConnectionProxy connection, int level) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setTransactionIsolation(this, connection, level); + return; + } + + connection.getRawObject().setTransactionIsolation(level); + } + + @Override + public void connection_setTypeMap(ConnectionProxy connection, Map> map) throws SQLException { + if (this.pos < filterSize) { + nextFilter().connection_setTypeMap(this, connection, map); + return; + } + + connection.getRawObject().setTypeMap(map); + } + + // /////////////////////////////////////// + + @Override + public boolean resultSet_next(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_next(this, resultSet); + } + + return resultSet.getResultSetRaw().next(); + } + + @Override + public void resultSet_close(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_close(this, resultSet); + return; + } + resultSet.getResultSetRaw().close(); + resultSet.clearAttributes(); + } + + @Override + public boolean resultSet_wasNull(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_wasNull(this, resultSet); + } + return resultSet.getResultSetRaw().wasNull(); + } + + @Override + public String resultSet_getString(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getString(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getString(columnIndex); + } + + @Override + public boolean resultSet_getBoolean(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBoolean(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getBoolean(columnIndex); + } + + @Override + public byte resultSet_getByte(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getByte(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getByte(columnIndex); + } + + @Override + public short resultSet_getShort(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getShort(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getShort(columnIndex); + } + + @Override + public int resultSet_getInt(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getInt(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getInt(columnIndex); + } + + @Override + public long resultSet_getLong(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getLong(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getLong(columnIndex); + } + + @Override + public float resultSet_getFloat(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getFloat(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getFloat(columnIndex); + } + + @Override + public double resultSet_getDouble(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDouble(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getDouble(columnIndex); + } + + @SuppressWarnings("deprecation") + @Override + public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, int columnIndex, int scale) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBigDecimal(this, resultSet, columnIndex, scale); + } + return resultSet.getResultSetRaw().getBigDecimal(columnIndex, scale); + } + + @Override + public byte[] resultSet_getBytes(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBytes(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getBytes(columnIndex); + } + + @Override + public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDate(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getDate(columnIndex); + } + + @Override + public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTime(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getTime(columnIndex); + } + + @Override + public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTimestamp(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getTimestamp(columnIndex); + } + + @Override + public java.io.InputStream resultSet_getAsciiStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getAsciiStream(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getAsciiStream(columnIndex); + } + + @SuppressWarnings("deprecation") + @Override + public java.io.InputStream resultSet_getUnicodeStream(ResultSetProxy resultSet, int columnIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getUnicodeStream(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getUnicodeStream(columnIndex); + } + + @Override + public java.io.InputStream resultSet_getBinaryStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBinaryStream(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getBinaryStream(columnIndex); + } + + @Override + public String resultSet_getString(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getString(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getString(columnLabel); + } + + @Override + public boolean resultSet_getBoolean(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBoolean(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getBoolean(columnLabel); + } + + @Override + public byte resultSet_getByte(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getByte(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getByte(columnLabel); + } + + @Override + public short resultSet_getShort(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getShort(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getShort(columnLabel); + } + + @Override + public int resultSet_getInt(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getInt(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getInt(columnLabel); + } + + @Override + public long resultSet_getLong(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getLong(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getLong(columnLabel); + } + + @Override + public float resultSet_getFloat(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getFloat(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getFloat(columnLabel); + } + + @Override + public double resultSet_getDouble(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDouble(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getDouble(columnLabel); + } + + @SuppressWarnings("deprecation") + @Override + public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, String columnLabel, int scale) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBigDecimal(this, resultSet, columnLabel, scale); + } + return resultSet.getResultSetRaw().getBigDecimal(columnLabel, scale); + } + + @Override + public byte[] resultSet_getBytes(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBytes(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getBytes(columnLabel); + } + + @Override + public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDate(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getDate(columnLabel); + } + + @Override + public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTime(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getTime(columnLabel); + } + + @Override + public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTimestamp(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getTimestamp(columnLabel); + } + + @Override + public java.io.InputStream resultSet_getAsciiStream(ResultSetProxy resultSet, String columnLabel) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getAsciiStream(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getAsciiStream(columnLabel); + } + + @SuppressWarnings("deprecation") + @Override + public java.io.InputStream resultSet_getUnicodeStream(ResultSetProxy resultSet, String columnLabel) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getUnicodeStream(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getUnicodeStream(columnLabel); + } + + @Override + public java.io.InputStream resultSet_getBinaryStream(ResultSetProxy resultSet, String columnLabel) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBinaryStream(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getBinaryStream(columnLabel); + } + + @Override + public SQLWarning resultSet_getWarnings(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getWarnings(this, resultSet); + } + return resultSet.getResultSetRaw().getWarnings(); + } + + @Override + public void resultSet_clearWarnings(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_clearWarnings(this, resultSet); + return; + } + resultSet.getResultSetRaw().clearWarnings(); + } + + @Override + public String resultSet_getCursorName(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getCursorName(this, resultSet); + } + return resultSet.getResultSetRaw().getCursorName(); + } + + @Override + public ResultSetMetaData resultSet_getMetaData(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getMetaData(this, resultSet); + } + return resultSet.getResultSetRaw().getMetaData(); + } + + @Override + public Object resultSet_getObject(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getObject(this, resultSet, columnIndex); + } + + Object obj = resultSet.getResultSetRaw().getObject(columnIndex); + + if (obj instanceof ResultSet) { + return wrap(resultSet.getStatementProxy(), (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(resultSet.getStatementProxy(), (Clob) obj); + } + + return obj; + } + + @Override + public Object resultSet_getObject(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getObject(this, resultSet, columnLabel); + } + + Object obj = resultSet.getResultSetRaw().getObject(columnLabel); + + if (obj instanceof ResultSet) { + return wrap(resultSet.getStatementProxy(), (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(resultSet.getStatementProxy(), (Clob) obj); + } + + return obj; + } + + @Override + public int resultSet_findColumn(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_findColumn(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().findColumn(columnLabel); + } + + @Override + public java.io.Reader resultSet_getCharacterStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getCharacterStream(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getCharacterStream(columnIndex); + } + + @Override + public java.io.Reader resultSet_getCharacterStream(ResultSetProxy resultSet, String columnLabel) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getCharacterStream(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getCharacterStream(columnLabel); + } + + @Override + public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBigDecimal(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getBigDecimal(columnIndex); + } + + @Override + public BigDecimal resultSet_getBigDecimal(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBigDecimal(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getBigDecimal(columnLabel); + } + + @Override + public boolean resultSet_isBeforeFirst(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_isBeforeFirst(this, resultSet); + } + return resultSet.getResultSetRaw().isBeforeFirst(); + } + + @Override + public boolean resultSet_isAfterLast(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_isAfterLast(this, resultSet); + } + return resultSet.getResultSetRaw().isAfterLast(); + } + + @Override + public boolean resultSet_isFirst(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_isFirst(this, resultSet); + } + return resultSet.getResultSetRaw().isFirst(); + } + + @Override + public boolean resultSet_isLast(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_isLast(this, resultSet); + } + return resultSet.getResultSetRaw().isLast(); + } + + @Override + public void resultSet_beforeFirst(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_beforeFirst(this, resultSet); + return; + } + resultSet.getResultSetRaw().beforeFirst(); + } + + @Override + public void resultSet_afterLast(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_afterLast(this, resultSet); + return; + } + resultSet.getResultSetRaw().afterLast(); + } + + @Override + public boolean resultSet_first(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_first(this, resultSet); + } + return resultSet.getResultSetRaw().first(); + } + + @Override + public boolean resultSet_last(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_last(this, resultSet); + } + return resultSet.getResultSetRaw().last(); + } + + @Override + public int resultSet_getRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getRow(this, resultSet); + } + return resultSet.getResultSetRaw().getRow(); + } + + @Override + public boolean resultSet_absolute(ResultSetProxy resultSet, int row) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_absolute(this, resultSet, row); + } + return resultSet.getResultSetRaw().absolute(row); + } + + @Override + public boolean resultSet_relative(ResultSetProxy resultSet, int rows) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_relative(this, resultSet, rows); + } + return resultSet.getResultSetRaw().relative(rows); + } + + @Override + public boolean resultSet_previous(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_previous(this, resultSet); + } + return resultSet.getResultSetRaw().previous(); + } + + @Override + public void resultSet_setFetchDirection(ResultSetProxy resultSet, int direction) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_setFetchDirection(this, resultSet, direction); + return; + } + resultSet.getResultSetRaw().setFetchDirection(direction); + } + + @Override + public int resultSet_getFetchDirection(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getFetchDirection(this, resultSet); + } + return resultSet.getResultSetRaw().getFetchDirection(); + } + + @Override + public void resultSet_setFetchSize(ResultSetProxy resultSet, int rows) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_setFetchSize(this, resultSet, rows); + return; + } + resultSet.getResultSetRaw().setFetchSize(rows); + } + + @Override + public int resultSet_getFetchSize(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getFetchSize(this, resultSet); + } + return resultSet.getResultSetRaw().getFetchSize(); + } + + @Override + public int resultSet_getType(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getType(this, resultSet); + } + return resultSet.getResultSetRaw().getType(); + } + + @Override + public int resultSet_getConcurrency(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getConcurrency(this, resultSet); + } + return resultSet.getResultSetRaw().getConcurrency(); + } + + @Override + public boolean resultSet_rowUpdated(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_rowUpdated(this, resultSet); + } + return resultSet.getResultSetRaw().rowUpdated(); + } + + @Override + public boolean resultSet_rowInserted(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_rowInserted(this, resultSet); + } + return resultSet.getResultSetRaw().rowInserted(); + } + + @Override + public boolean resultSet_rowDeleted(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_rowDeleted(this, resultSet); + } + return resultSet.getResultSetRaw().rowDeleted(); + } + + @Override + public void resultSet_updateNull(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNull(this, resultSet, columnIndex); + return; + } + resultSet.getResultSetRaw().updateNull(columnIndex); + } + + @Override + public void resultSet_updateBoolean(ResultSetProxy resultSet, int columnIndex, boolean x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBoolean(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateBoolean(columnIndex, x); + } + + @Override + public void resultSet_updateByte(ResultSetProxy resultSet, int columnIndex, byte x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateByte(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateByte(columnIndex, x); + } + + @Override + public void resultSet_updateShort(ResultSetProxy resultSet, int columnIndex, short x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateShort(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateShort(columnIndex, x); + } + + @Override + public void resultSet_updateInt(ResultSetProxy resultSet, int columnIndex, int x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateInt(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateInt(columnIndex, x); + } + + @Override + public void resultSet_updateLong(ResultSetProxy resultSet, int columnIndex, long x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateLong(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateLong(columnIndex, x); + } + + @Override + public void resultSet_updateFloat(ResultSetProxy resultSet, int columnIndex, float x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateFloat(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateFloat(columnIndex, x); + } + + @Override + public void resultSet_updateDouble(ResultSetProxy resultSet, int columnIndex, double x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateDouble(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateDouble(columnIndex, x); + } + + @Override + public void resultSet_updateBigDecimal(ResultSetProxy resultSet, int columnIndex, BigDecimal x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBigDecimal(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateBigDecimal(columnIndex, x); + } + + @Override + public void resultSet_updateString(ResultSetProxy resultSet, int columnIndex, String x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateString(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateString(columnIndex, x); + } + + @Override + public void resultSet_updateBytes(ResultSetProxy resultSet, int columnIndex, byte[] x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBytes(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateBytes(columnIndex, x); + } + + @Override + public void resultSet_updateDate(ResultSetProxy resultSet, int columnIndex, java.sql.Date x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateDate(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateDate(columnIndex, x); + } + + @Override + public void resultSet_updateTime(ResultSetProxy resultSet, int columnIndex, java.sql.Time x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateTime(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateTime(columnIndex, x); + } + + @Override + public void resultSet_updateTimestamp(ResultSetProxy resultSet, int columnIndex, java.sql.Timestamp x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateTimestamp(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateTimestamp(columnIndex, x); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, int length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, + int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, int length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateObject(ResultSetProxy resultSet, int columnIndex, Object x, int scaleOrLength) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateObject(this, resultSet, columnIndex, x, scaleOrLength); + return; + } + resultSet.getResultSetRaw().updateObject(columnIndex, x, scaleOrLength); + } + + @Override + public void resultSet_updateObject(ResultSetProxy resultSet, int columnIndex, Object x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateObject(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateObject(columnIndex, x); + } + + @Override + public void resultSet_updateNull(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNull(this, resultSet, columnLabel); + return; + } + resultSet.getResultSetRaw().updateNull(columnLabel); + } + + @Override + public void resultSet_updateBoolean(ResultSetProxy resultSet, String columnLabel, boolean x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBoolean(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateBoolean(columnLabel, x); + } + + @Override + public void resultSet_updateByte(ResultSetProxy resultSet, String columnLabel, byte x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateByte(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateByte(columnLabel, x); + } + + @Override + public void resultSet_updateShort(ResultSetProxy resultSet, String columnLabel, short x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateShort(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateShort(columnLabel, x); + } + + @Override + public void resultSet_updateInt(ResultSetProxy resultSet, String columnLabel, int x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateInt(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateInt(columnLabel, x); + } + + @Override + public void resultSet_updateLong(ResultSetProxy resultSet, String columnLabel, long x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateLong(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateLong(columnLabel, x); + } + + @Override + public void resultSet_updateFloat(ResultSetProxy resultSet, String columnLabel, float x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateFloat(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateFloat(columnLabel, x); + } + + @Override + public void resultSet_updateDouble(ResultSetProxy resultSet, String columnLabel, double x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateDouble(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateDouble(columnLabel, x); + } + + @Override + public void resultSet_updateBigDecimal(ResultSetProxy resultSet, String columnLabel, BigDecimal x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBigDecimal(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateBigDecimal(columnLabel, x); + } + + @Override + public void resultSet_updateString(ResultSetProxy resultSet, String columnLabel, String x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateString(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateString(columnLabel, x); + } + + @Override + public void resultSet_updateBytes(ResultSetProxy resultSet, String columnLabel, byte x[]) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBytes(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateBytes(columnLabel, x); + } + + @Override + public void resultSet_updateDate(ResultSetProxy resultSet, String columnLabel, java.sql.Date x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateDate(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateDate(columnLabel, x); + } + + @Override + public void resultSet_updateTime(ResultSetProxy resultSet, String columnLabel, java.sql.Time x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateTime(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateTime(columnLabel, x); + } + + @Override + public void resultSet_updateTimestamp(ResultSetProxy resultSet, String columnLabel, java.sql.Timestamp x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateTimestamp(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateTimestamp(columnLabel, x); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, + int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x, length); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x, length); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, + int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x, length); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x, length); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, + int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader, length); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader, length); + } + + @Override + public void resultSet_updateObject(ResultSetProxy resultSet, String columnLabel, Object x, int scaleOrLength) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateObject(this, resultSet, columnLabel, x, scaleOrLength); + return; + } + resultSet.getResultSetRaw().updateObject(columnLabel, x, scaleOrLength); + } + + @Override + public void resultSet_updateObject(ResultSetProxy resultSet, String columnLabel, Object x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateObject(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateObject(columnLabel, x); + } + + @Override + public void resultSet_insertRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_insertRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().insertRow(); + } + + @Override + public void resultSet_updateRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().updateRow(); + } + + @Override + public void resultSet_deleteRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_deleteRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().deleteRow(); + } + + @Override + public void resultSet_refreshRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_refreshRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().refreshRow(); + } + + @Override + public void resultSet_cancelRowUpdates(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_cancelRowUpdates(this, resultSet); + return; + } + resultSet.getResultSetRaw().cancelRowUpdates(); + } + + @Override + public void resultSet_moveToInsertRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_moveToInsertRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().moveToInsertRow(); + } + + @Override + public void resultSet_moveToCurrentRow(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_moveToCurrentRow(this, resultSet); + return; + } + resultSet.getResultSetRaw().moveToCurrentRow(); + } + + @Override + public Statement resultSet_getStatement(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getStatement(this, resultSet); + } + return resultSet.getResultSetRaw().getStatement(); + } + + @Override + public Object resultSet_getObject(ResultSetProxy resultSet, int columnIndex, java.util.Map> map) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getObject(this, resultSet, columnIndex, map); + } + + Object obj = resultSet.getResultSetRaw().getObject(columnIndex, map); + + if (obj instanceof ResultSet) { + return wrap(resultSet.getStatementProxy(), (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(resultSet.getStatementProxy(), (Clob) obj); + } + + return obj; + } + + @Override + public Ref resultSet_getRef(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getRef(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getRef(columnIndex); + } + + @Override + public Blob resultSet_getBlob(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBlob(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getBlob(columnIndex); + } + + @Override + public Clob resultSet_getClob(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getClob(this, resultSet, columnIndex); + } + + Clob clob = resultSet.getResultSetRaw().getClob(columnIndex); + + return wrap(resultSet.getStatementProxy(), clob); + } + + @Override + public Array resultSet_getArray(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getArray(this, resultSet, columnIndex); + } + + Array rawArray = resultSet.getResultSetRaw().getArray(columnIndex); + + return rawArray; + } + + @Override + public Object resultSet_getObject(ResultSetProxy resultSet, String columnLabel, java.util.Map> map) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getObject(this, resultSet, columnLabel, map); + } + + Object obj = resultSet.getResultSetRaw().getObject(columnLabel, map); + + if (obj instanceof ResultSet) { + return wrap(resultSet.getStatementProxy(), (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(resultSet.getStatementProxy(), (Clob) obj); + } + + return obj; + } + + @Override + public Ref resultSet_getRef(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getRef(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getRef(columnLabel); + } + + @Override + public Blob resultSet_getBlob(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getBlob(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getBlob(columnLabel); + } + + @Override + public Clob resultSet_getClob(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getClob(this, resultSet, columnLabel); + } + + Clob clob = resultSet.getResultSetRaw().getClob(columnLabel); + + return wrap(resultSet.getStatementProxy(), clob); + } + + @Override + public Array resultSet_getArray(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getArray(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getArray(columnLabel); + } + + @Override + public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, int columnIndex, Calendar cal) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDate(this, resultSet, columnIndex, cal); + } + return resultSet.getResultSetRaw().getDate(columnIndex, cal); + } + + @Override + public java.sql.Date resultSet_getDate(ResultSetProxy resultSet, String columnLabel, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getDate(this, resultSet, columnLabel, cal); + } + return resultSet.getResultSetRaw().getDate(columnLabel, cal); + } + + @Override + public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, int columnIndex, Calendar cal) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTime(this, resultSet, columnIndex, cal); + } + return resultSet.getResultSetRaw().getTime(columnIndex, cal); + } + + @Override + public java.sql.Time resultSet_getTime(ResultSetProxy resultSet, String columnLabel, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTime(this, resultSet, columnLabel, cal); + } + return resultSet.getResultSetRaw().getTime(columnLabel, cal); + } + + @Override + public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, int columnIndex, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTimestamp(this, resultSet, columnIndex, cal); + } + return resultSet.getResultSetRaw().getTimestamp(columnIndex, cal); + } + + @Override + public java.sql.Timestamp resultSet_getTimestamp(ResultSetProxy resultSet, String columnLabel, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getTimestamp(this, resultSet, columnLabel, cal); + } + return resultSet.getResultSetRaw().getTimestamp(columnLabel, cal); + } + + @Override + public java.net.URL resultSet_getURL(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getURL(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getURL(columnIndex); + } + + @Override + public java.net.URL resultSet_getURL(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getURL(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getURL(columnLabel); + } + + @Override + public void resultSet_updateRef(ResultSetProxy resultSet, int columnIndex, java.sql.Ref x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateRef(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateRef(columnIndex, x); + } + + @Override + public void resultSet_updateRef(ResultSetProxy resultSet, String columnLabel, java.sql.Ref x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateRef(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateRef(columnLabel, x); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, java.sql.Blob x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateBlob(columnIndex, x); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, java.sql.Blob x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateBlob(columnLabel, x); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, java.sql.Clob x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateClob(columnIndex, x); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, java.sql.Clob x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateClob(columnLabel, x); + } + + @Override + public void resultSet_updateArray(ResultSetProxy resultSet, int columnIndex, java.sql.Array x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateArray(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateArray(columnIndex, x); + } + + @Override + public void resultSet_updateArray(ResultSetProxy resultSet, String columnLabel, java.sql.Array x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateArray(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateArray(columnLabel, x); + } + + @Override + public RowId resultSet_getRowId(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getRowId(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getRowId(columnIndex); + } + + @Override + public RowId resultSet_getRowId(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getRowId(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getRowId(columnLabel); + } + + @Override + public void resultSet_updateRowId(ResultSetProxy resultSet, int columnIndex, RowId x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateRowId(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateRowId(columnIndex, x); + } + + @Override + public void resultSet_updateRowId(ResultSetProxy resultSet, String columnLabel, RowId x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateRowId(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateRowId(columnLabel, x); + } + + @Override + public int resultSet_getHoldability(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getHoldability(this, resultSet); + } + return resultSet.getResultSetRaw().getHoldability(); + } + + @Override + public boolean resultSet_isClosed(ResultSetProxy resultSet) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_isClosed(this, resultSet); + } + return resultSet.getResultSetRaw().isClosed(); + } + + @Override + public void resultSet_updateNString(ResultSetProxy resultSet, int columnIndex, String nString) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNString(this, resultSet, columnIndex, nString); + return; + } + resultSet.getResultSetRaw().updateNString(columnIndex, nString); + } + + @Override + public void resultSet_updateNString(ResultSetProxy resultSet, String columnLabel, String nString) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNString(this, resultSet, columnLabel, nString); + return; + } + resultSet.getResultSetRaw().updateNString(columnLabel, nString); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, NClob nClob) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, nClob); + return; + } + resultSet.getResultSetRaw().updateNClob(columnIndex, nClob); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, NClob nClob) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, nClob); + return; + } + resultSet.getResultSetRaw().updateNClob(columnLabel, nClob); + } + + @Override + public NClob resultSet_getNClob(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNClob(this, resultSet, columnIndex); + } + + NClob nclob = resultSet.getResultSetRaw().getNClob(columnIndex); + + return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); + } + + @Override + public NClob resultSet_getNClob(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNClob(this, resultSet, columnLabel); + } + + NClob nclob = resultSet.getResultSetRaw().getNClob(columnLabel); + + return wrap(resultSet.getStatementProxy().getConnectionProxy(), nclob); + } + + @Override + public SQLXML resultSet_getSQLXML(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getSQLXML(this, resultSet, columnIndex); + } + + return resultSet.getResultSetRaw().getSQLXML(columnIndex); + } + + @Override + public SQLXML resultSet_getSQLXML(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getSQLXML(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getSQLXML(columnLabel); + } + + @Override + public void resultSet_updateSQLXML(ResultSetProxy resultSet, int columnIndex, SQLXML xmlObject) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateSQLXML(this, resultSet, columnIndex, xmlObject); + return; + } + resultSet.getResultSetRaw().updateSQLXML(columnIndex, xmlObject); + } + + @Override + public void resultSet_updateSQLXML(ResultSetProxy resultSet, String columnLabel, SQLXML xmlObject) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateSQLXML(this, resultSet, columnLabel, xmlObject); + return; + } + resultSet.getResultSetRaw().updateSQLXML(columnLabel, xmlObject); + } + + @Override + public String resultSet_getNString(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNString(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getNString(columnIndex); + } + + @Override + public String resultSet_getNString(ResultSetProxy resultSet, String columnLabel) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNString(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getNString(columnLabel); + } + + @Override + public java.io.Reader resultSet_getNCharacterStream(ResultSetProxy resultSet, int columnIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNCharacterStream(this, resultSet, columnIndex); + } + return resultSet.getResultSetRaw().getNCharacterStream(columnIndex); + } + + @Override + public java.io.Reader resultSet_getNCharacterStream(ResultSetProxy resultSet, String columnLabel) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().resultSet_getNCharacterStream(this, resultSet, columnLabel); + } + return resultSet.getResultSetRaw().getNCharacterStream(columnLabel); + } + + @Override + public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateNCharacterStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnLabel, reader, length); + return; + } + resultSet.getResultSetRaw().updateNCharacterStream(columnLabel, reader, length); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x, length); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x, length); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x, length); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x, length); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x, length); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x, length); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader, length); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader, length); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, InputStream inputStream, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, inputStream, length); + return; + } + resultSet.getResultSetRaw().updateBlob(columnIndex, inputStream, length); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, InputStream inputStream, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, inputStream, length); + return; + } + resultSet.getResultSetRaw().updateBlob(columnLabel, inputStream, length); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, Reader reader, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnIndex, reader, length); + return; + } + resultSet.getResultSetRaw().updateClob(columnIndex, reader, length); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, Reader reader, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnLabel, reader, length); + return; + } + resultSet.getResultSetRaw().updateClob(columnLabel, reader, length); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, Reader reader, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, reader, length); + return; + } + resultSet.getResultSetRaw().updateNClob(columnIndex, reader, length); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, Reader reader, long length) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, reader, length); + return; + } + resultSet.getResultSetRaw().updateNClob(columnLabel, reader, length); + } + + @Override + public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateNCharacterStream(columnIndex, x); + } + + @Override + public void resultSet_updateNCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNCharacterStream(this, resultSet, columnLabel, reader); + return; + } + resultSet.getResultSetRaw().updateNCharacterStream(columnLabel, reader); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnIndex, x); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, int columnIndex, java.io.InputStream x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnIndex, x); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, int columnIndex, java.io.Reader x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnIndex, x); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnIndex, x); + } + + @Override + public void resultSet_updateAsciiStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateAsciiStream(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateAsciiStream(columnLabel, x); + } + + @Override + public void resultSet_updateBinaryStream(ResultSetProxy resultSet, String columnLabel, java.io.InputStream x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBinaryStream(this, resultSet, columnLabel, x); + return; + } + resultSet.getResultSetRaw().updateBinaryStream(columnLabel, x); + } + + @Override + public void resultSet_updateCharacterStream(ResultSetProxy resultSet, String columnLabel, java.io.Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateCharacterStream(this, resultSet, columnLabel, reader); + return; + } + resultSet.getResultSetRaw().updateCharacterStream(columnLabel, reader); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, int columnIndex, InputStream inputStream) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnIndex, inputStream); + return; + } + resultSet.getResultSetRaw().updateBlob(columnIndex, inputStream); + } + + @Override + public void resultSet_updateBlob(ResultSetProxy resultSet, String columnLabel, InputStream inputStream) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateBlob(this, resultSet, columnLabel, inputStream); + return; + } + resultSet.getResultSetRaw().updateBlob(columnLabel, inputStream); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, int columnIndex, Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnIndex, reader); + return; + } + resultSet.getResultSetRaw().updateClob(columnIndex, reader); + } + + @Override + public void resultSet_updateClob(ResultSetProxy resultSet, String columnLabel, Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateClob(this, resultSet, columnLabel, reader); + return; + } + resultSet.getResultSetRaw().updateClob(columnLabel, reader); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, int columnIndex, Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnIndex, reader); + return; + } + resultSet.getResultSetRaw().updateNClob(columnIndex, reader); + } + + @Override + public void resultSet_updateNClob(ResultSetProxy resultSet, String columnLabel, Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().resultSet_updateNClob(this, resultSet, columnLabel, reader); + return; + } + resultSet.getResultSetRaw().updateNClob(columnLabel, reader); + } + + // //////////////////////////////////////// statement + @Override + public ResultSetProxy statement_executeQuery(StatementProxy statement, String sql) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeQuery(this, statement, sql); + } + + ResultSet resultSet = statement.getRawObject().executeQuery(sql); + + if (resultSet == null) { + return null; + } + + return wrap(statement, resultSet); + } + + @Override + public int statement_executeUpdate(StatementProxy statement, String sql) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeUpdate(this, statement, sql); + } + return statement.getRawObject().executeUpdate(sql); + } + + @Override + public void statement_close(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_close(this, statement); + return; + } + statement.getRawObject().close(); + } + + @Override + public int statement_getMaxFieldSize(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getMaxFieldSize(this, statement); + } + return statement.getRawObject().getMaxFieldSize(); + } + + @Override + public void statement_setMaxFieldSize(StatementProxy statement, int max) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setMaxFieldSize(this, statement, max); + return; + } + statement.getRawObject().setMaxFieldSize(max); + } + + @Override + public int statement_getMaxRows(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getMaxRows(this, statement); + } + return statement.getRawObject().getMaxRows(); + } + + @Override + public void statement_setMaxRows(StatementProxy statement, int max) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setMaxRows(this, statement, max); + return; + } + statement.getRawObject().setMaxRows(max); + } + + @Override + public void statement_setEscapeProcessing(StatementProxy statement, boolean enable) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setEscapeProcessing(this, statement, enable); + return; + } + statement.getRawObject().setEscapeProcessing(enable); + } + + @Override + public int statement_getQueryTimeout(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getQueryTimeout(this, statement); + } + return statement.getRawObject().getQueryTimeout(); + } + + @Override + public void statement_setQueryTimeout(StatementProxy statement, int seconds) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setQueryTimeout(this, statement, seconds); + return; + } + statement.getRawObject().setQueryTimeout(seconds); + } + + @Override + public void statement_cancel(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_cancel(this, statement); + return; + } + statement.getRawObject().cancel(); + } + + @Override + public SQLWarning statement_getWarnings(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getWarnings(this, statement); + } + return statement.getRawObject().getWarnings(); + } + + @Override + public void statement_clearWarnings(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_clearWarnings(this, statement); + return; + } + statement.getRawObject().clearWarnings(); + } + + @Override + public void statement_setCursorName(StatementProxy statement, String name) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setCursorName(this, statement, name); + return; + } + statement.getRawObject().setCursorName(name); + } + + @Override + public boolean statement_execute(StatementProxy statement, String sql) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_execute(this, statement, sql); + } + return statement.getRawObject().execute(sql); + } + + @Override + public ResultSetProxy statement_getResultSet(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getResultSet(this, statement); + } + + ResultSet resultSet = statement.getRawObject().getResultSet(); + + if (resultSet == null) { + return null; + } + + return wrap(statement, resultSet); + } + + @Override + public int statement_getUpdateCount(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getUpdateCount(this, statement); + } + return statement.getRawObject().getUpdateCount(); + } + + @Override + public boolean statement_getMoreResults(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getMoreResults(this, statement); + } + return statement.getRawObject().getMoreResults(); + } + + @Override + public void statement_setFetchDirection(StatementProxy statement, int direction) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setFetchDirection(this, statement, direction); + return; + } + statement.getRawObject().setFetchDirection(direction); + } + + @Override + public int statement_getFetchDirection(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getFetchDirection(this, statement); + } + return statement.getRawObject().getFetchDirection(); + } + + @Override + public void statement_setFetchSize(StatementProxy statement, int rows) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setFetchSize(this, statement, rows); + return; + } + statement.getRawObject().setFetchSize(rows); + } + + @Override + public int statement_getFetchSize(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getFetchSize(this, statement); + } + return statement.getRawObject().getFetchSize(); + } + + @Override + public int statement_getResultSetConcurrency(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getResultSetConcurrency(this, statement); + } + return statement.getRawObject().getResultSetConcurrency(); + } + + @Override + public int statement_getResultSetType(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getResultSetType(this, statement); + } + return statement.getRawObject().getResultSetType(); + } + + @Override + public void statement_addBatch(StatementProxy statement, String sql) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_addBatch(this, statement, sql); + return; + } + statement.getRawObject().addBatch(sql); + } + + @Override + public void statement_clearBatch(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_clearBatch(this, statement); + return; + } + statement.getRawObject().clearBatch(); + } + + @Override + public int[] statement_executeBatch(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeBatch(this, statement); + } + return statement.getRawObject().executeBatch(); + } + + @Override + public Connection statement_getConnection(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getConnection(this, statement); + } + return statement.getRawObject().getConnection(); + } + + @Override + public boolean statement_getMoreResults(StatementProxy statement, int current) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getMoreResults(this, statement, current); + } + return statement.getRawObject().getMoreResults(current); + } + + @Override + public ResultSetProxy statement_getGeneratedKeys(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getGeneratedKeys(this, statement); + } + + ResultSet resultSet = statement.getRawObject().getGeneratedKeys(); + return wrap(statement, resultSet); + } + + @Override + public int statement_executeUpdate(StatementProxy statement, String sql, int autoGeneratedKeys) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeUpdate(this, statement, sql, autoGeneratedKeys); + } + return statement.getRawObject().executeUpdate(sql, autoGeneratedKeys); + } + + @Override + public int statement_executeUpdate(StatementProxy statement, String sql, int columnIndexes[]) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeUpdate(this, statement, sql, columnIndexes); + } + return statement.getRawObject().executeUpdate(sql, columnIndexes); + } + + @Override + public int statement_executeUpdate(StatementProxy statement, String sql, String columnNames[]) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_executeUpdate(this, statement, sql, columnNames); + } + return statement.getRawObject().executeUpdate(sql, columnNames); + } + + @Override + public boolean statement_execute(StatementProxy statement, String sql, int autoGeneratedKeys) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_execute(this, statement, sql, autoGeneratedKeys); + } + return statement.getRawObject().execute(sql, autoGeneratedKeys); + } + + @Override + public boolean statement_execute(StatementProxy statement, String sql, int columnIndexes[]) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_execute(this, statement, sql, columnIndexes); + } + return statement.getRawObject().execute(sql, columnIndexes); + } + + @Override + public boolean statement_execute(StatementProxy statement, String sql, String columnNames[]) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_execute(this, statement, sql, columnNames); + } + return statement.getRawObject().execute(sql, columnNames); + } + + @Override + public int statement_getResultSetHoldability(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_getResultSetHoldability(this, statement); + } + return statement.getRawObject().getResultSetHoldability(); + } + + @Override + public boolean statement_isClosed(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_isClosed(this, statement); + } + return statement.getRawObject().isClosed(); + } + + @Override + public void statement_setPoolable(StatementProxy statement, boolean poolable) throws SQLException { + if (this.pos < filterSize) { + nextFilter().statement_setPoolable(this, statement, poolable); + return; + } + statement.getRawObject().setPoolable(poolable); + } + + @Override + public boolean statement_isPoolable(StatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().statement_isPoolable(this, statement); + } + return statement.getRawObject().isPoolable(); + } + + // //////////////// + + @Override + public ResultSetProxy preparedStatement_executeQuery(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().preparedStatement_executeQuery(this, statement); + } + + ResultSet resultSet = statement.getRawObject().executeQuery(); + return wrap(statement, resultSet); + } + + @Override + public int preparedStatement_executeUpdate(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().preparedStatement_executeUpdate(this, statement); + } + return statement.getRawObject().executeUpdate(); + } + + @Override + public void preparedStatement_setNull(PreparedStatementProxy statement, int parameterIndex, int sqlType) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNull(this, statement, parameterIndex, sqlType); + return; + } + statement.getRawObject().setNull(parameterIndex, sqlType); + } + + @Override + public void preparedStatement_setBoolean(PreparedStatementProxy statement, int parameterIndex, boolean x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBoolean(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setBoolean(parameterIndex, x); + } + + @Override + public void preparedStatement_setByte(PreparedStatementProxy statement, int parameterIndex, byte x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setByte(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setByte(parameterIndex, x); + } + + @Override + public void preparedStatement_setShort(PreparedStatementProxy statement, int parameterIndex, short x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setShort(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setShort(parameterIndex, x); + } + + @Override + public void preparedStatement_setInt(PreparedStatementProxy statement, int parameterIndex, int x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setInt(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setInt(parameterIndex, x); + } + + @Override + public void preparedStatement_setLong(PreparedStatementProxy statement, int parameterIndex, long x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setLong(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setLong(parameterIndex, x); + } + + @Override + public void preparedStatement_setFloat(PreparedStatementProxy statement, int parameterIndex, float x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setFloat(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setFloat(parameterIndex, x); + } + + @Override + public void preparedStatement_setDouble(PreparedStatementProxy statement, int parameterIndex, double x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setDouble(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setDouble(parameterIndex, x); + } + + @Override + public void preparedStatement_setBigDecimal(PreparedStatementProxy statement, int parameterIndex, BigDecimal x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBigDecimal(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setBigDecimal(parameterIndex, x); + } + + @Override + public void preparedStatement_setString(PreparedStatementProxy statement, int parameterIndex, String x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setString(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setString(parameterIndex, x); + } + + @Override + public void preparedStatement_setBytes(PreparedStatementProxy statement, int parameterIndex, byte x[]) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBytes(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setBytes(parameterIndex, x); + } + + @Override + public void preparedStatement_setDate(PreparedStatementProxy statement, int parameterIndex, java.sql.Date x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setDate(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setDate(parameterIndex, x); + } + + @Override + public void preparedStatement_setTime(PreparedStatementProxy statement, int parameterIndex, java.sql.Time x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setTime(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setTime(parameterIndex, x); + } + + @Override + public void preparedStatement_setTimestamp(PreparedStatementProxy statement, int parameterIndex, + java.sql.Timestamp x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setTimestamp(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setTimestamp(parameterIndex, x); + } + + @Override + public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x, length); + return; + } + statement.getRawObject().setAsciiStream(parameterIndex, x, length); + } + + @SuppressWarnings("deprecation") + @Override + public void preparedStatement_setUnicodeStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setUnicodeStream(this, statement, parameterIndex, x, length); + return; + } + statement.getRawObject().setUnicodeStream(parameterIndex, x, length); + } + + @Override + public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x, length); + return; + } + statement.getRawObject().setBinaryStream(parameterIndex, x, length); + } + + @Override + public void preparedStatement_clearParameters(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_clearParameters(this, statement); + return; + } + statement.getRawObject().clearParameters(); + } + + @Override + public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x, + int targetSqlType) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x, targetSqlType); + return; + } + statement.getRawObject().setObject(parameterIndex, x, targetSqlType); + } + + @Override + public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setObject(parameterIndex, x); + } + + @Override + public boolean preparedStatement_execute(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().preparedStatement_execute(this, statement); + } + return statement.getRawObject().execute(); + } + + @Override + public void preparedStatement_addBatch(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_addBatch(this, statement); + return; + } + statement.getRawObject().addBatch(); + } + + @Override + public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, + java.io.Reader reader, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader, length); + return; + } + statement.getRawObject().setCharacterStream(parameterIndex, reader, length); + } + + @Override + public void preparedStatement_setRef(PreparedStatementProxy statement, int parameterIndex, Ref x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setRef(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setRef(parameterIndex, x); + } + + @Override + public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, Blob x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setBlob(parameterIndex, x); + } + + @Override + public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Clob x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setClob(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setClob(parameterIndex, x); + } + + @Override + public void preparedStatement_setArray(PreparedStatementProxy statement, int parameterIndex, Array x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setArray(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setArray(parameterIndex, x); + } + + @Override + public ResultSetMetaData preparedStatement_getMetaData(PreparedStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().preparedStatement_getMetaData(this, statement); + } + return statement.getRawObject().getMetaData(); + } + + @Override + public void preparedStatement_setDate(PreparedStatementProxy statement, int parameterIndex, java.sql.Date x, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setDate(this, statement, parameterIndex, x, cal); + return; + } + statement.getRawObject().setDate(parameterIndex, x, cal); + } + + @Override + public void preparedStatement_setTime(PreparedStatementProxy statement, int parameterIndex, java.sql.Time x, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setTime(this, statement, parameterIndex, x, cal); + return; + } + statement.getRawObject().setTime(parameterIndex, x, cal); + } + + @Override + public void preparedStatement_setTimestamp(PreparedStatementProxy statement, int parameterIndex, + java.sql.Timestamp x, Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setTimestamp(this, statement, parameterIndex, x, cal); + return; + } + statement.getRawObject().setTimestamp(parameterIndex, x, cal); + } + + @Override + public void preparedStatement_setNull(PreparedStatementProxy statement, int parameterIndex, int sqlType, + String typeName) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNull(this, statement, parameterIndex, sqlType, typeName); + return; + } + statement.getRawObject().setNull(parameterIndex, sqlType, typeName); + } + + @Override + public void preparedStatement_setURL(PreparedStatementProxy statement, int parameterIndex, java.net.URL x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setURL(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setURL(parameterIndex, x); + } + + @Override + public ParameterMetaData preparedStatement_getParameterMetaData(PreparedStatementProxy statement) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().preparedStatement_getParameterMetaData(this, statement); + } + return statement.getRawObject().getParameterMetaData(); + } + + @Override + public void preparedStatement_setRowId(PreparedStatementProxy statement, int parameterIndex, RowId x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setRowId(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setRowId(parameterIndex, x); + } + + @Override + public void preparedStatement_setNString(PreparedStatementProxy statement, int parameterIndex, String value) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNString(this, statement, parameterIndex, value); + return; + } + statement.getRawObject().setNString(parameterIndex, value); + } + + @Override + public void preparedStatement_setNCharacterStream(PreparedStatementProxy statement, int parameterIndex, + Reader value, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNCharacterStream(this, statement, parameterIndex, value, length); + return; + } + statement.getRawObject().setNCharacterStream(parameterIndex, value, length); + } + + @Override + public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, NClob value) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, value); + return; + } + statement.getRawObject().setNClob(parameterIndex, value); + } + + @Override + public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setClob(this, statement, parameterIndex, reader, length); + return; + } + statement.getRawObject().setClob(parameterIndex, reader, length); + } + + @Override + public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, + InputStream inputStream, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, inputStream, length); + return; + } + statement.getRawObject().setBlob(parameterIndex, inputStream, length); + } + + @Override + public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, reader, length); + return; + } + statement.getRawObject().setNClob(parameterIndex, reader, length); + } + + @Override + public void preparedStatement_setSQLXML(PreparedStatementProxy statement, int parameterIndex, SQLXML xmlObject) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setSQLXML(this, statement, parameterIndex, xmlObject); + return; + } + statement.getRawObject().setSQLXML(parameterIndex, xmlObject); + } + + @Override + public void preparedStatement_setObject(PreparedStatementProxy statement, int parameterIndex, Object x, + int targetSqlType, int scaleOrLength) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setObject(this, statement, parameterIndex, x, targetSqlType, scaleOrLength); + return; + } + statement.getRawObject().setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } + + @Override + public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x, length); + return; + } + statement.getRawObject().setAsciiStream(parameterIndex, x, length); + } + + @Override + public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x, length); + return; + } + statement.getRawObject().setBinaryStream(parameterIndex, x, length); + } + + @Override + public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, + java.io.Reader reader, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader, length); + return; + } + statement.getRawObject().setCharacterStream(parameterIndex, reader, length); + } + + @Override + public void preparedStatement_setAsciiStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setAsciiStream(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setAsciiStream(parameterIndex, x); + } + + @Override + public void preparedStatement_setBinaryStream(PreparedStatementProxy statement, int parameterIndex, + java.io.InputStream x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBinaryStream(this, statement, parameterIndex, x); + return; + } + statement.getRawObject().setBinaryStream(parameterIndex, x); + } + + @Override + public void preparedStatement_setCharacterStream(PreparedStatementProxy statement, int parameterIndex, + java.io.Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setCharacterStream(this, statement, parameterIndex, reader); + return; + } + statement.getRawObject().setCharacterStream(parameterIndex, reader); + } + + @Override + public void preparedStatement_setNCharacterStream(PreparedStatementProxy statement, int parameterIndex, Reader value) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNCharacterStream(this, statement, parameterIndex, value); + return; + } + statement.getRawObject().setNCharacterStream(parameterIndex, value); + } + + @Override + public void preparedStatement_setClob(PreparedStatementProxy statement, int parameterIndex, Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setClob(this, statement, parameterIndex, reader); + return; + } + statement.getRawObject().setClob(parameterIndex, reader); + } + + @Override + public void preparedStatement_setBlob(PreparedStatementProxy statement, int parameterIndex, InputStream inputStream) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setBlob(this, statement, parameterIndex, inputStream); + return; + } + statement.getRawObject().setBlob(parameterIndex, inputStream); + } + + @Override + public void preparedStatement_setNClob(PreparedStatementProxy statement, int parameterIndex, Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().preparedStatement_setNClob(this, statement, parameterIndex, reader); + return; + } + statement.getRawObject().setNClob(parameterIndex, reader); + } + + // ///////////////////////////////////// + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, int sqlType) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType); + return; + } + statement.getRawObject().registerOutParameter(parameterIndex, sqlType); + } + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, + int sqlType, int scale) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType, scale); + return; + } + statement.getRawObject().registerOutParameter(parameterIndex, sqlType, scale); + } + + @Override + public boolean callableStatement_wasNull(CallableStatementProxy statement) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_wasNull(this, statement); + } + return statement.getRawObject().wasNull(); + } + + @Override + public String callableStatement_getString(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getString(this, statement, parameterIndex); + } + return statement.getRawObject().getString(parameterIndex); + } + + @Override + public boolean callableStatement_getBoolean(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBoolean(this, statement, parameterIndex); + } + return statement.getRawObject().getBoolean(parameterIndex); + } + + @Override + public byte callableStatement_getByte(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getByte(this, statement, parameterIndex); + } + return statement.getRawObject().getByte(parameterIndex); + } + + @Override + public short callableStatement_getShort(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getShort(this, statement, parameterIndex); + } + return statement.getRawObject().getShort(parameterIndex); + } + + @Override + public int callableStatement_getInt(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getInt(this, statement, parameterIndex); + } + return statement.getRawObject().getInt(parameterIndex); + } + + @Override + public long callableStatement_getLong(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getLong(this, statement, parameterIndex); + } + return statement.getRawObject().getLong(parameterIndex); + } + + @Override + public float callableStatement_getFloat(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getFloat(this, statement, parameterIndex); + } + return statement.getRawObject().getFloat(parameterIndex); + } + + @Override + public double callableStatement_getDouble(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDouble(this, statement, parameterIndex); + } + return statement.getRawObject().getDouble(parameterIndex); + } + + @SuppressWarnings("deprecation") + @Override + public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, int parameterIndex, int scale) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBigDecimal(this, statement, parameterIndex, scale); + } + return statement.getRawObject().getBigDecimal(parameterIndex, scale); + } + + @Override + public byte[] callableStatement_getBytes(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBytes(this, statement, parameterIndex); + } + return statement.getRawObject().getBytes(parameterIndex); + } + + @Override + public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDate(this, statement, parameterIndex); + } + return statement.getRawObject().getDate(parameterIndex); + } + + @Override + public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTime(this, statement, parameterIndex); + } + return statement.getRawObject().getTime(parameterIndex); + } + + @Override + public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTimestamp(this, statement, parameterIndex); + } + return statement.getRawObject().getTimestamp(parameterIndex); + } + + @Override + public Object callableStatement_getObject(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getObject(this, statement, parameterIndex); + } + + Object obj = statement.getRawObject().getObject(parameterIndex); + + if (obj instanceof ResultSet) { + return wrap(statement, (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(statement, (Clob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(CallableStatementProxy statement, int parameterIndex, + java.util.Map> map) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getObject(this, statement, parameterIndex, map); + } + + Object obj = statement.getRawObject().getObject(parameterIndex, map); + + if (obj instanceof ResultSet) { + return wrap(statement, (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(statement, (Clob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getObject(this, statement, parameterName); + } + + Object obj = statement.getRawObject().getObject(parameterName); + + if (obj instanceof ResultSet) { + return wrap(statement, (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(statement, (Clob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName, + java.util.Map> map) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getObject(this, statement, parameterName, map); + } + + Object obj = statement.getRawObject().getObject(parameterName, map); + + if (obj instanceof ResultSet) { + return wrap(statement, (ResultSet) obj); + } + + if (obj instanceof Clob) { + return wrap(statement, (Clob) obj); + } + + return obj; + } + + @Override + public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBigDecimal(this, statement, parameterIndex); + } + return statement.getRawObject().getBigDecimal(parameterIndex); + } + + @Override + public Ref callableStatement_getRef(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getRef(this, statement, parameterIndex); + } + return statement.getRawObject().getRef(parameterIndex); + } + + @Override + public Blob callableStatement_getBlob(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBlob(this, statement, parameterIndex); + } + return statement.getRawObject().getBlob(parameterIndex); + } + + @Override + public Clob callableStatement_getClob(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getClob(this, statement, parameterIndex); + } + + Clob clob = statement.getRawObject().getClob(parameterIndex); + + return wrap(statement, clob); + } + + @Override + public Array callableStatement_getArray(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getArray(this, statement, parameterIndex); + } + return statement.getRawObject().getArray(parameterIndex); + } + + @Override + public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, int parameterIndex, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDate(this, statement, parameterIndex, cal); + } + return statement.getRawObject().getDate(parameterIndex, cal); + } + + @Override + public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, int parameterIndex, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTime(this, statement, parameterIndex, cal); + } + return statement.getRawObject().getTime(parameterIndex, cal); + } + + @Override + public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, int parameterIndex, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTimestamp(this, statement, parameterIndex, cal); + } + return statement.getRawObject().getTimestamp(parameterIndex, cal); + } + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, int parameterIndex, + int sqlType, String typeName) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterIndex, sqlType, typeName); + return; + } + statement.getRawObject().registerOutParameter(parameterIndex, sqlType, typeName); + } + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, + int sqlType) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType); + return; + } + statement.getRawObject().registerOutParameter(parameterName, sqlType); + } + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, + int sqlType, int scale) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType, scale); + return; + } + statement.getRawObject().registerOutParameter(parameterName, sqlType, scale); + } + + @Override + public void callableStatement_registerOutParameter(CallableStatementProxy statement, String parameterName, + int sqlType, String typeName) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_registerOutParameter(this, statement, parameterName, sqlType, typeName); + return; + } + statement.getRawObject().registerOutParameter(parameterName, sqlType, typeName); + } + + @Override + public java.net.URL callableStatement_getURL(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getURL(this, statement, parameterIndex); + } + return statement.getRawObject().getURL(parameterIndex); + } + + @Override + public void callableStatement_setURL(CallableStatementProxy statement, String parameterName, java.net.URL val) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setURL(this, statement, parameterName, val); + return; + } + statement.getRawObject().setURL(parameterName, val); + } + + @Override + public void callableStatement_setNull(CallableStatementProxy statement, String parameterName, int sqlType) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNull(this, statement, parameterName, sqlType); + return; + } + statement.getRawObject().setNull(parameterName, sqlType); + } + + @Override + public void callableStatement_setBoolean(CallableStatementProxy statement, String parameterName, boolean x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBoolean(this, statement, parameterName, x); + return; + } + statement.getRawObject().setBoolean(parameterName, x); + } + + @Override + public void callableStatement_setByte(CallableStatementProxy statement, String parameterName, byte x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setByte(this, statement, parameterName, x); + } + statement.getRawObject().setByte(parameterName, x); + } + + @Override + public void callableStatement_setShort(CallableStatementProxy statement, String parameterName, short x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setShort(this, statement, parameterName, x); + return; + } + statement.getRawObject().setShort(parameterName, x); + } + + @Override + public void callableStatement_setInt(CallableStatementProxy statement, String parameterName, int x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setInt(this, statement, parameterName, x); + return; + } + statement.getRawObject().setInt(parameterName, x); + } + + @Override + public void callableStatement_setLong(CallableStatementProxy statement, String parameterName, long x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setLong(this, statement, parameterName, x); + return; + } + statement.getRawObject().setLong(parameterName, x); + } + + @Override + public void callableStatement_setFloat(CallableStatementProxy statement, String parameterName, float x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setFloat(this, statement, parameterName, x); + return; + } + statement.getRawObject().setFloat(parameterName, x); + } + + @Override + public void callableStatement_setDouble(CallableStatementProxy statement, String parameterName, double x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setDouble(this, statement, parameterName, x); + return; + } + statement.getRawObject().setDouble(parameterName, x); + } + + @Override + public void callableStatement_setBigDecimal(CallableStatementProxy statement, String parameterName, BigDecimal x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBigDecimal(this, statement, parameterName, x); + return; + } + statement.getRawObject().setBigDecimal(parameterName, x); + } + + @Override + public void callableStatement_setString(CallableStatementProxy statement, String parameterName, String x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setString(this, statement, parameterName, x); + return; + } + statement.getRawObject().setString(parameterName, x); + } + + @Override + public void callableStatement_setBytes(CallableStatementProxy statement, String parameterName, byte x[]) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBytes(this, statement, parameterName, x); + return; + } + statement.getRawObject().setBytes(parameterName, x); + } + + @Override + public void callableStatement_setDate(CallableStatementProxy statement, String parameterName, java.sql.Date x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setDate(this, statement, parameterName, x); + return; + } + statement.getRawObject().setDate(parameterName, x); + } + + @Override + public void callableStatement_setTime(CallableStatementProxy statement, String parameterName, java.sql.Time x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setTime(this, statement, parameterName, x); + return; + } + statement.getRawObject().setTime(parameterName, x); + } + + @Override + public void callableStatement_setTimestamp(CallableStatementProxy statement, String parameterName, + java.sql.Timestamp x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setTimestamp(this, statement, parameterName, x); + return; + } + statement.getRawObject().setTimestamp(parameterName, x); + } + + @Override + public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x, length); + return; + } + statement.getRawObject().setAsciiStream(parameterName, x, length); + } + + @Override + public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x, length); + return; + } + statement.getRawObject().setBinaryStream(parameterName, x, length); + } + + @Override + public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, + int targetSqlType, int scale) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType, scale); + return; + } + statement.getRawObject().setObject(parameterName, x, targetSqlType, scale); + } + + @Override + public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x, + int targetSqlType) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setObject(this, statement, parameterName, x, targetSqlType); + return; + } + statement.getRawObject().setObject(parameterName, x, targetSqlType); + } + + @Override + public void callableStatement_setObject(CallableStatementProxy statement, String parameterName, Object x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setObject(this, statement, parameterName, x); + return; + } + statement.getRawObject().setObject(parameterName, x); + } + + @Override + public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, + java.io.Reader reader, int length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader, length); + return; + } + statement.getRawObject().setCharacterStream(parameterName, reader, length); + } + + @Override + public void callableStatement_setDate(CallableStatementProxy statement, String parameterName, java.sql.Date x, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setDate(this, statement, parameterName, x, cal); + return; + } + statement.getRawObject().setDate(parameterName, x, cal); + } + + @Override + public void callableStatement_setTime(CallableStatementProxy statement, String parameterName, java.sql.Time x, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setTime(this, statement, parameterName, x, cal); + return; + } + statement.getRawObject().setTime(parameterName, x, cal); + } + + @Override + public void callableStatement_setTimestamp(CallableStatementProxy statement, String parameterName, + java.sql.Timestamp x, Calendar cal) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setTimestamp(this, statement, parameterName, x, cal); + return; + } + statement.getRawObject().setTimestamp(parameterName, x, cal); + } + + @Override + public void callableStatement_setNull(CallableStatementProxy statement, String parameterName, int sqlType, + String typeName) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNull(this, statement, parameterName, sqlType, typeName); + return; + } + statement.getRawObject().setNull(parameterName, sqlType, typeName); + } + + @Override + public String callableStatement_getString(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getString(this, statement, parameterName); + } + return statement.getRawObject().getString(parameterName); + } + + @Override + public boolean callableStatement_getBoolean(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBoolean(this, statement, parameterName); + } + return statement.getRawObject().getBoolean(parameterName); + } + + @Override + public byte callableStatement_getByte(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getByte(this, statement, parameterName); + } + return statement.getRawObject().getByte(parameterName); + } + + @Override + public short callableStatement_getShort(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getShort(this, statement, parameterName); + } + return statement.getRawObject().getShort(parameterName); + } + + @Override + public int callableStatement_getInt(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getInt(this, statement, parameterName); + } + return statement.getRawObject().getInt(parameterName); + } + + @Override + public long callableStatement_getLong(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getLong(this, statement, parameterName); + } + return statement.getRawObject().getLong(parameterName); + } + + @Override + public float callableStatement_getFloat(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getFloat(this, statement, parameterName); + } + return statement.getRawObject().getFloat(parameterName); + } + + @Override + public double callableStatement_getDouble(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDouble(this, statement, parameterName); + } + return statement.getRawObject().getDouble(parameterName); + } + + @Override + public byte[] callableStatement_getBytes(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBytes(this, statement, parameterName); + } + return statement.getRawObject().getBytes(parameterName); + } + + @Override + public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDate(this, statement, parameterName); + } + return statement.getRawObject().getDate(parameterName); + } + + @Override + public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTime(this, statement, parameterName); + } + return statement.getRawObject().getTime(parameterName); + } + + @Override + public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTimestamp(this, statement, parameterName); + } + return statement.getRawObject().getTimestamp(parameterName); + } + + @Override + public BigDecimal callableStatement_getBigDecimal(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBigDecimal(this, statement, parameterName); + } + return statement.getRawObject().getBigDecimal(parameterName); + } + + @Override + public Ref callableStatement_getRef(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getRef(this, statement, parameterName); + } + return statement.getRawObject().getRef(parameterName); + } + + @Override + public Blob callableStatement_getBlob(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getBlob(this, statement, parameterName); + } + return statement.getRawObject().getBlob(parameterName); + } + + @Override + public Clob callableStatement_getClob(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getClob(this, statement, parameterName); + } + + Clob clob = statement.getRawObject().getClob(parameterName); + + return wrap(statement, clob); + } + + @Override + public Array callableStatement_getArray(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getArray(this, statement, parameterName); + } + return statement.getRawObject().getArray(parameterName); + } + + @Override + public java.sql.Date callableStatement_getDate(CallableStatementProxy statement, String parameterName, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getDate(this, statement, parameterName, cal); + } + return statement.getRawObject().getDate(parameterName, cal); + } + + @Override + public java.sql.Time callableStatement_getTime(CallableStatementProxy statement, String parameterName, Calendar cal) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTime(this, statement, parameterName, cal); + } + return statement.getRawObject().getTime(parameterName, cal); + } + + @Override + public java.sql.Timestamp callableStatement_getTimestamp(CallableStatementProxy statement, String parameterName, + Calendar cal) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getTimestamp(this, statement, parameterName, cal); + } + return statement.getRawObject().getTimestamp(parameterName, cal); + } + + @Override + public java.net.URL callableStatement_getURL(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getURL(this, statement, parameterName); + } + return statement.getRawObject().getURL(parameterName); + } + + @Override + public RowId callableStatement_getRowId(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getRowId(this, statement, parameterIndex); + } + return statement.getRawObject().getRowId(parameterIndex); + } + + @Override + public RowId callableStatement_getRowId(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getRowId(this, statement, parameterName); + } + return statement.getRawObject().getRowId(parameterName); + } + + @Override + public void callableStatement_setRowId(CallableStatementProxy statement, String parameterName, RowId x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setRowId(this, statement, parameterName, x); + return; + } + statement.getRawObject().setRowId(parameterName, x); + } + + @Override + public void callableStatement_setNString(CallableStatementProxy statement, String parameterName, String value) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNString(this, statement, parameterName, value); + return; + } + statement.getRawObject().setNString(parameterName, value); + } + + @Override + public void callableStatement_setNCharacterStream(CallableStatementProxy statement, String parameterName, + Reader value, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNCharacterStream(this, statement, parameterName, value, length); + return; + } + statement.getRawObject().setNCharacterStream(parameterName, value, length); + } + + @Override + public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, NClob value) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNClob(this, statement, parameterName, value); + return; + } + statement.getRawObject().setNClob(parameterName, value); + } + + @Override + public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setClob(this, statement, parameterName, reader, length); + return; + } + statement.getRawObject().setClob(parameterName, reader, length); + } + + @Override + public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, + InputStream inputStream, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBlob(this, statement, parameterName, inputStream, length); + return; + } + statement.getRawObject().setBlob(parameterName, inputStream, length); + } + + @Override + public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, Reader reader, + long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNClob(this, statement, parameterName, reader, length); + return; + } + statement.getRawObject().setNClob(parameterName, reader, length); + } + + @Override + public NClob callableStatement_getNClob(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNClob(this, statement, parameterIndex); + } + + NClob nclob = statement.getRawObject().getNClob(parameterIndex); + + return wrap(statement.getConnectionProxy(), nclob); + } + + @Override + public NClob callableStatement_getNClob(CallableStatementProxy statement, String parameterName) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNClob(this, statement, parameterName); + } + + NClob nclob = statement.getRawObject().getNClob(parameterName); + + return wrap(statement.getConnectionProxy(), nclob); + } + + @Override + public void callableStatement_setSQLXML(CallableStatementProxy statement, String parameterName, SQLXML xmlObject) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setSQLXML(this, statement, parameterName, xmlObject); + return; + } + statement.getRawObject().setSQLXML(parameterName, xmlObject); + } + + @Override + public SQLXML callableStatement_getSQLXML(CallableStatementProxy statement, int parameterIndex) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getSQLXML(this, statement, parameterIndex); + } + return statement.getRawObject().getSQLXML(parameterIndex); + } + + @Override + public SQLXML callableStatement_getSQLXML(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getSQLXML(this, statement, parameterName); + } + return statement.getRawObject().getSQLXML(parameterName); + } + + @Override + public String callableStatement_getNString(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNString(this, statement, parameterIndex); + } + return statement.getRawObject().getNString(parameterIndex); + } + + @Override + public String callableStatement_getNString(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNString(this, statement, parameterName); + } + return statement.getRawObject().getNString(parameterName); + } + + @Override + public java.io.Reader callableStatement_getNCharacterStream(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNCharacterStream(this, statement, parameterIndex); + } + return statement.getRawObject().getNCharacterStream(parameterIndex); + } + + @Override + public java.io.Reader callableStatement_getNCharacterStream(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getNCharacterStream(this, statement, parameterName); + } + return statement.getRawObject().getNCharacterStream(parameterName); + } + + @Override + public java.io.Reader callableStatement_getCharacterStream(CallableStatementProxy statement, int parameterIndex) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getCharacterStream(this, statement, parameterIndex); + } + return statement.getRawObject().getCharacterStream(parameterIndex); + } + + @Override + public java.io.Reader callableStatement_getCharacterStream(CallableStatementProxy statement, String parameterName) + throws SQLException { + if (this.pos < filterSize) { + return nextFilter().callableStatement_getCharacterStream(this, statement, parameterName); + } + return statement.getRawObject().getCharacterStream(parameterName); + } + + @Override + public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, Blob x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBlob(this, statement, parameterName, x); + return; + } + statement.getRawObject().setBlob(parameterName, x); + } + + @Override + public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Clob x) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setClob(this, statement, parameterName, x); + return; + } + statement.getRawObject().setClob(parameterName, x); + } + + @Override + public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x, length); + return; + } + statement.getRawObject().setAsciiStream(parameterName, x, length); + } + + @Override + public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x, length); + return; + } + statement.getRawObject().setBinaryStream(parameterName, x, length); + } + + @Override + public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, + java.io.Reader reader, long length) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader, length); + return; + } + statement.getRawObject().setCharacterStream(parameterName, reader, length); + } + + @Override + public void callableStatement_setAsciiStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setAsciiStream(this, statement, parameterName, x); + return; + } + statement.getRawObject().setAsciiStream(parameterName, x); + } + + @Override + public void callableStatement_setBinaryStream(CallableStatementProxy statement, String parameterName, + java.io.InputStream x) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBinaryStream(this, statement, parameterName, x); + return; + } + statement.getRawObject().setBinaryStream(parameterName, x); + } + + @Override + public void callableStatement_setCharacterStream(CallableStatementProxy statement, String parameterName, + java.io.Reader reader) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setCharacterStream(this, statement, parameterName, reader); + return; + } + statement.getRawObject().setCharacterStream(parameterName, reader); + } + + @Override + public void callableStatement_setNCharacterStream(CallableStatementProxy statement, String parameterName, + Reader value) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNCharacterStream(this, statement, parameterName, value); + return; + } + statement.getRawObject().setNCharacterStream(parameterName, value); + } + + @Override + public void callableStatement_setClob(CallableStatementProxy statement, String parameterName, Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setClob(this, statement, parameterName, reader); + return; + } + statement.getRawObject().setClob(parameterName, reader); + } + + @Override + public void callableStatement_setBlob(CallableStatementProxy statement, String parameterName, + InputStream inputStream) throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setBlob(this, statement, parameterName, inputStream); + return; + } + statement.getRawObject().setBlob(parameterName, inputStream); + } + + @Override + public void callableStatement_setNClob(CallableStatementProxy statement, String parameterName, Reader reader) + throws SQLException { + if (this.pos < filterSize) { + nextFilter().callableStatement_setNClob(this, statement, parameterName, reader); + return; + } + statement.getRawObject().setNClob(parameterName, reader); + } + + @Override + public long clob_length(ClobProxy clob) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_length(this, clob); + } + return clob.getRawClob().length(); + } + + @Override + public String clob_getSubString(ClobProxy clob, long pos, int length) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_getSubString(this, clob, pos, length); + } + return clob.getRawClob().getSubString(pos, length); + } + + @Override + public java.io.Reader clob_getCharacterStream(ClobProxy clob) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_getCharacterStream(this, clob); + } + return clob.getRawClob().getCharacterStream(); + } + + @Override + public java.io.InputStream clob_getAsciiStream(ClobProxy clob) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_getAsciiStream(this, clob); + } + return clob.getRawClob().getAsciiStream(); + } + + @Override + public long clob_position(ClobProxy clob, String searchstr, long start) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_position(this, clob, searchstr, start); + } + return clob.getRawClob().position(searchstr, start); + } + + @Override + public long clob_position(ClobProxy clob, Clob searchstr, long start) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_position(this, clob, searchstr, start); + } + return clob.getRawClob().position(searchstr, start); + } + + @Override + public int clob_setString(ClobProxy clob, long pos, String str) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_setString(this, clob, pos, str); + } + return clob.getRawClob().setString(pos, str); + } + + @Override + public int clob_setString(ClobProxy clob, long pos, String str, int offset, int len) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_setString(this, clob, pos, str, offset, len); + } + return clob.getRawClob().setString(pos, str, offset, len); + } + + @Override + public java.io.OutputStream clob_setAsciiStream(ClobProxy clob, long pos) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_setAsciiStream(this, clob, pos); + } + return clob.getRawClob().setAsciiStream(pos); + } + + @Override + public java.io.Writer clob_setCharacterStream(ClobProxy clob, long pos) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_setCharacterStream(this, clob, pos); + } + return clob.getRawClob().setCharacterStream(pos); + } + + @Override + public void clob_truncate(ClobProxy clob, long len) throws SQLException { + if (this.pos < filterSize) { + nextFilter().clob_truncate(this, clob, len); + return; + } + clob.getRawClob().truncate(len); + } + + @Override + public void clob_free(ClobProxy clob) throws SQLException { + if (this.pos < filterSize) { + nextFilter().clob_free(this, clob); + return; + } + clob.getRawClob().free(); + } + + @Override + public Reader clob_getCharacterStream(ClobProxy clob, long pos, long length) throws SQLException { + if (this.pos < filterSize) { + return nextFilter().clob_getCharacterStream(this, clob, pos, length); + } + return clob.getRawClob().getCharacterStream(pos, length); + } + + // //////////// + + public ConnectionProxy wrap(Connection connection, Properties info) { + if (connection == null) { + return null; + } + + return new ConnectionProxyImpl(dataSource, connection, info, dataSource.createConnectionId()); + } + + public StatementProxy wrap(ConnectionProxy connection, Statement statement) { + if (statement == null) { + return null; + } + + return new StatementProxyImpl(connection, statement, dataSource.createStatementId()); + } + + public PreparedStatementProxy wrap(ConnectionProxy connection, PreparedStatement statement, String sql) { + if (statement == null) { + return null; + } + + return new PreparedStatementProxyImpl(connection, statement, sql, dataSource.createStatementId()); + } + + public CallableStatementProxy wrap(ConnectionProxy connection, CallableStatement statement, String sql) { + if (statement == null) { + return null; + } + + return new CallableStatementProxyImpl(connection, statement, sql, dataSource.createStatementId()); + } + + public ResultSetProxy wrap(StatementProxy statement, ResultSet resultSet) { + if (resultSet == null) { + return null; + } + + return new ResultSetProxyImpl(statement, resultSet, dataSource.createResultSetId(), + statement.getLastExecuteSql()); + } + + public ClobProxy wrap(ConnectionProxy conn, Clob clob) { + if (clob == null) { + return null; + } + + if (clob instanceof NClob) { + return wrap(conn, (NClob) clob); + } + + return new ClobProxyImpl(dataSource, conn, clob); + } + + public NClobProxy wrap(ConnectionProxy conn, NClob clob) { + if (clob == null) { + return null; + } + + return new NClobProxyImpl(dataSource, conn, clob); + } + + public ClobProxy wrap(StatementProxy stmt, Clob clob) { + if (clob == null) { + return null; + } + + if (clob instanceof NClob) { + return wrap(stmt, (NClob) clob); + } + + return new ClobProxyImpl(dataSource, stmt.getConnectionProxy(), clob); + } + + public NClobProxy wrap(StatementProxy stmt, NClob nclob) { + if (nclob == null) { + return null; + } + + return new NClobProxyImpl(dataSource, stmt.getConnectionProxy(), nclob); + } + + @Override + public void dataSource_recycle(DruidPooledConnection connection) throws SQLException { + if (this.pos < filterSize) { + nextFilter().dataSource_releaseConnection(this, connection); + return; + } + + connection.recycle(); + } + + @Override + public DruidPooledConnection dataSource_connect(DruidDataSource dataSource, long maxWaitMillis) throws SQLException { + if (this.pos < filterSize) { + DruidPooledConnection conn = nextFilter().dataSource_getConnection(this, dataSource, maxWaitMillis); + return conn; + } + + return dataSource.getConnectionDirect(maxWaitMillis); + } + +} diff --git a/src/main/java/com/alibaba/druid/filter/FilterManager.java b/src/main/java/com/alibaba/druid/filter/FilterManager.java index cfef0f755b..0aacf25f70 100644 --- a/src/main/java/com/alibaba/druid/filter/FilterManager.java +++ b/src/main/java/com/alibaba/druid/filter/FilterManager.java @@ -33,7 +33,7 @@ public class FilterManager { private final static Log LOG = LogFactory.getLog(FilterManager.class); - private static final ConcurrentHashMap aliasMap = new ConcurrentHashMap(); + private static final ConcurrentHashMap aliasMap = new ConcurrentHashMap(16, 0.75f, 1); static { try { diff --git a/src/main/java/com/alibaba/druid/filter/encoding/EncodingConvertFilter.java b/src/main/java/com/alibaba/druid/filter/encoding/EncodingConvertFilter.java index 96a5428ce0..c7b04afab7 100644 --- a/src/main/java/com/alibaba/druid/filter/encoding/EncodingConvertFilter.java +++ b/src/main/java/com/alibaba/druid/filter/encoding/EncodingConvertFilter.java @@ -1,624 +1,624 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.filter.encoding; - -import java.io.Reader; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Properties; - -import com.alibaba.druid.filter.FilterAdapter; -import com.alibaba.druid.filter.FilterChain; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; -import com.alibaba.druid.proxy.jdbc.ClobProxy; -import com.alibaba.druid.proxy.jdbc.ConnectionProxy; -import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; -import com.alibaba.druid.proxy.jdbc.ResultSetProxy; -import com.alibaba.druid.proxy.jdbc.StatementProxy; -import com.alibaba.druid.util.IOUtils; - -/** - * @author wenshao - */ -public class EncodingConvertFilter extends FilterAdapter { - - public final static String ATTR_CHARSET_PARAMETER = "ali.charset.param"; - public final static String ATTR_CHARSET_CONVERTER = "ali.charset.converter"; - private String clientEncoding; - private String serverEncoding; - - public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException { - ConnectionProxy conn = chain.connection_connect(info); - - CharsetParameter param = new CharsetParameter(); - param.setClientEncoding(info.getProperty(CharsetParameter.CLIENTENCODINGKEY)); - param.setServerEncoding(info.getProperty(CharsetParameter.SERVERENCODINGKEY)); - - if (param.getClientEncoding() == null || "".equalsIgnoreCase(param.getClientEncoding())) { - param.setClientEncoding(clientEncoding); - } - if (param.getServerEncoding() == null || "".equalsIgnoreCase(param.getServerEncoding())) { - param.setServerEncoding(serverEncoding); - } - conn.getAttributes().put(ATTR_CHARSET_PARAMETER, param); - conn.getAttributes().put(ATTR_CHARSET_CONVERTER, - new CharsetConvert(param.getClientEncoding(), param.getServerEncoding())); - - return conn; - } - - @Override - public String resultSet_getString(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - String value = super.resultSet_getString(chain, result, columnIndex); - return decode(result.getStatementProxy().getConnectionProxy(), value); - } - - @Override - public String resultSet_getString(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - String value = super.resultSet_getString(chain, result, columnLabel); - return decode(result.getStatementProxy().getConnectionProxy(), value); - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - ResultSet rawResultSet = result.getResultSetRaw(); - ResultSetMetaData metadata = rawResultSet.getMetaData(); - int columnType = metadata.getColumnType(columnIndex); - - Object value = null; - switch (columnType) { - case Types.CHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.CLOB: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.LONGVARCHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.VARCHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - default: - value = super.resultSet_getObject(chain, result, columnIndex); - } - - return decodeObject(result.getStatementProxy().getConnectionProxy(), value); - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, - java.util.Map> map) throws SQLException { - ResultSet rawResultSet = result.getResultSetRaw(); - ResultSetMetaData metadata = rawResultSet.getMetaData(); - int columnType = metadata.getColumnType(columnIndex); - - Object value = null; - switch (columnType) { - case Types.CHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.CLOB: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.LONGVARCHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - case Types.VARCHAR: - value = super.resultSet_getString(chain, result, columnIndex); - break; - default: - value = super.resultSet_getObject(chain, result, columnIndex, map); - } - - return decodeObject(result.getStatementProxy().getConnectionProxy(), value); - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - ResultSet rawResultSet = result.getResultSetRaw(); - ResultSetMetaData metadata = rawResultSet.getMetaData(); - int columnIndex = rawResultSet.findColumn(columnLabel); - int columnType = metadata.getColumnType(columnIndex); - - Object value = null; - switch (columnType) { - case Types.CHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.CLOB: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.LONGVARCHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.VARCHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - default: - value = super.resultSet_getObject(chain, result, columnLabel); - } - return decodeObject(result.getStatementProxy().getConnectionProxy(), value); - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, - java.util.Map> map) throws SQLException { - ResultSet rawResultSet = result.getResultSetRaw(); - ResultSetMetaData metadata = rawResultSet.getMetaData(); - int columnIndex = rawResultSet.findColumn(columnLabel); - int columnType = metadata.getColumnType(columnIndex); - - Object value = null; - switch (columnType) { - case Types.CHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.CLOB: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.LONGVARCHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - case Types.VARCHAR: - value = super.resultSet_getString(chain, result, columnLabel); - break; - default: - value = super.resultSet_getObject(chain, result, columnLabel, map); - } - - return decodeObject(result.getStatementProxy().getConnectionProxy(), value); - } - - // /////////// - - public Object decodeObject(ConnectionProxy connection, Object object) throws SQLException { - if (object instanceof String) { - return decode(connection, (String) object); - } - - if (object instanceof Reader) { - Reader reader = (Reader) object; - String text = IOUtils.read(reader); - return new StringReader(decode(connection, text)); - } - - return object; - } - - public Object decodeObject(CallableStatementProxy stmt, Object object) throws SQLException { - if (object instanceof String) { - return decode(stmt.getConnectionProxy(), (String) object); - } - - if (object instanceof Reader) { - Reader reader = (Reader) object; - String text = IOUtils.read(reader); - return new StringReader(decode(stmt.getConnectionProxy(), text)); - } - - return object; - } - - public String encode(ConnectionProxy connection, String s) throws SQLException { - try { - CharsetConvert charsetConvert = (CharsetConvert) connection.getAttributes().get(ATTR_CHARSET_CONVERTER); - - return charsetConvert.encode(s); - } catch (UnsupportedEncodingException e) { - throw new SQLException(e.getMessage(), e); - } - } - - public String decode(ConnectionProxy connection, String s) throws SQLException { - try { - CharsetConvert charsetConvert = (CharsetConvert) connection.getAttributes().get(ATTR_CHARSET_CONVERTER); - return charsetConvert.decode(s); - } catch (UnsupportedEncodingException e) { - throw new SQLException(e.getMessage(), e); - } - } - - // //////////////// Connection - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) - throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql)); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int autoGeneratedKeys) throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql), autoGeneratedKeys); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql), resultSetType, - resultSetConcurrency); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql), resultSetType, - resultSetConcurrency, resultSetHoldability); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int[] columnIndexes) throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql), columnIndexes); - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, String[] columnNames) throws SQLException { - return super.connection_prepareStatement(chain, connection, encode(connection, sql), columnNames); - } - - // / precall - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) - throws SQLException { - return super.connection_prepareCall(chain, connection, encode(connection, sql)); - } - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency) - throws SQLException { - return super.connection_prepareCall(chain, connection, encode(connection, sql), resultSetType, - resultSetConcurrency); - } - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - return super.connection_prepareCall(chain, connection, encode(connection, sql), resultSetType, - resultSetConcurrency, resultSetHoldability); - } - - // nativeSQL - - @Override - public String connection_nativeSQL(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException { - String encodedSql = encode(connection, sql); - return super.connection_nativeSQL(chain, connection, encodedSql); - } - - // ////////////// statement - - @Override - public void statement_addBatch(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - super.statement_addBatch(chain, statement, encode(statement.getConnectionProxy(), sql)); - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql)); - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) - throws SQLException { - return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), autoGeneratedKeys); - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) - throws SQLException { - return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), columnIndexes); - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) - throws SQLException { - return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), columnNames); - } - - @Override - public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) - throws SQLException { - return super.statement_executeQuery(chain, statement, encode(statement.getConnectionProxy(), sql)); - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql)); - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) - throws SQLException { - return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), - autoGeneratedKeys); - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) - throws SQLException { - return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), - columnIndexes); - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) - throws SQLException { - return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), columnNames); - } - - // ========== preparedStatement - - @Override - public void preparedStatement_setString(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, - String x) throws SQLException { - super.preparedStatement_setString(chain, statement, parameterIndex, encode(statement.getConnectionProxy(), x)); - } - - @Override - public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, - int parameterIndex, java.io.Reader reader) throws SQLException { - String text = IOUtils.read(reader); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText)); - } - - @Override - public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, - int parameterIndex, java.io.Reader reader, int length) - throws SQLException { - String text = IOUtils.read(reader, length); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText), - encodedText.length()); - } - - @Override - public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, - int parameterIndex, java.io.Reader reader, long length) - throws SQLException { - String text = IOUtils.read(reader, (int) length); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText), - encodedText.length()); - } - - @Override - public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, - Object x) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText)); - } else { - super.preparedStatement_setObject(chain, statement, parameterIndex, x); - } - } - - @Override - public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, - Object x, int targetSqlType) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText), - targetSqlType); - } else { - super.preparedStatement_setObject(chain, statement, parameterIndex, x, targetSqlType); - } - } - - @Override - public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, - Object x, int targetSqlType, int scaleOrLength) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType, - scaleOrLength); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText), - targetSqlType, scaleOrLength); - } else { - super.preparedStatement_setObject(chain, statement, parameterIndex, x, targetSqlType, scaleOrLength); - } - } - - // ////////// - - @Override - public long clob_position(FilterChain chain, ClobProxy wrapper, String searchstr, long start) throws SQLException { - return chain.clob_position(wrapper, encode(wrapper.getConnectionWrapper(), searchstr), start); - } - - @Override - public String clob_getSubString(FilterChain chain, ClobProxy wrapper, long pos, int length) throws SQLException { - String text = super.clob_getSubString(chain, wrapper, pos, length); - return decode(wrapper.getConnectionWrapper(), text); - } - - @Override - public java.io.Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper) throws SQLException { - Reader reader = super.clob_getCharacterStream(chain, wrapper); - String text = IOUtils.read(reader); - return new StringReader(decode(wrapper.getConnectionWrapper(), text)); - } - - @Override - public Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper, long pos, long length) - throws SQLException { - Reader reader = super.clob_getCharacterStream(chain, wrapper, pos, length); - String text = IOUtils.read(reader); - return new StringReader(decode(wrapper.getConnectionWrapper(), text)); - } - - @Override - public int clob_setString(FilterChain chain, ClobProxy wrapper, long pos, String str) throws SQLException { - return chain.clob_setString(wrapper, pos, encode(wrapper.getConnectionWrapper(), str)); - } - - @Override - public int clob_setString(FilterChain chain, ClobProxy wrapper, long pos, String str, int offset, int len) - throws SQLException { - return chain.clob_setString(wrapper, pos, encode(wrapper.getConnectionWrapper(), str), offset, len); - } - - // ///////////// callableStatement_ - - @Override - public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, - String parameterName, java.io.Reader reader) throws SQLException { - String text = IOUtils.read(reader); - Reader encodeReader = new StringReader(encode(statement.getConnectionProxy(), text)); - super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader); - } - - @Override - public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, - String parameterName, java.io.Reader reader, int length) - throws SQLException { - String text = IOUtils.read(reader, length); - String encodeText = encode(statement.getConnectionProxy(), text); - Reader encodeReader = new StringReader(encodeText); - super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, encodeText.length()); - } - - @Override - public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, - String parameterName, java.io.Reader reader, long length) - throws SQLException { - String text = IOUtils.read(reader, (int) length); - String encodeText = encode(statement.getConnectionProxy(), text); - Reader encodeReader = new StringReader(encodeText); - super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, - (long) encodeText.length()); - } - - @Override - public void callableStatement_setString(FilterChain chain, CallableStatementProxy statement, String parameterName, - String x) throws SQLException { - super.callableStatement_setString(chain, statement, parameterName, encode(statement.getConnectionProxy(), x)); - } - - @Override - public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, - Object x) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.callableStatement_setObject(chain, statement, parameterName, encodedText); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText)); - } else { - super.callableStatement_setObject(chain, statement, parameterName, x); - } - } - - @Override - public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, - Object x, int targetSqlType) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText), - targetSqlType); - } else { - super.callableStatement_setObject(chain, statement, parameterName, x, targetSqlType); - } - } - - @Override - public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, - Object x, int targetSqlType, int scale) throws SQLException { - if (x instanceof String) { - String encodedText = encode(statement.getConnectionProxy(), (String) x); - super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType, scale); - } else if (x instanceof Reader) { - String text = IOUtils.read((Reader) x); - String encodedText = encode(statement.getConnectionProxy(), text); - super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText), - targetSqlType, scale); - } else { - super.callableStatement_setObject(chain, statement, parameterName, x, targetSqlType, scale); - } - } - - @Override - public String callableStatement_getString(FilterChain chain, CallableStatementProxy statement, int parameterIndex) - throws SQLException { - String value = super.callableStatement_getString(chain, statement, parameterIndex); - return decode(statement.getConnectionProxy(), value); - } - - @Override - public String callableStatement_getString(FilterChain chain, CallableStatementProxy statement, String parameterName) - throws SQLException { - String value = super.callableStatement_getString(chain, statement, parameterName); - return decode(statement.getConnectionProxy(), value); - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex) - throws SQLException { - Object value = chain.callableStatement_getObject(statement, parameterIndex); - return decodeObject(statement, value); - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex, - java.util.Map> map) throws SQLException { - Object value = chain.callableStatement_getObject(statement, parameterIndex, map); - return decodeObject(statement, value); - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, String parameterName) - throws SQLException { - Object value = chain.callableStatement_getObject(statement, parameterName); - return decodeObject(statement, value); - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, - String parameterName, java.util.Map> map) - throws SQLException { - Object value = chain.callableStatement_getObject(statement, parameterName, map); - return decodeObject(statement, value); - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.filter.encoding; + +import java.io.Reader; +import java.io.StringReader; +import java.io.UnsupportedEncodingException; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Properties; + +import com.alibaba.druid.filter.FilterAdapter; +import com.alibaba.druid.filter.FilterChain; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; +import com.alibaba.druid.proxy.jdbc.ClobProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxy; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; +import com.alibaba.druid.proxy.jdbc.ResultSetProxy; +import com.alibaba.druid.proxy.jdbc.StatementProxy; +import com.alibaba.druid.util.IOUtils; + +/** + * @author wenshao + */ +public class EncodingConvertFilter extends FilterAdapter { + + public final static String ATTR_CHARSET_PARAMETER = "ali.charset.param"; + public final static String ATTR_CHARSET_CONVERTER = "ali.charset.converter"; + private String clientEncoding; + private String serverEncoding; + + public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException { + ConnectionProxy conn = chain.connection_connect(info); + + CharsetParameter param = new CharsetParameter(); + param.setClientEncoding(info.getProperty(CharsetParameter.CLIENTENCODINGKEY)); + param.setServerEncoding(info.getProperty(CharsetParameter.SERVERENCODINGKEY)); + + if (param.getClientEncoding() == null || "".equalsIgnoreCase(param.getClientEncoding())) { + param.setClientEncoding(clientEncoding); + } + if (param.getServerEncoding() == null || "".equalsIgnoreCase(param.getServerEncoding())) { + param.setServerEncoding(serverEncoding); + } + conn.putAttribute(ATTR_CHARSET_PARAMETER, param); + conn.putAttribute(ATTR_CHARSET_CONVERTER, + new CharsetConvert(param.getClientEncoding(), param.getServerEncoding())); + + return conn; + } + + @Override + public String resultSet_getString(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + String value = super.resultSet_getString(chain, result, columnIndex); + return decode(result.getStatementProxy().getConnectionProxy(), value); + } + + @Override + public String resultSet_getString(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + String value = super.resultSet_getString(chain, result, columnLabel); + return decode(result.getStatementProxy().getConnectionProxy(), value); + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + ResultSet rawResultSet = result.getResultSetRaw(); + ResultSetMetaData metadata = rawResultSet.getMetaData(); + int columnType = metadata.getColumnType(columnIndex); + + Object value = null; + switch (columnType) { + case Types.CHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.CLOB: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.LONGVARCHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.VARCHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + default: + value = super.resultSet_getObject(chain, result, columnIndex); + } + + return decodeObject(result.getStatementProxy().getConnectionProxy(), value); + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, + java.util.Map> map) throws SQLException { + ResultSet rawResultSet = result.getResultSetRaw(); + ResultSetMetaData metadata = rawResultSet.getMetaData(); + int columnType = metadata.getColumnType(columnIndex); + + Object value = null; + switch (columnType) { + case Types.CHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.CLOB: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.LONGVARCHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + case Types.VARCHAR: + value = super.resultSet_getString(chain, result, columnIndex); + break; + default: + value = super.resultSet_getObject(chain, result, columnIndex, map); + } + + return decodeObject(result.getStatementProxy().getConnectionProxy(), value); + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + ResultSet rawResultSet = result.getResultSetRaw(); + ResultSetMetaData metadata = rawResultSet.getMetaData(); + int columnIndex = rawResultSet.findColumn(columnLabel); + int columnType = metadata.getColumnType(columnIndex); + + Object value = null; + switch (columnType) { + case Types.CHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.CLOB: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.LONGVARCHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.VARCHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + default: + value = super.resultSet_getObject(chain, result, columnLabel); + } + return decodeObject(result.getStatementProxy().getConnectionProxy(), value); + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, + java.util.Map> map) throws SQLException { + ResultSet rawResultSet = result.getResultSetRaw(); + ResultSetMetaData metadata = rawResultSet.getMetaData(); + int columnIndex = rawResultSet.findColumn(columnLabel); + int columnType = metadata.getColumnType(columnIndex); + + Object value = null; + switch (columnType) { + case Types.CHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.CLOB: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.LONGVARCHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + case Types.VARCHAR: + value = super.resultSet_getString(chain, result, columnLabel); + break; + default: + value = super.resultSet_getObject(chain, result, columnLabel, map); + } + + return decodeObject(result.getStatementProxy().getConnectionProxy(), value); + } + + // /////////// + + public Object decodeObject(ConnectionProxy connection, Object object) throws SQLException { + if (object instanceof String) { + return decode(connection, (String) object); + } + + if (object instanceof Reader) { + Reader reader = (Reader) object; + String text = IOUtils.read(reader); + return new StringReader(decode(connection, text)); + } + + return object; + } + + public Object decodeObject(CallableStatementProxy stmt, Object object) throws SQLException { + if (object instanceof String) { + return decode(stmt.getConnectionProxy(), (String) object); + } + + if (object instanceof Reader) { + Reader reader = (Reader) object; + String text = IOUtils.read(reader); + return new StringReader(decode(stmt.getConnectionProxy(), text)); + } + + return object; + } + + public String encode(ConnectionProxy connection, String s) throws SQLException { + try { + CharsetConvert charsetConvert = (CharsetConvert) connection.getAttribute(ATTR_CHARSET_CONVERTER); + + return charsetConvert.encode(s); + } catch (UnsupportedEncodingException e) { + throw new SQLException(e.getMessage(), e); + } + } + + public String decode(ConnectionProxy connection, String s) throws SQLException { + try { + CharsetConvert charsetConvert = (CharsetConvert) connection.getAttribute(ATTR_CHARSET_CONVERTER); + return charsetConvert.decode(s); + } catch (UnsupportedEncodingException e) { + throw new SQLException(e.getMessage(), e); + } + } + + // //////////////// Connection + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) + throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql)); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int autoGeneratedKeys) throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql), autoGeneratedKeys); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql), resultSetType, + resultSetConcurrency); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql), resultSetType, + resultSetConcurrency, resultSetHoldability); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int[] columnIndexes) throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql), columnIndexes); + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, String[] columnNames) throws SQLException { + return super.connection_prepareStatement(chain, connection, encode(connection, sql), columnNames); + } + + // / precall + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) + throws SQLException { + return super.connection_prepareCall(chain, connection, encode(connection, sql)); + } + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency) + throws SQLException { + return super.connection_prepareCall(chain, connection, encode(connection, sql), resultSetType, + resultSetConcurrency); + } + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return super.connection_prepareCall(chain, connection, encode(connection, sql), resultSetType, + resultSetConcurrency, resultSetHoldability); + } + + // nativeSQL + + @Override + public String connection_nativeSQL(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException { + String encodedSql = encode(connection, sql); + return super.connection_nativeSQL(chain, connection, encodedSql); + } + + // ////////////// statement + + @Override + public void statement_addBatch(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + super.statement_addBatch(chain, statement, encode(statement.getConnectionProxy(), sql)); + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql)); + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) + throws SQLException { + return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), autoGeneratedKeys); + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) + throws SQLException { + return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), columnIndexes); + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) + throws SQLException { + return super.statement_execute(chain, statement, encode(statement.getConnectionProxy(), sql), columnNames); + } + + @Override + public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) + throws SQLException { + return super.statement_executeQuery(chain, statement, encode(statement.getConnectionProxy(), sql)); + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql)); + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) + throws SQLException { + return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), + autoGeneratedKeys); + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) + throws SQLException { + return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), + columnIndexes); + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) + throws SQLException { + return super.statement_executeUpdate(chain, statement, encode(statement.getConnectionProxy(), sql), columnNames); + } + + // ========== preparedStatement + + @Override + public void preparedStatement_setString(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, + String x) throws SQLException { + super.preparedStatement_setString(chain, statement, parameterIndex, encode(statement.getConnectionProxy(), x)); + } + + @Override + public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, + int parameterIndex, java.io.Reader reader) throws SQLException { + String text = IOUtils.read(reader); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText)); + } + + @Override + public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, + int parameterIndex, java.io.Reader reader, int length) + throws SQLException { + String text = IOUtils.read(reader, length); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText), + encodedText.length()); + } + + @Override + public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement, + int parameterIndex, java.io.Reader reader, long length) + throws SQLException { + String text = IOUtils.read(reader, (int) length); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText), + encodedText.length()); + } + + @Override + public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, + Object x) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText)); + } else { + super.preparedStatement_setObject(chain, statement, parameterIndex, x); + } + } + + @Override + public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, + Object x, int targetSqlType) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText), + targetSqlType); + } else { + super.preparedStatement_setObject(chain, statement, parameterIndex, x, targetSqlType); + } + } + + @Override + public void preparedStatement_setObject(FilterChain chain, PreparedStatementProxy statement, int parameterIndex, + Object x, int targetSqlType, int scaleOrLength) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType, + scaleOrLength); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText), + targetSqlType, scaleOrLength); + } else { + super.preparedStatement_setObject(chain, statement, parameterIndex, x, targetSqlType, scaleOrLength); + } + } + + // ////////// + + @Override + public long clob_position(FilterChain chain, ClobProxy wrapper, String searchstr, long start) throws SQLException { + return chain.clob_position(wrapper, encode(wrapper.getConnectionWrapper(), searchstr), start); + } + + @Override + public String clob_getSubString(FilterChain chain, ClobProxy wrapper, long pos, int length) throws SQLException { + String text = super.clob_getSubString(chain, wrapper, pos, length); + return decode(wrapper.getConnectionWrapper(), text); + } + + @Override + public java.io.Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper) throws SQLException { + Reader reader = super.clob_getCharacterStream(chain, wrapper); + String text = IOUtils.read(reader); + return new StringReader(decode(wrapper.getConnectionWrapper(), text)); + } + + @Override + public Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper, long pos, long length) + throws SQLException { + Reader reader = super.clob_getCharacterStream(chain, wrapper, pos, length); + String text = IOUtils.read(reader); + return new StringReader(decode(wrapper.getConnectionWrapper(), text)); + } + + @Override + public int clob_setString(FilterChain chain, ClobProxy wrapper, long pos, String str) throws SQLException { + return chain.clob_setString(wrapper, pos, encode(wrapper.getConnectionWrapper(), str)); + } + + @Override + public int clob_setString(FilterChain chain, ClobProxy wrapper, long pos, String str, int offset, int len) + throws SQLException { + return chain.clob_setString(wrapper, pos, encode(wrapper.getConnectionWrapper(), str), offset, len); + } + + // ///////////// callableStatement_ + + @Override + public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, + String parameterName, java.io.Reader reader) throws SQLException { + String text = IOUtils.read(reader); + Reader encodeReader = new StringReader(encode(statement.getConnectionProxy(), text)); + super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader); + } + + @Override + public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, + String parameterName, java.io.Reader reader, int length) + throws SQLException { + String text = IOUtils.read(reader, length); + String encodeText = encode(statement.getConnectionProxy(), text); + Reader encodeReader = new StringReader(encodeText); + super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, encodeText.length()); + } + + @Override + public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement, + String parameterName, java.io.Reader reader, long length) + throws SQLException { + String text = IOUtils.read(reader, (int) length); + String encodeText = encode(statement.getConnectionProxy(), text); + Reader encodeReader = new StringReader(encodeText); + super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, + (long) encodeText.length()); + } + + @Override + public void callableStatement_setString(FilterChain chain, CallableStatementProxy statement, String parameterName, + String x) throws SQLException { + super.callableStatement_setString(chain, statement, parameterName, encode(statement.getConnectionProxy(), x)); + } + + @Override + public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, + Object x) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.callableStatement_setObject(chain, statement, parameterName, encodedText); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText)); + } else { + super.callableStatement_setObject(chain, statement, parameterName, x); + } + } + + @Override + public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, + Object x, int targetSqlType) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText), + targetSqlType); + } else { + super.callableStatement_setObject(chain, statement, parameterName, x, targetSqlType); + } + } + + @Override + public void callableStatement_setObject(FilterChain chain, CallableStatementProxy statement, String parameterName, + Object x, int targetSqlType, int scale) throws SQLException { + if (x instanceof String) { + String encodedText = encode(statement.getConnectionProxy(), (String) x); + super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType, scale); + } else if (x instanceof Reader) { + String text = IOUtils.read((Reader) x); + String encodedText = encode(statement.getConnectionProxy(), text); + super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText), + targetSqlType, scale); + } else { + super.callableStatement_setObject(chain, statement, parameterName, x, targetSqlType, scale); + } + } + + @Override + public String callableStatement_getString(FilterChain chain, CallableStatementProxy statement, int parameterIndex) + throws SQLException { + String value = super.callableStatement_getString(chain, statement, parameterIndex); + return decode(statement.getConnectionProxy(), value); + } + + @Override + public String callableStatement_getString(FilterChain chain, CallableStatementProxy statement, String parameterName) + throws SQLException { + String value = super.callableStatement_getString(chain, statement, parameterName); + return decode(statement.getConnectionProxy(), value); + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex) + throws SQLException { + Object value = chain.callableStatement_getObject(statement, parameterIndex); + return decodeObject(statement, value); + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex, + java.util.Map> map) throws SQLException { + Object value = chain.callableStatement_getObject(statement, parameterIndex, map); + return decodeObject(statement, value); + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, String parameterName) + throws SQLException { + Object value = chain.callableStatement_getObject(statement, parameterName); + return decodeObject(statement, value); + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, + String parameterName, java.util.Map> map) + throws SQLException { + Object value = chain.callableStatement_getObject(statement, parameterName, map); + return decodeObject(statement, value); + } + +} diff --git a/src/main/java/com/alibaba/druid/filter/logging/LogFilter.java b/src/main/java/com/alibaba/druid/filter/logging/LogFilter.java index 1412851959..745d1c334e 100644 --- a/src/main/java/com/alibaba/druid/filter/logging/LogFilter.java +++ b/src/main/java/com/alibaba/druid/filter/logging/LogFilter.java @@ -21,7 +21,6 @@ import java.sql.Savepoint; import java.sql.Types; import java.util.ArrayList; import java.util.List; -import java.util.Map; import com.alibaba.druid.filter.FilterChain; import com.alibaba.druid.filter.FilterEventAdapter; @@ -507,15 +506,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM return; } - Map parameterMap = statement.getParameters(); - if (parameterMap == null || parameterMap.size() == 0) { + int parametersSize = statement.getParametersSize(); + if (parametersSize == 0) { statementLog("{conn-" + statement.getConnectionProxy().getId() + ", " + stmtId(statement) + "} executed. " + sql); return; } - List parameters = new ArrayList(parameterMap.size()); - for (JdbcParameter jdbcParam : parameterMap.values()) { + List parameters = new ArrayList(parametersSize); + for (int i = 0; i < parametersSize; ++i) { + JdbcParameter jdbcParam = statement.getParameter(i); parameters.add(jdbcParam.getValue()); } @@ -737,11 +737,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM buf.append(stmtId(statement)); buf.append("}"); buf.append(" Parameters : ["); - int parameterIndex = 0; - for (JdbcParameter parameter : statement.getParameters().values()) { - if (parameterIndex != 0) { + + for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) { + JdbcParameter parameter = statement.getParameter(i); + if (i != 0) { buf.append(", "); } + if (parameter == null) { + continue; + } + int sqlType = parameter.getSqlType(); Object value = parameter.getValue(); switch (sqlType) { @@ -752,7 +757,6 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM buf.append(String.valueOf(value)); break; } - parameterIndex++; } buf.append("]"); statementLog(buf.toString()); @@ -765,14 +769,16 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM buf.append(stmtId(statement)); buf.append("}"); buf.append(" Types : ["); - int parameterIndex = 0; - for (JdbcParameter parameter : statement.getParameters().values()) { - if (parameterIndex != 0) { + for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) { + JdbcParameter parameter = statement.getParameter(i); + if (i != 0) { buf.append(", "); } + if (parameter == null) { + continue; + } int sqlType = parameter.getSqlType(); buf.append(JdbcUtils.getTypeName(sqlType)); - parameterIndex++; } buf.append("]"); statementLog(buf.toString()); diff --git a/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java b/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java index ef41aed979..d850e2f5b5 100644 --- a/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java +++ b/src/main/java/com/alibaba/druid/filter/stat/StatFilter.java @@ -1,1030 +1,1032 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.filter.stat; - -import java.io.InputStream; -import java.io.Reader; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.NClob; -import java.sql.SQLException; -import java.sql.Savepoint; -import java.util.Date; -import java.util.Properties; - -import com.alibaba.druid.filter.Filter; -import com.alibaba.druid.filter.FilterChain; -import com.alibaba.druid.filter.FilterEventAdapter; -import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.pool.DruidPooledConnection; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; -import com.alibaba.druid.proxy.jdbc.ClobProxy; -import com.alibaba.druid.proxy.jdbc.ConnectionProxy; -import com.alibaba.druid.proxy.jdbc.DataSourceProxy; -import com.alibaba.druid.proxy.jdbc.JdbcParameter; -import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; -import com.alibaba.druid.proxy.jdbc.ResultSetProxy; -import com.alibaba.druid.proxy.jdbc.StatementExecuteType; -import com.alibaba.druid.proxy.jdbc.StatementProxy; -import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils; -import com.alibaba.druid.stat.JdbcConnectionStat; -import com.alibaba.druid.stat.JdbcDataSourceStat; -import com.alibaba.druid.stat.JdbcResultSetStat; -import com.alibaba.druid.stat.JdbcSqlStat; -import com.alibaba.druid.stat.JdbcStatContext; -import com.alibaba.druid.stat.JdbcStatManager; -import com.alibaba.druid.stat.JdbcStatementStat; -import com.alibaba.druid.support.json.JSONWriter; -import com.alibaba.druid.support.logging.Log; -import com.alibaba.druid.support.logging.LogFactory; -import com.alibaba.druid.support.profile.Profiler; - -/** - * @author wenshao - */ -public class StatFilter extends FilterEventAdapter implements StatFilterMBean { - - private final static Log LOG = LogFactory.getLog(StatFilter.class); - - private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql"; - private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis"; - private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql"; - - public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn"; - public final static String ATTR_NAME_STATEMENT_STAT = "stat.stmt"; - public final static String ATTR_UPDATE_COUNT = "stat.updteCount"; - public final static String ATTR_TRANSACTION = "stat.tx"; - public final static String ATTR_RESULTSET_CLOSED = "stat.rs.closed"; - - // protected JdbcDataSourceStat dataSourceStat; - - @Deprecated - protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat(); - - @Deprecated - protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat(); - - private boolean connectionStackTraceEnable = false; - - // 3 seconds is slow sql - protected long slowSqlMillis = 3 * 1000; - - protected boolean logSlowSql = false; - - private String dbType; - - private boolean mergeSql = false; - - public StatFilter(){ - } - - public String getDbType() { - return dbType; - } - - public void setDbType(String dbType) { - this.dbType = dbType; - } - - public long getSlowSqlMillis() { - return slowSqlMillis; - } - - public void setSlowSqlMillis(long slowSqlMillis) { - this.slowSqlMillis = slowSqlMillis; - } - - public boolean isLogSlowSql() { - return logSlowSql; - } - - public void setLogSlowSql(boolean logSlowSql) { - this.logSlowSql = logSlowSql; - } - - public boolean isConnectionStackTraceEnable() { - return connectionStackTraceEnable; - } - - public void setConnectionStackTraceEnable(boolean connectionStackTraceEnable) { - this.connectionStackTraceEnable = connectionStackTraceEnable; - } - - public boolean isMergeSql() { - return mergeSql; - } - - public void setMergeSql(boolean mergeSql) { - this.mergeSql = mergeSql; - } - - @Deprecated - public String mergeSql(String sql) { - return this.mergeSql(sql, dbType); - } - - public String mergeSql(String sql, String dbType) { - if (!mergeSql) { - return sql; - } - - try { - sql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType); - } catch (Exception e) { - LOG.error("merge sql error, dbType " + dbType + ", sql : \n" + sql, e); - } - - return sql; - } - - @Override - public synchronized void init(DataSourceProxy dataSource) { - if (this.dbType == null || this.dbType.trim().length() == 0) { - this.dbType = dataSource.getDbType(); - } - - configFromProperties(dataSource.getConnectProperties()); - configFromProperties(System.getProperties()); - } - - public void configFromProperties(Properties properties) { - if (properties == null) { - return; - } - - { - String property = properties.getProperty(SYS_PROP_MERGE_SQL); - if ("true".equals(property)) { - this.mergeSql = true; - } else if ("false".equals(property)) { - this.mergeSql = false; - } - } - - { - String property = properties.getProperty(SYS_PROP_SLOW_SQL_MILLIS); - if (property != null && property.trim().length() > 0) { - property = property.trim(); - try { - this.slowSqlMillis = Long.parseLong(property); - } catch (Exception e) { - LOG.error("property 'druid.stat.slowSqlMillis' format error"); - } - } - } - - { - String property = properties.getProperty(SYS_PROP_LOG_SLOW_SQL); - if ("true".equals(property)) { - this.logSlowSql = true; - } else if ("false".equals(property)) { - this.logSlowSql = false; - } - } - } - - public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException { - ConnectionProxy connection = null; - { - long startNano = System.nanoTime(); - long startTime = System.currentTimeMillis(); - - long nanoSpan; - long nowTime = System.currentTimeMillis(); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getConnectionStat().beforeConnect(); - try { - connection = chain.connection_connect(info); - nanoSpan = System.nanoTime() - startNano; - } catch (SQLException ex) { - dataSourceStat.getConnectionStat().connectError(ex); - throw ex; - } - dataSourceStat.getConnectionStat().afterConnected(nanoSpan); - - if (connection != null) { - JdbcConnectionStat.Entry statEntry = getConnectionInfo(connection); - - dataSourceStat.getConnections().put(connection.getId(), statEntry); - - statEntry.setConnectTime(new Date(startTime)); - statEntry.setConnectTimespanNano(nanoSpan); - statEntry.setEstablishNano(System.nanoTime()); - statEntry.setEstablishTime(nowTime); - statEntry.setConnectStackTrace(new Exception()); - - dataSourceStat.getConnectionStat().setActiveCount(dataSourceStat.getConnections().size()); - } - } - return connection; - } - - @Override - public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException { - if (connection.getCloseCount() == 0) { - long nowNano = System.nanoTime(); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getConnectionStat().incrementConnectionCloseCount(); - - JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection); - - long aliveNanoSpan = nowNano - connectionInfo.getEstablishNano(); - - JdbcConnectionStat.Entry existsConnection = dataSourceStat.getConnections().remove(connection.getId()); - if (existsConnection != null) { - dataSourceStat.getConnectionStat().afterClose(aliveNanoSpan); - } - } - - chain.connection_close(connection); - // duplicate close, C3P0等连接池,在某些情况下会关闭连接多次。 - } - - @Override - public void connection_commit(FilterChain chain, ConnectionProxy connection) throws SQLException { - chain.connection_commit(connection); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getConnectionStat().incrementConnectionCommitCount(); - } - - @Override - public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException { - chain.connection_rollback(connection); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); - dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); - } - - @Override - public void connection_rollback(FilterChain chain, ConnectionProxy connection, Savepoint savepoint) - throws SQLException { - chain.connection_rollback(connection, savepoint); - - JdbcDataSourceStat dataSourceStat = connection.getDirectDataSource().getDataSourceStat(); - dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); - } - - @Override - public void statementCreateAfter(StatementProxy statement) { - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().incrementCreateCounter(); - - super.statementCreateAfter(statement); - } - - @Override - public void statementPrepareCallAfter(CallableStatementProxy statement) { - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().incrementPrepareCallCount(); - - JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql()); - statement.setSqlStat(sqlStat); - } - - @Override - public void statementPrepareAfter(PreparedStatementProxy statement) { - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().incrementPrepareCounter(); - JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql()); - statement.setSqlStat(sqlStat); - } - - @Override - public void statement_close(FilterChain chain, StatementProxy statement) throws SQLException { - chain.statement_close(statement); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().incrementStatementCloseCounter(); - JdbcStatContext context = JdbcStatManager.getInstance().getStatContext(); - if (context != null) { - context.setName(null); - context.setFile(null); - context.setSql(null); - } - } - - @Override - protected void statementExecuteUpdateBefore(StatementProxy statement, String sql) { - internalBeforeStatementExecute(statement, sql); - } - - @Override - protected void statementExecuteUpdateAfter(StatementProxy statement, String sql, int updateCount) { - internalAfterStatementExecute(statement, false, updateCount); - } - - @Override - protected void statementExecuteQueryBefore(StatementProxy statement, String sql) { - internalBeforeStatementExecute(statement, sql); - } - - @Override - protected void statementExecuteQueryAfter(StatementProxy statement, String sql, ResultSetProxy resultSet) { - internalAfterStatementExecute(statement, true); - } - - @Override - protected void statementExecuteBefore(StatementProxy statement, String sql) { - internalBeforeStatementExecute(statement, sql); - } - - @Override - protected void statementExecuteAfter(StatementProxy statement, String sql, boolean firstResult) { - internalAfterStatementExecute(statement, firstResult); - } - - @Override - protected void statementExecuteBatchBefore(StatementProxy statement) { - final String sql = statement.getBatchSql(); - - final int batchSize = statement.getBatchSqlList().size(); - JdbcSqlStat sqlStat = statement.getSqlStat(); - if (sqlStat == null || sqlStat.isRemoved()) { - sqlStat = createSqlStat(statement, sql); - statement.setSqlStat(sqlStat); - } - - if (sqlStat != null) { - sqlStat.addExecuteBatchCount(batchSize); - } - - internalBeforeStatementExecute(statement, sql); - - } - - @Override - protected void statementExecuteBatchAfter(StatementProxy statement, int[] result) { - internalAfterStatementExecute(statement, false, result); - - } - - private final void internalBeforeStatementExecute(StatementProxy statement, String sql) { - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().beforeExecute(); - - final ConnectionProxy connection = statement.getConnectionProxy(); - final JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection); - - statement.setLastExecuteStartNano(); - - connectionCounter.setLastSql(sql); - - if (connectionStackTraceEnable) { - connectionCounter.setLastStatementStatckTrace(new Exception()); - } - - // //////////SQL - - JdbcSqlStat sqlStat = statement.getSqlStat(); - if (sqlStat == null || sqlStat.isRemoved()) { - sqlStat = createSqlStat(statement, sql); - statement.setSqlStat(sqlStat); - } - - JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext(); - if (statContext != null) { - sqlStat.setName(statContext.getName()); - sqlStat.setFile(statContext.getFile()); - } - - boolean inTransaction = false; - try { - inTransaction = !statement.getConnectionProxy().getAutoCommit(); - } catch (SQLException e) { - LOG.error("getAutoCommit error", e); - } - - if (sqlStat != null) { - sqlStat.setExecuteLastStartTime(System.currentTimeMillis()); - sqlStat.incrementRunningCount(); - - if (inTransaction) { - sqlStat.incrementInTransactionCount(); - } - } - - StatFilterContext.getInstance().executeBefore(sql, inTransaction); - - Profiler.enter(sql, Profiler.PROFILE_TYPE_SQL); - } - - private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult, - int... updateCountArray) { - final long nowNano = System.nanoTime(); - final long nanos = nowNano - statement.getLastExecuteStartNano(); - - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().afterExecute(nanos); - - final JdbcSqlStat sqlStat = statement.getSqlStat(); - - if (sqlStat != null) { - sqlStat.incrementExecuteSuccessCount(); - - sqlStat.decrementRunningCount(); - sqlStat.addExecuteTime(statement.getLastExecuteType(), firstResult, nanos); - statement.setLastExecuteTimeNano(nanos); - if ((!statement.isFirstResultSet()) && statement.getLastExecuteType() == StatementExecuteType.Execute) { - try { - int updateCount = statement.getUpdateCount(); - sqlStat.addUpdateCount(updateCount); - } catch (SQLException e) { - LOG.error("getUpdateCount error", e); - } - } else { - for (int updateCount : updateCountArray) { - sqlStat.addUpdateCount(updateCount); - sqlStat.addFetchRowCount(0); - StatFilterContext.getInstance().addUpdateCount(updateCount); - } - } - - long millis = nanos / (1000 * 1000); - if (millis >= slowSqlMillis) { - String slowParameters = buildSlowParameters(statement); - sqlStat.setLastSlowParameters(slowParameters); - - if (logSlowSql) { - LOG.error("slow sql " + millis + " millis. \n" + statement.getLastExecuteSql() + "\n" - + slowParameters); - } - } - } - - String sql = statement.getLastExecuteSql(); - StatFilterContext.getInstance().executeAfter(sql, nanos, null); - - Profiler.release(nanos); - } - - @Override - protected void statement_executeErrorAfter(StatementProxy statement, String sql, Throwable error) { - - ConnectionProxy connection = statement.getConnectionProxy(); - JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection); - - long nanos = System.nanoTime() - statement.getLastExecuteStartNano(); - - JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getStatementStat().error(error); - dataSourceStat.getStatementStat().afterExecute(nanos); - - connectionCounter.error(error); - - // SQL - JdbcSqlStat sqlStat = statement.getSqlStat(); - - if (sqlStat != null) { - sqlStat.error(error); - sqlStat.addExecuteTime(statement.getLastExecuteType(), statement.isFirstResultSet(), nanos); - statement.setLastExecuteTimeNano(nanos); - } - - StatFilterContext.getInstance().executeAfter(sql, nanos, error); - Profiler.release(nanos); - } - - private String buildSlowParameters(StatementProxy statement) { - JSONWriter out = new JSONWriter(); - - out.writeArrayStart(); - int index = 0; - for (JdbcParameter parameter : statement.getParameters().values()) { - if (index != 0) { - out.writeComma(); - } - - Object value = parameter.getValue(); - if (value == null) { - out.writeNull(); - } else if (value instanceof String) { - String text = (String) value; - if (text.length() > 100) { - out.writeString(text.substring(0, 97) + "..."); - } else { - out.writeString(text); - } - } else if (value instanceof Number) { - out.writeObject(value); - } else if (value instanceof java.util.Date) { - out.writeObject(value); - } else if (value instanceof Boolean) { - out.writeObject(value); - } else if (value instanceof InputStream) { - out.writeString(""); - } else if (value instanceof NClob) { - out.writeString(""); - } else if (value instanceof Clob) { - out.writeString(""); - } else if (value instanceof Blob) { - out.writeString(""); - } else { - out.writeString('<' + value.getClass().getName() + '>'); - } - index++; - } - out.writeArrayEnd(); - - return out.toString(); - } - - @Override - protected void resultSetOpenAfter(ResultSetProxy resultSet) { - JdbcDataSourceStat dataSourceStat = resultSet.getStatementProxy().getConnectionProxy().getDirectDataSource().getDataSourceStat(); - dataSourceStat.getResultSetStat().beforeOpen(); - - resultSet.setConstructNano(); - - StatFilterContext.getInstance().resultSet_open(); - } - - @Override - public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException { - - long nanos = System.nanoTime() - resultSet.getConstructNano(); - - int fetchRowCount = resultSet.getFetchRowCount(); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getResultSetStat().afterClose(nanos); - dataSourceStat.getResultSetStat().addFetchRowCount(fetchRowCount); - dataSourceStat.getResultSetStat().incrementCloseCounter(); - - StatFilterContext.getInstance().addFetchRowCount(fetchRowCount); - - String sql = resultSet.getSql(); - if (sql != null) { - JdbcSqlStat sqlStat = resultSet.getSqlStat(); - if (sqlStat != null && resultSet.getCloseCount() == 0) { - sqlStat.addFetchRowCount(fetchRowCount); - long stmtExecuteNano = resultSet.getStatementProxy().getLastExecuteTimeNano(); - sqlStat.addResultSetHoldTimeNano(stmtExecuteNano, nanos); - if (resultSet.getReadStringLength() > 0) { - sqlStat.addStringReadLength(resultSet.getReadStringLength()); - } - if (resultSet.getReadBytesLength() > 0) { - sqlStat.addReadBytesLength(resultSet.getReadBytesLength()); - } - if (resultSet.getOpenInputStreamCount() > 0) { - sqlStat.addInputStreamOpenCount(resultSet.getOpenInputStreamCount()); - } - if (resultSet.getOpenReaderCount() > 0) { - sqlStat.addReaderOpenCount(resultSet.getOpenReaderCount()); - } - } - } - - chain.resultSet_close(resultSet); - - StatFilterContext.getInstance().resultSet_close(nanos); - } - - public JdbcConnectionStat.Entry getConnectionInfo(ConnectionProxy connection) { - JdbcConnectionStat.Entry counter = (JdbcConnectionStat.Entry) connection.getAttributes().get(ATTR_NAME_CONNECTION_STAT); - - if (counter == null) { - String dataSourceName = connection.getDirectDataSource().getName(); - connection.getAttributes().put(ATTR_NAME_CONNECTION_STAT, - new JdbcConnectionStat.Entry(dataSourceName, connection.getId())); - counter = (JdbcConnectionStat.Entry) connection.getAttributes().get(ATTR_NAME_CONNECTION_STAT); - } - - return counter; - } - - public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) { - DataSourceProxy dataSource = statement.getConnectionProxy().getDirectDataSource(); - JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat(); - - JdbcStatContext context = JdbcStatManager.getInstance().getStatContext(); - String contextSql = context != null ? context.getSql() : null; - if (contextSql != null && contextSql.length() > 0) { - return dataSourceStat.createSqlStat(contextSql); - } else { - String dbType = this.dbType; - - if (dbType == null) { - dbType = dataSource.getDbType(); - } - - sql = mergeSql(sql, dbType); - return dataSourceStat.createSqlStat(sql); - } - } - - public static StatFilter getStatFilter(DataSourceProxy dataSource) { - for (Filter filter : dataSource.getProxyFilters()) { - if (filter instanceof StatFilter) { - return (StatFilter) filter; - } - } - - return null; - } - - @Override - public void dataSource_releaseConnection(FilterChain chain, DruidPooledConnection conn) throws SQLException { - chain.dataSource_recycle(conn); - - long nanos = System.nanoTime() - conn.getConnectedTimeNano(); - - long millis = nanos / (1000L * 1000L); - - JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); - dataSourceStat.getConnectionHoldHistogram().record(millis); - - StatFilterContext.getInstance().pool_connection_close(nanos); - } - - @Override - public DruidPooledConnection dataSource_getConnection(FilterChain chain, DruidDataSource dataSource, - long maxWaitMillis) throws SQLException { - DruidPooledConnection conn = chain.dataSource_connect(dataSource, maxWaitMillis); - - if (conn != null) { - conn.setConnectedTimeNano(); - - StatFilterContext.getInstance().pool_connection_open(); - } - - return conn; - } - - @Override - public Clob resultSet_getClob(FilterChain chain, ResultSetProxy resultSet, int columnIndex) throws SQLException { - Clob clob = chain.resultSet_getClob(resultSet, columnIndex); - - if (clob != null) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), resultSet, (ClobProxy) clob); - } - - return clob; - } - - @Override - public Clob resultSet_getClob(FilterChain chain, ResultSetProxy resultSet, String columnLabel) throws SQLException { - Clob clob = chain.resultSet_getClob(resultSet, columnLabel); - - if (clob != null) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), resultSet, (ClobProxy) clob); - } - - return clob; - } - - @Override - public Blob callableStatement_getBlob(FilterChain chain, CallableStatementProxy statement, int parameterIndex) - throws SQLException { - Blob blob = chain.callableStatement_getBlob(statement, parameterIndex); - - if (blob != null) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, blob); - } - - return blob; - } - - @Override - public Blob callableStatement_getBlob(FilterChain chain, CallableStatementProxy statement, String parameterName) - throws SQLException { - Blob blob = chain.callableStatement_getBlob(statement, parameterName); - - if (blob != null) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, blob); - } - - return blob; - } - - @Override - public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - Blob blob = chain.resultSet_getBlob(result, columnIndex); - - if (blob != null) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, blob); - } - - return blob; - } - - @Override - public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - Blob blob = chain.resultSet_getBlob(result, columnLabel); - - if (blob != null) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, blob); - } - - return blob; - } - - @Override - public Clob callableStatement_getClob(FilterChain chain, CallableStatementProxy statement, int parameterIndex) - throws SQLException { - Clob clob = chain.callableStatement_getClob(statement, parameterIndex); - - if (clob != null) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) clob); - } - - return clob; - } - - @Override - public Clob callableStatement_getClob(FilterChain chain, CallableStatementProxy statement, String parameterName) - throws SQLException { - Clob clob = chain.callableStatement_getClob(statement, parameterName); - - if (clob != null) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) clob); - } - - return clob; - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - Object obj = chain.resultSet_getObject(result, columnIndex); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); - } else if (obj instanceof String) { - result.addReadStringLength(((String) obj).length()); - } - - return obj; - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, - java.util.Map> map) throws SQLException { - Object obj = chain.resultSet_getObject(result, columnIndex, map); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); - } else if (obj instanceof String) { - result.addReadStringLength(((String) obj).length()); - } - - return obj; - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - Object obj = chain.resultSet_getObject(result, columnLabel); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); - } else if (obj instanceof String) { - result.addReadStringLength(((String) obj).length()); - } - - return obj; - } - - @Override - public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, - java.util.Map> map) throws SQLException { - Object obj = chain.resultSet_getObject(result, columnLabel, map); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); - } else if (obj instanceof String) { - result.addReadStringLength(((String) obj).length()); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex) - throws SQLException { - Object obj = chain.callableStatement_getObject(statement, parameterIndex); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex, - java.util.Map> map) throws SQLException { - Object obj = chain.callableStatement_getObject(statement, parameterIndex, map); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, String parameterName) - throws SQLException { - Object obj = chain.callableStatement_getObject(statement, parameterName); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); - } - - return obj; - } - - @Override - public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, - String parameterName, java.util.Map> map) - throws SQLException { - Object obj = chain.callableStatement_getObject(statement, parameterName, map); - - if (obj instanceof Clob) { - clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); - } else if (obj instanceof Blob) { - blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); - } - - return obj; - } - - private void blobOpenAfter(JdbcDataSourceStat dataSourceStat, ResultSetProxy rs, Blob blob) { - blobOpenAfter(dataSourceStat, rs.getStatementProxy(), blob); - } - - private void clobOpenAfter(JdbcDataSourceStat dataSourceStat, ResultSetProxy rs, ClobProxy clob) { - clobOpenAfter(dataSourceStat, rs.getStatementProxy(), clob); - } - - private void blobOpenAfter(JdbcDataSourceStat dataSourceStat, StatementProxy stmt, Blob blob) { - dataSourceStat.incrementBlobOpenCount(); - - if (stmt != null) { - JdbcSqlStat sqlStat = stmt.getSqlStat(); - if (sqlStat != null) { - sqlStat.incrementBlobOpenCount(); - } - } - - StatFilterContext.getInstance().blob_open(); - } - - private void clobOpenAfter(JdbcDataSourceStat dataSourceStat, StatementProxy stmt, ClobProxy clob) { - dataSourceStat.incrementClobOpenCount(); - - if (stmt != null) { - JdbcSqlStat sqlStat = stmt.getSqlStat(); - if (sqlStat != null) { - sqlStat.incrementClobOpenCount(); - } - } - - StatFilterContext.getInstance().clob_open(); - } - - @Override - public String resultSet_getString(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - String value = chain.resultSet_getString(result, columnIndex); - - if (value != null) { - result.addReadStringLength(value.length()); - } - - return value; - } - - @Override - public String resultSet_getString(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - String value = chain.resultSet_getString(result, columnLabel); - - if (value != null) { - result.addReadStringLength(value.length()); - } - - return value; - } - - @Override - public byte[] resultSet_getBytes(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { - byte[] value = chain.resultSet_getBytes(result, columnIndex); - - if (value != null) { - result.addReadBytesLength(value.length); - } - - return value; - } - - @Override - public byte[] resultSet_getBytes(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { - byte[] value = chain.resultSet_getBytes(result, columnLabel); - - if (value != null) { - result.addReadBytesLength(value.length); - } - - return value; - } - - @Override - public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, int columnIndex) - throws SQLException { - InputStream input = chain.resultSet_getBinaryStream(result, columnIndex); - - if (input != null) { - result.incrementOpenInputStreamCount(); - } - - return input; - } - - @Override - public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, String columnLabel) - throws SQLException { - InputStream input = chain.resultSet_getBinaryStream(result, columnLabel); - - if (input != null) { - result.incrementOpenInputStreamCount(); - } - - return input; - } - - @Override - public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, int columnIndex) - throws SQLException { - InputStream input = chain.resultSet_getAsciiStream(result, columnIndex); - - if (input != null) { - result.incrementOpenInputStreamCount(); - } - - return input; - } - - @Override - public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, String columnLabel) - throws SQLException { - InputStream input = chain.resultSet_getAsciiStream(result, columnLabel); - - if (input != null) { - result.incrementOpenInputStreamCount(); - } - - return input; - } - - @Override - public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, int columnIndex) - throws SQLException { - Reader reader = chain.resultSet_getCharacterStream(result, columnIndex); - - if (reader != null) { - result.incrementOpenReaderCount(); - } - - return reader; - } - - @Override - public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, String columnLabel) - throws SQLException { - Reader reader = chain.resultSet_getCharacterStream(result, columnLabel); - - if (reader != null) { - result.incrementOpenReaderCount(); - } - - return reader; - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.filter.stat; + +import java.io.InputStream; +import java.io.Reader; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.NClob; +import java.sql.SQLException; +import java.sql.Savepoint; +import java.util.Date; +import java.util.Properties; + +import com.alibaba.druid.filter.Filter; +import com.alibaba.druid.filter.FilterChain; +import com.alibaba.druid.filter.FilterEventAdapter; +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.pool.DruidPooledConnection; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; +import com.alibaba.druid.proxy.jdbc.ClobProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxy; +import com.alibaba.druid.proxy.jdbc.DataSourceProxy; +import com.alibaba.druid.proxy.jdbc.JdbcParameter; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; +import com.alibaba.druid.proxy.jdbc.ResultSetProxy; +import com.alibaba.druid.proxy.jdbc.StatementExecuteType; +import com.alibaba.druid.proxy.jdbc.StatementProxy; +import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils; +import com.alibaba.druid.stat.JdbcConnectionStat; +import com.alibaba.druid.stat.JdbcDataSourceStat; +import com.alibaba.druid.stat.JdbcResultSetStat; +import com.alibaba.druid.stat.JdbcSqlStat; +import com.alibaba.druid.stat.JdbcStatContext; +import com.alibaba.druid.stat.JdbcStatManager; +import com.alibaba.druid.stat.JdbcStatementStat; +import com.alibaba.druid.support.json.JSONWriter; +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; +import com.alibaba.druid.support.profile.Profiler; + +/** + * @author wenshao + */ +public class StatFilter extends FilterEventAdapter implements StatFilterMBean { + + private final static Log LOG = LogFactory.getLog(StatFilter.class); + + private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql"; + private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis"; + private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql"; + + public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn"; + public final static String ATTR_NAME_STATEMENT_STAT = "stat.stmt"; + public final static String ATTR_UPDATE_COUNT = "stat.updteCount"; + public final static String ATTR_TRANSACTION = "stat.tx"; + public final static String ATTR_RESULTSET_CLOSED = "stat.rs.closed"; + + // protected JdbcDataSourceStat dataSourceStat; + + @Deprecated + protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat(); + + @Deprecated + protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat(); + + private boolean connectionStackTraceEnable = false; + + // 3 seconds is slow sql + protected long slowSqlMillis = 3 * 1000; + + protected boolean logSlowSql = false; + + private String dbType; + + private boolean mergeSql = false; + + public StatFilter(){ + } + + public String getDbType() { + return dbType; + } + + public void setDbType(String dbType) { + this.dbType = dbType; + } + + public long getSlowSqlMillis() { + return slowSqlMillis; + } + + public void setSlowSqlMillis(long slowSqlMillis) { + this.slowSqlMillis = slowSqlMillis; + } + + public boolean isLogSlowSql() { + return logSlowSql; + } + + public void setLogSlowSql(boolean logSlowSql) { + this.logSlowSql = logSlowSql; + } + + public boolean isConnectionStackTraceEnable() { + return connectionStackTraceEnable; + } + + public void setConnectionStackTraceEnable(boolean connectionStackTraceEnable) { + this.connectionStackTraceEnable = connectionStackTraceEnable; + } + + public boolean isMergeSql() { + return mergeSql; + } + + public void setMergeSql(boolean mergeSql) { + this.mergeSql = mergeSql; + } + + @Deprecated + public String mergeSql(String sql) { + return this.mergeSql(sql, dbType); + } + + public String mergeSql(String sql, String dbType) { + if (!mergeSql) { + return sql; + } + + try { + sql = ParameterizedOutputVisitorUtils.parameterize(sql, dbType); + } catch (Exception e) { + LOG.error("merge sql error, dbType " + dbType + ", sql : \n" + sql, e); + } + + return sql; + } + + @Override + public synchronized void init(DataSourceProxy dataSource) { + if (this.dbType == null || this.dbType.trim().length() == 0) { + this.dbType = dataSource.getDbType(); + } + + configFromProperties(dataSource.getConnectProperties()); + configFromProperties(System.getProperties()); + } + + public void configFromProperties(Properties properties) { + if (properties == null) { + return; + } + + { + String property = properties.getProperty(SYS_PROP_MERGE_SQL); + if ("true".equals(property)) { + this.mergeSql = true; + } else if ("false".equals(property)) { + this.mergeSql = false; + } + } + + { + String property = properties.getProperty(SYS_PROP_SLOW_SQL_MILLIS); + if (property != null && property.trim().length() > 0) { + property = property.trim(); + try { + this.slowSqlMillis = Long.parseLong(property); + } catch (Exception e) { + LOG.error("property 'druid.stat.slowSqlMillis' format error"); + } + } + } + + { + String property = properties.getProperty(SYS_PROP_LOG_SLOW_SQL); + if ("true".equals(property)) { + this.logSlowSql = true; + } else if ("false".equals(property)) { + this.logSlowSql = false; + } + } + } + + public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException { + ConnectionProxy connection = null; + { + long startNano = System.nanoTime(); + long startTime = System.currentTimeMillis(); + + long nanoSpan; + long nowTime = System.currentTimeMillis(); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getConnectionStat().beforeConnect(); + try { + connection = chain.connection_connect(info); + nanoSpan = System.nanoTime() - startNano; + } catch (SQLException ex) { + dataSourceStat.getConnectionStat().connectError(ex); + throw ex; + } + dataSourceStat.getConnectionStat().afterConnected(nanoSpan); + + if (connection != null) { + JdbcConnectionStat.Entry statEntry = getConnectionInfo(connection); + + dataSourceStat.getConnections().put(connection.getId(), statEntry); + + statEntry.setConnectTime(new Date(startTime)); + statEntry.setConnectTimespanNano(nanoSpan); + statEntry.setEstablishNano(System.nanoTime()); + statEntry.setEstablishTime(nowTime); + statEntry.setConnectStackTrace(new Exception()); + + dataSourceStat.getConnectionStat().setActiveCount(dataSourceStat.getConnections().size()); + } + } + return connection; + } + + @Override + public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException { + if (connection.getCloseCount() == 0) { + long nowNano = System.nanoTime(); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getConnectionStat().incrementConnectionCloseCount(); + + JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection); + + long aliveNanoSpan = nowNano - connectionInfo.getEstablishNano(); + + JdbcConnectionStat.Entry existsConnection = dataSourceStat.getConnections().remove(connection.getId()); + if (existsConnection != null) { + dataSourceStat.getConnectionStat().afterClose(aliveNanoSpan); + } + } + + chain.connection_close(connection); + // duplicate close, C3P0等连接池,在某些情况下会关闭连接多次。 + } + + @Override + public void connection_commit(FilterChain chain, ConnectionProxy connection) throws SQLException { + chain.connection_commit(connection); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getConnectionStat().incrementConnectionCommitCount(); + } + + @Override + public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException { + chain.connection_rollback(connection); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); + dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); + } + + @Override + public void connection_rollback(FilterChain chain, ConnectionProxy connection, Savepoint savepoint) + throws SQLException { + chain.connection_rollback(connection, savepoint); + + JdbcDataSourceStat dataSourceStat = connection.getDirectDataSource().getDataSourceStat(); + dataSourceStat.getConnectionStat().incrementConnectionRollbackCount(); + } + + @Override + public void statementCreateAfter(StatementProxy statement) { + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().incrementCreateCounter(); + + super.statementCreateAfter(statement); + } + + @Override + public void statementPrepareCallAfter(CallableStatementProxy statement) { + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().incrementPrepareCallCount(); + + JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql()); + statement.setSqlStat(sqlStat); + } + + @Override + public void statementPrepareAfter(PreparedStatementProxy statement) { + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().incrementPrepareCounter(); + JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql()); + statement.setSqlStat(sqlStat); + } + + @Override + public void statement_close(FilterChain chain, StatementProxy statement) throws SQLException { + chain.statement_close(statement); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().incrementStatementCloseCounter(); + JdbcStatContext context = JdbcStatManager.getInstance().getStatContext(); + if (context != null) { + context.setName(null); + context.setFile(null); + context.setSql(null); + } + } + + @Override + protected void statementExecuteUpdateBefore(StatementProxy statement, String sql) { + internalBeforeStatementExecute(statement, sql); + } + + @Override + protected void statementExecuteUpdateAfter(StatementProxy statement, String sql, int updateCount) { + internalAfterStatementExecute(statement, false, updateCount); + } + + @Override + protected void statementExecuteQueryBefore(StatementProxy statement, String sql) { + internalBeforeStatementExecute(statement, sql); + } + + @Override + protected void statementExecuteQueryAfter(StatementProxy statement, String sql, ResultSetProxy resultSet) { + internalAfterStatementExecute(statement, true); + } + + @Override + protected void statementExecuteBefore(StatementProxy statement, String sql) { + internalBeforeStatementExecute(statement, sql); + } + + @Override + protected void statementExecuteAfter(StatementProxy statement, String sql, boolean firstResult) { + internalAfterStatementExecute(statement, firstResult); + } + + @Override + protected void statementExecuteBatchBefore(StatementProxy statement) { + final String sql = statement.getBatchSql(); + + final int batchSize = statement.getBatchSqlList().size(); + JdbcSqlStat sqlStat = statement.getSqlStat(); + if (sqlStat == null || sqlStat.isRemoved()) { + sqlStat = createSqlStat(statement, sql); + statement.setSqlStat(sqlStat); + } + + if (sqlStat != null) { + sqlStat.addExecuteBatchCount(batchSize); + } + + internalBeforeStatementExecute(statement, sql); + + } + + @Override + protected void statementExecuteBatchAfter(StatementProxy statement, int[] result) { + internalAfterStatementExecute(statement, false, result); + + } + + private final void internalBeforeStatementExecute(StatementProxy statement, String sql) { + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().beforeExecute(); + + final ConnectionProxy connection = statement.getConnectionProxy(); + final JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection); + + statement.setLastExecuteStartNano(); + + connectionCounter.setLastSql(sql); + + if (connectionStackTraceEnable) { + connectionCounter.setLastStatementStatckTrace(new Exception()); + } + + // //////////SQL + + JdbcSqlStat sqlStat = statement.getSqlStat(); + if (sqlStat == null || sqlStat.isRemoved()) { + sqlStat = createSqlStat(statement, sql); + statement.setSqlStat(sqlStat); + } + + JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext(); + if (statContext != null) { + sqlStat.setName(statContext.getName()); + sqlStat.setFile(statContext.getFile()); + } + + boolean inTransaction = false; + try { + inTransaction = !statement.getConnectionProxy().getAutoCommit(); + } catch (SQLException e) { + LOG.error("getAutoCommit error", e); + } + + if (sqlStat != null) { + sqlStat.setExecuteLastStartTime(System.currentTimeMillis()); + sqlStat.incrementRunningCount(); + + if (inTransaction) { + sqlStat.incrementInTransactionCount(); + } + } + + StatFilterContext.getInstance().executeBefore(sql, inTransaction); + + Profiler.enter(sql, Profiler.PROFILE_TYPE_SQL); + } + + private final void internalAfterStatementExecute(StatementProxy statement, boolean firstResult, + int... updateCountArray) { + final long nowNano = System.nanoTime(); + final long nanos = nowNano - statement.getLastExecuteStartNano(); + + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().afterExecute(nanos); + + final JdbcSqlStat sqlStat = statement.getSqlStat(); + + if (sqlStat != null) { + sqlStat.incrementExecuteSuccessCount(); + + sqlStat.decrementRunningCount(); + sqlStat.addExecuteTime(statement.getLastExecuteType(), firstResult, nanos); + statement.setLastExecuteTimeNano(nanos); + if ((!statement.isFirstResultSet()) && statement.getLastExecuteType() == StatementExecuteType.Execute) { + try { + int updateCount = statement.getUpdateCount(); + sqlStat.addUpdateCount(updateCount); + } catch (SQLException e) { + LOG.error("getUpdateCount error", e); + } + } else { + for (int updateCount : updateCountArray) { + sqlStat.addUpdateCount(updateCount); + sqlStat.addFetchRowCount(0); + StatFilterContext.getInstance().addUpdateCount(updateCount); + } + } + + long millis = nanos / (1000 * 1000); + if (millis >= slowSqlMillis) { + String slowParameters = buildSlowParameters(statement); + sqlStat.setLastSlowParameters(slowParameters); + + if (logSlowSql) { + LOG.error("slow sql " + millis + " millis. \n" + statement.getLastExecuteSql() + "\n" + + slowParameters); + } + } + } + + String sql = statement.getLastExecuteSql(); + StatFilterContext.getInstance().executeAfter(sql, nanos, null); + + Profiler.release(nanos); + } + + @Override + protected void statement_executeErrorAfter(StatementProxy statement, String sql, Throwable error) { + + ConnectionProxy connection = statement.getConnectionProxy(); + JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection); + + long nanos = System.nanoTime() - statement.getLastExecuteStartNano(); + + JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getStatementStat().error(error); + dataSourceStat.getStatementStat().afterExecute(nanos); + + connectionCounter.error(error); + + // SQL + JdbcSqlStat sqlStat = statement.getSqlStat(); + + if (sqlStat != null) { + sqlStat.error(error); + sqlStat.addExecuteTime(statement.getLastExecuteType(), statement.isFirstResultSet(), nanos); + statement.setLastExecuteTimeNano(nanos); + } + + StatFilterContext.getInstance().executeAfter(sql, nanos, error); + Profiler.release(nanos); + } + + private String buildSlowParameters(StatementProxy statement) { + JSONWriter out = new JSONWriter(); + + out.writeArrayStart(); + for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) { + JdbcParameter parameter = statement.getParameter(i); + if (i != 0) { + out.writeComma(); + } + if (parameter == null) { + continue; + } + + Object value = parameter.getValue(); + if (value == null) { + out.writeNull(); + } else if (value instanceof String) { + String text = (String) value; + if (text.length() > 100) { + out.writeString(text.substring(0, 97) + "..."); + } else { + out.writeString(text); + } + } else if (value instanceof Number) { + out.writeObject(value); + } else if (value instanceof java.util.Date) { + out.writeObject(value); + } else if (value instanceof Boolean) { + out.writeObject(value); + } else if (value instanceof InputStream) { + out.writeString(""); + } else if (value instanceof NClob) { + out.writeString(""); + } else if (value instanceof Clob) { + out.writeString(""); + } else if (value instanceof Blob) { + out.writeString(""); + } else { + out.writeString('<' + value.getClass().getName() + '>'); + } + } + out.writeArrayEnd(); + + return out.toString(); + } + + @Override + protected void resultSetOpenAfter(ResultSetProxy resultSet) { + JdbcDataSourceStat dataSourceStat = resultSet.getStatementProxy().getConnectionProxy().getDirectDataSource().getDataSourceStat(); + dataSourceStat.getResultSetStat().beforeOpen(); + + resultSet.setConstructNano(); + + StatFilterContext.getInstance().resultSet_open(); + } + + @Override + public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException { + + long nanos = System.nanoTime() - resultSet.getConstructNano(); + + int fetchRowCount = resultSet.getFetchRowCount(); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getResultSetStat().afterClose(nanos); + dataSourceStat.getResultSetStat().addFetchRowCount(fetchRowCount); + dataSourceStat.getResultSetStat().incrementCloseCounter(); + + StatFilterContext.getInstance().addFetchRowCount(fetchRowCount); + + String sql = resultSet.getSql(); + if (sql != null) { + JdbcSqlStat sqlStat = resultSet.getSqlStat(); + if (sqlStat != null && resultSet.getCloseCount() == 0) { + sqlStat.addFetchRowCount(fetchRowCount); + long stmtExecuteNano = resultSet.getStatementProxy().getLastExecuteTimeNano(); + sqlStat.addResultSetHoldTimeNano(stmtExecuteNano, nanos); + if (resultSet.getReadStringLength() > 0) { + sqlStat.addStringReadLength(resultSet.getReadStringLength()); + } + if (resultSet.getReadBytesLength() > 0) { + sqlStat.addReadBytesLength(resultSet.getReadBytesLength()); + } + if (resultSet.getOpenInputStreamCount() > 0) { + sqlStat.addInputStreamOpenCount(resultSet.getOpenInputStreamCount()); + } + if (resultSet.getOpenReaderCount() > 0) { + sqlStat.addReaderOpenCount(resultSet.getOpenReaderCount()); + } + } + } + + chain.resultSet_close(resultSet); + + StatFilterContext.getInstance().resultSet_close(nanos); + } + + public JdbcConnectionStat.Entry getConnectionInfo(ConnectionProxy connection) { + JdbcConnectionStat.Entry counter = (JdbcConnectionStat.Entry) connection.getAttribute(ATTR_NAME_CONNECTION_STAT); + + if (counter == null) { + String dataSourceName = connection.getDirectDataSource().getName(); + connection.putAttribute(ATTR_NAME_CONNECTION_STAT, + new JdbcConnectionStat.Entry(dataSourceName, connection.getId())); + counter = (JdbcConnectionStat.Entry) connection.getAttribute(ATTR_NAME_CONNECTION_STAT); + } + + return counter; + } + + public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) { + DataSourceProxy dataSource = statement.getConnectionProxy().getDirectDataSource(); + JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat(); + + JdbcStatContext context = JdbcStatManager.getInstance().getStatContext(); + String contextSql = context != null ? context.getSql() : null; + if (contextSql != null && contextSql.length() > 0) { + return dataSourceStat.createSqlStat(contextSql); + } else { + String dbType = this.dbType; + + if (dbType == null) { + dbType = dataSource.getDbType(); + } + + sql = mergeSql(sql, dbType); + return dataSourceStat.createSqlStat(sql); + } + } + + public static StatFilter getStatFilter(DataSourceProxy dataSource) { + for (Filter filter : dataSource.getProxyFilters()) { + if (filter instanceof StatFilter) { + return (StatFilter) filter; + } + } + + return null; + } + + @Override + public void dataSource_releaseConnection(FilterChain chain, DruidPooledConnection conn) throws SQLException { + chain.dataSource_recycle(conn); + + long nanos = System.nanoTime() - conn.getConnectedTimeNano(); + + long millis = nanos / (1000L * 1000L); + + JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat(); + dataSourceStat.getConnectionHoldHistogram().record(millis); + + StatFilterContext.getInstance().pool_connection_close(nanos); + } + + @Override + public DruidPooledConnection dataSource_getConnection(FilterChain chain, DruidDataSource dataSource, + long maxWaitMillis) throws SQLException { + DruidPooledConnection conn = chain.dataSource_connect(dataSource, maxWaitMillis); + + if (conn != null) { + conn.setConnectedTimeNano(); + + StatFilterContext.getInstance().pool_connection_open(); + } + + return conn; + } + + @Override + public Clob resultSet_getClob(FilterChain chain, ResultSetProxy resultSet, int columnIndex) throws SQLException { + Clob clob = chain.resultSet_getClob(resultSet, columnIndex); + + if (clob != null) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), resultSet, (ClobProxy) clob); + } + + return clob; + } + + @Override + public Clob resultSet_getClob(FilterChain chain, ResultSetProxy resultSet, String columnLabel) throws SQLException { + Clob clob = chain.resultSet_getClob(resultSet, columnLabel); + + if (clob != null) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), resultSet, (ClobProxy) clob); + } + + return clob; + } + + @Override + public Blob callableStatement_getBlob(FilterChain chain, CallableStatementProxy statement, int parameterIndex) + throws SQLException { + Blob blob = chain.callableStatement_getBlob(statement, parameterIndex); + + if (blob != null) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, blob); + } + + return blob; + } + + @Override + public Blob callableStatement_getBlob(FilterChain chain, CallableStatementProxy statement, String parameterName) + throws SQLException { + Blob blob = chain.callableStatement_getBlob(statement, parameterName); + + if (blob != null) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, blob); + } + + return blob; + } + + @Override + public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + Blob blob = chain.resultSet_getBlob(result, columnIndex); + + if (blob != null) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, blob); + } + + return blob; + } + + @Override + public Blob resultSet_getBlob(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + Blob blob = chain.resultSet_getBlob(result, columnLabel); + + if (blob != null) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, blob); + } + + return blob; + } + + @Override + public Clob callableStatement_getClob(FilterChain chain, CallableStatementProxy statement, int parameterIndex) + throws SQLException { + Clob clob = chain.callableStatement_getClob(statement, parameterIndex); + + if (clob != null) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) clob); + } + + return clob; + } + + @Override + public Clob callableStatement_getClob(FilterChain chain, CallableStatementProxy statement, String parameterName) + throws SQLException { + Clob clob = chain.callableStatement_getClob(statement, parameterName); + + if (clob != null) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) clob); + } + + return clob; + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + Object obj = chain.resultSet_getObject(result, columnIndex); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); + } else if (obj instanceof String) { + result.addReadStringLength(((String) obj).length()); + } + + return obj; + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, int columnIndex, + java.util.Map> map) throws SQLException { + Object obj = chain.resultSet_getObject(result, columnIndex, map); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); + } else if (obj instanceof String) { + result.addReadStringLength(((String) obj).length()); + } + + return obj; + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + Object obj = chain.resultSet_getObject(result, columnLabel); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); + } else if (obj instanceof String) { + result.addReadStringLength(((String) obj).length()); + } + + return obj; + } + + @Override + public Object resultSet_getObject(FilterChain chain, ResultSetProxy result, String columnLabel, + java.util.Map> map) throws SQLException { + Object obj = chain.resultSet_getObject(result, columnLabel, map); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), result, (Blob) obj); + } else if (obj instanceof String) { + result.addReadStringLength(((String) obj).length()); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex) + throws SQLException { + Object obj = chain.callableStatement_getObject(statement, parameterIndex); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, int parameterIndex, + java.util.Map> map) throws SQLException { + Object obj = chain.callableStatement_getObject(statement, parameterIndex, map); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, String parameterName) + throws SQLException { + Object obj = chain.callableStatement_getObject(statement, parameterName); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); + } + + return obj; + } + + @Override + public Object callableStatement_getObject(FilterChain chain, CallableStatementProxy statement, + String parameterName, java.util.Map> map) + throws SQLException { + Object obj = chain.callableStatement_getObject(statement, parameterName, map); + + if (obj instanceof Clob) { + clobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (ClobProxy) obj); + } else if (obj instanceof Blob) { + blobOpenAfter(chain.getDataSource().getDataSourceStat(), statement, (Blob) obj); + } + + return obj; + } + + private void blobOpenAfter(JdbcDataSourceStat dataSourceStat, ResultSetProxy rs, Blob blob) { + blobOpenAfter(dataSourceStat, rs.getStatementProxy(), blob); + } + + private void clobOpenAfter(JdbcDataSourceStat dataSourceStat, ResultSetProxy rs, ClobProxy clob) { + clobOpenAfter(dataSourceStat, rs.getStatementProxy(), clob); + } + + private void blobOpenAfter(JdbcDataSourceStat dataSourceStat, StatementProxy stmt, Blob blob) { + dataSourceStat.incrementBlobOpenCount(); + + if (stmt != null) { + JdbcSqlStat sqlStat = stmt.getSqlStat(); + if (sqlStat != null) { + sqlStat.incrementBlobOpenCount(); + } + } + + StatFilterContext.getInstance().blob_open(); + } + + private void clobOpenAfter(JdbcDataSourceStat dataSourceStat, StatementProxy stmt, ClobProxy clob) { + dataSourceStat.incrementClobOpenCount(); + + if (stmt != null) { + JdbcSqlStat sqlStat = stmt.getSqlStat(); + if (sqlStat != null) { + sqlStat.incrementClobOpenCount(); + } + } + + StatFilterContext.getInstance().clob_open(); + } + + @Override + public String resultSet_getString(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + String value = chain.resultSet_getString(result, columnIndex); + + if (value != null) { + result.addReadStringLength(value.length()); + } + + return value; + } + + @Override + public String resultSet_getString(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + String value = chain.resultSet_getString(result, columnLabel); + + if (value != null) { + result.addReadStringLength(value.length()); + } + + return value; + } + + @Override + public byte[] resultSet_getBytes(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException { + byte[] value = chain.resultSet_getBytes(result, columnIndex); + + if (value != null) { + result.addReadBytesLength(value.length); + } + + return value; + } + + @Override + public byte[] resultSet_getBytes(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException { + byte[] value = chain.resultSet_getBytes(result, columnLabel); + + if (value != null) { + result.addReadBytesLength(value.length); + } + + return value; + } + + @Override + public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, int columnIndex) + throws SQLException { + InputStream input = chain.resultSet_getBinaryStream(result, columnIndex); + + if (input != null) { + result.incrementOpenInputStreamCount(); + } + + return input; + } + + @Override + public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, String columnLabel) + throws SQLException { + InputStream input = chain.resultSet_getBinaryStream(result, columnLabel); + + if (input != null) { + result.incrementOpenInputStreamCount(); + } + + return input; + } + + @Override + public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, int columnIndex) + throws SQLException { + InputStream input = chain.resultSet_getAsciiStream(result, columnIndex); + + if (input != null) { + result.incrementOpenInputStreamCount(); + } + + return input; + } + + @Override + public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, String columnLabel) + throws SQLException { + InputStream input = chain.resultSet_getAsciiStream(result, columnLabel); + + if (input != null) { + result.incrementOpenInputStreamCount(); + } + + return input; + } + + @Override + public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, int columnIndex) + throws SQLException { + Reader reader = chain.resultSet_getCharacterStream(result, columnIndex); + + if (reader != null) { + result.incrementOpenReaderCount(); + } + + return reader; + } + + @Override + public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, String columnLabel) + throws SQLException { + Reader reader = chain.resultSet_getCharacterStream(result, columnLabel); + + if (reader != null) { + result.incrementOpenReaderCount(); + } + + return reader; + } +} diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLogger.java b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLogger.java index bc42f5f400..f75c7e0415 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLogger.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLogger.java @@ -17,6 +17,8 @@ package com.alibaba.druid.pool; import java.util.Properties; +import com.alibaba.druid.support.logging.Log; + /** * @author wenshao * @since 0.2.19 @@ -30,4 +32,8 @@ public interface DruidDataSourceStatLogger { * @since 0.2.21 */ void configFromProperties(Properties properties); + + void setLogger(Log logger); + + void setLoggerName(String loggerName); } diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerAdapter.java b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerAdapter.java index 76df534148..e69560bdab 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerAdapter.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerAdapter.java @@ -17,12 +17,14 @@ package com.alibaba.druid.pool; import java.util.Properties; +import com.alibaba.druid.support.logging.Log; + /** * * @author wenshao * @since 0.2.21 */ -public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger { +public class DruidDataSourceStatLoggerAdapter implements DruidDataSourceStatLogger { @Override public void log(DruidDataSourceStatValue statValue) { @@ -34,4 +36,14 @@ public abstract class DruidDataSourceStatLoggerAdapter implements DruidDataSourc } + @Override + public void setLogger(Log logger) { + + } + + @Override + public void setLoggerName(String loggerName) { + + } + } diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java index 05c931c76d..2a4cd2d67d 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSourceStatLoggerImpl.java @@ -56,20 +56,30 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap return logger; } + @Override public void setLoggerName(String loggerName) { logger = LogFactory.getLog(loggerName); } + @Override public void setLogger(Log logger) { if (logger == null) { throw new IllegalArgumentException("logger can not be null"); } this.logger = logger; } + + public boolean isLogEnable() { + return logger.isInfoEnabled(); + } + + public void log(String value) { + logger.info(value); + } @Override public void log(DruidDataSourceStatValue statValue) { - if (logger.isInfoEnabled()) { + if (isLogEnable()) { Map map = new LinkedHashMap(); map.put("url", statValue.url); @@ -225,7 +235,7 @@ public class DruidDataSourceStatLoggerImpl extends DruidDataSourceStatLoggerAdap String text = JSONUtils.toJSONString(map); - logger.info(text); + log(text); } } diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledCallableStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledCallableStatement.java index ef106e769f..90e68419bb 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledCallableStatement.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledCallableStatement.java @@ -1,1089 +1,1089 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.pool; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLXML; -import java.util.Calendar; - -import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; - -/** - * @author wenshao - */ -public class DruidPooledCallableStatement extends DruidPooledPreparedStatement implements CallableStatement { - - private CallableStatement stmt; - - public DruidPooledCallableStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{ - super(conn, holder); - this.stmt = (CallableStatement) holder.getStatement(); - } - - public CallableStatement getCallableStatementRaw() { - return stmt; - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { - try { - stmt.registerOutParameter(parameterIndex, sqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { - try { - stmt.registerOutParameter(parameterIndex, sqlType, scale); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public boolean wasNull() throws SQLException { - try { - return stmt.wasNull(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public String getString(int parameterIndex) throws SQLException { - try { - return stmt.getString(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public boolean getBoolean(int parameterIndex) throws SQLException { - try { - return stmt.getBoolean(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public byte getByte(int parameterIndex) throws SQLException { - try { - return stmt.getByte(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public short getShort(int parameterIndex) throws SQLException { - try { - return stmt.getShort(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public int getInt(int parameterIndex) throws SQLException { - try { - return stmt.getInt(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public long getLong(int parameterIndex) throws SQLException { - try { - return stmt.getLong(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public float getFloat(int parameterIndex) throws SQLException { - try { - return stmt.getFloat(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public double getDouble(int parameterIndex) throws SQLException { - try { - return stmt.getDouble(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - @Deprecated - public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { - try { - return stmt.getBigDecimal(parameterIndex, scale); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public byte[] getBytes(int parameterIndex) throws SQLException { - try { - return stmt.getBytes(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Date getDate(int parameterIndex) throws SQLException { - try { - return stmt.getDate(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Time getTime(int parameterIndex) throws SQLException { - try { - return stmt.getTime(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Timestamp getTimestamp(int parameterIndex) throws SQLException { - try { - return stmt.getTimestamp(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Object getObject(int parameterIndex) throws SQLException { - try { - Object obj = stmt.getObject(parameterIndex); - return wrapObject(obj); - } catch (Throwable t) { - throw checkException(t); - } - } - - private Object wrapObject(Object obj) { - if (obj instanceof ResultSet) { - ResultSet rs = (ResultSet) obj; - - DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); - resultSetTrace.add(poolableResultSet); - - obj = poolableResultSet; - } - - return obj; - } - - @Override - public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { - try { - return stmt.getBigDecimal(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Object getObject(int parameterIndex, java.util.Map> map) throws SQLException { - try { - Object obj = stmt.getObject(parameterIndex, map); - return wrapObject(obj); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Ref getRef(int parameterIndex) throws SQLException { - try { - return stmt.getRef(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Blob getBlob(int parameterIndex) throws SQLException { - try { - return stmt.getBlob(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Clob getClob(int parameterIndex) throws SQLException { - try { - return stmt.getClob(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Array getArray(int parameterIndex) throws SQLException { - try { - return stmt.getArray(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Date getDate(int parameterIndex, Calendar cal) throws SQLException { - try { - return stmt.getDate(parameterIndex, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Time getTime(int parameterIndex, Calendar cal) throws SQLException { - try { - return stmt.getTime(parameterIndex, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { - try { - return stmt.getTimestamp(parameterIndex, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { - try { - stmt.registerOutParameter(parameterIndex, sqlType, typeName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void registerOutParameter(String parameterName, int sqlType) throws SQLException { - try { - stmt.registerOutParameter(parameterName, sqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { - try { - stmt.registerOutParameter(parameterName, sqlType, scale); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { - try { - stmt.registerOutParameter(parameterName, sqlType, typeName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.net.URL getURL(int parameterIndex) throws SQLException { - try { - return stmt.getURL(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setURL(String parameterName, java.net.URL val) throws SQLException { - try { - stmt.setURL(parameterName, val); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNull(String parameterName, int sqlType) throws SQLException { - try { - stmt.setNull(parameterName, sqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBoolean(String parameterName, boolean x) throws SQLException { - try { - stmt.setBoolean(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setByte(String parameterName, byte x) throws SQLException { - try { - stmt.setByte(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setShort(String parameterName, short x) throws SQLException { - try { - stmt.setShort(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setInt(String parameterName, int x) throws SQLException { - try { - stmt.setInt(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setLong(String parameterName, long x) throws SQLException { - try { - stmt.setLong(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setFloat(String parameterName, float x) throws SQLException { - try { - stmt.setFloat(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDouble(String parameterName, double x) throws SQLException { - try { - stmt.setDouble(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { - try { - stmt.setBigDecimal(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setString(String parameterName, String x) throws SQLException { - try { - stmt.setString(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBytes(String parameterName, byte x[]) throws SQLException { - try { - stmt.setBytes(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDate(String parameterName, java.sql.Date x) throws SQLException { - try { - stmt.setDate(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTime(String parameterName, java.sql.Time x) throws SQLException { - try { - stmt.setTime(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { - try { - stmt.setTimestamp(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x, int length) throws SQLException { - try { - stmt.setAsciiStream(parameterName, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x, int length) throws SQLException { - try { - stmt.setBinaryStream(parameterName, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { - try { - stmt.setObject(parameterName, x, targetSqlType, scale); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { - try { - stmt.setObject(parameterName, x, targetSqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(String parameterName, Object x) throws SQLException { - try { - stmt.setObject(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader, int length) throws SQLException { - try { - stmt.setCharacterStream(parameterName, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException { - try { - stmt.setDate(parameterName, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTime(String parameterName, java.sql.Time x, Calendar cal) throws SQLException { - try { - stmt.setTime(parameterName, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) throws SQLException { - try { - stmt.setTimestamp(parameterName, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { - try { - stmt.setNull(parameterName, sqlType, typeName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public String getString(String parameterName) throws SQLException { - try { - return stmt.getString(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public boolean getBoolean(String parameterName) throws SQLException { - try { - return stmt.getBoolean(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public byte getByte(String parameterName) throws SQLException { - try { - return stmt.getByte(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public short getShort(String parameterName) throws SQLException { - try { - return stmt.getShort(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public int getInt(String parameterName) throws SQLException { - try { - return stmt.getInt(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public long getLong(String parameterName) throws SQLException { - try { - return stmt.getLong(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public float getFloat(String parameterName) throws SQLException { - try { - return stmt.getFloat(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public double getDouble(String parameterName) throws SQLException { - try { - return stmt.getDouble(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public byte[] getBytes(String parameterName) throws SQLException { - try { - return stmt.getBytes(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Date getDate(String parameterName) throws SQLException { - try { - return stmt.getDate(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Time getTime(String parameterName) throws SQLException { - try { - return stmt.getTime(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException { - try { - return stmt.getTimestamp(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Object getObject(String parameterName) throws SQLException { - try { - Object obj = stmt.getObject(parameterName); - return wrapObject(obj); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public BigDecimal getBigDecimal(String parameterName) throws SQLException { - try { - return stmt.getBigDecimal(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Object getObject(String parameterName, java.util.Map> map) throws SQLException { - try { - Object obj = stmt.getObject(parameterName, map); - return wrapObject(obj); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Ref getRef(String parameterName) throws SQLException { - try { - return stmt.getRef(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Blob getBlob(String parameterName) throws SQLException { - try { - return stmt.getBlob(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Clob getClob(String parameterName) throws SQLException { - try { - return stmt.getClob(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public Array getArray(String parameterName) throws SQLException { - try { - return stmt.getArray(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException { - try { - return stmt.getDate(parameterName, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Time getTime(String parameterName, Calendar cal) throws SQLException { - try { - return stmt.getTime(parameterName, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - try { - return stmt.getTimestamp(parameterName, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.net.URL getURL(String parameterName) throws SQLException { - try { - return stmt.getURL(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public RowId getRowId(int parameterIndex) throws SQLException { - try { - return stmt.getRowId(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public RowId getRowId(String parameterName) throws SQLException { - try { - return stmt.getRowId(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setRowId(String parameterName, RowId x) throws SQLException { - try { - stmt.setRowId(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNString(String parameterName, String value) throws SQLException { - try { - stmt.setNString(parameterName, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { - try { - stmt.setNCharacterStream(parameterName, value, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(String parameterName, NClob value) throws SQLException { - try { - stmt.setNClob(parameterName, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(String parameterName, Reader reader, long length) throws SQLException { - try { - stmt.setClob(parameterName, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { - try { - stmt.setBlob(parameterName, inputStream, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(String parameterName, Reader reader, long length) throws SQLException { - try { - stmt.setNClob(parameterName, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public NClob getNClob(int parameterIndex) throws SQLException { - try { - return stmt.getNClob(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public NClob getNClob(String parameterName) throws SQLException { - try { - return stmt.getNClob(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { - try { - stmt.setSQLXML(parameterName, xmlObject); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - try { - return stmt.getSQLXML(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public SQLXML getSQLXML(String parameterName) throws SQLException { - try { - return stmt.getSQLXML(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public String getNString(int parameterIndex) throws SQLException { - try { - return stmt.getNString(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public String getNString(String parameterName) throws SQLException { - try { - return stmt.getNString(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.io.Reader getNCharacterStream(int parameterIndex) throws SQLException { - try { - return stmt.getNCharacterStream(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.io.Reader getNCharacterStream(String parameterName) throws SQLException { - try { - return stmt.getNCharacterStream(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.io.Reader getCharacterStream(int parameterIndex) throws SQLException { - try { - return stmt.getCharacterStream(parameterIndex); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public java.io.Reader getCharacterStream(String parameterName) throws SQLException { - try { - return stmt.getCharacterStream(parameterName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(String parameterName, Blob x) throws SQLException { - try { - stmt.setBlob(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(String parameterName, Clob x) throws SQLException { - try { - stmt.setClob(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x, long length) throws SQLException { - try { - stmt.setAsciiStream(parameterName, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x, long length) throws SQLException { - try { - stmt.setBinaryStream(parameterName, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader, long length) throws SQLException { - try { - stmt.setCharacterStream(parameterName, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x) throws SQLException { - try { - stmt.setAsciiStream(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x) throws SQLException { - try { - stmt.setBinaryStream(parameterName, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader) throws SQLException { - try { - stmt.setCharacterStream(parameterName, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNCharacterStream(String parameterName, Reader value) throws SQLException { - try { - stmt.setNCharacterStream(parameterName, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(String parameterName, Reader reader) throws SQLException { - try { - stmt.setClob(parameterName, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(String parameterName, InputStream inputStream) throws SQLException { - try { - stmt.setBlob(parameterName, inputStream); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(String parameterName, Reader reader) throws SQLException { - try { - stmt.setNClob(parameterName, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - public T getObject(int parameterIndex, Class type) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public T getObject(String parameterName, Class type) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface == CallableStatement.class || iface == PreparedStatement.class) { - if (stmt instanceof CallableStatementProxy) { - return stmt.unwrap(iface); - } - return (T) stmt; - } - - return super.unwrap(iface); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.pool; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLXML; +import java.util.Calendar; + +import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; + +/** + * @author wenshao + */ +public class DruidPooledCallableStatement extends DruidPooledPreparedStatement implements CallableStatement { + + private CallableStatement stmt; + + public DruidPooledCallableStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{ + super(conn, holder); + this.stmt = (CallableStatement) holder.getStatement(); + } + + public CallableStatement getCallableStatementRaw() { + return stmt; + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { + try { + stmt.registerOutParameter(parameterIndex, sqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { + try { + stmt.registerOutParameter(parameterIndex, sqlType, scale); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public boolean wasNull() throws SQLException { + try { + return stmt.wasNull(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public String getString(int parameterIndex) throws SQLException { + try { + return stmt.getString(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public boolean getBoolean(int parameterIndex) throws SQLException { + try { + return stmt.getBoolean(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public byte getByte(int parameterIndex) throws SQLException { + try { + return stmt.getByte(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public short getShort(int parameterIndex) throws SQLException { + try { + return stmt.getShort(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public int getInt(int parameterIndex) throws SQLException { + try { + return stmt.getInt(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public long getLong(int parameterIndex) throws SQLException { + try { + return stmt.getLong(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public float getFloat(int parameterIndex) throws SQLException { + try { + return stmt.getFloat(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public double getDouble(int parameterIndex) throws SQLException { + try { + return stmt.getDouble(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + @Deprecated + public BigDecimal getBigDecimal(int parameterIndex, int scale) throws SQLException { + try { + return stmt.getBigDecimal(parameterIndex, scale); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public byte[] getBytes(int parameterIndex) throws SQLException { + try { + return stmt.getBytes(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Date getDate(int parameterIndex) throws SQLException { + try { + return stmt.getDate(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Time getTime(int parameterIndex) throws SQLException { + try { + return stmt.getTime(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Timestamp getTimestamp(int parameterIndex) throws SQLException { + try { + return stmt.getTimestamp(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Object getObject(int parameterIndex) throws SQLException { + try { + Object obj = stmt.getObject(parameterIndex); + return wrapObject(obj); + } catch (Throwable t) { + throw checkException(t); + } + } + + private Object wrapObject(Object obj) { + if (obj instanceof ResultSet) { + ResultSet rs = (ResultSet) obj; + + DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); + addResultSetTrace(poolableResultSet); + + obj = poolableResultSet; + } + + return obj; + } + + @Override + public BigDecimal getBigDecimal(int parameterIndex) throws SQLException { + try { + return stmt.getBigDecimal(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Object getObject(int parameterIndex, java.util.Map> map) throws SQLException { + try { + Object obj = stmt.getObject(parameterIndex, map); + return wrapObject(obj); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Ref getRef(int parameterIndex) throws SQLException { + try { + return stmt.getRef(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Blob getBlob(int parameterIndex) throws SQLException { + try { + return stmt.getBlob(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Clob getClob(int parameterIndex) throws SQLException { + try { + return stmt.getClob(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Array getArray(int parameterIndex) throws SQLException { + try { + return stmt.getArray(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Date getDate(int parameterIndex, Calendar cal) throws SQLException { + try { + return stmt.getDate(parameterIndex, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Time getTime(int parameterIndex, Calendar cal) throws SQLException { + try { + return stmt.getTime(parameterIndex, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { + try { + return stmt.getTimestamp(parameterIndex, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { + try { + stmt.registerOutParameter(parameterIndex, sqlType, typeName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void registerOutParameter(String parameterName, int sqlType) throws SQLException { + try { + stmt.registerOutParameter(parameterName, sqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void registerOutParameter(String parameterName, int sqlType, int scale) throws SQLException { + try { + stmt.registerOutParameter(parameterName, sqlType, scale); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void registerOutParameter(String parameterName, int sqlType, String typeName) throws SQLException { + try { + stmt.registerOutParameter(parameterName, sqlType, typeName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.net.URL getURL(int parameterIndex) throws SQLException { + try { + return stmt.getURL(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setURL(String parameterName, java.net.URL val) throws SQLException { + try { + stmt.setURL(parameterName, val); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNull(String parameterName, int sqlType) throws SQLException { + try { + stmt.setNull(parameterName, sqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBoolean(String parameterName, boolean x) throws SQLException { + try { + stmt.setBoolean(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setByte(String parameterName, byte x) throws SQLException { + try { + stmt.setByte(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setShort(String parameterName, short x) throws SQLException { + try { + stmt.setShort(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setInt(String parameterName, int x) throws SQLException { + try { + stmt.setInt(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setLong(String parameterName, long x) throws SQLException { + try { + stmt.setLong(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setFloat(String parameterName, float x) throws SQLException { + try { + stmt.setFloat(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDouble(String parameterName, double x) throws SQLException { + try { + stmt.setDouble(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { + try { + stmt.setBigDecimal(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setString(String parameterName, String x) throws SQLException { + try { + stmt.setString(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBytes(String parameterName, byte x[]) throws SQLException { + try { + stmt.setBytes(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDate(String parameterName, java.sql.Date x) throws SQLException { + try { + stmt.setDate(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTime(String parameterName, java.sql.Time x) throws SQLException { + try { + stmt.setTime(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { + try { + stmt.setTimestamp(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x, int length) throws SQLException { + try { + stmt.setAsciiStream(parameterName, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x, int length) throws SQLException { + try { + stmt.setBinaryStream(parameterName, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { + try { + stmt.setObject(parameterName, x, targetSqlType, scale); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { + try { + stmt.setObject(parameterName, x, targetSqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(String parameterName, Object x) throws SQLException { + try { + stmt.setObject(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader, int length) throws SQLException { + try { + stmt.setCharacterStream(parameterName, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException { + try { + stmt.setDate(parameterName, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTime(String parameterName, java.sql.Time x, Calendar cal) throws SQLException { + try { + stmt.setTime(parameterName, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) throws SQLException { + try { + stmt.setTimestamp(parameterName, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { + try { + stmt.setNull(parameterName, sqlType, typeName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public String getString(String parameterName) throws SQLException { + try { + return stmt.getString(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public boolean getBoolean(String parameterName) throws SQLException { + try { + return stmt.getBoolean(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public byte getByte(String parameterName) throws SQLException { + try { + return stmt.getByte(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public short getShort(String parameterName) throws SQLException { + try { + return stmt.getShort(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public int getInt(String parameterName) throws SQLException { + try { + return stmt.getInt(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public long getLong(String parameterName) throws SQLException { + try { + return stmt.getLong(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public float getFloat(String parameterName) throws SQLException { + try { + return stmt.getFloat(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public double getDouble(String parameterName) throws SQLException { + try { + return stmt.getDouble(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public byte[] getBytes(String parameterName) throws SQLException { + try { + return stmt.getBytes(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Date getDate(String parameterName) throws SQLException { + try { + return stmt.getDate(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Time getTime(String parameterName) throws SQLException { + try { + return stmt.getTime(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException { + try { + return stmt.getTimestamp(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Object getObject(String parameterName) throws SQLException { + try { + Object obj = stmt.getObject(parameterName); + return wrapObject(obj); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + try { + return stmt.getBigDecimal(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Object getObject(String parameterName, java.util.Map> map) throws SQLException { + try { + Object obj = stmt.getObject(parameterName, map); + return wrapObject(obj); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Ref getRef(String parameterName) throws SQLException { + try { + return stmt.getRef(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Blob getBlob(String parameterName) throws SQLException { + try { + return stmt.getBlob(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Clob getClob(String parameterName) throws SQLException { + try { + return stmt.getClob(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public Array getArray(String parameterName) throws SQLException { + try { + return stmt.getArray(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException { + try { + return stmt.getDate(parameterName, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Time getTime(String parameterName, Calendar cal) throws SQLException { + try { + return stmt.getTime(parameterName, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { + try { + return stmt.getTimestamp(parameterName, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.net.URL getURL(String parameterName) throws SQLException { + try { + return stmt.getURL(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public RowId getRowId(int parameterIndex) throws SQLException { + try { + return stmt.getRowId(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public RowId getRowId(String parameterName) throws SQLException { + try { + return stmt.getRowId(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setRowId(String parameterName, RowId x) throws SQLException { + try { + stmt.setRowId(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNString(String parameterName, String value) throws SQLException { + try { + stmt.setNString(parameterName, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { + try { + stmt.setNCharacterStream(parameterName, value, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(String parameterName, NClob value) throws SQLException { + try { + stmt.setNClob(parameterName, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(String parameterName, Reader reader, long length) throws SQLException { + try { + stmt.setClob(parameterName, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { + try { + stmt.setBlob(parameterName, inputStream, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(String parameterName, Reader reader, long length) throws SQLException { + try { + stmt.setNClob(parameterName, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public NClob getNClob(int parameterIndex) throws SQLException { + try { + return stmt.getNClob(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public NClob getNClob(String parameterName) throws SQLException { + try { + return stmt.getNClob(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { + try { + stmt.setSQLXML(parameterName, xmlObject); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + try { + return stmt.getSQLXML(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public SQLXML getSQLXML(String parameterName) throws SQLException { + try { + return stmt.getSQLXML(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public String getNString(int parameterIndex) throws SQLException { + try { + return stmt.getNString(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public String getNString(String parameterName) throws SQLException { + try { + return stmt.getNString(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.io.Reader getNCharacterStream(int parameterIndex) throws SQLException { + try { + return stmt.getNCharacterStream(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.io.Reader getNCharacterStream(String parameterName) throws SQLException { + try { + return stmt.getNCharacterStream(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.io.Reader getCharacterStream(int parameterIndex) throws SQLException { + try { + return stmt.getCharacterStream(parameterIndex); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public java.io.Reader getCharacterStream(String parameterName) throws SQLException { + try { + return stmt.getCharacterStream(parameterName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(String parameterName, Blob x) throws SQLException { + try { + stmt.setBlob(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(String parameterName, Clob x) throws SQLException { + try { + stmt.setClob(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x, long length) throws SQLException { + try { + stmt.setAsciiStream(parameterName, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x, long length) throws SQLException { + try { + stmt.setBinaryStream(parameterName, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader, long length) throws SQLException { + try { + stmt.setCharacterStream(parameterName, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x) throws SQLException { + try { + stmt.setAsciiStream(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x) throws SQLException { + try { + stmt.setBinaryStream(parameterName, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader) throws SQLException { + try { + stmt.setCharacterStream(parameterName, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNCharacterStream(String parameterName, Reader value) throws SQLException { + try { + stmt.setNCharacterStream(parameterName, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(String parameterName, Reader reader) throws SQLException { + try { + stmt.setClob(parameterName, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(String parameterName, InputStream inputStream) throws SQLException { + try { + stmt.setBlob(parameterName, inputStream); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(String parameterName, Reader reader) throws SQLException { + try { + stmt.setNClob(parameterName, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + public T getObject(int parameterIndex, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public T getObject(String parameterName, Class type) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface == CallableStatement.class || iface == PreparedStatement.class) { + if (stmt instanceof CallableStatementProxy) { + return stmt.unwrap(iface); + } + return (T) stmt; + } + + return super.unwrap(iface); + } +} diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index 1a858d93e7..1b995eaa5d 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -145,7 +145,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. return; } - if (holder.isPoolPreparedStatements()) { + if (stmt.isPooled()) { try { rawStatement.clearParameters(); } catch (SQLException ex) { @@ -159,7 +159,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. } stmt.getPreparedStatementHolder().decrementInUseCount(); - if (holder.isPoolPreparedStatements()) { + if (stmt.isPooled() && holder.isPoolPreparedStatements()) { holder.getStatementPool().put(stmt.getPreparedStatementHolder()); stmt.clearResultSet(); diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java index e6344bba67..257bb3055d 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledPreparedStatement.java @@ -1,1061 +1,1071 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.pool; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.Calendar; - -import com.alibaba.druid.pool.PreparedStatementPool.MethodType; -import com.alibaba.druid.support.logging.Log; -import com.alibaba.druid.support.logging.LogFactory; -import com.alibaba.druid.util.OracleUtils; - -/** - * @author wenshao - */ -public class DruidPooledPreparedStatement extends DruidPooledStatement implements PreparedStatement { - - private final static Log LOG = LogFactory.getLog(DruidPooledPreparedStatement.class); - - private final PreparedStatementHolder holder; - private final PreparedStatement stmt; - private final String sql; - - private int defaultMaxFieldSize; - private int defaultMaxRows; - private int defaultQueryTimeout; - private int defaultFetchDirection; - private int defaultFetchSize; - private int currentMaxFieldSize; - private int currentMaxRows; - private int currentQueryTimeout; - private int currentFetchDirection; - private int currentFetchSize; - - public DruidPooledPreparedStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{ - super(conn, holder.getStatement()); - this.stmt = holder.getStatement(); - this.holder = holder; - this.sql = holder.getKey().sql; - - // Remember the defaults - try { - defaultMaxFieldSize = stmt.getMaxFieldSize(); - } catch (SQLException e) { - LOG.error("getMaxFieldSize error", e); - } - - try { - defaultMaxRows = stmt.getMaxRows(); - } catch (SQLException e) { - LOG.error("getMaxRows error", e); - } - - try { - defaultQueryTimeout = stmt.getQueryTimeout(); - } catch (SQLException e) { - LOG.error("getMaxRows error", e); - } - - try { - defaultFetchDirection = stmt.getFetchDirection(); - } catch (SQLException e) { - LOG.error("getFetchDirection error", e); - } - - try { - defaultFetchSize = stmt.getFetchSize(); - } catch (SQLException e) { - LOG.error("getFetchSize error", e); - } - - currentMaxFieldSize = defaultMaxFieldSize; - currentMaxRows = defaultMaxRows; - currentQueryTimeout = defaultQueryTimeout; - currentFetchDirection = defaultFetchDirection; - currentFetchSize = defaultFetchSize; - } - - public PreparedStatementHolder getPreparedStatementHolder() { - return holder; - } - - public int getHitCount() { - return holder.getHitCount(); - } - - public void setFetchSize(int rows) throws SQLException { - currentFetchSize = rows; - super.setFetchSize(rows); - } - - public void setFetchDirection(int direction) throws SQLException { - currentFetchDirection = direction; - super.setFetchDirection(direction); - } - - public void setMaxFieldSize(int max) throws SQLException { - currentMaxFieldSize = max; - super.setMaxFieldSize(max); - } - - public void setMaxRows(int max) throws SQLException { - currentMaxRows = max; - super.setMaxRows(max); - } - - public void setQueryTimeout(int seconds) throws SQLException { - currentQueryTimeout = seconds; - super.setQueryTimeout(seconds); - } - - public String getSql() { - return sql; - } - - public PreparedStatementKey getKey() { - return holder.getKey(); - } - - public PreparedStatement getRawPreparedStatement() { - return stmt; - } - - public PreparedStatement getRawStatement() { - return stmt; - } - - @Override - public void close() throws SQLException { - if (isClosed()) { - return; - } - - boolean connectionClosed = this.conn.isClosed(); - // Reset the defaults - if (!connectionClosed) { - try { - if (defaultMaxFieldSize != currentMaxFieldSize) { - stmt.setMaxFieldSize(defaultMaxFieldSize); - currentMaxFieldSize = defaultMaxFieldSize; - } - if (defaultMaxRows != currentMaxRows) { - stmt.setMaxRows(defaultMaxRows); - currentMaxRows = defaultMaxRows; - } - if (defaultQueryTimeout != currentQueryTimeout) { - stmt.setQueryTimeout(defaultQueryTimeout); - currentQueryTimeout = defaultQueryTimeout; - } - if (defaultFetchDirection != currentFetchDirection) { - stmt.setFetchDirection(defaultFetchDirection); - currentFetchDirection = defaultFetchDirection; - } - if (defaultFetchSize != currentFetchSize) { - stmt.setFetchSize(defaultFetchSize); - currentFetchSize = defaultFetchSize; - } - } catch (Exception e) { - this.conn.handleException(e); - } - } - - conn.closePoolableStatement(this); - } - - void closeInternal() throws SQLException { - super.close(); - } - - void setClosed(boolean value) { - this.closed = value; - } - - @Override - public ResultSet executeQuery() throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - oracleSetRowPrefetch(); - - conn.beforeExecute(); - try { - ResultSet rs = stmt.executeQuery(); - - if (rs == null) { - return null; - } - - DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); - resultSetTrace.add(poolableResultSet); - - return poolableResultSet; - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public int executeUpdate() throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeUpdate(); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public void setNull(int parameterIndex, int sqlType) throws SQLException { - checkOpen(); - - try { - stmt.setNull(parameterIndex, sqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - checkOpen(); - - try { - stmt.setBoolean(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setByte(int parameterIndex, byte x) throws SQLException { - checkOpen(); - - try { - stmt.setByte(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setShort(int parameterIndex, short x) throws SQLException { - checkOpen(); - - try { - stmt.setShort(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setInt(int parameterIndex, int x) throws SQLException { - checkOpen(); - - try { - stmt.setInt(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setLong(int parameterIndex, long x) throws SQLException { - checkOpen(); - - try { - stmt.setLong(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setFloat(int parameterIndex, float x) throws SQLException { - checkOpen(); - - try { - stmt.setFloat(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDouble(int parameterIndex, double x) throws SQLException { - checkOpen(); - - try { - stmt.setDouble(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - checkOpen(); - - try { - stmt.setBigDecimal(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setString(int parameterIndex, String x) throws SQLException { - checkOpen(); - - try { - stmt.setString(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - checkOpen(); - - try { - stmt.setBytes(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDate(int parameterIndex, Date x) throws SQLException { - checkOpen(); - - try { - stmt.setDate(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTime(int parameterIndex, Time x) throws SQLException { - checkOpen(); - - try { - stmt.setTime(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - checkOpen(); - - try { - stmt.setTimestamp(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - checkOpen(); - - try { - stmt.setAsciiStream(parameterIndex, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - @Deprecated - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - checkOpen(); - - try { - stmt.setUnicodeStream(parameterIndex, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - checkOpen(); - - try { - stmt.setBinaryStream(parameterIndex, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void clearParameters() throws SQLException { - checkOpen(); - - try { - stmt.clearParameters(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { - checkOpen(); - - try { - stmt.setObject(parameterIndex, x, targetSqlType); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(int parameterIndex, Object x) throws SQLException { - checkOpen(); - - try { - stmt.setObject(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public boolean execute() throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - // oracleSetRowPrefetch(); - - conn.beforeExecute(); - try { - return stmt.execute(); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - protected void oracleSetRowPrefetch() throws SQLException { - if (!conn.isOracle()) { - return; - } - - if (holder.getHitCount() == 0) { - return; - } - - int fetchRowPeak = holder.getFetchRowPeak(); - - if (fetchRowPeak < 0) { - return; - } - - if (holder.getDefaultRowPretch() == -1) { - int defaultRowPretch = OracleUtils.getRowPrefetch(this); - if (defaultRowPretch != holder.getDefaultRowPretch()) { - holder.setDefaultRowPretch(defaultRowPretch); - holder.setRowPrefetch(defaultRowPretch); - } - } - - int rowPrefetch; - - if (fetchRowPeak <= 1) { - rowPrefetch = 2; - } else if (fetchRowPeak > holder.getDefaultRowPretch()) { - rowPrefetch = holder.getDefaultRowPretch(); - } else { - rowPrefetch = fetchRowPeak + 1; - } - - if (rowPrefetch != holder.getRowPrefetch()) { - OracleUtils.setRowPrefetch(this, rowPrefetch); - holder.setRowPrefetch(rowPrefetch); - } - } - - @Override - public void addBatch() throws SQLException { - checkOpen(); - - try { - stmt.addBatch(); - } catch (Throwable t) { - throw checkException(t); - } - } - - public int[] executeBatch() throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeBatch(); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { - checkOpen(); - - try { - stmt.setCharacterStream(parameterIndex, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setRef(int parameterIndex, Ref x) throws SQLException { - checkOpen(); - - try { - stmt.setRef(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(int parameterIndex, Blob x) throws SQLException { - checkOpen(); - - try { - stmt.setBlob(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(int parameterIndex, Clob x) throws SQLException { - checkOpen(); - - try { - stmt.setClob(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setArray(int parameterIndex, Array x) throws SQLException { - checkOpen(); - - try { - stmt.setArray(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public ResultSetMetaData getMetaData() throws SQLException { - checkOpen(); - - try { - return stmt.getMetaData(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { - checkOpen(); - - try { - stmt.setDate(parameterIndex, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { - checkOpen(); - - try { - stmt.setTime(parameterIndex, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - checkOpen(); - - try { - stmt.setTimestamp(parameterIndex, x, cal); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { - checkOpen(); - - try { - stmt.setNull(parameterIndex, sqlType, typeName); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setURL(int parameterIndex, URL x) throws SQLException { - checkOpen(); - - try { - stmt.setURL(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public ParameterMetaData getParameterMetaData() throws SQLException { - checkOpen(); - - try { - return stmt.getParameterMetaData(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setRowId(int parameterIndex, RowId x) throws SQLException { - checkOpen(); - - try { - stmt.setRowId(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNString(int parameterIndex, String value) throws SQLException { - checkOpen(); - - try { - stmt.setNString(parameterIndex, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { - checkOpen(); - - try { - stmt.setNCharacterStream(parameterIndex, value, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(int parameterIndex, NClob value) throws SQLException { - checkOpen(); - - try { - stmt.setNClob(parameterIndex, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - checkOpen(); - - try { - stmt.setClob(parameterIndex, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { - checkOpen(); - - try { - stmt.setBlob(parameterIndex, inputStream, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { - checkOpen(); - - try { - stmt.setNClob(parameterIndex, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { - checkOpen(); - - try { - stmt.setSQLXML(parameterIndex, xmlObject); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { - checkOpen(); - - try { - stmt.setObject(parameterIndex, x, targetSqlType, scaleOrLength); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { - checkOpen(); - - try { - stmt.setAsciiStream(parameterIndex, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { - checkOpen(); - - try { - stmt.setBinaryStream(parameterIndex, x, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { - checkOpen(); - - try { - stmt.setCharacterStream(parameterIndex, reader, length); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - checkOpen(); - - try { - stmt.setAsciiStream(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { - checkOpen(); - - try { - stmt.setBinaryStream(parameterIndex, x); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { - checkOpen(); - - try { - stmt.setCharacterStream(parameterIndex, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - checkOpen(); - - try { - stmt.setNCharacterStream(parameterIndex, value); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setClob(int parameterIndex, Reader reader) throws SQLException { - checkOpen(); - - try { - stmt.setClob(parameterIndex, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { - checkOpen(); - - try { - stmt.setBlob(parameterIndex, inputStream); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - checkOpen(); - - try { - stmt.setNClob(parameterIndex, reader); - } catch (Throwable t) { - throw checkException(t); - } - } - - public static class PreparedStatementKey { - - private final String sql; - private final String catalog; - - protected final MethodType methodType; - - private final int resultSetType; - private final int resultSetConcurrency; - private final int resultSetHoldability; - private final int autoGeneratedKeys; - private final int[] columnIndexes; - private final String[] columnNames; - - public PreparedStatementKey(String sql, String catalog, MethodType methodType) throws SQLException{ - this(sql, catalog, methodType, 0, 0, 0, 0, null, null); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, - int resultSetConcurrency) throws SQLException{ - this(sql, catalog, methodType, resultSetType, resultSetConcurrency, 0, 0, null, null); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, - int resultSetConcurrency, int resultSetHoldability) throws SQLException{ - this(sql, catalog, methodType, resultSetType, resultSetConcurrency, resultSetHoldability, 0, null, null); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, int autoGeneratedKeys) - throws SQLException{ - this(sql, catalog, methodType, 0, 0, 0, autoGeneratedKeys, null, null); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, int[] columnIndexes) - throws SQLException{ - this(sql, catalog, methodType, 0, 0, 0, 0, columnIndexes, null); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, String[] columnNames) - throws SQLException{ - this(sql, catalog, methodType, 0, 0, 0, 0, null, columnNames); - } - - public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, - int resultSetConcurrency, int resultSetHoldability, int autoGeneratedKeys, - int[] columnIndexes, String[] columnNames) throws SQLException{ - if (sql == null) { - throw new SQLException("sql is null"); - } - - this.sql = sql; - this.catalog = catalog; - this.methodType = methodType; - this.resultSetType = resultSetType; - this.resultSetConcurrency = resultSetConcurrency; - this.resultSetHoldability = resultSetHoldability; - this.autoGeneratedKeys = autoGeneratedKeys; - this.columnIndexes = columnIndexes; - this.columnNames = columnNames; - } - - public int getResultSetType() { - return resultSetType; - } - - public int getResultSetConcurrency() { - return resultSetConcurrency; - } - - public int getResultSetHoldability() { - return resultSetHoldability; - } - - public boolean equals(Object object) { - PreparedStatementKey that = (PreparedStatementKey) object; - - if (!this.sql.equals(that.sql)) { - return false; - } - - if (this.catalog == null) { - if (that.catalog != null) { - return false; - } - } else { - if (!this.catalog.equals(that.catalog)) { - return false; - } - } - - if (this.methodType != that.methodType) { - return false; - } - - if (this.resultSetType != that.resultSetType) { - return false; - } - - if (this.resultSetConcurrency != that.resultSetConcurrency) { - return false; - } - - if (this.resultSetHoldability != that.resultSetHoldability) { - return false; - } - - if (this.autoGeneratedKeys != that.autoGeneratedKeys) { - return false; - } - - if (!Arrays.equals(columnIndexes, that.columnIndexes)) { - return false; - } - - if (!Arrays.equals(columnNames, that.columnNames)) { - return false; - } - - return true; - } - - public int hashCode() { - final int prime = 31; - int result = 1; - - result = prime * result + ((sql == null) ? 0 : sql.hashCode()); - result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); - result = prime * result + ((methodType == null) ? 0 : methodType.hashCode()); - - result = prime * result + resultSetConcurrency; - result = prime * result + resultSetHoldability; - result = prime * result + resultSetType; - - result = prime * result + autoGeneratedKeys; - - result = prime * result + Arrays.hashCode(columnIndexes); - result = prime * result + Arrays.hashCode(columnNames); - - return result; - } - - public String getSql() { - return sql; - } - - } - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - if (iface == PreparedStatementHolder.class) { - return true; - } - - return super.isWrapperFor(iface); - } - - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface == PreparedStatementHolder.class) { - return (T) holder; - } - return super.unwrap(iface); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.pool; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Calendar; + +import com.alibaba.druid.pool.PreparedStatementPool.MethodType; +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; +import com.alibaba.druid.util.OracleUtils; + +/** + * @author wenshao + */ +public class DruidPooledPreparedStatement extends DruidPooledStatement implements PreparedStatement { + + private final static Log LOG = LogFactory.getLog(DruidPooledPreparedStatement.class); + + private final PreparedStatementHolder holder; + private final PreparedStatement stmt; + private final String sql; + + private int defaultMaxFieldSize; + private int defaultMaxRows; + private int defaultQueryTimeout; + private int defaultFetchDirection; + private int defaultFetchSize; + private int currentMaxFieldSize; + private int currentMaxRows; + private int currentQueryTimeout; + private int currentFetchDirection; + private int currentFetchSize; + + private boolean pooled = false; + + public DruidPooledPreparedStatement(DruidPooledConnection conn, PreparedStatementHolder holder) throws SQLException{ + super(conn, holder.getStatement()); + this.stmt = holder.getStatement(); + this.holder = holder; + this.sql = holder.getKey().sql; + + pooled = conn.getConnectionHolder().isPoolPreparedStatements(); + // Remember the defaults + + if (pooled) { + try { + defaultMaxFieldSize = stmt.getMaxFieldSize(); + } catch (SQLException e) { + LOG.error("getMaxFieldSize error", e); + } + + try { + defaultMaxRows = stmt.getMaxRows(); + } catch (SQLException e) { + LOG.error("getMaxRows error", e); + } + + try { + defaultQueryTimeout = stmt.getQueryTimeout(); + } catch (SQLException e) { + LOG.error("getMaxRows error", e); + } + + try { + defaultFetchDirection = stmt.getFetchDirection(); + } catch (SQLException e) { + LOG.error("getFetchDirection error", e); + } + + try { + defaultFetchSize = stmt.getFetchSize(); + } catch (SQLException e) { + LOG.error("getFetchSize error", e); + } + } + + currentMaxFieldSize = defaultMaxFieldSize; + currentMaxRows = defaultMaxRows; + currentQueryTimeout = defaultQueryTimeout; + currentFetchDirection = defaultFetchDirection; + currentFetchSize = defaultFetchSize; + } + + public PreparedStatementHolder getPreparedStatementHolder() { + return holder; + } + + public int getHitCount() { + return holder.getHitCount(); + } + + public void setFetchSize(int rows) throws SQLException { + currentFetchSize = rows; + super.setFetchSize(rows); + } + + public void setFetchDirection(int direction) throws SQLException { + currentFetchDirection = direction; + super.setFetchDirection(direction); + } + + public void setMaxFieldSize(int max) throws SQLException { + currentMaxFieldSize = max; + super.setMaxFieldSize(max); + } + + public void setMaxRows(int max) throws SQLException { + currentMaxRows = max; + super.setMaxRows(max); + } + + public void setQueryTimeout(int seconds) throws SQLException { + currentQueryTimeout = seconds; + super.setQueryTimeout(seconds); + } + + public String getSql() { + return sql; + } + + public PreparedStatementKey getKey() { + return holder.getKey(); + } + + public PreparedStatement getRawPreparedStatement() { + return stmt; + } + + public PreparedStatement getRawStatement() { + return stmt; + } + + @Override + public void close() throws SQLException { + if (isClosed()) { + return; + } + + boolean connectionClosed = this.conn.isClosed(); + // Reset the defaults + if (pooled && !connectionClosed) { + try { + if (defaultMaxFieldSize != currentMaxFieldSize) { + stmt.setMaxFieldSize(defaultMaxFieldSize); + currentMaxFieldSize = defaultMaxFieldSize; + } + if (defaultMaxRows != currentMaxRows) { + stmt.setMaxRows(defaultMaxRows); + currentMaxRows = defaultMaxRows; + } + if (defaultQueryTimeout != currentQueryTimeout) { + stmt.setQueryTimeout(defaultQueryTimeout); + currentQueryTimeout = defaultQueryTimeout; + } + if (defaultFetchDirection != currentFetchDirection) { + stmt.setFetchDirection(defaultFetchDirection); + currentFetchDirection = defaultFetchDirection; + } + if (defaultFetchSize != currentFetchSize) { + stmt.setFetchSize(defaultFetchSize); + currentFetchSize = defaultFetchSize; + } + } catch (Exception e) { + this.conn.handleException(e); + } + } + + conn.closePoolableStatement(this); + } + + public boolean isPooled() { + return pooled; + } + + void closeInternal() throws SQLException { + super.close(); + } + + void setClosed(boolean value) { + this.closed = value; + } + + @Override + public ResultSet executeQuery() throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + oracleSetRowPrefetch(); + + conn.beforeExecute(); + try { + ResultSet rs = stmt.executeQuery(); + + if (rs == null) { + return null; + } + + DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); + addResultSetTrace(poolableResultSet); + + return poolableResultSet; + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public int executeUpdate() throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeUpdate(); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException { + checkOpen(); + + try { + stmt.setNull(parameterIndex, sqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + checkOpen(); + + try { + stmt.setBoolean(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setByte(int parameterIndex, byte x) throws SQLException { + checkOpen(); + + try { + stmt.setByte(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setShort(int parameterIndex, short x) throws SQLException { + checkOpen(); + + try { + stmt.setShort(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setInt(int parameterIndex, int x) throws SQLException { + checkOpen(); + + try { + stmt.setInt(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setLong(int parameterIndex, long x) throws SQLException { + checkOpen(); + + try { + stmt.setLong(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException { + checkOpen(); + + try { + stmt.setFloat(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + checkOpen(); + + try { + stmt.setDouble(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + checkOpen(); + + try { + stmt.setBigDecimal(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setString(int parameterIndex, String x) throws SQLException { + checkOpen(); + + try { + stmt.setString(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + checkOpen(); + + try { + stmt.setBytes(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException { + checkOpen(); + + try { + stmt.setDate(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + checkOpen(); + + try { + stmt.setTime(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + checkOpen(); + + try { + stmt.setTimestamp(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + checkOpen(); + + try { + stmt.setAsciiStream(parameterIndex, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + @Deprecated + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + checkOpen(); + + try { + stmt.setUnicodeStream(parameterIndex, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + checkOpen(); + + try { + stmt.setBinaryStream(parameterIndex, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void clearParameters() throws SQLException { + checkOpen(); + + try { + stmt.clearParameters(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + checkOpen(); + + try { + stmt.setObject(parameterIndex, x, targetSqlType); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + checkOpen(); + + try { + stmt.setObject(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public boolean execute() throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + // oracleSetRowPrefetch(); + + conn.beforeExecute(); + try { + return stmt.execute(); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + protected void oracleSetRowPrefetch() throws SQLException { + if (!conn.isOracle()) { + return; + } + + if (holder.getHitCount() == 0) { + return; + } + + int fetchRowPeak = holder.getFetchRowPeak(); + + if (fetchRowPeak < 0) { + return; + } + + if (holder.getDefaultRowPretch() == -1) { + int defaultRowPretch = OracleUtils.getRowPrefetch(this); + if (defaultRowPretch != holder.getDefaultRowPretch()) { + holder.setDefaultRowPretch(defaultRowPretch); + holder.setRowPrefetch(defaultRowPretch); + } + } + + int rowPrefetch; + + if (fetchRowPeak <= 1) { + rowPrefetch = 2; + } else if (fetchRowPeak > holder.getDefaultRowPretch()) { + rowPrefetch = holder.getDefaultRowPretch(); + } else { + rowPrefetch = fetchRowPeak + 1; + } + + if (rowPrefetch != holder.getRowPrefetch()) { + OracleUtils.setRowPrefetch(this, rowPrefetch); + holder.setRowPrefetch(rowPrefetch); + } + } + + @Override + public void addBatch() throws SQLException { + checkOpen(); + + try { + stmt.addBatch(); + } catch (Throwable t) { + throw checkException(t); + } + } + + public int[] executeBatch() throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeBatch(); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + checkOpen(); + + try { + stmt.setCharacterStream(parameterIndex, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + checkOpen(); + + try { + stmt.setRef(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException { + checkOpen(); + + try { + stmt.setBlob(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException { + checkOpen(); + + try { + stmt.setClob(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + checkOpen(); + + try { + stmt.setArray(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + checkOpen(); + + try { + return stmt.getMetaData(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + checkOpen(); + + try { + stmt.setDate(parameterIndex, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + checkOpen(); + + try { + stmt.setTime(parameterIndex, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + checkOpen(); + + try { + stmt.setTimestamp(parameterIndex, x, cal); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + checkOpen(); + + try { + stmt.setNull(parameterIndex, sqlType, typeName); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + checkOpen(); + + try { + stmt.setURL(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + checkOpen(); + + try { + return stmt.getParameterMetaData(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + checkOpen(); + + try { + stmt.setRowId(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNString(int parameterIndex, String value) throws SQLException { + checkOpen(); + + try { + stmt.setNString(parameterIndex, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + checkOpen(); + + try { + stmt.setNCharacterStream(parameterIndex, value, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(int parameterIndex, NClob value) throws SQLException { + checkOpen(); + + try { + stmt.setNClob(parameterIndex, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + checkOpen(); + + try { + stmt.setClob(parameterIndex, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + checkOpen(); + + try { + stmt.setBlob(parameterIndex, inputStream, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + checkOpen(); + + try { + stmt.setNClob(parameterIndex, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + checkOpen(); + + try { + stmt.setSQLXML(parameterIndex, xmlObject); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + checkOpen(); + + try { + stmt.setObject(parameterIndex, x, targetSqlType, scaleOrLength); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + checkOpen(); + + try { + stmt.setAsciiStream(parameterIndex, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + checkOpen(); + + try { + stmt.setBinaryStream(parameterIndex, x, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + checkOpen(); + + try { + stmt.setCharacterStream(parameterIndex, reader, length); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + checkOpen(); + + try { + stmt.setAsciiStream(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + checkOpen(); + + try { + stmt.setBinaryStream(parameterIndex, x); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { + checkOpen(); + + try { + stmt.setCharacterStream(parameterIndex, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { + checkOpen(); + + try { + stmt.setNCharacterStream(parameterIndex, value); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setClob(int parameterIndex, Reader reader) throws SQLException { + checkOpen(); + + try { + stmt.setClob(parameterIndex, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { + checkOpen(); + + try { + stmt.setBlob(parameterIndex, inputStream); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + checkOpen(); + + try { + stmt.setNClob(parameterIndex, reader); + } catch (Throwable t) { + throw checkException(t); + } + } + + public static class PreparedStatementKey { + + private final String sql; + private final String catalog; + + protected final MethodType methodType; + + private final int resultSetType; + private final int resultSetConcurrency; + private final int resultSetHoldability; + private final int autoGeneratedKeys; + private final int[] columnIndexes; + private final String[] columnNames; + + public PreparedStatementKey(String sql, String catalog, MethodType methodType) throws SQLException{ + this(sql, catalog, methodType, 0, 0, 0, 0, null, null); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, + int resultSetConcurrency) throws SQLException{ + this(sql, catalog, methodType, resultSetType, resultSetConcurrency, 0, 0, null, null); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, + int resultSetConcurrency, int resultSetHoldability) throws SQLException{ + this(sql, catalog, methodType, resultSetType, resultSetConcurrency, resultSetHoldability, 0, null, null); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, int autoGeneratedKeys) + throws SQLException{ + this(sql, catalog, methodType, 0, 0, 0, autoGeneratedKeys, null, null); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, int[] columnIndexes) + throws SQLException{ + this(sql, catalog, methodType, 0, 0, 0, 0, columnIndexes, null); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, String[] columnNames) + throws SQLException{ + this(sql, catalog, methodType, 0, 0, 0, 0, null, columnNames); + } + + public PreparedStatementKey(String sql, String catalog, MethodType methodType, int resultSetType, + int resultSetConcurrency, int resultSetHoldability, int autoGeneratedKeys, + int[] columnIndexes, String[] columnNames) throws SQLException{ + if (sql == null) { + throw new SQLException("sql is null"); + } + + this.sql = sql; + this.catalog = catalog; + this.methodType = methodType; + this.resultSetType = resultSetType; + this.resultSetConcurrency = resultSetConcurrency; + this.resultSetHoldability = resultSetHoldability; + this.autoGeneratedKeys = autoGeneratedKeys; + this.columnIndexes = columnIndexes; + this.columnNames = columnNames; + } + + public int getResultSetType() { + return resultSetType; + } + + public int getResultSetConcurrency() { + return resultSetConcurrency; + } + + public int getResultSetHoldability() { + return resultSetHoldability; + } + + public boolean equals(Object object) { + PreparedStatementKey that = (PreparedStatementKey) object; + + if (!this.sql.equals(that.sql)) { + return false; + } + + if (this.catalog == null) { + if (that.catalog != null) { + return false; + } + } else { + if (!this.catalog.equals(that.catalog)) { + return false; + } + } + + if (this.methodType != that.methodType) { + return false; + } + + if (this.resultSetType != that.resultSetType) { + return false; + } + + if (this.resultSetConcurrency != that.resultSetConcurrency) { + return false; + } + + if (this.resultSetHoldability != that.resultSetHoldability) { + return false; + } + + if (this.autoGeneratedKeys != that.autoGeneratedKeys) { + return false; + } + + if (!Arrays.equals(columnIndexes, that.columnIndexes)) { + return false; + } + + if (!Arrays.equals(columnNames, that.columnNames)) { + return false; + } + + return true; + } + + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + ((sql == null) ? 0 : sql.hashCode()); + result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + result = prime * result + ((methodType == null) ? 0 : methodType.hashCode()); + + result = prime * result + resultSetConcurrency; + result = prime * result + resultSetHoldability; + result = prime * result + resultSetType; + + result = prime * result + autoGeneratedKeys; + + result = prime * result + Arrays.hashCode(columnIndexes); + result = prime * result + Arrays.hashCode(columnNames); + + return result; + } + + public String getSql() { + return sql; + } + + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + if (iface == PreparedStatementHolder.class) { + return true; + } + + return super.isWrapperFor(iface); + } + + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface == PreparedStatementHolder.class) { + return (T) holder; + } + return super.unwrap(iface); + } +} diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java index 4085f821f7..7b13e79296 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledStatement.java @@ -1,641 +1,652 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.pool; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.druid.support.logging.Log; -import com.alibaba.druid.support.logging.LogFactory; - -/** - * @author wenshao - */ -public class DruidPooledStatement extends PoolableWrapper implements Statement { - - private final static Log LOG = LogFactory.getLog(DruidPooledStatement.class); - - private final Statement stmt; - protected DruidPooledConnection conn; - protected final List resultSetTrace = new ArrayList(); - protected boolean closed = false; - protected int fetchRowPeak = -1; - - public DruidPooledStatement(DruidPooledConnection conn, Statement stmt){ - super(stmt); - - this.conn = conn; - this.stmt = stmt; - } - - protected void recordFetchRowCount(int fetchRowCount) { - if (fetchRowPeak < fetchRowCount) { - fetchRowPeak = fetchRowCount; - } - } - - public int getFetchRowPeak() { - return fetchRowPeak; - } - - protected SQLException checkException(Throwable error) throws SQLException { - return conn.handleException(error); - } - - public DruidPooledConnection getPoolableConnection() { - return conn; - } - - public Statement getStatement() { - return stmt; - } - - protected void checkOpen() throws SQLException { - if (closed) { - Throwable disableError = null; - if (this.conn != null) { - disableError = this.conn.getDisableError(); - } - - if (disableError != null) { - throw new SQLException("statement is closed", disableError); - } else { - throw new SQLException("statement is closed"); - } - } - } - - protected void clearResultSet() { - for (ResultSet rs : resultSetTrace) { - try { - if (!rs.isClosed()) { - rs.close(); - } - } catch (SQLException ex) { - LOG.error("clearResultSet error", ex); - } - } - resultSetTrace.clear(); - } - - public void incrementExecuteCount() { - DruidPooledConnection conn = this.getPoolableConnection(); - - if (conn == null) { - return; - } - - DruidConnectionHolder holder = conn.getConnectionHolder(); - if (holder == null) { - return; - } - - if (holder.getDataSource() == null) { - return; - } - - holder.getDataSource().incrementExecuteCount(); - } - - protected void transactionRecord(String sql) throws SQLException { - conn.transactionRecord(sql); - } - - @Override - public final ResultSet executeQuery(String sql) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - ResultSet rs = stmt.executeQuery(sql); - - if (rs == null) { - return rs; - } - - DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); - resultSetTrace.add(poolableResultSet); - - return poolableResultSet; - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final int executeUpdate(String sql) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeUpdate(sql); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeUpdate(sql, autoGeneratedKeys); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final int executeUpdate(String sql, int columnIndexes[]) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeUpdate(sql, columnIndexes); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final int executeUpdate(String sql, String columnNames[]) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.executeUpdate(sql, columnNames); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.execute(sql, autoGeneratedKeys); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final boolean execute(String sql, int columnIndexes[]) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.execute(sql, columnIndexes); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final boolean execute(String sql, String columnNames[]) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - conn.beforeExecute(); - try { - return stmt.execute(sql, columnNames); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public int getMaxFieldSize() throws SQLException { - checkOpen(); - - try { - return stmt.getMaxFieldSize(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void close() throws SQLException { - if (!this.closed) { - clearResultSet(); - stmt.close(); - this.closed = true; - - if (conn.getConnectionHolder() != null) { - conn.getConnectionHolder().removeTrace(this); - } - } - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - checkOpen(); - - try { - stmt.setMaxFieldSize(max); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getMaxRows() throws SQLException { - checkOpen(); - - try { - return stmt.getMaxRows(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setMaxRows(int max) throws SQLException { - checkOpen(); - - try { - stmt.setMaxRows(max); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void setEscapeProcessing(boolean enable) throws SQLException { - checkOpen(); - - try { - stmt.setEscapeProcessing(enable); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getQueryTimeout() throws SQLException { - checkOpen(); - - try { - return stmt.getQueryTimeout(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - checkOpen(); - - try { - stmt.setQueryTimeout(seconds); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void cancel() throws SQLException { - checkOpen(); - - try { - stmt.cancel(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final SQLWarning getWarnings() throws SQLException { - checkOpen(); - - try { - return stmt.getWarnings(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void clearWarnings() throws SQLException { - checkOpen(); - - try { - stmt.clearWarnings(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void setCursorName(String name) throws SQLException { - checkOpen(); - - try { - stmt.setCursorName(name); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final boolean execute(String sql) throws SQLException { - checkOpen(); - - incrementExecuteCount(); - transactionRecord(sql); - - try { - return stmt.execute(sql); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final ResultSet getResultSet() throws SQLException { - checkOpen(); - - try { - ResultSet rs = stmt.getResultSet(); - if (rs == null) { - return null; - } - - DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); - resultSetTrace.add(poolableResultSet); - - return poolableResultSet; - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getUpdateCount() throws SQLException { - checkOpen(); - - try { - return stmt.getUpdateCount(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final boolean getMoreResults() throws SQLException { - checkOpen(); - - try { - return stmt.getMoreResults(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setFetchDirection(int direction) throws SQLException { - checkOpen(); - - try { - stmt.setFetchDirection(direction); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getFetchDirection() throws SQLException { - checkOpen(); - - try { - return stmt.getFetchDirection(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public void setFetchSize(int rows) throws SQLException { - checkOpen(); - - try { - stmt.setFetchSize(rows); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getFetchSize() throws SQLException { - checkOpen(); - - try { - return stmt.getFetchSize(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getResultSetConcurrency() throws SQLException { - checkOpen(); - - try { - return stmt.getResultSetConcurrency(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getResultSetType() throws SQLException { - checkOpen(); - - try { - return stmt.getResultSetType(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void addBatch(String sql) throws SQLException { - checkOpen(); - - transactionRecord(sql); - - try { - stmt.addBatch(sql); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final void clearBatch() throws SQLException { - if (closed) { - return; - } - - try { - stmt.clearBatch(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public int[] executeBatch() throws SQLException { - checkOpen(); - - incrementExecuteCount(); - - conn.beforeExecute(); - try { - return stmt.executeBatch(); - } catch (Throwable t) { - throw checkException(t); - } finally { - conn.afterExecute(); - } - } - - @Override - public final Connection getConnection() throws SQLException { - checkOpen(); - - return conn; - } - - @Override - public final boolean getMoreResults(int current) throws SQLException { - checkOpen(); - - try { - return stmt.getMoreResults(current); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final ResultSet getGeneratedKeys() throws SQLException { - checkOpen(); - - try { - ResultSet rs = stmt.getGeneratedKeys(); - - DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); - - resultSetTrace.add(poolableResultSet); - - return poolableResultSet; - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final int getResultSetHoldability() throws SQLException { - checkOpen(); - - try { - return stmt.getResultSetHoldability(); - } catch (Throwable t) { - throw checkException(t); - } - } - - @Override - public final boolean isClosed() throws SQLException { - return closed; - } - - @Override - public final void setPoolable(boolean poolable) throws SQLException { - if (poolable) { - return; - } - - throw new SQLException("not support"); - } - - @Override - public final boolean isPoolable() throws SQLException { - return false; - } - - public String toString() { - return stmt.toString(); - } - - public void closeOnCompletion() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public boolean isCloseOnCompletion() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.pool; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; + +/** + * @author wenshao + */ +public class DruidPooledStatement extends PoolableWrapper implements Statement { + + private final static Log LOG = LogFactory.getLog(DruidPooledStatement.class); + + private final Statement stmt; + protected DruidPooledConnection conn; + protected List resultSetTrace; + protected boolean closed = false; + protected int fetchRowPeak = -1; + + public DruidPooledStatement(DruidPooledConnection conn, Statement stmt){ + super(stmt); + + this.conn = conn; + this.stmt = stmt; + } + + protected void addResultSetTrace(ResultSet resultSet) { + if (resultSetTrace == null) { + resultSetTrace = new ArrayList(1); + } + resultSetTrace.add(resultSet); + } + + protected void recordFetchRowCount(int fetchRowCount) { + if (fetchRowPeak < fetchRowCount) { + fetchRowPeak = fetchRowCount; + } + } + + public int getFetchRowPeak() { + return fetchRowPeak; + } + + protected SQLException checkException(Throwable error) throws SQLException { + return conn.handleException(error); + } + + public DruidPooledConnection getPoolableConnection() { + return conn; + } + + public Statement getStatement() { + return stmt; + } + + protected void checkOpen() throws SQLException { + if (closed) { + Throwable disableError = null; + if (this.conn != null) { + disableError = this.conn.getDisableError(); + } + + if (disableError != null) { + throw new SQLException("statement is closed", disableError); + } else { + throw new SQLException("statement is closed"); + } + } + } + + protected void clearResultSet() { + if (resultSetTrace == null) { + return; + } + + for (ResultSet rs : resultSetTrace) { + try { + if (!rs.isClosed()) { + rs.close(); + } + } catch (SQLException ex) { + LOG.error("clearResultSet error", ex); + } + } + resultSetTrace.clear(); + } + + public void incrementExecuteCount() { + DruidPooledConnection conn = this.getPoolableConnection(); + + if (conn == null) { + return; + } + + DruidConnectionHolder holder = conn.getConnectionHolder(); + if (holder == null) { + return; + } + + if (holder.getDataSource() == null) { + return; + } + + holder.getDataSource().incrementExecuteCount(); + } + + protected void transactionRecord(String sql) throws SQLException { + conn.transactionRecord(sql); + } + + @Override + public final ResultSet executeQuery(String sql) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + ResultSet rs = stmt.executeQuery(sql); + + if (rs == null) { + return rs; + } + + DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); + addResultSetTrace(poolableResultSet); + + return poolableResultSet; + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final int executeUpdate(String sql) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeUpdate(sql); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeUpdate(sql, autoGeneratedKeys); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final int executeUpdate(String sql, int columnIndexes[]) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeUpdate(sql, columnIndexes); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final int executeUpdate(String sql, String columnNames[]) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.executeUpdate(sql, columnNames); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.execute(sql, autoGeneratedKeys); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final boolean execute(String sql, int columnIndexes[]) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.execute(sql, columnIndexes); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final boolean execute(String sql, String columnNames[]) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + conn.beforeExecute(); + try { + return stmt.execute(sql, columnNames); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public int getMaxFieldSize() throws SQLException { + checkOpen(); + + try { + return stmt.getMaxFieldSize(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void close() throws SQLException { + if (!this.closed) { + clearResultSet(); + stmt.close(); + this.closed = true; + + if (conn.getConnectionHolder() != null) { + conn.getConnectionHolder().removeTrace(this); + } + } + } + + @Override + public void setMaxFieldSize(int max) throws SQLException { + checkOpen(); + + try { + stmt.setMaxFieldSize(max); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getMaxRows() throws SQLException { + checkOpen(); + + try { + return stmt.getMaxRows(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setMaxRows(int max) throws SQLException { + checkOpen(); + + try { + stmt.setMaxRows(max); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void setEscapeProcessing(boolean enable) throws SQLException { + checkOpen(); + + try { + stmt.setEscapeProcessing(enable); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getQueryTimeout() throws SQLException { + checkOpen(); + + try { + return stmt.getQueryTimeout(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException { + checkOpen(); + + try { + stmt.setQueryTimeout(seconds); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void cancel() throws SQLException { + checkOpen(); + + try { + stmt.cancel(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final SQLWarning getWarnings() throws SQLException { + checkOpen(); + + try { + return stmt.getWarnings(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void clearWarnings() throws SQLException { + checkOpen(); + + try { + stmt.clearWarnings(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void setCursorName(String name) throws SQLException { + checkOpen(); + + try { + stmt.setCursorName(name); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final boolean execute(String sql) throws SQLException { + checkOpen(); + + incrementExecuteCount(); + transactionRecord(sql); + + try { + return stmt.execute(sql); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final ResultSet getResultSet() throws SQLException { + checkOpen(); + + try { + ResultSet rs = stmt.getResultSet(); + if (rs == null) { + return null; + } + + DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); + addResultSetTrace(poolableResultSet); + + return poolableResultSet; + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getUpdateCount() throws SQLException { + checkOpen(); + + try { + return stmt.getUpdateCount(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final boolean getMoreResults() throws SQLException { + checkOpen(); + + try { + return stmt.getMoreResults(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + checkOpen(); + + try { + stmt.setFetchDirection(direction); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getFetchDirection() throws SQLException { + checkOpen(); + + try { + return stmt.getFetchDirection(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public void setFetchSize(int rows) throws SQLException { + checkOpen(); + + try { + stmt.setFetchSize(rows); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getFetchSize() throws SQLException { + checkOpen(); + + try { + return stmt.getFetchSize(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getResultSetConcurrency() throws SQLException { + checkOpen(); + + try { + return stmt.getResultSetConcurrency(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getResultSetType() throws SQLException { + checkOpen(); + + try { + return stmt.getResultSetType(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void addBatch(String sql) throws SQLException { + checkOpen(); + + transactionRecord(sql); + + try { + stmt.addBatch(sql); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final void clearBatch() throws SQLException { + if (closed) { + return; + } + + try { + stmt.clearBatch(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public int[] executeBatch() throws SQLException { + checkOpen(); + + incrementExecuteCount(); + + conn.beforeExecute(); + try { + return stmt.executeBatch(); + } catch (Throwable t) { + throw checkException(t); + } finally { + conn.afterExecute(); + } + } + + @Override + public final Connection getConnection() throws SQLException { + checkOpen(); + + return conn; + } + + @Override + public final boolean getMoreResults(int current) throws SQLException { + checkOpen(); + + try { + return stmt.getMoreResults(current); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final ResultSet getGeneratedKeys() throws SQLException { + checkOpen(); + + try { + ResultSet rs = stmt.getGeneratedKeys(); + + DruidPooledResultSet poolableResultSet = new DruidPooledResultSet(this, rs); + + addResultSetTrace(poolableResultSet); + + return poolableResultSet; + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final int getResultSetHoldability() throws SQLException { + checkOpen(); + + try { + return stmt.getResultSetHoldability(); + } catch (Throwable t) { + throw checkException(t); + } + } + + @Override + public final boolean isClosed() throws SQLException { + return closed; + } + + @Override + public final void setPoolable(boolean poolable) throws SQLException { + if (poolable) { + return; + } + + throw new SQLException("not support"); + } + + @Override + public final boolean isPoolable() throws SQLException { + return false; + } + + public String toString() { + return stmt.toString(); + } + + public void closeOnCompletion() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public boolean isCloseOnCompletion() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/DruidDriver.java b/src/main/java/com/alibaba/druid/proxy/DruidDriver.java index b2a77cb9e9..3472728d46 100644 --- a/src/main/java/com/alibaba/druid/proxy/DruidDriver.java +++ b/src/main/java/com/alibaba/druid/proxy/DruidDriver.java @@ -53,7 +53,7 @@ public class DruidDriver implements Driver, DruidDriverMBean { private final static DruidDriver instance = new DruidDriver(); - private final static ConcurrentMap proxyDataSources = new ConcurrentHashMap(); + private final static ConcurrentMap proxyDataSources = new ConcurrentHashMap(16, 0.75f, 1); private final static AtomicInteger dataSourceIdSeed = new AtomicInteger(0); private final static AtomicInteger sqlStatIdSeed = new AtomicInteger(0); diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/ConnectionProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/ConnectionProxyImpl.java index 23598fe3a2..43176dec5e 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/ConnectionProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/ConnectionProxyImpl.java @@ -1,537 +1,537 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.NClob; -import java.sql.PreparedStatement; -import java.sql.SQLClientInfoException; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; -import java.sql.SQLXML; -import java.sql.Savepoint; -import java.sql.Statement; -import java.sql.Struct; -import java.util.Date; -import java.util.Map; -import java.util.Properties; -import java.util.concurrent.Executor; - -import com.alibaba.druid.filter.FilterChainImpl; -import com.alibaba.druid.filter.stat.StatFilter; - -/** - * @author wenshao - */ -public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionProxy { - - private final Connection connection; - - private final DataSourceProxy dataSource; - - private final Properties properties; - - private final long connectedTime; - - private TransactionInfo transcationInfo; - - private int closeCount; - - private FilterChainImpl filterChain = null; - - public ConnectionProxyImpl(DataSourceProxy dataSource, Connection connection, Properties properties, long id){ - super(connection, id); - this.dataSource = dataSource; - this.connection = connection; - this.properties = properties; - this.connectedTime = System.currentTimeMillis(); - } - - public Date getConnectedTime() { - return new Date(connectedTime); - } - - public Properties getProperties() { - return properties; - } - - public Connection getConnectionRaw() { - return connection; - } - - public Connection getRawObject() { - return connection; - } - - public DataSourceProxy getDirectDataSource() { - return this.dataSource; - } - - public FilterChainImpl createChain() { - FilterChainImpl chain = this.filterChain; - if (chain == null) { - chain = new FilterChainImpl(dataSource); - } else { - this.filterChain = null; - } - - return chain; - } - - public void recycleFilterChain(FilterChainImpl chain) { - chain.reset(); - this.filterChain = chain; - } - - @Override - public void clearWarnings() throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_clearWarnings(this); - recycleFilterChain(chain); - } - - @Override - public void close() throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_close(this); - closeCount++; - recycleFilterChain(chain); - } - - @Override - public void commit() throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_commit(this); - - if (transcationInfo != null) { - transcationInfo.setEndTimeMillis(); - } - recycleFilterChain(chain); - } - - @Override - public Array createArrayOf(String typeName, Object[] elements) throws SQLException { - FilterChainImpl chain = createChain(); - Array value = chain.connection_createArrayOf(this, typeName, elements); - recycleFilterChain(chain); - return value; - } - - @Override - public Blob createBlob() throws SQLException { - FilterChainImpl chain = createChain(); - Blob value = chain.connection_createBlob(this); - recycleFilterChain(chain); - return value; - } - - @Override - public Clob createClob() throws SQLException { - FilterChainImpl chain = createChain(); - Clob value = chain.connection_createClob(this); - recycleFilterChain(chain); - return value; - } - - @Override - public NClob createNClob() throws SQLException { - FilterChainImpl chain = createChain(); - NClob value = chain.connection_createNClob(this); - recycleFilterChain(chain); - return value; - } - - @Override - public SQLXML createSQLXML() throws SQLException { - FilterChainImpl chain = createChain(); - SQLXML value = chain.connection_createSQLXML(this); - recycleFilterChain(chain); - return value; - } - - @Override - public Statement createStatement() throws SQLException { - FilterChainImpl chain = createChain(); - Statement stmt = chain.connection_createStatement(this); - recycleFilterChain(chain); - return stmt; - } - - @Override - public Statement createStatement(int resultSetType, // - int resultSetConcurrency // - ) throws SQLException { - FilterChainImpl chain = createChain(); - Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency); - recycleFilterChain(chain); - return stmt; - } - - @Override - public Statement createStatement(int resultSetType, // - int resultSetConcurrency, // - int resultSetHoldability // - ) throws SQLException { - FilterChainImpl chain = createChain(); - Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency, - resultSetHoldability); - recycleFilterChain(chain); - return stmt; - } - - @Override - public Struct createStruct(String typeName, Object[] attributes) throws SQLException { - FilterChainImpl chain = createChain(); - Struct value = chain.connection_createStruct(this, typeName, attributes); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean getAutoCommit() throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.connection_getAutoCommit(this); - recycleFilterChain(chain); - return value; - } - - @Override - public String getCatalog() throws SQLException { - FilterChainImpl chain = createChain(); - String value = chain.connection_getCatalog(this); - recycleFilterChain(chain); - return value; - } - - @Override - public Properties getClientInfo() throws SQLException { - FilterChainImpl chain = createChain(); - Properties value = chain.connection_getClientInfo(this); - recycleFilterChain(chain); - return value; - } - - @Override - public String getClientInfo(String name) throws SQLException { - FilterChainImpl chain = createChain(); - String value = chain.connection_getClientInfo(this, name); - recycleFilterChain(chain); - return value; - } - - @Override - public int getHoldability() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.connection_getHoldability(this); - recycleFilterChain(chain); - return value; - } - - @Override - public DatabaseMetaData getMetaData() throws SQLException { - FilterChainImpl chain = createChain(); - DatabaseMetaData value = chain.connection_getMetaData(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getTransactionIsolation() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.connection_getTransactionIsolation(this); - recycleFilterChain(chain); - return value; - } - - @Override - public Map> getTypeMap() throws SQLException { - FilterChainImpl chain = createChain(); - Map> value = chain.connection_getTypeMap(this); - recycleFilterChain(chain); - return value; - } - - @Override - public SQLWarning getWarnings() throws SQLException { - FilterChainImpl chain = createChain(); - SQLWarning value = chain.connection_getWarnings(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean isClosed() throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.connection_isClosed(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean isReadOnly() throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.connection_isReadOnly(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean isValid(int timeout) throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.connection_isValid(this, timeout); - recycleFilterChain(chain); - return value; - } - - @Override - public String nativeSQL(String sql) throws SQLException { - FilterChainImpl chain = createChain(); - String value = chain.connection_nativeSQL(this, sql); - recycleFilterChain(chain); - return value; - } - - @Override - public CallableStatement prepareCall(String sql) throws SQLException { - FilterChainImpl chain = createChain(); - CallableStatement stmt = chain.connection_prepareCall(this, sql); - recycleFilterChain(chain); - return stmt; - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { - FilterChainImpl chain = createChain(); - CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency); - recycleFilterChain(chain); - return stmt; - } - - @Override - public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - FilterChainImpl chain = createChain(); - CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency, - resultSetHoldability); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql) throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql, autoGeneratedKeys); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnIndexes); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnNames); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency); - recycleFilterChain(chain); - return stmt; - } - - @Override - public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - FilterChainImpl chain = createChain(); - PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency, - resultSetHoldability); - recycleFilterChain(chain); - return stmt; - } - - @Override - public void releaseSavepoint(Savepoint savepoint) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_releaseSavepoint(this, savepoint); - recycleFilterChain(chain); - } - - @Override - public void rollback() throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_rollback(this); - recycleFilterChain(chain); - if (transcationInfo != null) { - transcationInfo.setEndTimeMillis(); - } - } - - @Override - public void rollback(Savepoint savepoint) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_rollback(this, savepoint); - recycleFilterChain(chain); - if (transcationInfo != null) { - transcationInfo.setEndTimeMillis(); - } - } - - @Override - public void setAutoCommit(boolean autoCommit) throws SQLException { - if (!autoCommit) { - if (transcationInfo == null) { - long transactionId = this.dataSource.createTransactionId(); - transcationInfo = new TransactionInfo(transactionId); - this.getAttributes().put(StatFilter.ATTR_TRANSACTION, transcationInfo); // compatible for druid 0.1.18 - } - } else { - transcationInfo = null; - } - - FilterChainImpl chain = createChain(); - chain.connection_setAutoCommit(this, autoCommit); - recycleFilterChain(chain); - } - - @Override - public void setCatalog(String catalog) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_setCatalog(this, catalog); - recycleFilterChain(chain); - } - - @Override - public void setClientInfo(Properties properties) throws SQLClientInfoException { - FilterChainImpl chain = createChain(); - chain.connection_setClientInfo(this, properties); - recycleFilterChain(chain); - } - - @Override - public void setClientInfo(String name, String value) throws SQLClientInfoException { - FilterChainImpl chain = createChain(); - chain.connection_setClientInfo(this, name, value); - recycleFilterChain(chain); - } - - @Override - public void setHoldability(int holdability) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_setHoldability(this, holdability); - recycleFilterChain(chain); - } - - @Override - public void setReadOnly(boolean readOnly) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_setReadOnly(this, readOnly); - recycleFilterChain(chain); - } - - @Override - public Savepoint setSavepoint() throws SQLException { - FilterChainImpl chain = createChain(); - Savepoint savepoint = chain.connection_setSavepoint(this); - recycleFilterChain(chain); - return savepoint; - } - - @Override - public Savepoint setSavepoint(String name) throws SQLException { - FilterChainImpl chain = createChain(); - Savepoint savepoint = chain.connection_setSavepoint(this, name); - recycleFilterChain(chain); - return savepoint; - } - - @Override - public void setTransactionIsolation(int level) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_setTransactionIsolation(this, level); - recycleFilterChain(chain); - } - - @Override - public void setTypeMap(Map> map) throws SQLException { - FilterChainImpl chain = createChain(); - chain.connection_setTypeMap(this, map); - recycleFilterChain(chain); - } - - public void setSchema(String schema) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public String getSchema() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public void abort(Executor executor) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public int getNetworkTimeout() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface == this.getClass() || iface == ConnectionProxy.class) { - return (T) this; - } - - return super.unwrap(iface); - } - - @Override - public TransactionInfo getTransactionInfo() { - return transcationInfo; - } - - @Override - public int getCloseCount() { - return closeCount; - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.NClob; +import java.sql.PreparedStatement; +import java.sql.SQLClientInfoException; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.SQLXML; +import java.sql.Savepoint; +import java.sql.Statement; +import java.sql.Struct; +import java.util.Date; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +import com.alibaba.druid.filter.FilterChainImpl; +import com.alibaba.druid.filter.stat.StatFilter; + +/** + * @author wenshao + */ +public class ConnectionProxyImpl extends WrapperProxyImpl implements ConnectionProxy { + + private final Connection connection; + + private final DataSourceProxy dataSource; + + private final Properties properties; + + private final long connectedTime; + + private TransactionInfo transcationInfo; + + private int closeCount; + + private FilterChainImpl filterChain = null; + + public ConnectionProxyImpl(DataSourceProxy dataSource, Connection connection, Properties properties, long id){ + super(connection, id); + this.dataSource = dataSource; + this.connection = connection; + this.properties = properties; + this.connectedTime = System.currentTimeMillis(); + } + + public Date getConnectedTime() { + return new Date(connectedTime); + } + + public Properties getProperties() { + return properties; + } + + public Connection getConnectionRaw() { + return connection; + } + + public Connection getRawObject() { + return connection; + } + + public DataSourceProxy getDirectDataSource() { + return this.dataSource; + } + + public FilterChainImpl createChain() { + FilterChainImpl chain = this.filterChain; + if (chain == null) { + chain = new FilterChainImpl(dataSource); + } else { + this.filterChain = null; + } + + return chain; + } + + public void recycleFilterChain(FilterChainImpl chain) { + chain.reset(); + this.filterChain = chain; + } + + @Override + public void clearWarnings() throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_clearWarnings(this); + recycleFilterChain(chain); + } + + @Override + public void close() throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_close(this); + closeCount++; + recycleFilterChain(chain); + } + + @Override + public void commit() throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_commit(this); + + if (transcationInfo != null) { + transcationInfo.setEndTimeMillis(); + } + recycleFilterChain(chain); + } + + @Override + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + FilterChainImpl chain = createChain(); + Array value = chain.connection_createArrayOf(this, typeName, elements); + recycleFilterChain(chain); + return value; + } + + @Override + public Blob createBlob() throws SQLException { + FilterChainImpl chain = createChain(); + Blob value = chain.connection_createBlob(this); + recycleFilterChain(chain); + return value; + } + + @Override + public Clob createClob() throws SQLException { + FilterChainImpl chain = createChain(); + Clob value = chain.connection_createClob(this); + recycleFilterChain(chain); + return value; + } + + @Override + public NClob createNClob() throws SQLException { + FilterChainImpl chain = createChain(); + NClob value = chain.connection_createNClob(this); + recycleFilterChain(chain); + return value; + } + + @Override + public SQLXML createSQLXML() throws SQLException { + FilterChainImpl chain = createChain(); + SQLXML value = chain.connection_createSQLXML(this); + recycleFilterChain(chain); + return value; + } + + @Override + public Statement createStatement() throws SQLException { + FilterChainImpl chain = createChain(); + Statement stmt = chain.connection_createStatement(this); + recycleFilterChain(chain); + return stmt; + } + + @Override + public Statement createStatement(int resultSetType, // + int resultSetConcurrency // + ) throws SQLException { + FilterChainImpl chain = createChain(); + Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency); + recycleFilterChain(chain); + return stmt; + } + + @Override + public Statement createStatement(int resultSetType, // + int resultSetConcurrency, // + int resultSetHoldability // + ) throws SQLException { + FilterChainImpl chain = createChain(); + Statement stmt = chain.connection_createStatement(this, resultSetType, resultSetConcurrency, + resultSetHoldability); + recycleFilterChain(chain); + return stmt; + } + + @Override + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { + FilterChainImpl chain = createChain(); + Struct value = chain.connection_createStruct(this, typeName, attributes); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean getAutoCommit() throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.connection_getAutoCommit(this); + recycleFilterChain(chain); + return value; + } + + @Override + public String getCatalog() throws SQLException { + FilterChainImpl chain = createChain(); + String value = chain.connection_getCatalog(this); + recycleFilterChain(chain); + return value; + } + + @Override + public Properties getClientInfo() throws SQLException { + FilterChainImpl chain = createChain(); + Properties value = chain.connection_getClientInfo(this); + recycleFilterChain(chain); + return value; + } + + @Override + public String getClientInfo(String name) throws SQLException { + FilterChainImpl chain = createChain(); + String value = chain.connection_getClientInfo(this, name); + recycleFilterChain(chain); + return value; + } + + @Override + public int getHoldability() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.connection_getHoldability(this); + recycleFilterChain(chain); + return value; + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + FilterChainImpl chain = createChain(); + DatabaseMetaData value = chain.connection_getMetaData(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getTransactionIsolation() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.connection_getTransactionIsolation(this); + recycleFilterChain(chain); + return value; + } + + @Override + public Map> getTypeMap() throws SQLException { + FilterChainImpl chain = createChain(); + Map> value = chain.connection_getTypeMap(this); + recycleFilterChain(chain); + return value; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + FilterChainImpl chain = createChain(); + SQLWarning value = chain.connection_getWarnings(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean isClosed() throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.connection_isClosed(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean isReadOnly() throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.connection_isReadOnly(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean isValid(int timeout) throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.connection_isValid(this, timeout); + recycleFilterChain(chain); + return value; + } + + @Override + public String nativeSQL(String sql) throws SQLException { + FilterChainImpl chain = createChain(); + String value = chain.connection_nativeSQL(this, sql); + recycleFilterChain(chain); + return value; + } + + @Override + public CallableStatement prepareCall(String sql) throws SQLException { + FilterChainImpl chain = createChain(); + CallableStatement stmt = chain.connection_prepareCall(this, sql); + recycleFilterChain(chain); + return stmt; + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { + FilterChainImpl chain = createChain(); + CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency); + recycleFilterChain(chain); + return stmt; + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + FilterChainImpl chain = createChain(); + CallableStatement stmt = chain.connection_prepareCall(this, sql, resultSetType, resultSetConcurrency, + resultSetHoldability); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql) throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql, autoGeneratedKeys); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnIndexes); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql, columnNames); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency); + recycleFilterChain(chain); + return stmt; + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + FilterChainImpl chain = createChain(); + PreparedStatement stmt = chain.connection_prepareStatement(this, sql, resultSetType, resultSetConcurrency, + resultSetHoldability); + recycleFilterChain(chain); + return stmt; + } + + @Override + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_releaseSavepoint(this, savepoint); + recycleFilterChain(chain); + } + + @Override + public void rollback() throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_rollback(this); + recycleFilterChain(chain); + if (transcationInfo != null) { + transcationInfo.setEndTimeMillis(); + } + } + + @Override + public void rollback(Savepoint savepoint) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_rollback(this, savepoint); + recycleFilterChain(chain); + if (transcationInfo != null) { + transcationInfo.setEndTimeMillis(); + } + } + + @Override + public void setAutoCommit(boolean autoCommit) throws SQLException { + if (!autoCommit) { + if (transcationInfo == null) { + long transactionId = this.dataSource.createTransactionId(); + transcationInfo = new TransactionInfo(transactionId); + this.putAttribute(StatFilter.ATTR_TRANSACTION, transcationInfo); // compatible for druid 0.1.18 + } + } else { + transcationInfo = null; + } + + FilterChainImpl chain = createChain(); + chain.connection_setAutoCommit(this, autoCommit); + recycleFilterChain(chain); + } + + @Override + public void setCatalog(String catalog) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_setCatalog(this, catalog); + recycleFilterChain(chain); + } + + @Override + public void setClientInfo(Properties properties) throws SQLClientInfoException { + FilterChainImpl chain = createChain(); + chain.connection_setClientInfo(this, properties); + recycleFilterChain(chain); + } + + @Override + public void setClientInfo(String name, String value) throws SQLClientInfoException { + FilterChainImpl chain = createChain(); + chain.connection_setClientInfo(this, name, value); + recycleFilterChain(chain); + } + + @Override + public void setHoldability(int holdability) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_setHoldability(this, holdability); + recycleFilterChain(chain); + } + + @Override + public void setReadOnly(boolean readOnly) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_setReadOnly(this, readOnly); + recycleFilterChain(chain); + } + + @Override + public Savepoint setSavepoint() throws SQLException { + FilterChainImpl chain = createChain(); + Savepoint savepoint = chain.connection_setSavepoint(this); + recycleFilterChain(chain); + return savepoint; + } + + @Override + public Savepoint setSavepoint(String name) throws SQLException { + FilterChainImpl chain = createChain(); + Savepoint savepoint = chain.connection_setSavepoint(this, name); + recycleFilterChain(chain); + return savepoint; + } + + @Override + public void setTransactionIsolation(int level) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_setTransactionIsolation(this, level); + recycleFilterChain(chain); + } + + @Override + public void setTypeMap(Map> map) throws SQLException { + FilterChainImpl chain = createChain(); + chain.connection_setTypeMap(this, map); + recycleFilterChain(chain); + } + + public void setSchema(String schema) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public String getSchema() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public void abort(Executor executor) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public int getNetworkTimeout() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface == this.getClass() || iface == ConnectionProxy.class) { + return (T) this; + } + + return super.unwrap(iface); + } + + @Override + public TransactionInfo getTransactionInfo() { + return transcationInfo; + } + + @Override + public int getCloseCount() { + return closeCount; + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameter.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameter.java index 1a77f9556a..a5c7aa1887 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameter.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameter.java @@ -20,7 +20,7 @@ import java.util.Calendar; /** * @author wenshao */ -public class JdbcParameter { +public interface JdbcParameter { public static final int BinaryInputStream = 10001; public static final int AsciiInputStream = 10002; @@ -28,56 +28,6 @@ public class JdbcParameter { public static final int NCharacterInputStream = 10004; public static final int URL = 10005; - private final int sqlType; - private final Object value; - private final long length; - private final Calendar calendar; - private final int scaleOrLength; - - public JdbcParameter(int sqlType, Object value, long length, Calendar calendar, int scaleOrLength){ - this.sqlType = sqlType; - this.value = value; - this.length = length; - this.calendar = calendar; - this.scaleOrLength = scaleOrLength; - } - - public JdbcParameter(int sqlType, Object value, long length, Calendar calendar){ - this(sqlType, value, -1, null, -1); - } - - public JdbcParameter(int sqlType, Object value){ - this(sqlType, value, -1, null); - } - - public JdbcParameter(int sqlType, Object value, long length){ - this(sqlType, value, length, null); - } - - public JdbcParameter(int sqlType, Object value, Calendar calendar){ - this(sqlType, value, -1, calendar); - } - - public int getScaleOrLength() { - return scaleOrLength; - } - - public Object getValue() { - return value; - } - - public long getLength() { - return length; - } - - public Calendar getCalendar() { - return calendar; - } - - public int getSqlType() { - return sqlType; - } - public static interface TYPE { public static final int BinaryInputStream = 10001; @@ -89,4 +39,12 @@ public class JdbcParameter { public static final int BYTES = 10007; } + + Object getValue(); + + long getLength(); + + Calendar getCalendar(); + + int getSqlType(); } diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDate.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDate.java new file mode 100644 index 0000000000..b3c9f8868e --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDate.java @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Types; +import java.util.Calendar; +import java.util.Date; + +public final class JdbcParameterDate implements JdbcParameter { + private final Date value; + + public JdbcParameterDate(Date value){ + this.value = value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.DATE; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDecimal.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDecimal.java new file mode 100644 index 0000000000..c40eca044f --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterDecimal.java @@ -0,0 +1,70 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.math.BigDecimal; +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterDecimal implements JdbcParameter { + + private final BigDecimal value; + + public static JdbcParameterDecimal NULL = new JdbcParameterDecimal(null); + public static JdbcParameterDecimal ZERO = new JdbcParameterDecimal(BigDecimal.ZERO); + public static JdbcParameterDecimal TEN = new JdbcParameterDecimal(BigDecimal.TEN); + + private JdbcParameterDecimal(BigDecimal value){ + this.value = value; + } + + public static JdbcParameterDecimal valueOf(BigDecimal x) { + if (x == null) { + return NULL; + } + + if (x == BigDecimal.ZERO) { + return ZERO; + } + + if (x == BigDecimal.TEN) { + return TEN; + } + + return new JdbcParameterDecimal(x); + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.DECIMAL; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterImpl.java new file mode 100644 index 0000000000..6b81a9d58c --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.util.Calendar; + +public final class JdbcParameterImpl implements JdbcParameter { + + private final int sqlType; + private final Object value; + private final long length; + private final Calendar calendar; + private final int scaleOrLength; + + public JdbcParameterImpl(int sqlType, Object value, long length, Calendar calendar, int scaleOrLength){ + this.sqlType = sqlType; + this.value = value; + this.length = length; + this.calendar = calendar; + this.scaleOrLength = scaleOrLength; + } + + public JdbcParameterImpl(int sqlType, Object value, long length, Calendar calendar){ + this(sqlType, value, -1, null, -1); + } + + public JdbcParameterImpl(int sqlType, Object value){ + this(sqlType, value, -1, null); + } + + public JdbcParameterImpl(int sqlType, Object value, long length){ + this(sqlType, value, length, null); + } + + public JdbcParameterImpl(int sqlType, Object value, Calendar calendar){ + this(sqlType, value, -1, calendar); + } + + public int getScaleOrLength() { + return scaleOrLength; + } + + public Object getValue() { + return value; + } + + public long getLength() { + return length; + } + + public Calendar getCalendar() { + return calendar; + } + + public int getSqlType() { + return sqlType; + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterInt.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterInt.java new file mode 100644 index 0000000000..9ec8a47f29 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterInt.java @@ -0,0 +1,67 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterInt implements JdbcParameter { + + private static JdbcParameterInt[] cache; + + static { + int cacheSize = 127; + cache = new JdbcParameterInt[cacheSize]; + for (int i = 0; i < cache.length; ++i) { + cache[i] = new JdbcParameterInt(i); + } + } + + private final int value; + + private JdbcParameterInt(int value){ + this.value = value; + } + + public static JdbcParameterInt valueOf(int value) { + if (value >= 0 && value < cache.length) { + return cache[value]; + } + + return new JdbcParameterInt(value); + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.INTEGER; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterLong.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterLong.java new file mode 100644 index 0000000000..a51e1cea04 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterLong.java @@ -0,0 +1,66 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterLong implements JdbcParameter { + private static JdbcParameterLong[] cache; + + static { + int cacheSize = 127; + cache = new JdbcParameterLong[cacheSize]; + for (int i = 0; i < cache.length; ++i) { + cache[i] = new JdbcParameterLong(i); + } + } + + private final long value; + + private JdbcParameterLong(long value){ + this.value = value; + } + + public static JdbcParameterLong valueOf(long value) { + if (value >= 0 && value < cache.length) { + return cache[(int) value]; + } + + return new JdbcParameterLong(value); + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.BIGINT; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterNull.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterNull.java new file mode 100644 index 0000000000..6c01a7ecb0 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterNull.java @@ -0,0 +1,118 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterNull implements JdbcParameter { + + private final int sqlType; + + public final static JdbcParameterNull CHAR = new JdbcParameterNull(Types.CHAR); + public final static JdbcParameterNull VARCHAR = new JdbcParameterNull(Types.VARCHAR); + public final static JdbcParameterNull NVARCHAR = new JdbcParameterNull(Types.NVARCHAR); + + public final static JdbcParameterNull BINARY = new JdbcParameterNull(Types.BINARY); + public final static JdbcParameterNull VARBINARY = new JdbcParameterNull(Types.VARBINARY); + + public final static JdbcParameterNull TINYINT = new JdbcParameterNull(Types.TINYINT); + public final static JdbcParameterNull SMALLINT = new JdbcParameterNull(Types.SMALLINT); + public final static JdbcParameterNull INTEGER = new JdbcParameterNull(Types.INTEGER); + public final static JdbcParameterNull BIGINT = new JdbcParameterNull(Types.BIGINT); + + public final static JdbcParameterNull DECIMAL = new JdbcParameterNull(Types.DECIMAL); + public final static JdbcParameterNull NUMERIC = new JdbcParameterNull(Types.NUMERIC); + public final static JdbcParameterNull FLOAT = new JdbcParameterNull(Types.FLOAT); + public final static JdbcParameterNull DOUBLE = new JdbcParameterNull(Types.DOUBLE); + + public final static JdbcParameterNull NULL = new JdbcParameterNull(Types.NULL); + + public final static JdbcParameterNull DATE = new JdbcParameterNull(Types.DATE); + public final static JdbcParameterNull TIME = new JdbcParameterNull(Types.TIME); + public final static JdbcParameterNull TIMESTAMP = new JdbcParameterNull(Types.TIMESTAMP); + + private JdbcParameterNull(int sqlType){ + this.sqlType = sqlType; + } + + @Override + public Object getValue() { + return null; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return sqlType; + } + + public static JdbcParameterNull valueOf(int sqlType) { + switch (sqlType) { + case Types.TINYINT: + return INTEGER; + case Types.SMALLINT: + return SMALLINT; + case Types.INTEGER: + return INTEGER; + case Types.BIGINT: + return BIGINT; + + case Types.DECIMAL: + return DECIMAL; + case Types.NUMERIC: + return NUMERIC; + case Types.FLOAT: + return FLOAT; + case Types.DOUBLE: + return DOUBLE; + + case Types.CHAR: + return CHAR; + case Types.VARCHAR: + return VARCHAR; + case Types.NVARCHAR: + return NVARCHAR; + + case Types.BINARY: + return BINARY; + case Types.VARBINARY: + return VARBINARY; + + case Types.TIME: + return TIME; + case Types.DATE: + return DATE; + case Types.TIMESTAMP: + return TIMESTAMP; + + case Types.NULL: + return NULL; + + default: + return new JdbcParameterNull(sqlType); + } + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterString.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterString.java new file mode 100644 index 0000000000..f0adf73dd5 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterString.java @@ -0,0 +1,49 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterString implements JdbcParameter { + + private final String value; + + public JdbcParameterString(String value){ + this.value = value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.VARCHAR; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterTimestamp.java b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterTimestamp.java new file mode 100644 index 0000000000..64f28e1fc1 --- /dev/null +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/JdbcParameterTimestamp.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Timestamp; +import java.sql.Types; +import java.util.Calendar; + +public final class JdbcParameterTimestamp implements JdbcParameter { + + private final Timestamp value; + + public JdbcParameterTimestamp(Timestamp value){ + this.value = value; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public long getLength() { + return 0; + } + + @Override + public Calendar getCalendar() { + return null; + } + + @Override + public int getSqlType() { + return Types.TIMESTAMP; + } + +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/PreparedStatementProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/PreparedStatementProxyImpl.java index 047cc463c5..7b7af74ab9 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/PreparedStatementProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/PreparedStatementProxyImpl.java @@ -1,593 +1,690 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.NClob; -import java.sql.ParameterMetaData; -import java.sql.PreparedStatement; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.sql.Types; -import java.util.Calendar; -import java.util.Map; -import java.util.TreeMap; - -import com.alibaba.druid.proxy.jdbc.JdbcParameter.TYPE; - -/** - * @author wenshao - */ -public class PreparedStatementProxyImpl extends StatementProxyImpl implements PreparedStatementProxy { - - protected final PreparedStatement statement; - protected final String sql; - protected final Map parameters = new TreeMap(); - - public PreparedStatementProxyImpl(ConnectionProxy connection, PreparedStatement statement, String sql, long id){ - super(connection, statement, id); - this.statement = statement; - this.sql = sql; - } - - public Map getParameters() { - return parameters; - } - - public String getSql() { - return this.sql; - } - - public PreparedStatement getRawObject() { - return this.statement; - } - - @Override - public void addBatch() throws SQLException { - createChain().preparedStatement_addBatch(this); - } - - @Override - public void clearParameters() throws SQLException { - createChain().preparedStatement_clearParameters(this); - } - - @Override - public String getBatchSql() { - return this.sql; - } - - @Override - public boolean execute() throws SQLException { - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.Execute; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - firstResultSet = createChain().preparedStatement_execute(this); - return firstResultSet; - } - - @Override - public ResultSet executeQuery() throws SQLException { - firstResultSet = true; - - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteQuery; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - return createChain().preparedStatement_executeQuery(this); - } - - @Override - public int executeUpdate() throws SQLException { - firstResultSet = false; - - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteUpdate; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - updateCount = createChain().preparedStatement_executeUpdate(this); - return updateCount; - } - - @Override - public ResultSetMetaData getMetaData() throws SQLException { - return createChain().preparedStatement_getMetaData(this); - } - - @Override - public ParameterMetaData getParameterMetaData() throws SQLException { - return createChain().preparedStatement_getParameterMetaData(this); - } - - @Override - public void setArray(int parameterIndex, Array x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.ARRAY, x)); - - createChain().preparedStatement_setArray(this, parameterIndex, x); - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.AsciiInputStream, x)); - - createChain().preparedStatement_setAsciiStream(this, parameterIndex, x); - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.AsciiInputStream, x, length)); - - createChain().preparedStatement_setAsciiStream(this, parameterIndex, x, length); - } - - @Override - public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.AsciiInputStream, x, length)); - - createChain().preparedStatement_setAsciiStream(this, parameterIndex, x, length); - } - - @Override - public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.DECIMAL, x)); - createChain().preparedStatement_setBigDecimal(this, parameterIndex, x); - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.BinaryInputStream, x)); - - createChain().preparedStatement_setBinaryStream(this, parameterIndex, x); - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.BinaryInputStream, x, length)); - - createChain().preparedStatement_setBinaryStream(this, parameterIndex, x, length); - } - - @Override - public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.BinaryInputStream, x, length)); - - createChain().preparedStatement_setBinaryStream(this, parameterIndex, x, length); - } - - @Override - public void setBlob(int parameterIndex, Blob x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.BLOB, x)); - - createChain().preparedStatement_setBlob(this, parameterIndex, x); - } - - @Override - public void setBlob(int parameterIndex, InputStream x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.BLOB, x)); - - createChain().preparedStatement_setBlob(this, parameterIndex, x); - } - - @Override - public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.BLOB, x, length)); - createChain().preparedStatement_setBlob(this, parameterIndex, x, length); - } - - @Override - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.BOOLEAN, x)); - createChain().preparedStatement_setBoolean(this, parameterIndex, x); - } - - @Override - public void setByte(int parameterIndex, byte x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.TINYINT, x)); - - createChain().preparedStatement_setByte(this, parameterIndex, x); - } - - @Override - public void setBytes(int parameterIndex, byte[] x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.BYTES, x)); - - createChain().preparedStatement_setBytes(this, parameterIndex, x); - } - - @Override - public void setCharacterStream(int parameterIndex, Reader x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.CharacterInputStream, x)); - - createChain().preparedStatement_setCharacterStream(this, parameterIndex, x); - } - - @Override - public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.CharacterInputStream, x, length)); - - createChain().preparedStatement_setCharacterStream(this, parameterIndex, x, length); - } - - @Override - public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.CharacterInputStream, x, length)); - - createChain().preparedStatement_setCharacterStream(this, parameterIndex, x, length); - } - - @Override - public void setClob(int parameterIndex, Clob x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.CLOB, x)); - - createChain().preparedStatement_setClob(this, parameterIndex, x); - } - - @Override - public void setClob(int parameterIndex, Reader x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.CLOB, x)); - - createChain().preparedStatement_setClob(this, parameterIndex, x); - } - - @Override - public void setClob(int parameterIndex, Reader x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.CLOB, x, length)); - - createChain().preparedStatement_setClob(this, parameterIndex, x, length); - } - - @Override - public void setDate(int parameterIndex, Date x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.DATE, x)); - - createChain().preparedStatement_setDate(this, parameterIndex, x); - } - - @Override - public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.DATE, x, cal)); - - createChain().preparedStatement_setDate(this, parameterIndex, x, cal); - } - - @Override - public void setDouble(int parameterIndex, double x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.DOUBLE, x)); - - createChain().preparedStatement_setDouble(this, parameterIndex, x); - } - - @Override - public void setFloat(int parameterIndex, float x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.FLOAT, x)); - - createChain().preparedStatement_setFloat(this, parameterIndex, x); - } - - @Override - public void setInt(int parameterIndex, int x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.INTEGER, x)); - - createChain().preparedStatement_setInt(this, parameterIndex, x); - } - - @Override - public void setLong(int parameterIndex, long x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.BIGINT, x)); - - createChain().preparedStatement_setLong(this, parameterIndex, x); - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.NCharacterInputStream, x)); - - createChain().preparedStatement_setNCharacterStream(this, parameterIndex, x); - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.NCharacterInputStream, x, length)); - - createChain().preparedStatement_setNCharacterStream(this, parameterIndex, x, length); - } - - @Override - public void setNClob(int parameterIndex, NClob x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.NCLOB, x)); - - createChain().preparedStatement_setNClob(this, parameterIndex, x); - } - - @Override - public void setNClob(int parameterIndex, Reader x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.NCLOB, x)); - - createChain().preparedStatement_setNClob(this, parameterIndex, x); - } - - @Override - public void setNClob(int parameterIndex, Reader x, long length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.NCLOB, x, length)); - - createChain().preparedStatement_setNClob(this, parameterIndex, x, length); - } - - @Override - public void setNString(int parameterIndex, String x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.NVARCHAR, x)); - - createChain().preparedStatement_setNString(this, parameterIndex, x); - } - - @Override - public void setNull(int parameterIndex, int sqlType) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(sqlType, null)); - - createChain().preparedStatement_setNull(this, parameterIndex, sqlType); - } - - @Override - public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(sqlType, null)); - - createChain().preparedStatement_setNull(this, parameterIndex, sqlType, typeName); - } - - @Override - public void setObject(int parameterIndex, Object x) throws SQLException { - setObjectParameter(parameterIndex, x); - - createChain().preparedStatement_setObject(this, parameterIndex, x); - } - - private void setObjectParameter(int parameterIndex, Object x) { - if (x == null) { - setParameter(parameterIndex, new JdbcParameter(Types.OTHER, null)); - return; - } - - Class clazz = x.getClass(); - if (clazz == Byte.class) { - setParameter(parameterIndex, new JdbcParameter(Types.TINYINT, x)); - return; - } - - if (clazz == Short.class) { - setParameter(parameterIndex, new JdbcParameter(Types.SMALLINT, x)); - return; - } - - if (clazz == Integer.class) { - setParameter(parameterIndex, new JdbcParameter(Types.INTEGER, x)); - return; - } - - if (clazz == Long.class) { - setParameter(parameterIndex, new JdbcParameter(Types.BIGINT, x)); - return; - } - - if (clazz == String.class) { - setParameter(parameterIndex, new JdbcParameter(Types.VARCHAR, x)); - return; - } - - if (clazz == BigDecimal.class) { - setParameter(parameterIndex, new JdbcParameter(Types.DECIMAL, x)); - return; - } - - if (clazz == Float.class) { - setParameter(parameterIndex, new JdbcParameter(Types.FLOAT, x)); - return; - } - - if (clazz == Double.class) { - setParameter(parameterIndex, new JdbcParameter(Types.DOUBLE, x)); - return; - } - - if (clazz == java.sql.Date.class || clazz == java.util.Date.class) { - setParameter(parameterIndex, new JdbcParameter(Types.DATE, x)); - return; - } - - if (clazz == java.sql.Timestamp.class) { - setParameter(parameterIndex, new JdbcParameter(Types.TIMESTAMP, x)); - return; - } - - if (clazz == java.sql.Time.class) { - setParameter(parameterIndex, new JdbcParameter(Types.TIME, x)); - return; - } - - if (clazz == Boolean.class) { - setParameter(parameterIndex, new JdbcParameter(Types.BOOLEAN, x)); - return; - } - - if (clazz == byte[].class) { - setParameter(parameterIndex, new JdbcParameter(TYPE.BYTES, x)); - return; - } - - if (x instanceof InputStream) { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.BinaryInputStream, x)); - return; - } - - if (x instanceof Reader) { - setParameter(parameterIndex, new JdbcParameter(JdbcParameter.TYPE.CharacterInputStream, x)); - return; - } - - if (x instanceof Clob) { - setParameter(parameterIndex, new JdbcParameter(Types.CLOB, x)); - return; - } - - if (x instanceof NClob) { - setParameter(parameterIndex, new JdbcParameter(Types.NCLOB, x)); - return; - } - - if (x instanceof Blob) { - setParameter(parameterIndex, new JdbcParameter(Types.BLOB, x)); - return; - } - - setParameter(parameterIndex, new JdbcParameter(Types.OTHER, null)); - } - - @Override - public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(targetSqlType, x)); - - createChain().preparedStatement_setObject(this, parameterIndex, x, targetSqlType); - } - - @Override - public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(targetSqlType, x, -1, null, scaleOrLength)); - - createChain().preparedStatement_setObject(this, parameterIndex, x, targetSqlType, scaleOrLength); - } - - @Override - public void setRef(int parameterIndex, Ref x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.REF, x)); - - createChain().preparedStatement_setRef(this, parameterIndex, x); - } - - @Override - public void setRowId(int parameterIndex, RowId x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.ROWID, x)); - - createChain().preparedStatement_setRowId(this, parameterIndex, x); - } - - @Override - public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.SQLXML, x)); - - createChain().preparedStatement_setSQLXML(this, parameterIndex, x); - } - - @Override - public void setShort(int parameterIndex, short x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.SMALLINT, x)); - - createChain().preparedStatement_setShort(this, parameterIndex, x); - } - - @Override - public void setString(int parameterIndex, String x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.VARCHAR, x)); - - createChain().preparedStatement_setString(this, parameterIndex, x); - } - - @Override - public void setTime(int parameterIndex, Time x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.TIME, x)); - - createChain().preparedStatement_setTime(this, parameterIndex, x); - } - - @Override - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.TIME, x, cal)); - - createChain().preparedStatement_setTime(this, parameterIndex, x, cal); - } - - @Override - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.TIMESTAMP, x)); - - createChain().preparedStatement_setTimestamp(this, parameterIndex, x); - } - - @Override - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(Types.TIMESTAMP, x)); - - createChain().preparedStatement_setTimestamp(this, parameterIndex, x, cal); - } - - @Override - public void setURL(int parameterIndex, URL x) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.URL, x)); - - createChain().preparedStatement_setURL(this, parameterIndex, x); - } - - @Override - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - setParameter(parameterIndex, new JdbcParameter(TYPE.UnicodeStream, x, length)); - - createChain().preparedStatement_setUnicodeStream(this, parameterIndex, x, length); - } - - public void setParameter(int parameterIndex, JdbcParameter parameter) { - this.getParameters().put(parameterIndex, parameter); - } - - @Override - public String getLastExecuteSql() { - return this.sql; - } - - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface == PreparedStatementProxy.class) { - return (T) this; - } - - return super.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - if (iface == PreparedStatementProxy.class) { - return true; - } - - return super.isWrapperFor(iface); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.NClob; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.Types; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Map; + +import com.alibaba.druid.proxy.jdbc.JdbcParameter.TYPE; + +/** + * @author wenshao + */ +public class PreparedStatementProxyImpl extends StatementProxyImpl implements PreparedStatementProxy { + + protected final PreparedStatement statement; + protected final String sql; + private JdbcParameter[] parameters = new JdbcParameter[16]; + private int parametersSize = 0; + + public PreparedStatementProxyImpl(ConnectionProxy connection, PreparedStatement statement, String sql, long id){ + super(connection, statement, id); + this.statement = statement; + this.sql = sql; + } + + public Map getParameters() { + return null; + } + + void setParameter(int jdbcIndex, JdbcParameter parameter) { + int index = jdbcIndex - 1; + + if (jdbcIndex > parametersSize) { + parametersSize = jdbcIndex; + } + if (parametersSize >= parameters.length) { + parameters = Arrays.copyOf(parameters, parametersSize + 16); + } + parameters[index] = parameter; + } + + public int getParametersSize() { + return parametersSize; + } + + public JdbcParameter getParameter(int i) { + if (i > parametersSize) { + return null; + } + return this.parameters[i]; + } + + public String getSql() { + return this.sql; + } + + public PreparedStatement getRawObject() { + return this.statement; + } + + @Override + public void addBatch() throws SQLException { + createChain().preparedStatement_addBatch(this); + } + + @Override + public void clearParameters() throws SQLException { + createChain().preparedStatement_clearParameters(this); + } + + @Override + public String getBatchSql() { + return this.sql; + } + + @Override + public boolean execute() throws SQLException { + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.Execute; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + firstResultSet = createChain().preparedStatement_execute(this); + return firstResultSet; + } + + @Override + public ResultSet executeQuery() throws SQLException { + firstResultSet = true; + + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteQuery; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + return createChain().preparedStatement_executeQuery(this); + } + + @Override + public int executeUpdate() throws SQLException { + firstResultSet = false; + + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteUpdate; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + updateCount = createChain().preparedStatement_executeUpdate(this); + return updateCount; + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return createChain().preparedStatement_getMetaData(this); + } + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + return createChain().preparedStatement_getParameterMetaData(this); + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.ARRAY, x)); + + createChain().preparedStatement_setArray(this, parameterIndex, x); + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.AsciiInputStream, x)); + + createChain().preparedStatement_setAsciiStream(this, parameterIndex, x); + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.AsciiInputStream, x, length)); + + createChain().preparedStatement_setAsciiStream(this, parameterIndex, x, length); + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.AsciiInputStream, x, length)); + + createChain().preparedStatement_setAsciiStream(this, parameterIndex, x, length); + } + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + setParameter(parameterIndex, createParameter(x)); + createChain().preparedStatement_setBigDecimal(this, parameterIndex, x); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.BinaryInputStream, x)); + + createChain().preparedStatement_setBinaryStream(this, parameterIndex, x); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.BinaryInputStream, x, length)); + + createChain().preparedStatement_setBinaryStream(this, parameterIndex, x, length); + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(JdbcParameter.TYPE.BinaryInputStream, x, length)); + + createChain().preparedStatement_setBinaryStream(this, parameterIndex, x, length); + } + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.BLOB, x)); + + createChain().preparedStatement_setBlob(this, parameterIndex, x); + } + + @Override + public void setBlob(int parameterIndex, InputStream x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.BLOB, x)); + + createChain().preparedStatement_setBlob(this, parameterIndex, x); + } + + @Override + public void setBlob(int parameterIndex, InputStream x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(Types.BLOB, x, length)); + createChain().preparedStatement_setBlob(this, parameterIndex, x, length); + } + + @Override + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.BOOLEAN, x)); + createChain().preparedStatement_setBoolean(this, parameterIndex, x); + } + + @Override + public void setByte(int parameterIndex, byte x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.TINYINT, x)); + + createChain().preparedStatement_setByte(this, parameterIndex, x); + } + + @Override + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.BYTES, x)); + + createChain().preparedStatement_setBytes(this, parameterIndex, x); + } + + @Override + public void setCharacterStream(int parameterIndex, Reader x) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.CharacterInputStream, x)); + + createChain().preparedStatement_setCharacterStream(this, parameterIndex, x); + } + + @Override + public void setCharacterStream(int parameterIndex, Reader x, int length) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.CharacterInputStream, x, length)); + + createChain().preparedStatement_setCharacterStream(this, parameterIndex, x, length); + } + + @Override + public void setCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.CharacterInputStream, x, length)); + + createChain().preparedStatement_setCharacterStream(this, parameterIndex, x, length); + } + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.CLOB, x)); + + createChain().preparedStatement_setClob(this, parameterIndex, x); + } + + @Override + public void setClob(int parameterIndex, Reader x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.CLOB, x)); + + createChain().preparedStatement_setClob(this, parameterIndex, x); + } + + @Override + public void setClob(int parameterIndex, Reader x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(Types.CLOB, x, length)); + + createChain().preparedStatement_setClob(this, parameterIndex, x, length); + } + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException { + setParameter(parameterIndex, createParameter(x)); + + createChain().preparedStatement_setDate(this, parameterIndex, x); + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + setParameter(parameterIndex, createParameter(Types.DATE, x, cal)); + + createChain().preparedStatement_setDate(this, parameterIndex, x, cal); + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.DOUBLE, x)); + + createChain().preparedStatement_setDouble(this, parameterIndex, x); + } + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.FLOAT, x)); + + createChain().preparedStatement_setFloat(this, parameterIndex, x); + } + + @Override + public void setInt(int parameterIndex, int x) throws SQLException { + setParameter(parameterIndex, createParemeter(x)); + + createChain().preparedStatement_setInt(this, parameterIndex, x); + } + + @Override + public void setLong(int parameterIndex, long x) throws SQLException { + setParameter(parameterIndex, createParameter(x)); + + createChain().preparedStatement_setLong(this, parameterIndex, x); + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.NCharacterInputStream, x)); + + createChain().preparedStatement_setNCharacterStream(this, parameterIndex, x); + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.NCharacterInputStream, x, length)); + + createChain().preparedStatement_setNCharacterStream(this, parameterIndex, x, length); + } + + @Override + public void setNClob(int parameterIndex, NClob x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.NCLOB, x)); + + createChain().preparedStatement_setNClob(this, parameterIndex, x); + } + + @Override + public void setNClob(int parameterIndex, Reader x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.NCLOB, x)); + + createChain().preparedStatement_setNClob(this, parameterIndex, x); + } + + @Override + public void setNClob(int parameterIndex, Reader x, long length) throws SQLException { + setParameter(parameterIndex, createParameter(Types.NCLOB, x, length)); + + createChain().preparedStatement_setNClob(this, parameterIndex, x, length); + } + + @Override + public void setNString(int parameterIndex, String x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.NVARCHAR, x)); + + createChain().preparedStatement_setNString(this, parameterIndex, x); + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException { + setParameter(parameterIndex, createParameterNull(sqlType)); + + createChain().preparedStatement_setNull(this, parameterIndex, sqlType); + } + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + setParameter(parameterIndex, createParameterNull(sqlType)); + + createChain().preparedStatement_setNull(this, parameterIndex, sqlType, typeName); + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + setObjectParameter(parameterIndex, x); + + createChain().preparedStatement_setObject(this, parameterIndex, x); + } + + private void setObjectParameter(int parameterIndex, Object x) { + if (x == null) { + setParameter(parameterIndex, createParameterNull(Types.OTHER)); + return; + } + + Class clazz = x.getClass(); + if (clazz == Byte.class) { + setParameter(parameterIndex, createParameter(Types.TINYINT, x)); + return; + } + + if (clazz == Short.class) { + setParameter(parameterIndex, createParameter(Types.SMALLINT, x)); + return; + } + + if (clazz == Integer.class) { + setParameter(parameterIndex, createParemeter((Integer) x)); + return; + } + + if (clazz == Long.class) { + setParameter(parameterIndex, createParameter((Long) x)); + return; + } + + if (clazz == String.class) { + setParameter(parameterIndex, createParameter((String) x)); + return; + } + + if (clazz == BigDecimal.class) { + setParameter(parameterIndex, createParameter((BigDecimal) x)); + return; + } + + if (clazz == Float.class) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.FLOAT, x)); + return; + } + + if (clazz == Double.class) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.DOUBLE, x)); + return; + } + + if (clazz == java.sql.Date.class || clazz == java.util.Date.class) { + setParameter(parameterIndex, createParameter((java.util.Date) x)); + return; + } + + if (clazz == java.sql.Timestamp.class) { + setParameter(parameterIndex, createParameter((java.sql.Timestamp) x)); + return; + } + + if (clazz == java.sql.Time.class) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.TIME, x)); + return; + } + + if (clazz == Boolean.class) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.BOOLEAN, x)); + return; + } + + if (clazz == byte[].class) { + setParameter(parameterIndex, new JdbcParameterImpl(TYPE.BYTES, x)); + return; + } + + if (x instanceof InputStream) { + setParameter(parameterIndex, new JdbcParameterImpl(JdbcParameter.TYPE.BinaryInputStream, x)); + return; + } + + if (x instanceof Reader) { + setParameter(parameterIndex, new JdbcParameterImpl(JdbcParameter.TYPE.CharacterInputStream, x)); + return; + } + + if (x instanceof Clob) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.CLOB, x)); + return; + } + + if (x instanceof NClob) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.NCLOB, x)); + return; + } + + if (x instanceof Blob) { + setParameter(parameterIndex, new JdbcParameterImpl(Types.BLOB, x)); + return; + } + + setParameter(parameterIndex, createParameter(Types.OTHER, null)); + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + setParameter(parameterIndex, createParameter(targetSqlType, x)); + + createChain().preparedStatement_setObject(this, parameterIndex, x, targetSqlType); + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + setParameter(parameterIndex, createParameter(x, targetSqlType, scaleOrLength)); + + createChain().preparedStatement_setObject(this, parameterIndex, x, targetSqlType, scaleOrLength); + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.REF, x)); + + createChain().preparedStatement_setRef(this, parameterIndex, x); + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.ROWID, x)); + + createChain().preparedStatement_setRowId(this, parameterIndex, x); + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.SQLXML, x)); + + createChain().preparedStatement_setSQLXML(this, parameterIndex, x); + } + + @Override + public void setShort(int parameterIndex, short x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.SMALLINT, x)); + + createChain().preparedStatement_setShort(this, parameterIndex, x); + } + + @Override + public void setString(int parameterIndex, String x) throws SQLException { + setParameter(parameterIndex, createParameter(x)); + + createChain().preparedStatement_setString(this, parameterIndex, x); + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + setParameter(parameterIndex, createParameter(Types.TIME, x)); + + createChain().preparedStatement_setTime(this, parameterIndex, x); + } + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + setParameter(parameterIndex, createParameter(Types.TIME, x, cal)); + + createChain().preparedStatement_setTime(this, parameterIndex, x, cal); + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + setParameter(parameterIndex, createParameter(x)); + + createChain().preparedStatement_setTimestamp(this, parameterIndex, x); + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + setParameter(parameterIndex, createParameter(Types.TIMESTAMP, x)); + + createChain().preparedStatement_setTimestamp(this, parameterIndex, x, cal); + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.URL, x)); + + createChain().preparedStatement_setURL(this, parameterIndex, x); + } + + @Override + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + setParameter(parameterIndex, createParameter(TYPE.UnicodeStream, x, length)); + + createChain().preparedStatement_setUnicodeStream(this, parameterIndex, x, length); + } + + @Override + public String getLastExecuteSql() { + return this.sql; + } + + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface == PreparedStatementProxy.class) { + return (T) this; + } + + return super.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + if (iface == PreparedStatementProxy.class) { + return true; + } + + return super.isWrapperFor(iface); + } + + private JdbcParameter createParemeter(int x) { + return JdbcParameterInt.valueOf(x); + } + + private JdbcParameter createParameter(long x) { + return JdbcParameterLong.valueOf(x); + } + + private JdbcParameter createParameterNull(int sqlType) { + return JdbcParameterNull.valueOf(sqlType); + + } + + private JdbcParameter createParameter(java.util.Date x) { + if (x == null) { + return JdbcParameterNull.DATE; + } + + return new JdbcParameterDate(x); + } + + private JdbcParameter createParameter(BigDecimal x) { + if (x == null) { + return JdbcParameterNull.DECIMAL; + } + + return JdbcParameterDecimal.valueOf(x); + } + + private JdbcParameter createParameter(String x) { + if (x == null) { + return JdbcParameterNull.VARCHAR; + } + + return new JdbcParameterString(x); + } + + private JdbcParameter createParameter(Timestamp x) { + if (x == null) { + return JdbcParameterNull.TIMESTAMP; + } + + return new JdbcParameterTimestamp(x); + } + + private JdbcParameter createParameter(Object x, int sqlType, int scaleOrLength) { + if (x == null) { + return JdbcParameterNull.valueOf(sqlType); + } + + return new JdbcParameterImpl(sqlType, x, -1, null, scaleOrLength); + } + + private JdbcParameter createParameter(int sqlType, Object value, long length) { + if (value == null) { + return JdbcParameterNull.valueOf(sqlType); + } + + return new JdbcParameterImpl(sqlType, value, length); + } + + private JdbcParameter createParameter(int sqlType, Object value) { + if (value == null) { + return JdbcParameterNull.valueOf(sqlType); + } + + return new JdbcParameterImpl(sqlType, value); + } + + public JdbcParameter createParameter(int sqlType, Object value, Calendar calendar) { + if (value == null) { + return JdbcParameterNull.valueOf(sqlType); + } + + return new JdbcParameterImpl(sqlType, value, calendar); + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxy.java b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxy.java index aa6a0d9b16..5e15c29e73 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxy.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxy.java @@ -1,56 +1,59 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.sql.Statement; -import java.util.List; -import java.util.Map; - -import com.alibaba.druid.stat.JdbcSqlStat; - -/** - * @author wenshao - */ -public interface StatementProxy extends Statement, WrapperProxy { - - ConnectionProxy getConnectionProxy(); - - Statement getRawObject(); - - List getBatchSqlList(); - - String getBatchSql(); - - JdbcSqlStat getSqlStat(); - - StatementExecuteType getLastExecuteType(); - - void setSqlStat(JdbcSqlStat sqlStat); - - String getLastExecuteSql(); - - long getLastExecuteStartNano(); - void setLastExecuteStartNano(long lastExecuteStartNano); - void setLastExecuteStartNano(); - - long getLastExecuteTimeNano(); - void setLastExecuteTimeNano(long nano); - void setLastExecuteTimeNano(); - - Map getParameters(); - - boolean isFirstResultSet(); -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Statement; +import java.util.List; +import java.util.Map; + +import com.alibaba.druid.stat.JdbcSqlStat; + +/** + * @author wenshao + */ +public interface StatementProxy extends Statement, WrapperProxy { + + ConnectionProxy getConnectionProxy(); + + Statement getRawObject(); + + List getBatchSqlList(); + + String getBatchSql(); + + JdbcSqlStat getSqlStat(); + + StatementExecuteType getLastExecuteType(); + + void setSqlStat(JdbcSqlStat sqlStat); + + String getLastExecuteSql(); + + long getLastExecuteStartNano(); + void setLastExecuteStartNano(long lastExecuteStartNano); + void setLastExecuteStartNano(); + + long getLastExecuteTimeNano(); + void setLastExecuteTimeNano(long nano); + void setLastExecuteTimeNano(); + + Map getParameters(); + + int getParametersSize(); + JdbcParameter getParameter(int i); + + boolean isFirstResultSet(); +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java index c983019d18..db76323977 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java @@ -1,569 +1,579 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.sql.SQLWarning; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import com.alibaba.druid.filter.FilterChainImpl; -import com.alibaba.druid.stat.JdbcSqlStat; - -/** - * @author wenshao - */ -public class StatementProxyImpl extends WrapperProxyImpl implements StatementProxy { - - private final ConnectionProxy connection; - private final Statement statement; - - protected String lastExecuteSql; - protected long lastExecuteStartNano; - protected long lastExecuteTimeNano; - - protected JdbcSqlStat sqlStat; - protected boolean firstResultSet; - - protected ArrayList batchSqlList; - - protected StatementExecuteType lastExecuteType; - - protected Integer updateCount = null; - - private FilterChainImpl filterChain = null; - - public StatementProxyImpl(ConnectionProxy connection, Statement statement, long id){ - super(statement, id); - this.connection = connection; - this.statement = statement; - } - - public ConnectionProxy getConnectionProxy() { - return connection; - } - - public Statement getRawObject() { - return this.statement; - } - - public FilterChainImpl createChain() { - FilterChainImpl chain = this.filterChain; - if (chain == null) { - chain = new FilterChainImpl(this.getConnectionProxy().getDirectDataSource()); - } else { - this.filterChain = null; - } - - return chain; - } - - public void recycleFilterChain(FilterChainImpl chain) { - chain.reset(); - this.filterChain = chain; - } - - @Override - public void addBatch(String sql) throws SQLException { - if (batchSqlList == null) { - batchSqlList = new ArrayList(); - } - - createChain().statement_addBatch(this, sql); - batchSqlList.add(sql); - } - - @Override - public void cancel() throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_cancel(this); - recycleFilterChain(chain); - } - - @Override - public void clearBatch() throws SQLException { - if (batchSqlList == null) { - batchSqlList = new ArrayList(); - } - - FilterChainImpl chain = createChain(); - chain.statement_clearBatch(this); - recycleFilterChain(chain); - batchSqlList.clear(); - } - - @Override - public void clearWarnings() throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_clearWarnings(this); - recycleFilterChain(chain); - } - - @Override - public void close() throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_close(this); - recycleFilterChain(chain); - } - - @Override - public boolean execute(String sql) throws SQLException { - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.Execute; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - firstResultSet = chain.statement_execute(this, sql); - recycleFilterChain(chain); - return firstResultSet; - } - - @Override - public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.Execute; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - firstResultSet = chain.statement_execute(this, sql, autoGeneratedKeys); - recycleFilterChain(chain); - return firstResultSet; - } - - @Override - public boolean execute(String sql, int[] columnIndexes) throws SQLException { - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.Execute; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - firstResultSet = chain.statement_execute(this, sql, columnIndexes); - recycleFilterChain(chain); - return firstResultSet; - } - - @Override - public boolean execute(String sql, String[] columnNames) throws SQLException { - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.Execute; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - firstResultSet = chain.statement_execute(this, sql, columnNames); - recycleFilterChain(chain); - return firstResultSet; - } - - @Override - public int[] executeBatch() throws SQLException { - firstResultSet = false; - lastExecuteType = StatementExecuteType.ExecuteBatch; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - int[] updateCounts = chain.statement_executeBatch(this); - recycleFilterChain(chain); - if (updateCounts != null && updateCounts.length == 1) { - updateCount = updateCounts[0]; - } - - return updateCounts; - } - - @Override - public ResultSet executeQuery(String sql) throws SQLException { - firstResultSet = true; - updateCount = null; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteQuery; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - ResultSet resultSet = chain.statement_executeQuery(this, sql); - recycleFilterChain(chain); - return resultSet; - } - - @Override - public int executeUpdate(String sql) throws SQLException { - firstResultSet = false; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteUpdate; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - updateCount = chain.statement_executeUpdate(this, sql); - recycleFilterChain(chain); - return updateCount; - } - - @Override - public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { - firstResultSet = false; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteUpdate; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - updateCount = chain.statement_executeUpdate(this, sql, autoGeneratedKeys); - recycleFilterChain(chain); - return updateCount; - } - - @Override - public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { - firstResultSet = false; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteUpdate; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - updateCount = chain.statement_executeUpdate(this, sql, columnIndexes); - recycleFilterChain(chain); - return updateCount; - } - - @Override - public int executeUpdate(String sql, String[] columnNames) throws SQLException { - firstResultSet = false; - lastExecuteSql = sql; - lastExecuteType = StatementExecuteType.ExecuteUpdate; - lastExecuteStartNano = -1L; - lastExecuteTimeNano = -1L; - - FilterChainImpl chain = createChain(); - updateCount = chain.statement_executeUpdate(this, sql, columnNames); - recycleFilterChain(chain); - return updateCount; - } - - @Override - public Connection getConnection() throws SQLException { - FilterChainImpl chain = createChain(); - Connection conn = chain.statement_getConnection(this); - recycleFilterChain(chain); - return conn; - } - - @Override - public int getFetchDirection() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getFetchDirection(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getFetchSize() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getFetchSize(this); - recycleFilterChain(chain); - return value; - } - - @Override - public ResultSet getGeneratedKeys() throws SQLException { - FilterChainImpl chain = createChain(); - ResultSet value = chain.statement_getGeneratedKeys(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getMaxFieldSize() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getMaxFieldSize(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getMaxRows() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getMaxRows(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean getMoreResults() throws SQLException { - updateCount = null; - FilterChainImpl chain = createChain(); - boolean value = chain.statement_getMoreResults(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean getMoreResults(int current) throws SQLException { - updateCount = null; - FilterChainImpl chain = createChain(); - boolean value = chain.statement_getMoreResults(this, current); - recycleFilterChain(chain); - return value; - } - - @Override - public int getQueryTimeout() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getQueryTimeout(this); - recycleFilterChain(chain); - return value; - } - - @Override - public ResultSet getResultSet() throws SQLException { - FilterChainImpl chain = createChain(); - ResultSet value = chain.statement_getResultSet(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getResultSetConcurrency() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getResultSetConcurrency(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getResultSetHoldability() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getResultSetHoldability(this); - recycleFilterChain(chain); - return value; - } - - @Override - public int getResultSetType() throws SQLException { - FilterChainImpl chain = createChain(); - int value = chain.statement_getResultSetType(this); - recycleFilterChain(chain); - return value; - } - - // bug fixed for oracle - @Override - public int getUpdateCount() throws SQLException { - if (updateCount == null) { - FilterChainImpl chain = createChain(); - updateCount = chain.statement_getUpdateCount(this); - recycleFilterChain(chain); - } - return updateCount; - } - - @Override - public SQLWarning getWarnings() throws SQLException { - FilterChainImpl chain = createChain(); - SQLWarning value = chain.statement_getWarnings(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean isClosed() throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.statement_isClosed(this); - recycleFilterChain(chain); - return value; - } - - @Override - public boolean isPoolable() throws SQLException { - FilterChainImpl chain = createChain(); - boolean value = chain.statement_isPoolable(this); - recycleFilterChain(chain); - return value; - } - - @Override - public void setCursorName(String name) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setCursorName(this, name); - recycleFilterChain(chain); - } - - @Override - public void setEscapeProcessing(boolean enable) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setEscapeProcessing(this, enable); - recycleFilterChain(chain); - } - - @Override - public void setFetchDirection(int direction) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setFetchDirection(this, direction); - recycleFilterChain(chain); - } - - @Override - public void setFetchSize(int rows) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setFetchSize(this, rows); - recycleFilterChain(chain); - } - - @Override - public void setMaxFieldSize(int max) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setMaxFieldSize(this, max); - recycleFilterChain(chain); - } - - @Override - public void setMaxRows(int max) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setMaxRows(this, max); - recycleFilterChain(chain); - } - - @Override - public void setPoolable(boolean poolable) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setPoolable(this, poolable); - recycleFilterChain(chain); - } - - @Override - public void setQueryTimeout(int seconds) throws SQLException { - FilterChainImpl chain = createChain(); - chain.statement_setQueryTimeout(this, seconds); - recycleFilterChain(chain); - } - - @Override - public List getBatchSqlList() { - if (batchSqlList == null) { - batchSqlList = new ArrayList(); - } - - return batchSqlList; - } - - @Override - public String getBatchSql() { - List sqlList = getBatchSqlList(); - StringBuffer buf = new StringBuffer(); - for (String item : sqlList) { - if (buf.length() > 0) { - buf.append("\n;\n"); - } - buf.append(item); - } - return buf.toString(); - } - - public String getLastExecuteSql() { - return lastExecuteSql; - } - - public void closeOnCompletion() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - public boolean isCloseOnCompletion() throws SQLException { - throw new SQLFeatureNotSupportedException(); - } - - @Override - public Map getParameters() { - return Collections.emptyMap(); - } - - public JdbcSqlStat getSqlStat() { - return sqlStat; - } - - public void setSqlStat(JdbcSqlStat sqlStat) { - this.sqlStat = sqlStat; - } - - public long getLastExecuteTimeNano() { - return lastExecuteTimeNano; - } - - public void setLastExecuteTimeNano(long lastExecuteTimeNano) { - this.lastExecuteTimeNano = lastExecuteTimeNano; - } - - public void setLastExecuteTimeNano() { - if (this.lastExecuteTimeNano <= 0 && this.lastExecuteStartNano > 0) { - this.lastExecuteTimeNano = System.nanoTime() - this.lastExecuteStartNano; - } - } - - public long getLastExecuteStartNano() { - return lastExecuteStartNano; - } - - public void setLastExecuteStartNano(long lastExecuteStartNano) { - this.lastExecuteStartNano = lastExecuteStartNano; - this.lastExecuteTimeNano = -1L; - } - - public void setLastExecuteStartNano() { - if (lastExecuteStartNano <= 0) { - setLastExecuteStartNano(System.nanoTime()); - } - } - - public StatementExecuteType getLastExecuteType() { - return lastExecuteType; - } - - public boolean isFirstResultSet() { - return firstResultSet; - } - - @SuppressWarnings("unchecked") - public T unwrap(Class iface) throws SQLException { - if (iface == StatementProxy.class) { - return (T) this; - } - - return super.unwrap(iface); - } - - public boolean isWrapperFor(Class iface) throws SQLException { - if (iface == StatementProxy.class) { - return true; - } - - return super.isWrapperFor(iface); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.sql.SQLWarning; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import com.alibaba.druid.filter.FilterChainImpl; +import com.alibaba.druid.stat.JdbcSqlStat; + +/** + * @author wenshao + */ +public class StatementProxyImpl extends WrapperProxyImpl implements StatementProxy { + + private final ConnectionProxy connection; + private final Statement statement; + + protected String lastExecuteSql; + protected long lastExecuteStartNano; + protected long lastExecuteTimeNano; + + protected JdbcSqlStat sqlStat; + protected boolean firstResultSet; + + protected ArrayList batchSqlList; + + protected StatementExecuteType lastExecuteType; + + protected Integer updateCount = null; + + private FilterChainImpl filterChain = null; + + public StatementProxyImpl(ConnectionProxy connection, Statement statement, long id){ + super(statement, id); + this.connection = connection; + this.statement = statement; + } + + public ConnectionProxy getConnectionProxy() { + return connection; + } + + public Statement getRawObject() { + return this.statement; + } + + public FilterChainImpl createChain() { + FilterChainImpl chain = this.filterChain; + if (chain == null) { + chain = new FilterChainImpl(this.getConnectionProxy().getDirectDataSource()); + } else { + this.filterChain = null; + } + + return chain; + } + + public void recycleFilterChain(FilterChainImpl chain) { + chain.reset(); + this.filterChain = chain; + } + + @Override + public void addBatch(String sql) throws SQLException { + if (batchSqlList == null) { + batchSqlList = new ArrayList(); + } + + createChain().statement_addBatch(this, sql); + batchSqlList.add(sql); + } + + @Override + public void cancel() throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_cancel(this); + recycleFilterChain(chain); + } + + @Override + public void clearBatch() throws SQLException { + if (batchSqlList == null) { + batchSqlList = new ArrayList(); + } + + FilterChainImpl chain = createChain(); + chain.statement_clearBatch(this); + recycleFilterChain(chain); + batchSqlList.clear(); + } + + @Override + public void clearWarnings() throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_clearWarnings(this); + recycleFilterChain(chain); + } + + @Override + public void close() throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_close(this); + recycleFilterChain(chain); + } + + @Override + public boolean execute(String sql) throws SQLException { + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.Execute; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + firstResultSet = chain.statement_execute(this, sql); + recycleFilterChain(chain); + return firstResultSet; + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.Execute; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + firstResultSet = chain.statement_execute(this, sql, autoGeneratedKeys); + recycleFilterChain(chain); + return firstResultSet; + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.Execute; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + firstResultSet = chain.statement_execute(this, sql, columnIndexes); + recycleFilterChain(chain); + return firstResultSet; + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.Execute; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + firstResultSet = chain.statement_execute(this, sql, columnNames); + recycleFilterChain(chain); + return firstResultSet; + } + + @Override + public int[] executeBatch() throws SQLException { + firstResultSet = false; + lastExecuteType = StatementExecuteType.ExecuteBatch; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + int[] updateCounts = chain.statement_executeBatch(this); + recycleFilterChain(chain); + if (updateCounts != null && updateCounts.length == 1) { + updateCount = updateCounts[0]; + } + + return updateCounts; + } + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + firstResultSet = true; + updateCount = null; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteQuery; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + ResultSet resultSet = chain.statement_executeQuery(this, sql); + recycleFilterChain(chain); + return resultSet; + } + + @Override + public int executeUpdate(String sql) throws SQLException { + firstResultSet = false; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteUpdate; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + updateCount = chain.statement_executeUpdate(this, sql); + recycleFilterChain(chain); + return updateCount; + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + firstResultSet = false; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteUpdate; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + updateCount = chain.statement_executeUpdate(this, sql, autoGeneratedKeys); + recycleFilterChain(chain); + return updateCount; + } + + @Override + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + firstResultSet = false; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteUpdate; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + updateCount = chain.statement_executeUpdate(this, sql, columnIndexes); + recycleFilterChain(chain); + return updateCount; + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + firstResultSet = false; + lastExecuteSql = sql; + lastExecuteType = StatementExecuteType.ExecuteUpdate; + lastExecuteStartNano = -1L; + lastExecuteTimeNano = -1L; + + FilterChainImpl chain = createChain(); + updateCount = chain.statement_executeUpdate(this, sql, columnNames); + recycleFilterChain(chain); + return updateCount; + } + + @Override + public Connection getConnection() throws SQLException { + FilterChainImpl chain = createChain(); + Connection conn = chain.statement_getConnection(this); + recycleFilterChain(chain); + return conn; + } + + @Override + public int getFetchDirection() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getFetchDirection(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getFetchSize() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getFetchSize(this); + recycleFilterChain(chain); + return value; + } + + @Override + public ResultSet getGeneratedKeys() throws SQLException { + FilterChainImpl chain = createChain(); + ResultSet value = chain.statement_getGeneratedKeys(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getMaxFieldSize() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getMaxFieldSize(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getMaxRows() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getMaxRows(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean getMoreResults() throws SQLException { + updateCount = null; + FilterChainImpl chain = createChain(); + boolean value = chain.statement_getMoreResults(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean getMoreResults(int current) throws SQLException { + updateCount = null; + FilterChainImpl chain = createChain(); + boolean value = chain.statement_getMoreResults(this, current); + recycleFilterChain(chain); + return value; + } + + @Override + public int getQueryTimeout() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getQueryTimeout(this); + recycleFilterChain(chain); + return value; + } + + @Override + public ResultSet getResultSet() throws SQLException { + FilterChainImpl chain = createChain(); + ResultSet value = chain.statement_getResultSet(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getResultSetConcurrency() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getResultSetConcurrency(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getResultSetHoldability() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getResultSetHoldability(this); + recycleFilterChain(chain); + return value; + } + + @Override + public int getResultSetType() throws SQLException { + FilterChainImpl chain = createChain(); + int value = chain.statement_getResultSetType(this); + recycleFilterChain(chain); + return value; + } + + // bug fixed for oracle + @Override + public int getUpdateCount() throws SQLException { + if (updateCount == null) { + FilterChainImpl chain = createChain(); + updateCount = chain.statement_getUpdateCount(this); + recycleFilterChain(chain); + } + return updateCount; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + FilterChainImpl chain = createChain(); + SQLWarning value = chain.statement_getWarnings(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean isClosed() throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.statement_isClosed(this); + recycleFilterChain(chain); + return value; + } + + @Override + public boolean isPoolable() throws SQLException { + FilterChainImpl chain = createChain(); + boolean value = chain.statement_isPoolable(this); + recycleFilterChain(chain); + return value; + } + + @Override + public void setCursorName(String name) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setCursorName(this, name); + recycleFilterChain(chain); + } + + @Override + public void setEscapeProcessing(boolean enable) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setEscapeProcessing(this, enable); + recycleFilterChain(chain); + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setFetchDirection(this, direction); + recycleFilterChain(chain); + } + + @Override + public void setFetchSize(int rows) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setFetchSize(this, rows); + recycleFilterChain(chain); + } + + @Override + public void setMaxFieldSize(int max) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setMaxFieldSize(this, max); + recycleFilterChain(chain); + } + + @Override + public void setMaxRows(int max) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setMaxRows(this, max); + recycleFilterChain(chain); + } + + @Override + public void setPoolable(boolean poolable) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setPoolable(this, poolable); + recycleFilterChain(chain); + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException { + FilterChainImpl chain = createChain(); + chain.statement_setQueryTimeout(this, seconds); + recycleFilterChain(chain); + } + + @Override + public List getBatchSqlList() { + if (batchSqlList == null) { + batchSqlList = new ArrayList(); + } + + return batchSqlList; + } + + @Override + public String getBatchSql() { + List sqlList = getBatchSqlList(); + StringBuffer buf = new StringBuffer(); + for (String item : sqlList) { + if (buf.length() > 0) { + buf.append("\n;\n"); + } + buf.append(item); + } + return buf.toString(); + } + + public String getLastExecuteSql() { + return lastExecuteSql; + } + + public void closeOnCompletion() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + public boolean isCloseOnCompletion() throws SQLException { + throw new SQLFeatureNotSupportedException(); + } + + @Override + public Map getParameters() { + return Collections.emptyMap(); + } + + public JdbcSqlStat getSqlStat() { + return sqlStat; + } + + public void setSqlStat(JdbcSqlStat sqlStat) { + this.sqlStat = sqlStat; + } + + public long getLastExecuteTimeNano() { + return lastExecuteTimeNano; + } + + public void setLastExecuteTimeNano(long lastExecuteTimeNano) { + this.lastExecuteTimeNano = lastExecuteTimeNano; + } + + public void setLastExecuteTimeNano() { + if (this.lastExecuteTimeNano <= 0 && this.lastExecuteStartNano > 0) { + this.lastExecuteTimeNano = System.nanoTime() - this.lastExecuteStartNano; + } + } + + public long getLastExecuteStartNano() { + return lastExecuteStartNano; + } + + public void setLastExecuteStartNano(long lastExecuteStartNano) { + this.lastExecuteStartNano = lastExecuteStartNano; + this.lastExecuteTimeNano = -1L; + } + + public void setLastExecuteStartNano() { + if (lastExecuteStartNano <= 0) { + setLastExecuteStartNano(System.nanoTime()); + } + } + + public StatementExecuteType getLastExecuteType() { + return lastExecuteType; + } + + public boolean isFirstResultSet() { + return firstResultSet; + } + + @SuppressWarnings("unchecked") + public T unwrap(Class iface) throws SQLException { + if (iface == StatementProxy.class) { + return (T) this; + } + + return super.unwrap(iface); + } + + public boolean isWrapperFor(Class iface) throws SQLException { + if (iface == StatementProxy.class) { + return true; + } + + return super.isWrapperFor(iface); + } + + @Override + public int getParametersSize() { + return 0; + } + + @Override + public JdbcParameter getParameter(int i) { + return null; + } +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxy.java b/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxy.java index 0f03390009..b49dab027e 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxy.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxy.java @@ -1,31 +1,39 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.sql.Wrapper; -import java.util.Map; - -/** - * @author wenshao - */ -public interface WrapperProxy extends Wrapper { - - long getId(); - - Object getRawObject(); - - Map getAttributes(); -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.Wrapper; +import java.util.Map; + +/** + * @author wenshao + */ +public interface WrapperProxy extends Wrapper { + + long getId(); + + Object getRawObject(); + + int getAttributesSize(); + + void clearAttributes(); + + Map getAttributes(); + + Object getAttribute(String key); + + void putAttribute(String key, Object value); +} diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxyImpl.java index 4afc514d25..0f9dd2e9f6 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/WrapperProxyImpl.java @@ -1,82 +1,116 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.proxy.jdbc; - -import java.sql.SQLException; -import java.sql.Wrapper; -import java.util.HashMap; -import java.util.Map; - -import com.alibaba.druid.filter.FilterChain; - -/** - * @author wenshao - */ -public abstract class WrapperProxyImpl implements WrapperProxy { - - private final Wrapper raw; - - private final long id; - - private final Map attributes = new HashMap(4); // 不需要线程安全 - - public WrapperProxyImpl(Wrapper wrapper, long id){ - this.raw = wrapper; - this.id = id; - } - - public long getId() { - return this.id; - } - - public Object getRawObject() { - return raw; - } - - public abstract FilterChain createChain(); - - @Override - public boolean isWrapperFor(Class iface) throws SQLException { - if (iface == null) { - return false; - } - - if (iface == this.getClass()) { - return true; - } - - return createChain().isWrapperFor(raw, iface); - } - - @SuppressWarnings("unchecked") - @Override - public T unwrap(Class iface) throws SQLException { - if (iface == null) { - return null; - } - - if (iface == this.getClass()) { - return (T) this; - } - - return createChain().unwrap(raw, iface); - } - - public Map getAttributes() { - return this.attributes; - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.proxy.jdbc; + +import java.sql.SQLException; +import java.sql.Wrapper; +import java.util.HashMap; +import java.util.Map; + +import com.alibaba.druid.filter.FilterChain; + +/** + * @author wenshao + */ +public abstract class WrapperProxyImpl implements WrapperProxy { + + private final Wrapper raw; + + private final long id; + + private Map attributes; // 不需要线程安全 + + public WrapperProxyImpl(Wrapper wrapper, long id){ + this.raw = wrapper; + this.id = id; + } + + public long getId() { + return this.id; + } + + public Object getRawObject() { + return raw; + } + + public abstract FilterChain createChain(); + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + if (iface == null) { + return false; + } + + if (iface == this.getClass()) { + return true; + } + + return createChain().isWrapperFor(raw, iface); + } + + @SuppressWarnings("unchecked") + @Override + public T unwrap(Class iface) throws SQLException { + if (iface == null) { + return null; + } + + if (iface == this.getClass()) { + return (T) this; + } + + return createChain().unwrap(raw, iface); + } + + public int getAttributesSize() { + if (attributes == null) { + return 0; + } + + return attributes.size(); + } + + public void clearAttributes() { + if (this.attributes == null) { + return; + } + + this.attributes.clear(); + } + + public Map getAttributes() { + if (attributes == null) { + attributes = new HashMap(4); + } + return this.attributes; + } + + public void putAttribute(String key, Object value) { + if (attributes == null) { + attributes = new HashMap(4); + } + this.attributes.put(key, value); + } + + public Object getAttribute(String key){ + if (attributes == null) { + return null; + } + + return this.attributes.get(key); + } + +} diff --git a/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java b/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java index 258dee05cd..055e1ee4f1 100644 --- a/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java +++ b/src/main/java/com/alibaba/druid/sql/ast/SQLObjectImpl.java @@ -48,6 +48,10 @@ public abstract class SQLObjectImpl implements SQLObject, Serializable { protected abstract void accept0(SQLASTVisitor visitor); protected final void acceptChild(SQLASTVisitor visitor, List children) { + if (children == null) { + return; + } + for (SQLObject child : children) { acceptChild(visitor, child); } diff --git a/src/main/java/com/alibaba/druid/sql/ast/statement/SQLTableSourceImpl.java b/src/main/java/com/alibaba/druid/sql/ast/statement/SQLTableSourceImpl.java index cf700cff3d..70844c3707 100644 --- a/src/main/java/com/alibaba/druid/sql/ast/statement/SQLTableSourceImpl.java +++ b/src/main/java/com/alibaba/druid/sql/ast/statement/SQLTableSourceImpl.java @@ -1,57 +1,67 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.sql.ast.statement; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.druid.sql.ast.SQLHint; -import com.alibaba.druid.sql.ast.SQLObjectImpl; - -public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource { - - private static final long serialVersionUID = 1L; - - protected String alias; - - protected List hints = new ArrayList(2); - - public SQLTableSourceImpl(){ - - } - - public SQLTableSourceImpl(String alias){ - - this.alias = alias; - } - - public String getAlias() { - return this.alias; - } - - public void setAlias(String alias) { - this.alias = alias; - } - - public List getHints() { - return hints; - } - - public void setHints(List hints) { - this.hints = hints; - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.sql.ast.statement; + +import java.util.ArrayList; +import java.util.List; + +import com.alibaba.druid.sql.ast.SQLHint; +import com.alibaba.druid.sql.ast.SQLObjectImpl; + +public abstract class SQLTableSourceImpl extends SQLObjectImpl implements SQLTableSource { + + private static final long serialVersionUID = 1L; + + protected String alias; + + protected List hints; + + public SQLTableSourceImpl(){ + + } + + public SQLTableSourceImpl(String alias){ + + this.alias = alias; + } + + public String getAlias() { + return this.alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public int getHintsSize() { + if (hints == null) { + return 0; + } + + return hints.size(); + } + + public List getHints() { + if (hints == null) { + hints = new ArrayList(2); + } + return hints; + } + + public void setHints(List hints) { + this.hints = hints; + } +} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/ast/statement/MySqlSelectQueryBlock.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/ast/statement/MySqlSelectQueryBlock.java index 45139561ae..74138433d5 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/ast/statement/MySqlSelectQueryBlock.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/ast/statement/MySqlSelectQueryBlock.java @@ -1,252 +1,266 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.sql.dialect.mysql.ast.statement; - -import java.util.ArrayList; -import java.util.List; - -import com.alibaba.druid.sql.ast.SQLCommentHint; -import com.alibaba.druid.sql.ast.SQLExpr; -import com.alibaba.druid.sql.ast.SQLName; -import com.alibaba.druid.sql.ast.SQLObjectImpl; -import com.alibaba.druid.sql.ast.SQLOrderBy; -import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject; -import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor; -import com.alibaba.druid.sql.visitor.SQLASTVisitor; - -@SuppressWarnings("serial") -public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlObject { - - private boolean hignPriority; - private boolean straightJoin; - - private boolean smallResult; - private boolean bigResult; - private boolean bufferResult; - private Boolean cache; - private boolean calcFoundRows; - - private SQLOrderBy orderBy; - - private Limit limit; - - private SQLName procedureName; - private List procedureArgumentList = new ArrayList(); - - private boolean forUpdate = false; - private boolean lockInShareMode = false; - - private List hints = new ArrayList(); - - public MySqlSelectQueryBlock(){ - - } - - public List getHints() { - return hints; - } - - public void setHints(List hints) { - this.hints = hints; - } - - public boolean isForUpdate() { - return forUpdate; - } - - public void setForUpdate(boolean forUpdate) { - this.forUpdate = forUpdate; - } - - public boolean isLockInShareMode() { - return lockInShareMode; - } - - public void setLockInShareMode(boolean lockInShareMode) { - this.lockInShareMode = lockInShareMode; - } - - public SQLName getProcedureName() { - return procedureName; - } - - public void setProcedureName(SQLName procedureName) { - this.procedureName = procedureName; - } - - public List getProcedureArgumentList() { - return procedureArgumentList; - } - - public void setProcedureArgumentList(List procedureArgumentList) { - this.procedureArgumentList = procedureArgumentList; - } - - public boolean isHignPriority() { - return hignPriority; - } - - public void setHignPriority(boolean hignPriority) { - this.hignPriority = hignPriority; - } - - public boolean isStraightJoin() { - return straightJoin; - } - - public void setStraightJoin(boolean straightJoin) { - this.straightJoin = straightJoin; - } - - public boolean isSmallResult() { - return smallResult; - } - - public void setSmallResult(boolean smallResult) { - this.smallResult = smallResult; - } - - public boolean isBigResult() { - return bigResult; - } - - public void setBigResult(boolean bigResult) { - this.bigResult = bigResult; - } - - public boolean isBufferResult() { - return bufferResult; - } - - public void setBufferResult(boolean bufferResult) { - this.bufferResult = bufferResult; - } - - public Boolean getCache() { - return cache; - } - - public void setCache(Boolean cache) { - this.cache = cache; - } - - public boolean isCalcFoundRows() { - return calcFoundRows; - } - - public void setCalcFoundRows(boolean calcFoundRows) { - this.calcFoundRows = calcFoundRows; - } - - public SQLOrderBy getOrderBy() { - return orderBy; - } - - public void setOrderBy(SQLOrderBy orderBy) { - this.orderBy = orderBy; - } - - public Limit getLimit() { - return limit; - } - - public void setLimit(Limit limit) { - if (limit != null) { - limit.setParent(this); - } - this.limit = limit; - } - - @Override - protected void accept0(SQLASTVisitor visitor) { - if (visitor instanceof MySqlASTVisitor) { - accept0((MySqlASTVisitor) visitor); - return; - } - - if (visitor.visit(this)) { - acceptChild(visitor, this.selectList); - acceptChild(visitor, this.from); - acceptChild(visitor, this.where); - acceptChild(visitor, this.groupBy); - acceptChild(visitor, this.orderBy); - acceptChild(visitor, this.limit); - acceptChild(visitor, this.procedureName); - acceptChild(visitor, this.procedureArgumentList); - acceptChild(visitor, this.into); - } - - visitor.endVisit(this); - } - - @Override - public void accept0(MySqlASTVisitor visitor) { - if (visitor.visit(this)) { - acceptChild(visitor, this.selectList); - acceptChild(visitor, this.from); - acceptChild(visitor, this.where); - acceptChild(visitor, this.groupBy); - acceptChild(visitor, this.orderBy); - acceptChild(visitor, this.limit); - acceptChild(visitor, this.procedureName); - acceptChild(visitor, this.procedureArgumentList); - acceptChild(visitor, this.into); - } - - visitor.endVisit(this); - } - - public static class Limit extends SQLObjectImpl { - - public Limit(){ - - } - - private SQLExpr rowCount; - private SQLExpr offset; - - public SQLExpr getRowCount() { - return rowCount; - } - - public void setRowCount(SQLExpr rowCount) { - this.rowCount = rowCount; - } - - public SQLExpr getOffset() { - return offset; - } - - public void setOffset(SQLExpr offset) { - this.offset = offset; - } - - @Override - protected void accept0(SQLASTVisitor visitor) { - if (visitor instanceof MySqlASTVisitor) { - MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor; - - if (mysqlVisitor.visit(this)) { - acceptChild(visitor, offset); - acceptChild(visitor, rowCount); - } - } - } - - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.sql.dialect.mysql.ast.statement; + +import java.util.ArrayList; +import java.util.List; + +import com.alibaba.druid.sql.ast.SQLCommentHint; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.SQLName; +import com.alibaba.druid.sql.ast.SQLObjectImpl; +import com.alibaba.druid.sql.ast.SQLOrderBy; +import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObject; +import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor; +import com.alibaba.druid.sql.visitor.SQLASTVisitor; + +@SuppressWarnings("serial") +public class MySqlSelectQueryBlock extends SQLSelectQueryBlock implements MySqlObject { + + private boolean hignPriority; + private boolean straightJoin; + + private boolean smallResult; + private boolean bigResult; + private boolean bufferResult; + private Boolean cache; + private boolean calcFoundRows; + + private SQLOrderBy orderBy; + + private Limit limit; + + private SQLName procedureName; + private List procedureArgumentList; + + private boolean forUpdate = false; + private boolean lockInShareMode = false; + + private List hints; + + public MySqlSelectQueryBlock(){ + + } + + public int getHintsSize() { + if (hints == null) { + return 0; + } + + return hints.size(); + } + + public List getHints() { + if (hints == null) { + hints = new ArrayList(2); + } + return hints; + } + + public void setHints(List hints) { + this.hints = hints; + } + + public boolean isForUpdate() { + return forUpdate; + } + + public void setForUpdate(boolean forUpdate) { + this.forUpdate = forUpdate; + } + + public boolean isLockInShareMode() { + return lockInShareMode; + } + + public void setLockInShareMode(boolean lockInShareMode) { + this.lockInShareMode = lockInShareMode; + } + + public SQLName getProcedureName() { + return procedureName; + } + + public void setProcedureName(SQLName procedureName) { + this.procedureName = procedureName; + } + + public List getProcedureArgumentList() { + if (procedureArgumentList == null) { + procedureArgumentList = new ArrayList(2); + } + return procedureArgumentList; + } + + public void setProcedureArgumentList(List procedureArgumentList) { + this.procedureArgumentList = procedureArgumentList; + } + + public boolean isHignPriority() { + return hignPriority; + } + + public void setHignPriority(boolean hignPriority) { + this.hignPriority = hignPriority; + } + + public boolean isStraightJoin() { + return straightJoin; + } + + public void setStraightJoin(boolean straightJoin) { + this.straightJoin = straightJoin; + } + + public boolean isSmallResult() { + return smallResult; + } + + public void setSmallResult(boolean smallResult) { + this.smallResult = smallResult; + } + + public boolean isBigResult() { + return bigResult; + } + + public void setBigResult(boolean bigResult) { + this.bigResult = bigResult; + } + + public boolean isBufferResult() { + return bufferResult; + } + + public void setBufferResult(boolean bufferResult) { + this.bufferResult = bufferResult; + } + + public Boolean getCache() { + return cache; + } + + public void setCache(Boolean cache) { + this.cache = cache; + } + + public boolean isCalcFoundRows() { + return calcFoundRows; + } + + public void setCalcFoundRows(boolean calcFoundRows) { + this.calcFoundRows = calcFoundRows; + } + + public SQLOrderBy getOrderBy() { + return orderBy; + } + + public void setOrderBy(SQLOrderBy orderBy) { + this.orderBy = orderBy; + } + + public Limit getLimit() { + return limit; + } + + public void setLimit(Limit limit) { + if (limit != null) { + limit.setParent(this); + } + this.limit = limit; + } + + @Override + protected void accept0(SQLASTVisitor visitor) { + if (visitor instanceof MySqlASTVisitor) { + accept0((MySqlASTVisitor) visitor); + return; + } + + if (visitor.visit(this)) { + acceptChild(visitor, this.selectList); + acceptChild(visitor, this.from); + acceptChild(visitor, this.where); + acceptChild(visitor, this.groupBy); + acceptChild(visitor, this.orderBy); + acceptChild(visitor, this.limit); + acceptChild(visitor, this.procedureName); + acceptChild(visitor, this.procedureArgumentList); + acceptChild(visitor, this.into); + } + + visitor.endVisit(this); + } + + @Override + public void accept0(MySqlASTVisitor visitor) { + if (visitor.visit(this)) { + acceptChild(visitor, this.selectList); + acceptChild(visitor, this.from); + acceptChild(visitor, this.where); + acceptChild(visitor, this.groupBy); + acceptChild(visitor, this.orderBy); + acceptChild(visitor, this.limit); + acceptChild(visitor, this.procedureName); + acceptChild(visitor, this.procedureArgumentList); + acceptChild(visitor, this.into); + } + + visitor.endVisit(this); + } + + public static class Limit extends SQLObjectImpl { + + public Limit(){ + + } + + private SQLExpr rowCount; + private SQLExpr offset; + + public SQLExpr getRowCount() { + return rowCount; + } + + public void setRowCount(SQLExpr rowCount) { + this.rowCount = rowCount; + } + + public SQLExpr getOffset() { + return offset; + } + + public void setOffset(SQLExpr offset) { + this.offset = offset; + } + + @Override + protected void accept0(SQLASTVisitor visitor) { + if (visitor instanceof MySqlASTVisitor) { + MySqlASTVisitor mysqlVisitor = (MySqlASTVisitor) visitor; + + if (mysqlVisitor.visit(this)) { + acceptChild(visitor, offset); + acceptChild(visitor, rowCount); + } + } + } + + } + +} diff --git a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java index f6651c53a9..e1efa7860e 100644 --- a/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java +++ b/src/main/java/com/alibaba/druid/sql/dialect/mysql/visitor/MySqlOutputVisitor.java @@ -1,3063 +1,3064 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.sql.dialect.mysql.visitor; - -import java.util.List; -import java.util.Map; - -import com.alibaba.druid.sql.ast.SQLCommentHint; -import com.alibaba.druid.sql.ast.SQLDataType; -import com.alibaba.druid.sql.ast.SQLExpr; -import com.alibaba.druid.sql.ast.SQLObject; -import com.alibaba.druid.sql.ast.SQLSetQuantifier; -import com.alibaba.druid.sql.ast.expr.SQLCharExpr; -import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; -import com.alibaba.druid.sql.ast.expr.SQLNullExpr; -import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem; -import com.alibaba.druid.sql.ast.statement.SQLAssignItem; -import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType; -import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint; -import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; -import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForeignKey; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique; -import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBinaryExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBooleanExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr; -import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddColumn; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddIndex; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddUnique; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableCharacter; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableDiscardTablespace; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTablespace; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateIndexStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDescribeStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropUser; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropViewStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExecuteStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHelpStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByList; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByRange; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef.InValues; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef.LessThanValues; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlResetStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRollbackStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSQLColumnDefinition; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectGroupBy; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionIsolationLevelStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowAuthorsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinLogEventsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinaryLogsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCharacterSetStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCollationStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowColumnsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEventsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionCodeStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowGrantsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowIndexesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowKeysStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowOpenTablesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPluginsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPrivilegesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureCodeStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcessListStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfileStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfilesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowRelayLogEventsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveHostsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTableStatusStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement; -import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement; -import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor; - -public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTVisitor { - - public MySqlOutputVisitor(Appendable appender){ - super(appender); - } - - public boolean visit(MySqlBooleanExpr x) { - print(x.getValue() ? "true" : "false"); - - return false; - } - - public void endVisit(MySqlBooleanExpr x) { - } - - @Override - public boolean visit(SQLSelectQueryBlock select) { - if (select instanceof MySqlSelectQueryBlock) { - return visit((MySqlSelectQueryBlock) select); - } - - return false; - } - - public boolean visit(MySqlSelectQueryBlock x) { - if (x.getOrderBy() != null) { - x.getOrderBy().setParent(x); - } - - print("SELECT "); - - for (SQLCommentHint hint : x.getHints()) { - hint.accept(this); - print(' '); - } - - if (SQLSetQuantifier.ALL == x.getDistionOption()) { - print("ALL "); - } else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) { - print("DISTINCT "); - } else if (SQLSetQuantifier.DISTINCTROW == x.getDistionOption()) { - print("DISTINCTROW "); - } - - if (x.isHignPriority()) { - print("HIGH_PRIORITY "); - } - - if (x.isStraightJoin()) { - print("STRAIGHT_JOIN "); - } - - if (x.isSmallResult()) { - print("SQL_SMALL_RESULT "); - } - - if (x.isBigResult()) { - print("SQL_BIG_RESULT "); - } - - if (x.isBufferResult()) { - print("SQL_BUFFER_RESULT "); - } - - if (x.getCache() != null) { - if (x.getCache().booleanValue()) { - print("SQL_CACHE "); - } else { - print("SQL_NO_CACHE "); - } - } - - if (x.isCalcFoundRows()) { - print("SQL_CALC_FOUND_ROWS "); - } - - printSelectList(x.getSelectList()); - - if (x.getInto() != null) { - println(); - print("INTO "); - x.getInto().accept(this); - } - - if (x.getFrom() != null) { - println(); - print("FROM "); - x.getFrom().accept(this); - } - - if (x.getWhere() != null) { - println(); - print("WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - if (x.getGroupBy() != null) { - println(); - x.getGroupBy().accept(this); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - if (x.getLimit() != null) { - println(); - x.getLimit().accept(this); - } - - if (x.getProcedureName() != null) { - print(" PROCEDURE "); - x.getProcedureName().accept(this); - if (x.getProcedureArgumentList().size() > 0) { - print("("); - printAndAccept(x.getProcedureArgumentList(), ", "); - print(")"); - } - } - - if (x.isForUpdate()) { - println(); - print("FOR UPDATE"); - } - - if (x.isLockInShareMode()) { - println(); - print("LOCK IN SHARE MODE"); - } - - return false; - } - - public boolean visit(SQLColumnDefinition x) { - MySqlSQLColumnDefinition mysqlColumn = null; - - if (x instanceof MySqlSQLColumnDefinition) { - mysqlColumn = (MySqlSQLColumnDefinition) x; - } - - x.getName().accept(this); - print(' '); - x.getDataType().accept(this); - - if (x.getDefaultExpr() != null) { - if (x.getDefaultExpr() instanceof SQLNullExpr) { - print(" NULL"); - } else { - print(" DEFAULT"); - x.getDefaultExpr().accept(this); - } - } - - if (mysqlColumn != null && mysqlColumn.getStorage() != null) { - print(" STORAGE "); - mysqlColumn.getStorage().accept(this); - } - - if (mysqlColumn != null && mysqlColumn.getOnUpdate() != null) { - print(" ON UPDATE "); - - mysqlColumn.getOnUpdate().accept(this); - } - - if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) { - print(" AUTO_INCREMENT"); - } - - for (SQLColumnConstraint item : x.getConstaints()) { - print(' '); - item.accept(this); - } - - return false; - } - - public boolean visit(MySqlSelectQueryBlock.Limit x) { - print("LIMIT "); - if (x.getOffset() != null) { - x.getOffset().accept(this); - print(", "); - } - x.getRowCount().accept(this); - - return false; - } - - public boolean visit(SQLDataType x) { - print(x.getName()); - if (x.getArguments().size() > 0) { - print("("); - printAndAccept(x.getArguments(), ", "); - print(")"); - } - - if (Boolean.TRUE == x.getAttribute("unsigned")) { - print(" unsigned"); - } - - if (x instanceof SQLCharactorDataType) { - SQLCharactorDataType charType = (SQLCharactorDataType) x; - if (charType.getCharSetName() != null) { - print(" CHARACTER SET "); - print(charType.getCharSetName()); - - if (charType.getCollate() != null) { - print(" COLLATE "); - print(charType.getCollate()); - } - } - } - return false; - } - - public boolean visit(SQLCharactorDataType x) { - print(x.getName()); - if (x.getArguments().size() > 0) { - print("("); - printAndAccept(x.getArguments(), ", "); - print(")"); - } - - if (x.getCharSetName() != null) { - print(" CHARACTER SET "); - print(x.getCharSetName()); - - if (x.getCollate() != null) { - print(" COLLATE "); - print(x.getCollate()); - } - } - return false; - } - - @Override - public void endVisit(Limit x) { - - } - - @Override - public void endVisit(MySqlTableIndex x) { - - } - - @Override - public boolean visit(MySqlTableIndex x) { - print("INDEX"); - if (x.getName() != null) { - print(" "); - x.getName().accept(this); - } - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print("("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - return false; - } - - public boolean visit(MySqlCreateTableStatement x) { - - print("CREATE "); - - for (SQLCommentHint hint : x.getHints()) { - hint.accept(this); - print(' '); - } - - if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { - print("TEMPORARY TABLE "); - } else { - print("TABLE "); - } - - if (x.isIfNotExiists()) { - print("IF NOT EXISTS "); - } - - x.getName().accept(this); - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - int size = x.getTableElementList().size(); - if (size > 0) { - print(" ("); - incrementIndent(); - println(); - for (int i = 0; i < size; ++i) { - if (i != 0) { - print(", "); - println(); - } - x.getTableElementList().get(i).accept(this); - } - decrementIndent(); - println(); - print(")"); - } - - for (Map.Entry option : x.getTableOptions().entrySet()) { - String key = option.getKey(); - - print(' '); - print(key); - - if ("TABLESPACE".equals(key)) { - print(' '); - option.getValue().accept(this); - continue; - } - - print(" = "); - - option.getValue().accept(this); - } - - if (x.getPartitioning() != null) { - print(' '); - x.getPartitioning().accept(this); - } - - if (x.getQuery() != null) { - incrementIndent(); - println(); - x.getQuery().accept(this); - decrementIndent(); - } - - return false; - } - - @Override - public void endVisit(MySqlKey x) { - - } - - @Override - public void endVisit(MySqlPrimaryKey x) { - - } - - @Override - public boolean visit(MySqlKey x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - - print("KEY"); - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print(" ("); - - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - - return false; - } - - @Override - public boolean visit(MySqlPrimaryKey x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - - print("PRIAMRY KEY"); - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print(" ("); - - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - - return false; - } - - public boolean visit(SQLCharExpr x) { - print('\''); - - String text = x.getText(); - text = text.replaceAll("'", "''"); - text = text.replaceAll("\\\\", "\\\\"); - - print(text); - - print('\''); - return false; - } - - public boolean visit(SQLVariantRefExpr x) { - { - List parameters = this.getParameters(); - int index = x.getIndex(); - - if (parameters != null && index >= 0 && index < parameters.size()) { - Object param = parameters.get(index); - printParameter(param); - return false; - } - } - - String varName = x.getName(); - if (x.isGlobal()) { - print("@@global."); - } else { - if ((!varName.startsWith("@")) // / - && (!varName.equals("?")) // - && (!varName.startsWith("#")) // - && (!varName.startsWith("$")) // - && (!varName.startsWith(":")) - ) { - print("@@"); - } - } - - for (int i = 0; i < x.getName().length(); ++i) { - char ch = x.getName().charAt(i); - if (ch == '\'') { - if (x.getName().startsWith("@@") && i == 2) { - print(ch); - } else if (x.getName().startsWith("@") && i == 1) { - print(ch); - } else if (i != 0 && i != x.getName().length() - 1) { - print("\\'"); - } else { - print(ch); - } - } else { - print(ch); - } - } - - String collate = (String) x.getAttribute("COLLATE"); - if (collate != null) { - print(" COLLATE "); - print(collate); - } - - return false; - } - - public boolean visit(SQLMethodInvokeExpr x) { - if ("SUBSTRING".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - printAndAccept(x.getParameters(), ", "); - SQLExpr from = (SQLExpr) x.getAttribute("FROM"); - if (from != null) { - print(" FROM "); - from.accept(this); - } - - SQLExpr forExpr = (SQLExpr) x.getAttribute("FOR"); - if (forExpr != null) { - print(" FOR "); - forExpr.accept(this); - } - print(")"); - - return false; - } - - if ("TRIM".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - - String trimType = (String) x.getAttribute("TRIM_TYPE"); - if (trimType != null) { - print(trimType); - print(' '); - } - - printAndAccept(x.getParameters(), ", "); - - SQLExpr from = (SQLExpr) x.getAttribute("FROM"); - if (from != null) { - print(" FROM "); - from.accept(this); - } - - print(")"); - - return false; - } - - if ("CONVERT".equalsIgnoreCase(x.getMethodName())) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - printAndAccept(x.getParameters(), ", "); - - String charset = (String) x.getAttribute("USING"); - if (charset != null) { - print(" USING "); - print(charset); - } - print(")"); - return false; - } - - return super.visit(x); - } - - @Override - public void endVisit(MySqlIntervalExpr x) { - - } - - @Override - public boolean visit(MySqlIntervalExpr x) { - print("INTERVAL "); - x.getValue().accept(this); - print(' '); - print(x.getUnit().name()); - return false; - } - - @Override - public boolean visit(MySqlExtractExpr x) { - print("EXTRACT("); - print(x.getUnit().name()); - print(" FROM "); - x.getValue().accept(this); - print(')'); - return false; - } - - @Override - public void endVisit(MySqlExtractExpr x) { - - } - - @Override - public void endVisit(MySqlMatchAgainstExpr x) { - - } - - @Override - public boolean visit(MySqlMatchAgainstExpr x) { - print("MATCH ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - - print(" AGAINST ("); - x.getAgainst().accept(this); - if (x.getSearchModifier() != null) { - print(' '); - print(x.getSearchModifier().name); - } - print(')'); - - return false; - } - - @Override - public void endVisit(MySqlBinaryExpr x) { - - } - - @Override - public boolean visit(MySqlBinaryExpr x) { - print("b'"); - print(x.getValue()); - print('\''); - - return false; - } - - @Override - public void endVisit(MySqlPrepareStatement x) { - } - - @Override - public boolean visit(MySqlPrepareStatement x) { - print("PREPARE "); - x.getName().accept(this); - print(" FROM "); - x.getFrom().accept(this); - return false; - } - - @Override - public void endVisit(MySqlExecuteStatement x) { - - } - - @Override - public boolean visit(MySqlExecuteStatement x) { - print("EXECUTE "); - x.getStatementName().accept(this); - if (x.getParameters().size() > 0) { - print(" USING "); - printAndAccept(x.getParameters(), ", "); - } - return false; - } - - @Override - public void endVisit(MySqlDeleteStatement x) { - - } - - @Override - public boolean visit(MySqlDeleteStatement x) { - print("DELETE "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isQuick()) { - print("QUICK "); - } - - if (x.isIgnore()) { - print("IGNORE "); - } - - if (x.getFrom() == null) { - print("FROM "); - x.getTableSource().accept(this); - } else { - x.getTableSource().accept(this); - println(); - print("FROM "); - x.getFrom().accept(this); - } - - if (x.getUsing() != null) { - println(); - print("USING "); - x.getUsing().accept(this); - } - - if (x.getWhere() != null) { - println(); - incrementIndent(); - print("WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - decrementIndent(); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - if (x.getLimit() != null) { - println(); - x.getLimit().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlInsertStatement x) { - - } - - @Override - public boolean visit(MySqlInsertStatement x) { - print("INSERT "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isDelayed()) { - print("DELAYED "); - } - - if (x.isHighPriority()) { - print("HIGH_PRIORITY "); - } - - if (x.isIgnore()) { - print("IGNORE "); - } - - print("INTO "); - - x.getTableSource().accept(this); - - if (x.getColumns().size() > 0) { - incrementIndent(); - print(" ("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - print(", "); - } - - x.getColumns().get(i).accept(this); - } - print(")"); - decrementIndent(); - } - - if (x.getValuesList().size() != 0) { - println(); - print("VALUES "); - if (x.getValuesList().size() > 1) { - incrementIndent(); - } - for (int i = 0, size = x.getValuesList().size(); i < size; ++i) { - if (i != 0) { - print(","); - println(); - } - x.getValuesList().get(i).accept(this); - } - if (x.getValuesList().size() > 1) { - decrementIndent(); - } - } - - if (x.getQuery() != null) { - println(); - x.getQuery().accept(this); - } - - if (x.getDuplicateKeyUpdate().size() != 0) { - println(); - print("ON DUPLICATE KEY UPDATE "); - for (int i = 0, size = x.getDuplicateKeyUpdate().size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - print(", "); - } - x.getDuplicateKeyUpdate().get(i).accept(this); - } - } - - return false; - } - - @Override - public void endVisit(MySqlLoadDataInFileStatement x) { - - } - - @Override - public boolean visit(MySqlLoadDataInFileStatement x) { - print("LOAD DATA "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isConcurrent()) { - print("CONCURRENT "); - } - - if (x.isLocal()) { - print("LOCAL "); - } - - print("INFILE "); - - x.getFileName().accept(this); - - if (x.isReplicate()) { - print(" REPLACE "); - } - - if (x.isIgnore()) { - print(" IGNORE "); - } - - print(" INTO TABLE "); - x.getTableName().accept(this); - - if (x.getColumnsTerminatedBy() != null || x.getColumnsEnclosedBy() != null || x.getColumnsEscaped() != null) { - print(" COLUMNS"); - if (x.getColumnsTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getColumnsTerminatedBy().accept(this); - } - - if (x.getColumnsEnclosedBy() != null) { - if (x.isColumnsEnclosedOptionally()) { - print(" OPTIONALLY"); - } - print(" ENCLOSED BY "); - x.getColumnsEnclosedBy().accept(this); - } - - if (x.getColumnsEscaped() != null) { - print(" ESCAPED BY "); - x.getColumnsEscaped().accept(this); - } - } - - if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { - print(" LINES"); - if (x.getLinesStartingBy() != null) { - print(" STARTING BY "); - x.getLinesStartingBy().accept(this); - } - - if (x.getLinesTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getLinesTerminatedBy().accept(this); - } - } - - if (x.getSetList().size() != 0) { - print(" SET "); - printAndAccept(x.getSetList(), ", "); - } - - return false; - } - - @Override - public void endVisit(MySqlReplaceStatement x) { - - } - - @Override - public boolean visit(MySqlReplaceStatement x) { - print("REPLACE "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isDelayed()) { - print("DELAYED "); - } - - print("INTO "); - - x.getTableName().accept(this); - - if (x.getColumns().size() > 0) { - print(" ("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - } - - if (x.getValuesList().size() != 0) { - println(); - print("VALUES "); - int size = x.getValuesList().size(); - if (size == 0) { - print("()"); - } else { - for (int i = 0; i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getValuesList().get(i).accept(this); - } - } - } - - if (x.getQuery() != null) { - x.getQuery().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlSelectGroupBy x) { - - } - - @Override - public boolean visit(MySqlSelectGroupBy x) { - super.visit(x); - - if (x.isRollUp()) { - print(" WITH ROLLUP"); - } - - return false; - } - - @Override - public void endVisit(MySqlStartTransactionStatement x) { - - } - - @Override - public boolean visit(MySqlStartTransactionStatement x) { - print("START TRANSACTION"); - if (x.isConsistentSnapshot()) { - print(" WITH CONSISTENT SNAPSHOT"); - } - - if (x.isBegin()) { - print(" BEGIN"); - } - - if (x.isWork()) { - print(" WORK"); - } - - return false; - } - - @Override - public void endVisit(MySqlCommitStatement x) { - - } - - @Override - public boolean visit(MySqlCommitStatement x) { - print("COMMIT"); - - if (x.isWork()) { - print(" WORK"); - } - - if (x.getChain() != null) { - if (x.getChain().booleanValue()) { - print(" AND CHAIN"); - } else { - print(" AND NO CHAIN"); - } - } - - if (x.getRelease() != null) { - if (x.getRelease().booleanValue()) { - print(" AND RELEASE"); - } else { - print(" AND NO RELEASE"); - } - } - - return false; - } - - @Override - public void endVisit(MySqlRollbackStatement x) { - - } - - @Override - public boolean visit(MySqlRollbackStatement x) { - print("ROLLBACK"); - - if (x.getChain() != null) { - if (x.getChain().booleanValue()) { - print(" AND CHAIN"); - } else { - print(" AND NO CHAIN"); - } - } - - if (x.getRelease() != null) { - if (x.getRelease().booleanValue()) { - print(" AND RELEASE"); - } else { - print(" AND NO RELEASE"); - } - } - - if (x.getTo() != null) { - print(" TO "); - x.getTo().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowColumnsStatement x) { - - } - - @Override - public boolean visit(MySqlShowColumnsStatement x) { - if (x.isFull()) { - print("SHOW FULL COLUMNS"); - } else { - print("SHOW COLUMNS"); - } - - if (x.getTable() != null) { - print(" FROM "); - if (x.getDatabase() != null) { - x.getDatabase().accept(this); - print('.'); - } - x.getTable().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowTablesStatement x) { - - } - - @Override - public boolean visit(MySqlShowTablesStatement x) { - if (x.isFull()) { - print("SHOW FULL TABLES"); - } else { - print("SHOW TABLES"); - } - - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowDatabasesStatement x) { - - } - - @Override - public boolean visit(MySqlShowDatabasesStatement x) { - print("SHOW DATABASES"); - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowWarningsStatement x) { - - } - - @Override - public boolean visit(MySqlShowWarningsStatement x) { - if (x.isCount()) { - print("SHOW COUNT(*) WARNINGS"); - } else { - print("SHOW WARNINGS"); - if (x.getLimit() != null) { - print(' '); - x.getLimit().accept(this); - } - } - - return false; - } - - @Override - public void endVisit(MySqlShowStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowStatusStatement x) { - print("SHOW "); - - if (x.isGlobal()) { - print("GLOBAL "); - } - - if (x.isSession()) { - print("SESSION "); - } - - print("STATUS"); - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlLoadXmlStatement x) { - - } - - @Override - public boolean visit(MySqlLoadXmlStatement x) { - print("LOAD XML "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isConcurrent()) { - print("CONCURRENT "); - } - - if (x.isLocal()) { - print("LOCAL "); - } - - print("INFILE "); - - x.getFileName().accept(this); - - if (x.isReplicate()) { - print(" REPLACE "); - } - - if (x.isIgnore()) { - print(" IGNORE "); - } - - print(" INTO TABLE "); - x.getTableName().accept(this); - - if (x.getCharset() != null) { - print(" CHARSET "); - print(x.getCharset()); - } - - if (x.getRowsIdentifiedBy() != null) { - print(" ROWS IDENTIFIED BY "); - x.getRowsIdentifiedBy().accept(this); - } - - if (x.getSetList().size() != 0) { - print(" SET "); - printAndAccept(x.getSetList(), ", "); - } - - return false; - } - - @Override - public void endVisit(CobarShowStatus x) { - - } - - @Override - public boolean visit(CobarShowStatus x) { - print("SHOW COBAR_STATUS"); - return false; - } - - @Override - public void endVisit(MySqlKillStatement x) { - - } - - @Override - public boolean visit(MySqlKillStatement x) { - if (MySqlKillStatement.Type.CONNECTION.equals(x.getType())) { - print("KILL CONNECTION "); - } else if (MySqlKillStatement.Type.QUERY.equals(x.getType())) { - print("KILL QUERY "); - } - x.getThreadId().accept(this); - return false; - } - - @Override - public void endVisit(MySqlBinlogStatement x) { - - } - - @Override - public boolean visit(MySqlBinlogStatement x) { - print("BINLOG "); - x.getExpr().accept(this); - return false; - } - - @Override - public void endVisit(MySqlResetStatement x) { - - } - - @Override - public boolean visit(MySqlResetStatement x) { - print("RESET "); - for (int i = 0; i < x.getOptions().size(); ++i) { - if (i != 0) { - print(", "); - } - print(x.getOptions().get(i)); - } - return false; - } - - @Override - public void endVisit(MySqlCreateUserStatement x) { - - } - - @Override - public boolean visit(MySqlCreateUserStatement x) { - print("CREATE USER "); - printAndAccept(x.getUsers(), ", "); - return false; - } - - @Override - public void endVisit(UserSpecification x) { - - } - - @Override - public boolean visit(UserSpecification x) { - x.getUser().accept(this); - - if (x.getPassword() != null) { - print(" IDENTIFIED BY "); - x.getPassword().accept(this); - } - - if (x.getAuthPlugin() != null) { - print(" IDENTIFIED WITH "); - x.getAuthPlugin().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlDropUser x) { - - } - - @Override - public boolean visit(MySqlDropUser x) { - print("DROP USER "); - printAndAccept(x.getUsers(), ", "); - return false; - } - - @Override - public void endVisit(MySqlDropTableStatement x) { - - } - - @Override - public boolean visit(MySqlDropTableStatement x) { - if (x.isTemporary()) { - print("DROP TEMPORARY TABLE "); - } else { - print("DROP TABLE "); - } - if (x.isIfExists()) { - print("IF EXISTS "); - } - - printAndAccept(x.getTableSources(), ", "); - - if (x.getOption() != null) { - print(' '); - print(x.getOption()); - } - return false; - } - - @Override - public void endVisit(MySqlPartitionByKey x) { - - } - - @Override - public boolean visit(MySqlPartitionByKey x) { - if (x.isLinear()) { - print("PARTITION BY LINEAR KEY ("); - } else { - print("PARTITION BY KEY ("); - } - printAndAccept(x.getColumns(), ", "); - print(")"); - - if (x.getPartitionCount() != null) { - print(" PARTITIONS "); - x.getPartitionCount().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlPartitionByRange x) { - - } - - @Override - public boolean visit(MySqlPartitionByRange x) { - print("PARTITION BY RANGE"); - if (x.getExpr() != null) { - print(" ("); - x.getExpr().accept(this); - print(")"); - } else { - print(" COLUMNS ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - } - - if (x.getPartitionCount() != null) { - print(" PARTITIONS "); - x.getPartitionCount().accept(this); - } - - List partitions = x.getPartitions(); - int partitionsSize = partitions.size(); - if (partitionsSize > 0) { - print("("); - incrementIndent(); - for (int i = 0; i < partitionsSize; ++i) { - println(); - partitions.get(i).accept(this); - if (i != partitionsSize - 1) { - print(", "); - } - } - decrementIndent(); - println(); - print(")"); - } - return false; - } - - @Override - public void endVisit(MySqlPartitionByList x) { - - } - - @Override - public boolean visit(MySqlPartitionByList x) { - print("PARTITION BY LIST "); - if (x.getExpr() != null) { - print("("); - x.getExpr().accept(this); - print(") "); - } else { - print("COLUMNS ("); - printAndAccept(x.getColumns(), ", "); - print(") "); - } - - if (x.getPartitionCount() != null) { - print(" PARTITIONS "); - x.getPartitionCount().accept(this); - } - - List partitions = x.getPartitions(); - int partitionsSize = partitions.size(); - if (partitionsSize > 0) { - print("("); - incrementIndent(); - for (int i = 0; i < partitionsSize; ++i) { - println(); - partitions.get(i).accept(this); - if (i != partitionsSize - 1) { - print(", "); - } - } - decrementIndent(); - println(); - print(")"); - } - return false; - } - - // - - @Override - public void endVisit(MySqlPartitionByHash x) { - - } - - @Override - public boolean visit(MySqlPartitionByHash x) { - if (x.isLinear()) { - print("PARTITION BY LINEAR HASH ("); - } else { - print("PARTITION BY HASH ("); - } - // - x.getExpr().accept(this); - print(")"); - - if (x.getPartitionCount() != null) { - print(" PARTITIONS "); - x.getPartitionCount().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlSelectQueryBlock x) { - - } - - @Override - public boolean visit(MySqlOutFileExpr x) { - print("OUTFILE "); - x.getFile().accept(this); - - if (x.getCharset() != null) { - print(" CHARACTER SET "); - print(x.getCharset()); - } - - if (x.getColumnsTerminatedBy() != null || x.getColumnsEnclosedBy() != null || x.getColumnsEscaped() != null) { - print(" COLUMNS"); - if (x.getColumnsTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getColumnsTerminatedBy().accept(this); - } - - if (x.getColumnsEnclosedBy() != null) { - if (x.isColumnsEnclosedOptionally()) { - print(" OPTIONALLY"); - } - print(" ENCLOSED BY "); - x.getColumnsEnclosedBy().accept(this); - } - - if (x.getColumnsEscaped() != null) { - print(" ESCAPED BY "); - x.getColumnsEscaped().accept(this); - } - } - - if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { - print(" LINES"); - if (x.getLinesStartingBy() != null) { - print(" STARTING BY "); - x.getLinesStartingBy().accept(this); - } - - if (x.getLinesTerminatedBy() != null) { - print(" TERMINATED BY "); - x.getLinesTerminatedBy().accept(this); - } - } - - return false; - } - - @Override - public void endVisit(MySqlOutFileExpr x) { - - } - - @Override - public boolean visit(MySqlDescribeStatement x) { - print("DESC "); - x.getObject().accept(this); - return false; - } - - @Override - public void endVisit(MySqlDescribeStatement x) { - - } - - @Override - public boolean visit(MySqlUpdateStatement x) { - print("UPDATE "); - - if (x.isLowPriority()) { - print("LOW_PRIORITY "); - } - - if (x.isIgnore()) { - print("IGNORE "); - } - - x.getTableSource().accept(this); - - println(); - print("SET "); - for (int i = 0, size = x.getItems().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getItems().get(i).accept(this); - } - - if (x.getWhere() != null) { - println(); - incrementIndent(); - print("WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - decrementIndent(); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - if (x.getLimit() != null) { - println(); - x.getLimit().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlUpdateStatement x) { - - } - - @Override - public boolean visit(MySqlSetTransactionIsolationLevelStatement x) { - return false; - } - - @Override - public void endVisit(MySqlSetTransactionIsolationLevelStatement x) { - if (x.getGlobal() == null) { - print("SET TRANSACTION ISOLATION LEVEL "); - } else if (x.getGlobal().booleanValue()) { - print("SET GLOBAL TRANSACTION ISOLATION LEVEL "); - } else { - print("SET SESSION TRANSACTION ISOLATION LEVEL "); - } - print(x.getLevel()); - } - - @Override - public boolean visit(MySqlSetNamesStatement x) { - print("SET NAMES "); - if (x.isDefault()) { - print("DEFAULT"); - } else { - print(x.getCharSet()); - if (x.getCollate() != null) { - print(" COLLATE "); - print(x.getCollate()); - } - } - return false; - } - - @Override - public void endVisit(MySqlSetNamesStatement x) { - - } - - @Override - public boolean visit(MySqlSetCharSetStatement x) { - print("SET CHARACTER SET "); - if (x.isDefault()) { - print("DEFAULT"); - } else { - print(x.getCharSet()); - if (x.getCollate() != null) { - print(" COLLATE "); - print(x.getCollate()); - } - } - return false; - } - - @Override - public void endVisit(MySqlSetCharSetStatement x) { - - } - - @Override - public void endVisit(MySqlShowAuthorsStatement x) { - - } - - @Override - public boolean visit(MySqlShowAuthorsStatement x) { - print("SHOW AUTHORS"); - return false; - } - - @Override - public void endVisit(MySqlShowBinaryLogsStatement x) { - - } - - @Override - public boolean visit(MySqlShowBinaryLogsStatement x) { - print("SHOW BINARY LOGS"); - return false; - } - - @Override - public boolean visit(MySqlShowMasterLogsStatement x) { - print("SHOW MASTER LOGS"); - return false; - } - - @Override - public void endVisit(MySqlShowMasterLogsStatement x) { - - } - - @Override - public boolean visit(MySqlShowCollationStatement x) { - print("SHOW COLLATION"); - if (x.getPattern() != null) { - print(" LIKE "); - x.getPattern().accept(this); - } - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowCollationStatement x) { - - } - - @Override - public boolean visit(MySqlShowBinLogEventsStatement x) { - print("SHOW BINLOG EVENTS"); - if (x.getIn() != null) { - print(" IN "); - x.getIn().accept(this); - } - if (x.getFrom() != null) { - print(" FROM "); - x.getFrom().accept(this); - } - if (x.getLimit() != null) { - print(" "); - x.getLimit().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowBinLogEventsStatement x) { - - } - - @Override - public boolean visit(MySqlShowCharacterSetStatement x) { - print("SHOW CHARACTER SET"); - if (x.getPattern() != null) { - print(" LIKE "); - x.getPattern().accept(this); - } - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowCharacterSetStatement x) { - - } - - @Override - public boolean visit(MySqlShowContributorsStatement x) { - print("SHOW CONTRIBUTORS"); - return false; - } - - @Override - public void endVisit(MySqlShowContributorsStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateDatabaseStatement x) { - print("SHOW CREATE DATABASE "); - x.getDatabase().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateDatabaseStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateEventStatement x) { - print("SHOW CREATE EVENT "); - x.getEventName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateEventStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateFunctionStatement x) { - print("SHOW CREATE FUNCTION "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateFunctionStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateProcedureStatement x) { - print("SHOW CREATE PROCEDURE "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateProcedureStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateTableStatement x) { - print("SHOW CREATE TABLE "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateTableStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateTriggerStatement x) { - print("SHOW CREATE TRIGGER "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateTriggerStatement x) { - - } - - @Override - public boolean visit(MySqlShowCreateViewStatement x) { - print("SHOW CREATE VIEW "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowCreateViewStatement x) { - - } - - @Override - public boolean visit(MySqlShowEngineStatement x) { - print("SHOW ENGINE "); - x.getName().accept(this); - print(' '); - print(x.getOption().name()); - return false; - } - - @Override - public void endVisit(MySqlShowEngineStatement x) { - - } - - @Override - public boolean visit(MySqlShowEventsStatement x) { - print("SHOW EVENTS"); - if (x.getSchema() != null) { - print(" FROM "); - x.getSchema().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowEventsStatement x) { - - } - - @Override - public boolean visit(MySqlShowFunctionCodeStatement x) { - print("SHOW FUNCTION CODE "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowFunctionCodeStatement x) { - - } - - @Override - public boolean visit(MySqlShowFunctionStatusStatement x) { - print("SHOW FUNCTION STATUS"); - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowFunctionStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowEnginesStatement x) { - if (x.isStorage()) { - print("SHOW STORAGE ENGINES"); - } else { - print("SHOW ENGINES"); - } - return false; - } - - @Override - public void endVisit(MySqlShowEnginesStatement x) { - - } - - @Override - public boolean visit(MySqlShowErrorsStatement x) { - if (x.isCount()) { - print("SHOW COUNT(*) ERRORS"); - } else { - print("SHOW ERRORS"); - if (x.getLimit() != null) { - print(' '); - x.getLimit().accept(this); - } - } - return false; - } - - @Override - public void endVisit(MySqlShowErrorsStatement x) { - - } - - @Override - public boolean visit(MySqlShowGrantsStatement x) { - print("SHOW GRANTS"); - if (x.getUser() != null) { - print(" FOR "); - x.getUser().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowGrantsStatement x) { - - } - - @Override - public boolean visit(MySqlUserName x) { - print(x.getUserName()); - if (x.getHost() != null) { - print('@'); - print(x.getHost()); - } - return false; - } - - @Override - public void endVisit(MySqlUserName x) { - - } - - @Override - public boolean visit(MySqlShowIndexesStatement x) { - print("SHOW INDEX"); - - if (x.getTable() != null) { - print(" FROM "); - if (x.getDatabase() != null) { - x.getDatabase().accept(this); - print('.'); - } - x.getTable().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowIndexesStatement x) { - - } - - @Override - public boolean visit(MySqlShowKeysStatement x) { - print("SHOW KEYS"); - - if (x.getTable() != null) { - print(" FROM "); - if (x.getDatabase() != null) { - x.getDatabase().accept(this); - print('.'); - } - x.getTable().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowKeysStatement x) { - - } - - @Override - public boolean visit(MySqlShowMasterStatusStatement x) { - print("SHOW MASTER STATUS"); - return false; - } - - @Override - public void endVisit(MySqlShowMasterStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowOpenTablesStatement x) { - print("SHOW OPEN TABLES"); - - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowOpenTablesStatement x) { - - } - - @Override - public boolean visit(MySqlShowPluginsStatement x) { - print("SHOW PLUGINS"); - return false; - } - - @Override - public void endVisit(MySqlShowPluginsStatement x) { - - } - - @Override - public boolean visit(MySqlShowPrivilegesStatement x) { - print("SHOW PRIVILEGES"); - return false; - } - - @Override - public void endVisit(MySqlShowPrivilegesStatement x) { - - } - - @Override - public boolean visit(MySqlShowProcedureCodeStatement x) { - print("SHOW PROCEDURE CODE "); - x.getName().accept(this); - return false; - } - - @Override - public void endVisit(MySqlShowProcedureCodeStatement x) { - - } - - @Override - public boolean visit(MySqlShowProcedureStatusStatement x) { - print("SHOW PROCEDURE STATUS"); - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowProcedureStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowProcessListStatement x) { - if (x.isFull()) { - print("SHOW FULL PROCESSLIST"); - } else { - print("SHOW PROCESSLIST"); - } - return false; - } - - @Override - public void endVisit(MySqlShowProcessListStatement x) { - - } - - @Override - public boolean visit(MySqlShowProfileStatement x) { - print("SHOW PROFILE"); - for (int i = 0; i < x.getTypes().size(); ++i) { - if (i == 0) { - print(' '); - } else { - print(", "); - } - print(x.getTypes().get(i).name); - } - - if (x.getForQuery() != null) { - print(" FOR QUERY "); - x.getForQuery().accept(this); - } - - if (x.getLimit() != null) { - print(' '); - x.getLimit().accept(this); - } - return false; - } - - @Override - public void endVisit(MySqlShowProfileStatement x) { - - } - - @Override - public boolean visit(MySqlShowProfilesStatement x) { - print("SHOW PROFILES"); - return false; - } - - @Override - public void endVisit(MySqlShowProfilesStatement x) { - - } - - @Override - public boolean visit(MySqlShowRelayLogEventsStatement x) { - print("SHOW RELAYLOG EVENTS"); - - if (x.getLogName() != null) { - print(" IN "); - x.getLogName().accept(this); - } - - if (x.getFrom() != null) { - print(" FROM "); - x.getFrom().accept(this); - } - - if (x.getLimit() != null) { - print(' '); - x.getLimit().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowRelayLogEventsStatement x) { - - } - - @Override - public boolean visit(MySqlShowSlaveHostsStatement x) { - print("SHOW SLAVE HOSTS"); - return false; - } - - @Override - public void endVisit(MySqlShowSlaveHostsStatement x) { - - } - - @Override - public boolean visit(MySqlShowSlaveStatusStatement x) { - print("SHOW SLAVE STATUS"); - return false; - } - - @Override - public void endVisit(MySqlShowSlaveStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowTableStatusStatement x) { - print("SHOW TABLE STATUS"); - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowTableStatusStatement x) { - - } - - @Override - public boolean visit(MySqlShowTriggersStatement x) { - print("SHOW TRIGGERS"); - - if (x.getDatabase() != null) { - print(" FROM "); - x.getDatabase().accept(this); - } - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowTriggersStatement x) { - - } - - @Override - public boolean visit(MySqlShowVariantsStatement x) { - print("SHOW "); - - if (x.isGlobal()) { - print("GLOBAL "); - } - - if (x.isSession()) { - print("SESSION "); - } - - print("VARIABLES"); - - if (x.getLike() != null) { - print(" LIKE "); - x.getLike().accept(this); - } - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlShowVariantsStatement x) { - - } - - @Override - public boolean visit(MySqlAlterTableStatement x) { - if (x.isIgnore()) { - print("ALTER IGNORE TABLE "); - } else { - print("ALTER TABLE "); - } - x.getName().accept(this); - incrementIndent(); - for (int i = 0; i < x.getItems().size(); ++i) { - SQLAlterTableItem item = x.getItems().get(i); - if (i != 0) { - print(','); - } - println(); - item.accept(this); - } - decrementIndent(); - return false; - } - - @Override - public void endVisit(MySqlAlterTableStatement x) { - - } - - @Override - public boolean visit(MySqlAlterTableAddColumn x) { - print("ADD COLUMN "); - printAndAccept(x.getColumns(), ", "); - if (x.getFirstColumn() != null) { - print(" FIRST "); - x.getFirstColumn().accept(this); - } else if (x.getAfterColumn() != null) { - print(" AFTER "); - x.getAfterColumn().accept(this); - } else if (x.isFirst()) { - print(" FIRST"); - } - return false; - } - - @Override - public void endVisit(MySqlAlterTableAddColumn x) { - - } - - @Override - public boolean visit(MySqlCreateIndexStatement x) { - print("CREATE "); - if (x.getType() != null) { - print(x.getType()); - print(" "); - } - - print("INDEX "); - - x.getName().accept(this); - print(" ON "); - x.getTable().accept(this); - print(" ("); - printAndAccept(x.getItems(), ", "); - print(")"); - - if (x.getUsing() != null) { - print(" USING "); - print(x.getUsing()); - } - return false; - } - - @Override - public void endVisit(MySqlCreateIndexStatement x) { - - } - - @Override - public boolean visit(MySqlRenameTableStatement.Item x) { - x.getName().accept(this); - print(" TO "); - x.getTo().accept(this); - return false; - } - - @Override - public void endVisit(MySqlRenameTableStatement.Item x) { - - } - - @Override - public boolean visit(MySqlRenameTableStatement x) { - print("RENAME TABLE "); - printAndAccept(x.getItems(), ", "); - return false; - } - - @Override - public void endVisit(MySqlRenameTableStatement x) { - - } - - @Override - public boolean visit(MySqlDropViewStatement x) { - print("DROP VIEW "); - if (x.isIfExists()) { - print("IF EXISTS "); - } - - printAndAccept(x.getTableSources(), ", "); - - if (x.getOption() != null) { - print(' '); - print(x.getOption()); - } - return false; - } - - @Override - public void endVisit(MySqlDropViewStatement x) { - - } - - @Override - public boolean visit(MySqlUnionQuery x) { - { - boolean needParen = false; - if (x.getLeft() instanceof MySqlSelectQueryBlock) { - MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getLeft(); - if (right.getOrderBy() != null || right.getLimit() != null) { - needParen = true; - } - } - if (needParen) { - print('('); - x.getLeft().accept(this); - print(')'); - } else { - x.getLeft().accept(this); - } - } - println(); - print(x.getOperator().name); - println(); - - boolean needParen = false; - - if (x.getOrderBy() != null || x.getLimit() != null) { - needParen = true; - } else if (x.getRight() instanceof MySqlSelectQueryBlock) { - MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getRight(); - if (right.getOrderBy() != null || right.getLimit() != null) { - needParen = true; - } - } - - if (needParen) { - print('('); - x.getRight().accept(this); - print(')'); - } else { - x.getRight().accept(this); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - if (x.getLimit() != null) { - println(); - x.getLimit().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlUnionQuery x) { - - } - - @Override - public boolean visit(MySqlUseIndexHint x) { - print("USE INDEX "); - if (x.getOption() != null) { - print("FOR "); - print(x.getOption().name); - print(' '); - } - print('('); - printAndAccept(x.getIndexList(), ", "); - print(')'); - return false; - } - - @Override - public void endVisit(MySqlUseIndexHint x) { - - } - - @Override - public boolean visit(MySqlIgnoreIndexHint x) { - print("IGNORE INDEX "); - if (x.getOption() != null) { - print("FOR "); - print(x.getOption().name); - print(' '); - } - print('('); - printAndAccept(x.getIndexList(), ", "); - print(')'); - return false; - } - - @Override - public void endVisit(MySqlIgnoreIndexHint x) { - - } - - public boolean visit(SQLExprTableSource x) { - x.getExpr().accept(this); - - if (x.getAlias() != null) { - print(' '); - print(x.getAlias()); - } - - for (int i = 0; i < x.getHints().size(); ++i) { - print(' '); - x.getHints().get(i).accept(this); - } - - return false; - } - - @Override - public boolean visit(MySqlLockTableStatement x) { - print("LOCK TABLES "); - x.getTableSource().accept(this); - if (x.getLockType() != null) { - print(' '); - print(x.getLockType().name); - } - return false; - } - - @Override - public void endVisit(MySqlLockTableStatement x) { - - } - - @Override - public boolean visit(MySqlUnlockTablesStatement x) { - print("UNLOCK TABLES"); - return false; - } - - @Override - public void endVisit(MySqlUnlockTablesStatement x) { - - } - - @Override - public boolean visit(MySqlForceIndexHint x) { - print("FORCE INDEX "); - if (x.getOption() != null) { - print("FOR "); - print(x.getOption().name); - print(' '); - } - print('('); - printAndAccept(x.getIndexList(), ", "); - print(')'); - return false; - } - - @Override - public void endVisit(MySqlForceIndexHint x) { - - } - - @Override - public boolean visit(MySqlAlterTableChangeColumn x) { - print("CHANGE COLUMN "); - x.getColumnName().accept(this); - print(' '); - x.getNewColumnDefinition().accept(this); - if (x.getFirstColumn() != null) { - print(" FIRST "); - x.getFirstColumn().accept(this); - } else if (x.getAfterColumn() != null) { - print(" AFTER "); - x.getAfterColumn().accept(this); - } else if (x.isFirst()) { - print(" FIRST"); - } - - return false; - } - - @Override - public void endVisit(MySqlAlterTableChangeColumn x) { - - } - - @Override - public boolean visit(MySqlAlterTableModifyColumn x) { - print("MODIFY COLUMN "); - x.getNewColumnDefinition().accept(this); - if (x.getFirstColumn() != null) { - print(" FIRST "); - x.getFirstColumn().accept(this); - } else if (x.getAfterColumn() != null) { - print(" AFTER "); - x.getAfterColumn().accept(this); - } else if (x.isFirst()) { - print(" FIRST"); - } - - return false; - } - - @Override - public void endVisit(MySqlAlterTableModifyColumn x) { - - } - - @Override - public boolean visit(MySqlAlterTableCharacter x) { - print("CHARACTER SET = "); - x.getCharacterSet().accept(this); - - if (x.getCollate() != null) { - print(", COLLATE = "); - x.getCollate().accept(this); - } - - return false; - } - - @Override - public void endVisit(MySqlAlterTableCharacter x) { - - } - - @Override - public boolean visit(MySqlAlterTableAddIndex x) { - print("ADD "); - if (x.getType() != null) { - print(x.getType()); - print(" "); - } - - print("INDEX "); - - if (x.getName() != null) { - x.getName().accept(this); - print(' '); - } - print("("); - printAndAccept(x.getItems(), ", "); - print(")"); - - if (x.getUsing() != null) { - print(" USING "); - print(x.getUsing()); - } - return false; - } - - @Override - public void endVisit(MySqlAlterTableAddIndex x) { - - } - - @Override - public boolean visit(MySqlAlterTableAddUnique x) { - print("ADD "); - if (x.getType() != null) { - print(x.getType()); - print(" "); - } - - print("UNIQUE "); - - if (x.getName() != null) { - x.getName().accept(this); - print(' '); - } - print("("); - printAndAccept(x.getItems(), ", "); - print(")"); - - if (x.getUsing() != null) { - print(" USING "); - print(x.getUsing()); - } - return false; - } - - @Override - public void endVisit(MySqlAlterTableAddUnique x) { - - } - - @Override - public boolean visit(MySqlAlterTableOption x) { - print(x.getName()); - print(" = "); - print(x.getValue().toString()); - return false; - } - - @Override - public void endVisit(MySqlAlterTableOption x) { - - } - - @Override - public void endVisit(MySqlCreateTableStatement x) { - - } - - @Override - public boolean visit(MySqlHelpStatement x) { - print("HELP "); - x.getContent().accept(this); - return false; - } - - @Override - public void endVisit(MySqlHelpStatement x) { - - } - - @Override - public boolean visit(MySqlCharExpr x) { - print(x.toString()); - return false; - } - - @Override - public void endVisit(MySqlCharExpr x) { - - } - - @Override - public boolean visit(MySqlUnique x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - - print("UNIQUE"); - - if (x.getIndexType() != null) { - print(" USING "); - print(x.getIndexType()); - } - - print(" ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - - return false; - } - - @Override - public void endVisit(MySqlUnique x) { - - } - - @Override - public boolean visit(MySqlForeignKey x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - - print("FOREIGN KEY ("); - printAndAccept(x.getReferencedColumns(), ", "); - print(")"); - - print(" REFERENCES "); - x.getReferencedTableName().accept(this); - - print(" ("); - printAndAccept(x.getReferencedColumns(), ", "); - print(")"); - return false; - } - - @Override - public void endVisit(MySqlForeignKey x) { - - } - - @Override - public boolean visit(MySqlAlterTableDiscardTablespace x) { - print("DISCARD TABLESPACE"); - return false; - } - - @Override - public void endVisit(MySqlAlterTableDiscardTablespace x) { - - } - - @Override - public boolean visit(MySqlAlterTableImportTablespace x) { - print("IMPORT TABLESPACE"); - return false; - } - - @Override - public void endVisit(MySqlAlterTableImportTablespace x) { - - } - - @Override - public boolean visit(SQLAssignItem x) { - x.getTarget().accept(this); - if (!"NAMES".equalsIgnoreCase(x.getTarget().toString())) { - print(" = "); - } - x.getValue().accept(this); - return false; - } - - @Override - public boolean visit(TableSpaceOption x) { - x.getName().accept(this); - - if (x.getStorage() != null) { - print(' '); - x.getStorage().accept(this); - } - return false; - } - - @Override - public void endVisit(TableSpaceOption x) { - - } - - @Override - public boolean visit(MySqlPartitioningDef x) { - print("PARTITION "); - x.getName().accept(this); - if (x.getValues() != null) { - print(' '); - x.getValues().accept(this); - } - - if (x.getDataDirectory() != null) { - incrementIndent(); - println(); - print("DATA DIRECTORY "); - x.getDataDirectory().accept(this); - decrementIndent(); - } - if (x.getIndexDirectory() != null) { - incrementIndent(); - println(); - print("INDEX DIRECTORY "); - x.getIndexDirectory().accept(this); - decrementIndent(); - } - - return false; - } - - @Override - public void endVisit(MySqlPartitioningDef x) { - - } - - @Override - public boolean visit(LessThanValues x) { - print("VALUES LESS THAN ("); - printAndAccept(x.getItems(), ", "); - print(')'); - return false; - } - - @Override - public void endVisit(LessThanValues x) { - - } - - @Override - public boolean visit(InValues x) { - print("VALUES IN ("); - printAndAccept(x.getItems(), ", "); - print(')'); - return false; - } - - @Override - public void endVisit(InValues x) { - - } - -} // +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.sql.dialect.mysql.visitor; + +import java.util.List; +import java.util.Map; + +import com.alibaba.druid.sql.ast.SQLCommentHint; +import com.alibaba.druid.sql.ast.SQLDataType; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.SQLObject; +import com.alibaba.druid.sql.ast.SQLSetQuantifier; +import com.alibaba.druid.sql.ast.expr.SQLCharExpr; +import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; +import com.alibaba.druid.sql.ast.expr.SQLNullExpr; +import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem; +import com.alibaba.druid.sql.ast.statement.SQLAssignItem; +import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType; +import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint; +import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; +import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; +import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; +import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForeignKey; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBinaryExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlBooleanExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlExtractExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlIntervalExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr; +import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlUserName; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddColumn; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddIndex; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAddUnique; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableCharacter; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableDiscardTablespace; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableImportTablespace; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableModifyColumn; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateIndexStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement.UserSpecification; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDescribeStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropUser; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDropViewStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExecuteStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHelpStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByHash; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByKey; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByList; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitionByRange; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef.InValues; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPartitioningDef.LessThanValues; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRenameTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlResetStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlRollbackStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSQLColumnDefinition; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectGroupBy; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetTransactionIsolationLevelStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowAuthorsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinLogEventsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinaryLogsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCharacterSetStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCollationStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowColumnsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEventsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionCodeStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowGrantsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowIndexesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowKeysStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowOpenTablesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPluginsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPrivilegesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureCodeStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcessListStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfileStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfilesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowRelayLogEventsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveHostsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTableStatusStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTablesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlStartTransactionStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnionQuery; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement; +import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor; + +public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTVisitor { + + public MySqlOutputVisitor(Appendable appender){ + super(appender); + } + + public boolean visit(MySqlBooleanExpr x) { + print(x.getValue() ? "true" : "false"); + + return false; + } + + public void endVisit(MySqlBooleanExpr x) { + } + + @Override + public boolean visit(SQLSelectQueryBlock select) { + if (select instanceof MySqlSelectQueryBlock) { + return visit((MySqlSelectQueryBlock) select); + } + + return false; + } + + public boolean visit(MySqlSelectQueryBlock x) { + if (x.getOrderBy() != null) { + x.getOrderBy().setParent(x); + } + + print("SELECT "); + + for (int i = 0, size = x.getHintsSize(); i < size; ++i) { + SQLCommentHint hint = x.getHints().get(i); + hint.accept(this); + print(' '); + } + + if (SQLSetQuantifier.ALL == x.getDistionOption()) { + print("ALL "); + } else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) { + print("DISTINCT "); + } else if (SQLSetQuantifier.DISTINCTROW == x.getDistionOption()) { + print("DISTINCTROW "); + } + + if (x.isHignPriority()) { + print("HIGH_PRIORITY "); + } + + if (x.isStraightJoin()) { + print("STRAIGHT_JOIN "); + } + + if (x.isSmallResult()) { + print("SQL_SMALL_RESULT "); + } + + if (x.isBigResult()) { + print("SQL_BIG_RESULT "); + } + + if (x.isBufferResult()) { + print("SQL_BUFFER_RESULT "); + } + + if (x.getCache() != null) { + if (x.getCache().booleanValue()) { + print("SQL_CACHE "); + } else { + print("SQL_NO_CACHE "); + } + } + + if (x.isCalcFoundRows()) { + print("SQL_CALC_FOUND_ROWS "); + } + + printSelectList(x.getSelectList()); + + if (x.getInto() != null) { + println(); + print("INTO "); + x.getInto().accept(this); + } + + if (x.getFrom() != null) { + println(); + print("FROM "); + x.getFrom().accept(this); + } + + if (x.getWhere() != null) { + println(); + print("WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + if (x.getGroupBy() != null) { + println(); + x.getGroupBy().accept(this); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + if (x.getLimit() != null) { + println(); + x.getLimit().accept(this); + } + + if (x.getProcedureName() != null) { + print(" PROCEDURE "); + x.getProcedureName().accept(this); + if (x.getProcedureArgumentList().size() > 0) { + print("("); + printAndAccept(x.getProcedureArgumentList(), ", "); + print(")"); + } + } + + if (x.isForUpdate()) { + println(); + print("FOR UPDATE"); + } + + if (x.isLockInShareMode()) { + println(); + print("LOCK IN SHARE MODE"); + } + + return false; + } + + public boolean visit(SQLColumnDefinition x) { + MySqlSQLColumnDefinition mysqlColumn = null; + + if (x instanceof MySqlSQLColumnDefinition) { + mysqlColumn = (MySqlSQLColumnDefinition) x; + } + + x.getName().accept(this); + print(' '); + x.getDataType().accept(this); + + if (x.getDefaultExpr() != null) { + if (x.getDefaultExpr() instanceof SQLNullExpr) { + print(" NULL"); + } else { + print(" DEFAULT"); + x.getDefaultExpr().accept(this); + } + } + + if (mysqlColumn != null && mysqlColumn.getStorage() != null) { + print(" STORAGE "); + mysqlColumn.getStorage().accept(this); + } + + if (mysqlColumn != null && mysqlColumn.getOnUpdate() != null) { + print(" ON UPDATE "); + + mysqlColumn.getOnUpdate().accept(this); + } + + if (mysqlColumn != null && mysqlColumn.isAutoIncrement()) { + print(" AUTO_INCREMENT"); + } + + for (SQLColumnConstraint item : x.getConstaints()) { + print(' '); + item.accept(this); + } + + return false; + } + + public boolean visit(MySqlSelectQueryBlock.Limit x) { + print("LIMIT "); + if (x.getOffset() != null) { + x.getOffset().accept(this); + print(", "); + } + x.getRowCount().accept(this); + + return false; + } + + public boolean visit(SQLDataType x) { + print(x.getName()); + if (x.getArguments().size() > 0) { + print("("); + printAndAccept(x.getArguments(), ", "); + print(")"); + } + + if (Boolean.TRUE == x.getAttribute("unsigned")) { + print(" unsigned"); + } + + if (x instanceof SQLCharactorDataType) { + SQLCharactorDataType charType = (SQLCharactorDataType) x; + if (charType.getCharSetName() != null) { + print(" CHARACTER SET "); + print(charType.getCharSetName()); + + if (charType.getCollate() != null) { + print(" COLLATE "); + print(charType.getCollate()); + } + } + } + return false; + } + + public boolean visit(SQLCharactorDataType x) { + print(x.getName()); + if (x.getArguments().size() > 0) { + print("("); + printAndAccept(x.getArguments(), ", "); + print(")"); + } + + if (x.getCharSetName() != null) { + print(" CHARACTER SET "); + print(x.getCharSetName()); + + if (x.getCollate() != null) { + print(" COLLATE "); + print(x.getCollate()); + } + } + return false; + } + + @Override + public void endVisit(Limit x) { + + } + + @Override + public void endVisit(MySqlTableIndex x) { + + } + + @Override + public boolean visit(MySqlTableIndex x) { + print("INDEX"); + if (x.getName() != null) { + print(" "); + x.getName().accept(this); + } + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print("("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + return false; + } + + public boolean visit(MySqlCreateTableStatement x) { + + print("CREATE "); + + for (SQLCommentHint hint : x.getHints()) { + hint.accept(this); + print(' '); + } + + if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { + print("TEMPORARY TABLE "); + } else { + print("TABLE "); + } + + if (x.isIfNotExiists()) { + print("IF NOT EXISTS "); + } + + x.getName().accept(this); + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + int size = x.getTableElementList().size(); + if (size > 0) { + print(" ("); + incrementIndent(); + println(); + for (int i = 0; i < size; ++i) { + if (i != 0) { + print(", "); + println(); + } + x.getTableElementList().get(i).accept(this); + } + decrementIndent(); + println(); + print(")"); + } + + for (Map.Entry option : x.getTableOptions().entrySet()) { + String key = option.getKey(); + + print(' '); + print(key); + + if ("TABLESPACE".equals(key)) { + print(' '); + option.getValue().accept(this); + continue; + } + + print(" = "); + + option.getValue().accept(this); + } + + if (x.getPartitioning() != null) { + print(' '); + x.getPartitioning().accept(this); + } + + if (x.getQuery() != null) { + incrementIndent(); + println(); + x.getQuery().accept(this); + decrementIndent(); + } + + return false; + } + + @Override + public void endVisit(MySqlKey x) { + + } + + @Override + public void endVisit(MySqlPrimaryKey x) { + + } + + @Override + public boolean visit(MySqlKey x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + + print("KEY"); + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print(" ("); + + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + + return false; + } + + @Override + public boolean visit(MySqlPrimaryKey x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + + print("PRIAMRY KEY"); + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print(" ("); + + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + + return false; + } + + public boolean visit(SQLCharExpr x) { + print('\''); + + String text = x.getText(); + text = text.replaceAll("'", "''"); + text = text.replaceAll("\\\\", "\\\\"); + + print(text); + + print('\''); + return false; + } + + public boolean visit(SQLVariantRefExpr x) { + { + int parametersSize = this.getParametersSize(); + int index = x.getIndex(); + + if (index >= 0 && index < parametersSize) { + Object param = this.getParameters().get(index); + printParameter(param); + return false; + } + } + + String varName = x.getName(); + if (x.isGlobal()) { + print("@@global."); + } else { + if ((!varName.startsWith("@")) // / + && (!varName.equals("?")) // + && (!varName.startsWith("#")) // + && (!varName.startsWith("$")) // + && (!varName.startsWith(":")) + ) { + print("@@"); + } + } + + for (int i = 0; i < x.getName().length(); ++i) { + char ch = x.getName().charAt(i); + if (ch == '\'') { + if (x.getName().startsWith("@@") && i == 2) { + print(ch); + } else if (x.getName().startsWith("@") && i == 1) { + print(ch); + } else if (i != 0 && i != x.getName().length() - 1) { + print("\\'"); + } else { + print(ch); + } + } else { + print(ch); + } + } + + String collate = (String) x.getAttribute("COLLATE"); + if (collate != null) { + print(" COLLATE "); + print(collate); + } + + return false; + } + + public boolean visit(SQLMethodInvokeExpr x) { + if ("SUBSTRING".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + printAndAccept(x.getParameters(), ", "); + SQLExpr from = (SQLExpr) x.getAttribute("FROM"); + if (from != null) { + print(" FROM "); + from.accept(this); + } + + SQLExpr forExpr = (SQLExpr) x.getAttribute("FOR"); + if (forExpr != null) { + print(" FOR "); + forExpr.accept(this); + } + print(")"); + + return false; + } + + if ("TRIM".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + + String trimType = (String) x.getAttribute("TRIM_TYPE"); + if (trimType != null) { + print(trimType); + print(' '); + } + + printAndAccept(x.getParameters(), ", "); + + SQLExpr from = (SQLExpr) x.getAttribute("FROM"); + if (from != null) { + print(" FROM "); + from.accept(this); + } + + print(")"); + + return false; + } + + if ("CONVERT".equalsIgnoreCase(x.getMethodName())) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + printAndAccept(x.getParameters(), ", "); + + String charset = (String) x.getAttribute("USING"); + if (charset != null) { + print(" USING "); + print(charset); + } + print(")"); + return false; + } + + return super.visit(x); + } + + @Override + public void endVisit(MySqlIntervalExpr x) { + + } + + @Override + public boolean visit(MySqlIntervalExpr x) { + print("INTERVAL "); + x.getValue().accept(this); + print(' '); + print(x.getUnit().name()); + return false; + } + + @Override + public boolean visit(MySqlExtractExpr x) { + print("EXTRACT("); + print(x.getUnit().name()); + print(" FROM "); + x.getValue().accept(this); + print(')'); + return false; + } + + @Override + public void endVisit(MySqlExtractExpr x) { + + } + + @Override + public void endVisit(MySqlMatchAgainstExpr x) { + + } + + @Override + public boolean visit(MySqlMatchAgainstExpr x) { + print("MATCH ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + + print(" AGAINST ("); + x.getAgainst().accept(this); + if (x.getSearchModifier() != null) { + print(' '); + print(x.getSearchModifier().name); + } + print(')'); + + return false; + } + + @Override + public void endVisit(MySqlBinaryExpr x) { + + } + + @Override + public boolean visit(MySqlBinaryExpr x) { + print("b'"); + print(x.getValue()); + print('\''); + + return false; + } + + @Override + public void endVisit(MySqlPrepareStatement x) { + } + + @Override + public boolean visit(MySqlPrepareStatement x) { + print("PREPARE "); + x.getName().accept(this); + print(" FROM "); + x.getFrom().accept(this); + return false; + } + + @Override + public void endVisit(MySqlExecuteStatement x) { + + } + + @Override + public boolean visit(MySqlExecuteStatement x) { + print("EXECUTE "); + x.getStatementName().accept(this); + if (x.getParameters().size() > 0) { + print(" USING "); + printAndAccept(x.getParameters(), ", "); + } + return false; + } + + @Override + public void endVisit(MySqlDeleteStatement x) { + + } + + @Override + public boolean visit(MySqlDeleteStatement x) { + print("DELETE "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isQuick()) { + print("QUICK "); + } + + if (x.isIgnore()) { + print("IGNORE "); + } + + if (x.getFrom() == null) { + print("FROM "); + x.getTableSource().accept(this); + } else { + x.getTableSource().accept(this); + println(); + print("FROM "); + x.getFrom().accept(this); + } + + if (x.getUsing() != null) { + println(); + print("USING "); + x.getUsing().accept(this); + } + + if (x.getWhere() != null) { + println(); + incrementIndent(); + print("WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + decrementIndent(); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + if (x.getLimit() != null) { + println(); + x.getLimit().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlInsertStatement x) { + + } + + @Override + public boolean visit(MySqlInsertStatement x) { + print("INSERT "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isDelayed()) { + print("DELAYED "); + } + + if (x.isHighPriority()) { + print("HIGH_PRIORITY "); + } + + if (x.isIgnore()) { + print("IGNORE "); + } + + print("INTO "); + + x.getTableSource().accept(this); + + if (x.getColumns().size() > 0) { + incrementIndent(); + print(" ("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + print(", "); + } + + x.getColumns().get(i).accept(this); + } + print(")"); + decrementIndent(); + } + + if (x.getValuesList().size() != 0) { + println(); + print("VALUES "); + if (x.getValuesList().size() > 1) { + incrementIndent(); + } + for (int i = 0, size = x.getValuesList().size(); i < size; ++i) { + if (i != 0) { + print(","); + println(); + } + x.getValuesList().get(i).accept(this); + } + if (x.getValuesList().size() > 1) { + decrementIndent(); + } + } + + if (x.getQuery() != null) { + println(); + x.getQuery().accept(this); + } + + if (x.getDuplicateKeyUpdate().size() != 0) { + println(); + print("ON DUPLICATE KEY UPDATE "); + for (int i = 0, size = x.getDuplicateKeyUpdate().size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + print(", "); + } + x.getDuplicateKeyUpdate().get(i).accept(this); + } + } + + return false; + } + + @Override + public void endVisit(MySqlLoadDataInFileStatement x) { + + } + + @Override + public boolean visit(MySqlLoadDataInFileStatement x) { + print("LOAD DATA "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isConcurrent()) { + print("CONCURRENT "); + } + + if (x.isLocal()) { + print("LOCAL "); + } + + print("INFILE "); + + x.getFileName().accept(this); + + if (x.isReplicate()) { + print(" REPLACE "); + } + + if (x.isIgnore()) { + print(" IGNORE "); + } + + print(" INTO TABLE "); + x.getTableName().accept(this); + + if (x.getColumnsTerminatedBy() != null || x.getColumnsEnclosedBy() != null || x.getColumnsEscaped() != null) { + print(" COLUMNS"); + if (x.getColumnsTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getColumnsTerminatedBy().accept(this); + } + + if (x.getColumnsEnclosedBy() != null) { + if (x.isColumnsEnclosedOptionally()) { + print(" OPTIONALLY"); + } + print(" ENCLOSED BY "); + x.getColumnsEnclosedBy().accept(this); + } + + if (x.getColumnsEscaped() != null) { + print(" ESCAPED BY "); + x.getColumnsEscaped().accept(this); + } + } + + if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { + print(" LINES"); + if (x.getLinesStartingBy() != null) { + print(" STARTING BY "); + x.getLinesStartingBy().accept(this); + } + + if (x.getLinesTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getLinesTerminatedBy().accept(this); + } + } + + if (x.getSetList().size() != 0) { + print(" SET "); + printAndAccept(x.getSetList(), ", "); + } + + return false; + } + + @Override + public void endVisit(MySqlReplaceStatement x) { + + } + + @Override + public boolean visit(MySqlReplaceStatement x) { + print("REPLACE "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isDelayed()) { + print("DELAYED "); + } + + print("INTO "); + + x.getTableName().accept(this); + + if (x.getColumns().size() > 0) { + print(" ("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + } + + if (x.getValuesList().size() != 0) { + println(); + print("VALUES "); + int size = x.getValuesList().size(); + if (size == 0) { + print("()"); + } else { + for (int i = 0; i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getValuesList().get(i).accept(this); + } + } + } + + if (x.getQuery() != null) { + x.getQuery().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlSelectGroupBy x) { + + } + + @Override + public boolean visit(MySqlSelectGroupBy x) { + super.visit(x); + + if (x.isRollUp()) { + print(" WITH ROLLUP"); + } + + return false; + } + + @Override + public void endVisit(MySqlStartTransactionStatement x) { + + } + + @Override + public boolean visit(MySqlStartTransactionStatement x) { + print("START TRANSACTION"); + if (x.isConsistentSnapshot()) { + print(" WITH CONSISTENT SNAPSHOT"); + } + + if (x.isBegin()) { + print(" BEGIN"); + } + + if (x.isWork()) { + print(" WORK"); + } + + return false; + } + + @Override + public void endVisit(MySqlCommitStatement x) { + + } + + @Override + public boolean visit(MySqlCommitStatement x) { + print("COMMIT"); + + if (x.isWork()) { + print(" WORK"); + } + + if (x.getChain() != null) { + if (x.getChain().booleanValue()) { + print(" AND CHAIN"); + } else { + print(" AND NO CHAIN"); + } + } + + if (x.getRelease() != null) { + if (x.getRelease().booleanValue()) { + print(" AND RELEASE"); + } else { + print(" AND NO RELEASE"); + } + } + + return false; + } + + @Override + public void endVisit(MySqlRollbackStatement x) { + + } + + @Override + public boolean visit(MySqlRollbackStatement x) { + print("ROLLBACK"); + + if (x.getChain() != null) { + if (x.getChain().booleanValue()) { + print(" AND CHAIN"); + } else { + print(" AND NO CHAIN"); + } + } + + if (x.getRelease() != null) { + if (x.getRelease().booleanValue()) { + print(" AND RELEASE"); + } else { + print(" AND NO RELEASE"); + } + } + + if (x.getTo() != null) { + print(" TO "); + x.getTo().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowColumnsStatement x) { + + } + + @Override + public boolean visit(MySqlShowColumnsStatement x) { + if (x.isFull()) { + print("SHOW FULL COLUMNS"); + } else { + print("SHOW COLUMNS"); + } + + if (x.getTable() != null) { + print(" FROM "); + if (x.getDatabase() != null) { + x.getDatabase().accept(this); + print('.'); + } + x.getTable().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowTablesStatement x) { + + } + + @Override + public boolean visit(MySqlShowTablesStatement x) { + if (x.isFull()) { + print("SHOW FULL TABLES"); + } else { + print("SHOW TABLES"); + } + + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowDatabasesStatement x) { + + } + + @Override + public boolean visit(MySqlShowDatabasesStatement x) { + print("SHOW DATABASES"); + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowWarningsStatement x) { + + } + + @Override + public boolean visit(MySqlShowWarningsStatement x) { + if (x.isCount()) { + print("SHOW COUNT(*) WARNINGS"); + } else { + print("SHOW WARNINGS"); + if (x.getLimit() != null) { + print(' '); + x.getLimit().accept(this); + } + } + + return false; + } + + @Override + public void endVisit(MySqlShowStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowStatusStatement x) { + print("SHOW "); + + if (x.isGlobal()) { + print("GLOBAL "); + } + + if (x.isSession()) { + print("SESSION "); + } + + print("STATUS"); + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlLoadXmlStatement x) { + + } + + @Override + public boolean visit(MySqlLoadXmlStatement x) { + print("LOAD XML "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isConcurrent()) { + print("CONCURRENT "); + } + + if (x.isLocal()) { + print("LOCAL "); + } + + print("INFILE "); + + x.getFileName().accept(this); + + if (x.isReplicate()) { + print(" REPLACE "); + } + + if (x.isIgnore()) { + print(" IGNORE "); + } + + print(" INTO TABLE "); + x.getTableName().accept(this); + + if (x.getCharset() != null) { + print(" CHARSET "); + print(x.getCharset()); + } + + if (x.getRowsIdentifiedBy() != null) { + print(" ROWS IDENTIFIED BY "); + x.getRowsIdentifiedBy().accept(this); + } + + if (x.getSetList().size() != 0) { + print(" SET "); + printAndAccept(x.getSetList(), ", "); + } + + return false; + } + + @Override + public void endVisit(CobarShowStatus x) { + + } + + @Override + public boolean visit(CobarShowStatus x) { + print("SHOW COBAR_STATUS"); + return false; + } + + @Override + public void endVisit(MySqlKillStatement x) { + + } + + @Override + public boolean visit(MySqlKillStatement x) { + if (MySqlKillStatement.Type.CONNECTION.equals(x.getType())) { + print("KILL CONNECTION "); + } else if (MySqlKillStatement.Type.QUERY.equals(x.getType())) { + print("KILL QUERY "); + } + x.getThreadId().accept(this); + return false; + } + + @Override + public void endVisit(MySqlBinlogStatement x) { + + } + + @Override + public boolean visit(MySqlBinlogStatement x) { + print("BINLOG "); + x.getExpr().accept(this); + return false; + } + + @Override + public void endVisit(MySqlResetStatement x) { + + } + + @Override + public boolean visit(MySqlResetStatement x) { + print("RESET "); + for (int i = 0; i < x.getOptions().size(); ++i) { + if (i != 0) { + print(", "); + } + print(x.getOptions().get(i)); + } + return false; + } + + @Override + public void endVisit(MySqlCreateUserStatement x) { + + } + + @Override + public boolean visit(MySqlCreateUserStatement x) { + print("CREATE USER "); + printAndAccept(x.getUsers(), ", "); + return false; + } + + @Override + public void endVisit(UserSpecification x) { + + } + + @Override + public boolean visit(UserSpecification x) { + x.getUser().accept(this); + + if (x.getPassword() != null) { + print(" IDENTIFIED BY "); + x.getPassword().accept(this); + } + + if (x.getAuthPlugin() != null) { + print(" IDENTIFIED WITH "); + x.getAuthPlugin().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlDropUser x) { + + } + + @Override + public boolean visit(MySqlDropUser x) { + print("DROP USER "); + printAndAccept(x.getUsers(), ", "); + return false; + } + + @Override + public void endVisit(MySqlDropTableStatement x) { + + } + + @Override + public boolean visit(MySqlDropTableStatement x) { + if (x.isTemporary()) { + print("DROP TEMPORARY TABLE "); + } else { + print("DROP TABLE "); + } + if (x.isIfExists()) { + print("IF EXISTS "); + } + + printAndAccept(x.getTableSources(), ", "); + + if (x.getOption() != null) { + print(' '); + print(x.getOption()); + } + return false; + } + + @Override + public void endVisit(MySqlPartitionByKey x) { + + } + + @Override + public boolean visit(MySqlPartitionByKey x) { + if (x.isLinear()) { + print("PARTITION BY LINEAR KEY ("); + } else { + print("PARTITION BY KEY ("); + } + printAndAccept(x.getColumns(), ", "); + print(")"); + + if (x.getPartitionCount() != null) { + print(" PARTITIONS "); + x.getPartitionCount().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlPartitionByRange x) { + + } + + @Override + public boolean visit(MySqlPartitionByRange x) { + print("PARTITION BY RANGE"); + if (x.getExpr() != null) { + print(" ("); + x.getExpr().accept(this); + print(")"); + } else { + print(" COLUMNS ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + } + + if (x.getPartitionCount() != null) { + print(" PARTITIONS "); + x.getPartitionCount().accept(this); + } + + List partitions = x.getPartitions(); + int partitionsSize = partitions.size(); + if (partitionsSize > 0) { + print("("); + incrementIndent(); + for (int i = 0; i < partitionsSize; ++i) { + println(); + partitions.get(i).accept(this); + if (i != partitionsSize - 1) { + print(", "); + } + } + decrementIndent(); + println(); + print(")"); + } + return false; + } + + @Override + public void endVisit(MySqlPartitionByList x) { + + } + + @Override + public boolean visit(MySqlPartitionByList x) { + print("PARTITION BY LIST "); + if (x.getExpr() != null) { + print("("); + x.getExpr().accept(this); + print(") "); + } else { + print("COLUMNS ("); + printAndAccept(x.getColumns(), ", "); + print(") "); + } + + if (x.getPartitionCount() != null) { + print(" PARTITIONS "); + x.getPartitionCount().accept(this); + } + + List partitions = x.getPartitions(); + int partitionsSize = partitions.size(); + if (partitionsSize > 0) { + print("("); + incrementIndent(); + for (int i = 0; i < partitionsSize; ++i) { + println(); + partitions.get(i).accept(this); + if (i != partitionsSize - 1) { + print(", "); + } + } + decrementIndent(); + println(); + print(")"); + } + return false; + } + + // + + @Override + public void endVisit(MySqlPartitionByHash x) { + + } + + @Override + public boolean visit(MySqlPartitionByHash x) { + if (x.isLinear()) { + print("PARTITION BY LINEAR HASH ("); + } else { + print("PARTITION BY HASH ("); + } + // + x.getExpr().accept(this); + print(")"); + + if (x.getPartitionCount() != null) { + print(" PARTITIONS "); + x.getPartitionCount().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlSelectQueryBlock x) { + + } + + @Override + public boolean visit(MySqlOutFileExpr x) { + print("OUTFILE "); + x.getFile().accept(this); + + if (x.getCharset() != null) { + print(" CHARACTER SET "); + print(x.getCharset()); + } + + if (x.getColumnsTerminatedBy() != null || x.getColumnsEnclosedBy() != null || x.getColumnsEscaped() != null) { + print(" COLUMNS"); + if (x.getColumnsTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getColumnsTerminatedBy().accept(this); + } + + if (x.getColumnsEnclosedBy() != null) { + if (x.isColumnsEnclosedOptionally()) { + print(" OPTIONALLY"); + } + print(" ENCLOSED BY "); + x.getColumnsEnclosedBy().accept(this); + } + + if (x.getColumnsEscaped() != null) { + print(" ESCAPED BY "); + x.getColumnsEscaped().accept(this); + } + } + + if (x.getLinesStartingBy() != null || x.getLinesTerminatedBy() != null) { + print(" LINES"); + if (x.getLinesStartingBy() != null) { + print(" STARTING BY "); + x.getLinesStartingBy().accept(this); + } + + if (x.getLinesTerminatedBy() != null) { + print(" TERMINATED BY "); + x.getLinesTerminatedBy().accept(this); + } + } + + return false; + } + + @Override + public void endVisit(MySqlOutFileExpr x) { + + } + + @Override + public boolean visit(MySqlDescribeStatement x) { + print("DESC "); + x.getObject().accept(this); + return false; + } + + @Override + public void endVisit(MySqlDescribeStatement x) { + + } + + @Override + public boolean visit(MySqlUpdateStatement x) { + print("UPDATE "); + + if (x.isLowPriority()) { + print("LOW_PRIORITY "); + } + + if (x.isIgnore()) { + print("IGNORE "); + } + + x.getTableSource().accept(this); + + println(); + print("SET "); + for (int i = 0, size = x.getItems().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getItems().get(i).accept(this); + } + + if (x.getWhere() != null) { + println(); + incrementIndent(); + print("WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + decrementIndent(); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + if (x.getLimit() != null) { + println(); + x.getLimit().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlUpdateStatement x) { + + } + + @Override + public boolean visit(MySqlSetTransactionIsolationLevelStatement x) { + return false; + } + + @Override + public void endVisit(MySqlSetTransactionIsolationLevelStatement x) { + if (x.getGlobal() == null) { + print("SET TRANSACTION ISOLATION LEVEL "); + } else if (x.getGlobal().booleanValue()) { + print("SET GLOBAL TRANSACTION ISOLATION LEVEL "); + } else { + print("SET SESSION TRANSACTION ISOLATION LEVEL "); + } + print(x.getLevel()); + } + + @Override + public boolean visit(MySqlSetNamesStatement x) { + print("SET NAMES "); + if (x.isDefault()) { + print("DEFAULT"); + } else { + print(x.getCharSet()); + if (x.getCollate() != null) { + print(" COLLATE "); + print(x.getCollate()); + } + } + return false; + } + + @Override + public void endVisit(MySqlSetNamesStatement x) { + + } + + @Override + public boolean visit(MySqlSetCharSetStatement x) { + print("SET CHARACTER SET "); + if (x.isDefault()) { + print("DEFAULT"); + } else { + print(x.getCharSet()); + if (x.getCollate() != null) { + print(" COLLATE "); + print(x.getCollate()); + } + } + return false; + } + + @Override + public void endVisit(MySqlSetCharSetStatement x) { + + } + + @Override + public void endVisit(MySqlShowAuthorsStatement x) { + + } + + @Override + public boolean visit(MySqlShowAuthorsStatement x) { + print("SHOW AUTHORS"); + return false; + } + + @Override + public void endVisit(MySqlShowBinaryLogsStatement x) { + + } + + @Override + public boolean visit(MySqlShowBinaryLogsStatement x) { + print("SHOW BINARY LOGS"); + return false; + } + + @Override + public boolean visit(MySqlShowMasterLogsStatement x) { + print("SHOW MASTER LOGS"); + return false; + } + + @Override + public void endVisit(MySqlShowMasterLogsStatement x) { + + } + + @Override + public boolean visit(MySqlShowCollationStatement x) { + print("SHOW COLLATION"); + if (x.getPattern() != null) { + print(" LIKE "); + x.getPattern().accept(this); + } + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowCollationStatement x) { + + } + + @Override + public boolean visit(MySqlShowBinLogEventsStatement x) { + print("SHOW BINLOG EVENTS"); + if (x.getIn() != null) { + print(" IN "); + x.getIn().accept(this); + } + if (x.getFrom() != null) { + print(" FROM "); + x.getFrom().accept(this); + } + if (x.getLimit() != null) { + print(" "); + x.getLimit().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowBinLogEventsStatement x) { + + } + + @Override + public boolean visit(MySqlShowCharacterSetStatement x) { + print("SHOW CHARACTER SET"); + if (x.getPattern() != null) { + print(" LIKE "); + x.getPattern().accept(this); + } + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowCharacterSetStatement x) { + + } + + @Override + public boolean visit(MySqlShowContributorsStatement x) { + print("SHOW CONTRIBUTORS"); + return false; + } + + @Override + public void endVisit(MySqlShowContributorsStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateDatabaseStatement x) { + print("SHOW CREATE DATABASE "); + x.getDatabase().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateDatabaseStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateEventStatement x) { + print("SHOW CREATE EVENT "); + x.getEventName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateEventStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateFunctionStatement x) { + print("SHOW CREATE FUNCTION "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateFunctionStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateProcedureStatement x) { + print("SHOW CREATE PROCEDURE "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateProcedureStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateTableStatement x) { + print("SHOW CREATE TABLE "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateTableStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateTriggerStatement x) { + print("SHOW CREATE TRIGGER "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateTriggerStatement x) { + + } + + @Override + public boolean visit(MySqlShowCreateViewStatement x) { + print("SHOW CREATE VIEW "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowCreateViewStatement x) { + + } + + @Override + public boolean visit(MySqlShowEngineStatement x) { + print("SHOW ENGINE "); + x.getName().accept(this); + print(' '); + print(x.getOption().name()); + return false; + } + + @Override + public void endVisit(MySqlShowEngineStatement x) { + + } + + @Override + public boolean visit(MySqlShowEventsStatement x) { + print("SHOW EVENTS"); + if (x.getSchema() != null) { + print(" FROM "); + x.getSchema().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowEventsStatement x) { + + } + + @Override + public boolean visit(MySqlShowFunctionCodeStatement x) { + print("SHOW FUNCTION CODE "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowFunctionCodeStatement x) { + + } + + @Override + public boolean visit(MySqlShowFunctionStatusStatement x) { + print("SHOW FUNCTION STATUS"); + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowFunctionStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowEnginesStatement x) { + if (x.isStorage()) { + print("SHOW STORAGE ENGINES"); + } else { + print("SHOW ENGINES"); + } + return false; + } + + @Override + public void endVisit(MySqlShowEnginesStatement x) { + + } + + @Override + public boolean visit(MySqlShowErrorsStatement x) { + if (x.isCount()) { + print("SHOW COUNT(*) ERRORS"); + } else { + print("SHOW ERRORS"); + if (x.getLimit() != null) { + print(' '); + x.getLimit().accept(this); + } + } + return false; + } + + @Override + public void endVisit(MySqlShowErrorsStatement x) { + + } + + @Override + public boolean visit(MySqlShowGrantsStatement x) { + print("SHOW GRANTS"); + if (x.getUser() != null) { + print(" FOR "); + x.getUser().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowGrantsStatement x) { + + } + + @Override + public boolean visit(MySqlUserName x) { + print(x.getUserName()); + if (x.getHost() != null) { + print('@'); + print(x.getHost()); + } + return false; + } + + @Override + public void endVisit(MySqlUserName x) { + + } + + @Override + public boolean visit(MySqlShowIndexesStatement x) { + print("SHOW INDEX"); + + if (x.getTable() != null) { + print(" FROM "); + if (x.getDatabase() != null) { + x.getDatabase().accept(this); + print('.'); + } + x.getTable().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowIndexesStatement x) { + + } + + @Override + public boolean visit(MySqlShowKeysStatement x) { + print("SHOW KEYS"); + + if (x.getTable() != null) { + print(" FROM "); + if (x.getDatabase() != null) { + x.getDatabase().accept(this); + print('.'); + } + x.getTable().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowKeysStatement x) { + + } + + @Override + public boolean visit(MySqlShowMasterStatusStatement x) { + print("SHOW MASTER STATUS"); + return false; + } + + @Override + public void endVisit(MySqlShowMasterStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowOpenTablesStatement x) { + print("SHOW OPEN TABLES"); + + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowOpenTablesStatement x) { + + } + + @Override + public boolean visit(MySqlShowPluginsStatement x) { + print("SHOW PLUGINS"); + return false; + } + + @Override + public void endVisit(MySqlShowPluginsStatement x) { + + } + + @Override + public boolean visit(MySqlShowPrivilegesStatement x) { + print("SHOW PRIVILEGES"); + return false; + } + + @Override + public void endVisit(MySqlShowPrivilegesStatement x) { + + } + + @Override + public boolean visit(MySqlShowProcedureCodeStatement x) { + print("SHOW PROCEDURE CODE "); + x.getName().accept(this); + return false; + } + + @Override + public void endVisit(MySqlShowProcedureCodeStatement x) { + + } + + @Override + public boolean visit(MySqlShowProcedureStatusStatement x) { + print("SHOW PROCEDURE STATUS"); + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowProcedureStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowProcessListStatement x) { + if (x.isFull()) { + print("SHOW FULL PROCESSLIST"); + } else { + print("SHOW PROCESSLIST"); + } + return false; + } + + @Override + public void endVisit(MySqlShowProcessListStatement x) { + + } + + @Override + public boolean visit(MySqlShowProfileStatement x) { + print("SHOW PROFILE"); + for (int i = 0; i < x.getTypes().size(); ++i) { + if (i == 0) { + print(' '); + } else { + print(", "); + } + print(x.getTypes().get(i).name); + } + + if (x.getForQuery() != null) { + print(" FOR QUERY "); + x.getForQuery().accept(this); + } + + if (x.getLimit() != null) { + print(' '); + x.getLimit().accept(this); + } + return false; + } + + @Override + public void endVisit(MySqlShowProfileStatement x) { + + } + + @Override + public boolean visit(MySqlShowProfilesStatement x) { + print("SHOW PROFILES"); + return false; + } + + @Override + public void endVisit(MySqlShowProfilesStatement x) { + + } + + @Override + public boolean visit(MySqlShowRelayLogEventsStatement x) { + print("SHOW RELAYLOG EVENTS"); + + if (x.getLogName() != null) { + print(" IN "); + x.getLogName().accept(this); + } + + if (x.getFrom() != null) { + print(" FROM "); + x.getFrom().accept(this); + } + + if (x.getLimit() != null) { + print(' '); + x.getLimit().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowRelayLogEventsStatement x) { + + } + + @Override + public boolean visit(MySqlShowSlaveHostsStatement x) { + print("SHOW SLAVE HOSTS"); + return false; + } + + @Override + public void endVisit(MySqlShowSlaveHostsStatement x) { + + } + + @Override + public boolean visit(MySqlShowSlaveStatusStatement x) { + print("SHOW SLAVE STATUS"); + return false; + } + + @Override + public void endVisit(MySqlShowSlaveStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowTableStatusStatement x) { + print("SHOW TABLE STATUS"); + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowTableStatusStatement x) { + + } + + @Override + public boolean visit(MySqlShowTriggersStatement x) { + print("SHOW TRIGGERS"); + + if (x.getDatabase() != null) { + print(" FROM "); + x.getDatabase().accept(this); + } + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowTriggersStatement x) { + + } + + @Override + public boolean visit(MySqlShowVariantsStatement x) { + print("SHOW "); + + if (x.isGlobal()) { + print("GLOBAL "); + } + + if (x.isSession()) { + print("SESSION "); + } + + print("VARIABLES"); + + if (x.getLike() != null) { + print(" LIKE "); + x.getLike().accept(this); + } + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlShowVariantsStatement x) { + + } + + @Override + public boolean visit(MySqlAlterTableStatement x) { + if (x.isIgnore()) { + print("ALTER IGNORE TABLE "); + } else { + print("ALTER TABLE "); + } + x.getName().accept(this); + incrementIndent(); + for (int i = 0; i < x.getItems().size(); ++i) { + SQLAlterTableItem item = x.getItems().get(i); + if (i != 0) { + print(','); + } + println(); + item.accept(this); + } + decrementIndent(); + return false; + } + + @Override + public void endVisit(MySqlAlterTableStatement x) { + + } + + @Override + public boolean visit(MySqlAlterTableAddColumn x) { + print("ADD COLUMN "); + printAndAccept(x.getColumns(), ", "); + if (x.getFirstColumn() != null) { + print(" FIRST "); + x.getFirstColumn().accept(this); + } else if (x.getAfterColumn() != null) { + print(" AFTER "); + x.getAfterColumn().accept(this); + } else if (x.isFirst()) { + print(" FIRST"); + } + return false; + } + + @Override + public void endVisit(MySqlAlterTableAddColumn x) { + + } + + @Override + public boolean visit(MySqlCreateIndexStatement x) { + print("CREATE "); + if (x.getType() != null) { + print(x.getType()); + print(" "); + } + + print("INDEX "); + + x.getName().accept(this); + print(" ON "); + x.getTable().accept(this); + print(" ("); + printAndAccept(x.getItems(), ", "); + print(")"); + + if (x.getUsing() != null) { + print(" USING "); + print(x.getUsing()); + } + return false; + } + + @Override + public void endVisit(MySqlCreateIndexStatement x) { + + } + + @Override + public boolean visit(MySqlRenameTableStatement.Item x) { + x.getName().accept(this); + print(" TO "); + x.getTo().accept(this); + return false; + } + + @Override + public void endVisit(MySqlRenameTableStatement.Item x) { + + } + + @Override + public boolean visit(MySqlRenameTableStatement x) { + print("RENAME TABLE "); + printAndAccept(x.getItems(), ", "); + return false; + } + + @Override + public void endVisit(MySqlRenameTableStatement x) { + + } + + @Override + public boolean visit(MySqlDropViewStatement x) { + print("DROP VIEW "); + if (x.isIfExists()) { + print("IF EXISTS "); + } + + printAndAccept(x.getTableSources(), ", "); + + if (x.getOption() != null) { + print(' '); + print(x.getOption()); + } + return false; + } + + @Override + public void endVisit(MySqlDropViewStatement x) { + + } + + @Override + public boolean visit(MySqlUnionQuery x) { + { + boolean needParen = false; + if (x.getLeft() instanceof MySqlSelectQueryBlock) { + MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getLeft(); + if (right.getOrderBy() != null || right.getLimit() != null) { + needParen = true; + } + } + if (needParen) { + print('('); + x.getLeft().accept(this); + print(')'); + } else { + x.getLeft().accept(this); + } + } + println(); + print(x.getOperator().name); + println(); + + boolean needParen = false; + + if (x.getOrderBy() != null || x.getLimit() != null) { + needParen = true; + } else if (x.getRight() instanceof MySqlSelectQueryBlock) { + MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getRight(); + if (right.getOrderBy() != null || right.getLimit() != null) { + needParen = true; + } + } + + if (needParen) { + print('('); + x.getRight().accept(this); + print(')'); + } else { + x.getRight().accept(this); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + if (x.getLimit() != null) { + println(); + x.getLimit().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlUnionQuery x) { + + } + + @Override + public boolean visit(MySqlUseIndexHint x) { + print("USE INDEX "); + if (x.getOption() != null) { + print("FOR "); + print(x.getOption().name); + print(' '); + } + print('('); + printAndAccept(x.getIndexList(), ", "); + print(')'); + return false; + } + + @Override + public void endVisit(MySqlUseIndexHint x) { + + } + + @Override + public boolean visit(MySqlIgnoreIndexHint x) { + print("IGNORE INDEX "); + if (x.getOption() != null) { + print("FOR "); + print(x.getOption().name); + print(' '); + } + print('('); + printAndAccept(x.getIndexList(), ", "); + print(')'); + return false; + } + + @Override + public void endVisit(MySqlIgnoreIndexHint x) { + + } + + public boolean visit(SQLExprTableSource x) { + x.getExpr().accept(this); + + if (x.getAlias() != null) { + print(' '); + print(x.getAlias()); + } + + for (int i = 0; i < x.getHintsSize(); ++i) { + print(' '); + x.getHints().get(i).accept(this); + } + + return false; + } + + @Override + public boolean visit(MySqlLockTableStatement x) { + print("LOCK TABLES "); + x.getTableSource().accept(this); + if (x.getLockType() != null) { + print(' '); + print(x.getLockType().name); + } + return false; + } + + @Override + public void endVisit(MySqlLockTableStatement x) { + + } + + @Override + public boolean visit(MySqlUnlockTablesStatement x) { + print("UNLOCK TABLES"); + return false; + } + + @Override + public void endVisit(MySqlUnlockTablesStatement x) { + + } + + @Override + public boolean visit(MySqlForceIndexHint x) { + print("FORCE INDEX "); + if (x.getOption() != null) { + print("FOR "); + print(x.getOption().name); + print(' '); + } + print('('); + printAndAccept(x.getIndexList(), ", "); + print(')'); + return false; + } + + @Override + public void endVisit(MySqlForceIndexHint x) { + + } + + @Override + public boolean visit(MySqlAlterTableChangeColumn x) { + print("CHANGE COLUMN "); + x.getColumnName().accept(this); + print(' '); + x.getNewColumnDefinition().accept(this); + if (x.getFirstColumn() != null) { + print(" FIRST "); + x.getFirstColumn().accept(this); + } else if (x.getAfterColumn() != null) { + print(" AFTER "); + x.getAfterColumn().accept(this); + } else if (x.isFirst()) { + print(" FIRST"); + } + + return false; + } + + @Override + public void endVisit(MySqlAlterTableChangeColumn x) { + + } + + @Override + public boolean visit(MySqlAlterTableModifyColumn x) { + print("MODIFY COLUMN "); + x.getNewColumnDefinition().accept(this); + if (x.getFirstColumn() != null) { + print(" FIRST "); + x.getFirstColumn().accept(this); + } else if (x.getAfterColumn() != null) { + print(" AFTER "); + x.getAfterColumn().accept(this); + } else if (x.isFirst()) { + print(" FIRST"); + } + + return false; + } + + @Override + public void endVisit(MySqlAlterTableModifyColumn x) { + + } + + @Override + public boolean visit(MySqlAlterTableCharacter x) { + print("CHARACTER SET = "); + x.getCharacterSet().accept(this); + + if (x.getCollate() != null) { + print(", COLLATE = "); + x.getCollate().accept(this); + } + + return false; + } + + @Override + public void endVisit(MySqlAlterTableCharacter x) { + + } + + @Override + public boolean visit(MySqlAlterTableAddIndex x) { + print("ADD "); + if (x.getType() != null) { + print(x.getType()); + print(" "); + } + + print("INDEX "); + + if (x.getName() != null) { + x.getName().accept(this); + print(' '); + } + print("("); + printAndAccept(x.getItems(), ", "); + print(")"); + + if (x.getUsing() != null) { + print(" USING "); + print(x.getUsing()); + } + return false; + } + + @Override + public void endVisit(MySqlAlterTableAddIndex x) { + + } + + @Override + public boolean visit(MySqlAlterTableAddUnique x) { + print("ADD "); + if (x.getType() != null) { + print(x.getType()); + print(" "); + } + + print("UNIQUE "); + + if (x.getName() != null) { + x.getName().accept(this); + print(' '); + } + print("("); + printAndAccept(x.getItems(), ", "); + print(")"); + + if (x.getUsing() != null) { + print(" USING "); + print(x.getUsing()); + } + return false; + } + + @Override + public void endVisit(MySqlAlterTableAddUnique x) { + + } + + @Override + public boolean visit(MySqlAlterTableOption x) { + print(x.getName()); + print(" = "); + print(x.getValue().toString()); + return false; + } + + @Override + public void endVisit(MySqlAlterTableOption x) { + + } + + @Override + public void endVisit(MySqlCreateTableStatement x) { + + } + + @Override + public boolean visit(MySqlHelpStatement x) { + print("HELP "); + x.getContent().accept(this); + return false; + } + + @Override + public void endVisit(MySqlHelpStatement x) { + + } + + @Override + public boolean visit(MySqlCharExpr x) { + print(x.toString()); + return false; + } + + @Override + public void endVisit(MySqlCharExpr x) { + + } + + @Override + public boolean visit(MySqlUnique x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + + print("UNIQUE"); + + if (x.getIndexType() != null) { + print(" USING "); + print(x.getIndexType()); + } + + print(" ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + + return false; + } + + @Override + public void endVisit(MySqlUnique x) { + + } + + @Override + public boolean visit(MySqlForeignKey x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + + print("FOREIGN KEY ("); + printAndAccept(x.getReferencedColumns(), ", "); + print(")"); + + print(" REFERENCES "); + x.getReferencedTableName().accept(this); + + print(" ("); + printAndAccept(x.getReferencedColumns(), ", "); + print(")"); + return false; + } + + @Override + public void endVisit(MySqlForeignKey x) { + + } + + @Override + public boolean visit(MySqlAlterTableDiscardTablespace x) { + print("DISCARD TABLESPACE"); + return false; + } + + @Override + public void endVisit(MySqlAlterTableDiscardTablespace x) { + + } + + @Override + public boolean visit(MySqlAlterTableImportTablespace x) { + print("IMPORT TABLESPACE"); + return false; + } + + @Override + public void endVisit(MySqlAlterTableImportTablespace x) { + + } + + @Override + public boolean visit(SQLAssignItem x) { + x.getTarget().accept(this); + if (!"NAMES".equalsIgnoreCase(x.getTarget().toString())) { + print(" = "); + } + x.getValue().accept(this); + return false; + } + + @Override + public boolean visit(TableSpaceOption x) { + x.getName().accept(this); + + if (x.getStorage() != null) { + print(' '); + x.getStorage().accept(this); + } + return false; + } + + @Override + public void endVisit(TableSpaceOption x) { + + } + + @Override + public boolean visit(MySqlPartitioningDef x) { + print("PARTITION "); + x.getName().accept(this); + if (x.getValues() != null) { + print(' '); + x.getValues().accept(this); + } + + if (x.getDataDirectory() != null) { + incrementIndent(); + println(); + print("DATA DIRECTORY "); + x.getDataDirectory().accept(this); + decrementIndent(); + } + if (x.getIndexDirectory() != null) { + incrementIndent(); + println(); + print("INDEX DIRECTORY "); + x.getIndexDirectory().accept(this); + decrementIndent(); + } + + return false; + } + + @Override + public void endVisit(MySqlPartitioningDef x) { + + } + + @Override + public boolean visit(LessThanValues x) { + print("VALUES LESS THAN ("); + printAndAccept(x.getItems(), ", "); + print(')'); + return false; + } + + @Override + public void endVisit(LessThanValues x) { + + } + + @Override + public boolean visit(InValues x) { + print("VALUES IN ("); + printAndAccept(x.getItems(), ", "); + print(')'); + return false; + } + + @Override + public void endVisit(InValues x) { + + } + +} // diff --git a/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java index 4fcf9a609b..311e642d59 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/ParameterizedOutputVisitorUtils.java @@ -39,6 +39,10 @@ public class ParameterizedOutputVisitorUtils { public static String parameterize(String sql, String dbType) { SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType); List statementList = parser.parseStatementList(); + if (statementList.size() == 0) { + return sql; + } + SQLStatement stmt = statementList.get(0); StringBuilder out = new StringBuilder(); diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java index 3d344a6b5c..36ea07a12e 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLASTOutputVisitor.java @@ -1,1482 +1,1490 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.sql.visitor; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.NClob; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import com.alibaba.druid.sql.ast.SQLCommentHint; -import com.alibaba.druid.sql.ast.SQLDataType; -import com.alibaba.druid.sql.ast.SQLExpr; -import com.alibaba.druid.sql.ast.SQLObject; -import com.alibaba.druid.sql.ast.SQLOrderBy; -import com.alibaba.druid.sql.ast.SQLOver; -import com.alibaba.druid.sql.ast.SQLSetQuantifier; -import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr; -import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr; -import com.alibaba.druid.sql.ast.expr.SQLAllExpr; -import com.alibaba.druid.sql.ast.expr.SQLAnyExpr; -import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr; -import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; -import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator; -import com.alibaba.druid.sql.ast.expr.SQLCaseExpr; -import com.alibaba.druid.sql.ast.expr.SQLCastExpr; -import com.alibaba.druid.sql.ast.expr.SQLCharExpr; -import com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr; -import com.alibaba.druid.sql.ast.expr.SQLDefaultExpr; -import com.alibaba.druid.sql.ast.expr.SQLExistsExpr; -import com.alibaba.druid.sql.ast.expr.SQLHexExpr; -import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; -import com.alibaba.druid.sql.ast.expr.SQLInListExpr; -import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr; -import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; -import com.alibaba.druid.sql.ast.expr.SQLListExpr; -import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; -import com.alibaba.druid.sql.ast.expr.SQLNCharExpr; -import com.alibaba.druid.sql.ast.expr.SQLNotExpr; -import com.alibaba.druid.sql.ast.expr.SQLNullExpr; -import com.alibaba.druid.sql.ast.expr.SQLNumberExpr; -import com.alibaba.druid.sql.ast.expr.SQLObjectCreateExpr; -import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; -import com.alibaba.druid.sql.ast.expr.SQLQueryExpr; -import com.alibaba.druid.sql.ast.expr.SQLSomeExpr; -import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr; -import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr; -import com.alibaba.druid.sql.ast.statement.NotNullConstraint; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddForeignKey; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeinKey; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem; -import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement; -import com.alibaba.druid.sql.ast.statement.SQLAssignItem; -import com.alibaba.druid.sql.ast.statement.SQLCallStatement; -import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType; -import com.alibaba.druid.sql.ast.statement.SQLCheck; -import com.alibaba.druid.sql.ast.statement.SQLColumnCheck; -import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint; -import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; -import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey; -import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueIndex; -import com.alibaba.druid.sql.ast.statement.SQLCommentStatement; -import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement; -import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; -import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement; -import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement; -import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement; -import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement; -import com.alibaba.druid.sql.ast.statement.SQLExprHint; -import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; -import com.alibaba.druid.sql.ast.statement.SQLInsertStatement; -import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause; -import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource; -import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource.JoinType; -import com.alibaba.druid.sql.ast.statement.SQLReleaseSavePointStatement; -import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement; -import com.alibaba.druid.sql.ast.statement.SQLSavePointStatement; -import com.alibaba.druid.sql.ast.statement.SQLSelect; -import com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause; -import com.alibaba.druid.sql.ast.statement.SQLSelectItem; -import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem; -import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; -import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; -import com.alibaba.druid.sql.ast.statement.SQLSetStatement; -import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource; -import com.alibaba.druid.sql.ast.statement.SQLTableElement; -import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement; -import com.alibaba.druid.sql.ast.statement.SQLUnionQuery; -import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint; -import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem; -import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; -import com.alibaba.druid.sql.ast.statement.SQLUseStatement; -import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause; - -public class SQLASTOutputVisitor extends SQLASTVisitorAdapter { - - protected final Appendable appender; - private String indent = "\t"; - private int indentCount = 0; - private boolean prettyFormat = true; - - private List parameters; - - public SQLASTOutputVisitor(Appendable appender){ - this.appender = appender; - } - - public List getParameters() { - if (parameters == null) { - parameters = new ArrayList(); - } - - return parameters; - } - - public void setParameters(List parameters) { - this.parameters = parameters; - } - - public int getIndentCount() { - return indentCount; - } - - public Appendable getAppender() { - return appender; - } - - public boolean isPrettyFormat() { - return prettyFormat; - } - - public void setPrettyFormat(boolean prettyFormat) { - this.prettyFormat = prettyFormat; - } - - public void decrementIndent() { - this.indentCount -= 1; - } - - public void incrementIndent() { - this.indentCount += 1; - } - - public void print(char value) { - try { - this.appender.append(value); - } catch (IOException e) { - throw new RuntimeException("println error", e); - } - } - - public void print(int value) { - print(Integer.toString(value)); - } - - public void print(Date date) { - SimpleDateFormat dateFormat; - if (date instanceof java.sql.Timestamp) { - dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - } else { - dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - } - print("'" + dateFormat.format(date) + "'"); - } - - public void print(long value) { - print(Long.toString(value)); - } - - public void print(String text) { - try { - this.appender.append(text); - } catch (IOException e) { - throw new RuntimeException("println error", e); - } - } - - protected void printAlias(String alias) { - if ((alias != null) && (alias.length() > 0)) { - print(" "); - print(alias); - } - } - - protected void printAndAccept(List nodes, String seperator) { - for (int i = 0, size = nodes.size(); i < size; ++i) { - if (i != 0) { - print(seperator); - } - nodes.get(i).accept(this); - } - } - - protected void printSelectList(List selectList) { - incrementIndent(); - for (int i = 0, size = selectList.size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - - print(", "); - } - - selectList.get(i).accept(this); - } - decrementIndent(); - } - - protected void printlnAndAccept(List nodes, String seperator) { - for (int i = 0, size = nodes.size(); i < size; ++i) { - if (i != 0) { - println(seperator); - } - - ((SQLObject) nodes.get(i)).accept(this); - } - } - - public void printIndent() { - for (int i = 0; i < this.indentCount; ++i) { - print(this.indent); - } - } - - public void println() { - if (!isPrettyFormat()) { - print(' '); - return; - } - - print("\n"); - printIndent(); - } - - public void println(String text) { - print(text); - println(); - } - - // //////////////////// - - public boolean visit(SQLBetweenExpr x) { - x.getTestExpr().accept(this); - - if (x.isNot()) { - print(" NOT BETWEEN "); - } else { - print(" BETWEEN "); - } - - x.getBeginExpr().accept(this); - print(" AND "); - x.getEndExpr().accept(this); - - return false; - } - - public boolean visit(SQLBinaryOpExpr x) { - SQLObject parent = x.getParent(); - boolean isRoot = parent instanceof SQLSelectQueryBlock; - boolean relational = x.getOperator() == SQLBinaryOperator.BooleanAnd - || x.getOperator() == SQLBinaryOperator.BooleanOr; - - if (isRoot && relational) { - incrementIndent(); - } - - List groupList = new ArrayList(); - SQLExpr left = x.getLeft(); - for (;;) { - if (left instanceof SQLBinaryOpExpr && ((SQLBinaryOpExpr) left).getOperator() == x.getOperator()) { - SQLBinaryOpExpr binaryLeft = (SQLBinaryOpExpr) left; - groupList.add(binaryLeft.getRight()); - left = binaryLeft.getLeft(); - } else { - groupList.add(left); - break; - } - } - - for (int i = groupList.size() - 1; i >= 0; --i) { - SQLExpr item = groupList.get(i); - visitBinaryLeft(item, x.getOperator()); - - if (relational) { - println(); - } else { - print(" "); - } - print(x.getOperator().name); - print(" "); - } - - visitorBinaryRight(x); - - if (isRoot && relational) { - decrementIndent(); - } - - return false; - } - - private void visitorBinaryRight(SQLBinaryOpExpr x) { - if (x.getRight() instanceof SQLBinaryOpExpr) { - SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight(); - boolean rightRational = right.getOperator() == SQLBinaryOperator.BooleanAnd - || right.getOperator() == SQLBinaryOperator.BooleanOr; - - if (right.getOperator().priority >= x.getOperator().priority) { - if (rightRational) { - incrementIndent(); - } - - print('('); - right.accept(this); - print(')'); - - if (rightRational) { - decrementIndent(); - } - } else { - right.accept(this); - } - } else { - x.getRight().accept(this); - } - } - - private void visitBinaryLeft(SQLExpr left, SQLBinaryOperator op) { - if (left instanceof SQLBinaryOpExpr) { - SQLBinaryOpExpr binaryLeft = (SQLBinaryOpExpr) left; - boolean leftRational = binaryLeft.getOperator() == SQLBinaryOperator.BooleanAnd - || binaryLeft.getOperator() == SQLBinaryOperator.BooleanOr; - - if (binaryLeft.getOperator().priority > op.priority) { - if (leftRational) { - incrementIndent(); - } - print('('); - left.accept(this); - print(')'); - - if (leftRational) { - decrementIndent(); - } - } else { - left.accept(this); - } - } else { - left.accept(this); - } - } - - public boolean visit(SQLCaseExpr x) { - print("CASE "); - if (x.getValueExpr() != null) { - x.getValueExpr().accept(this); - print(" "); - } - - printAndAccept(x.getItems(), " "); - - if (x.getElseExpr() != null) { - print(" ELSE "); - x.getElseExpr().accept(this); - } - - print(" END"); - return false; - } - - public boolean visit(SQLCaseExpr.Item x) { - print("WHEN "); - x.getConditionExpr().accept(this); - print(" THEN "); - x.getValueExpr().accept(this); - return false; - } - - public boolean visit(SQLCastExpr x) { - print("CAST("); - x.getExpr().accept(this); - print(" AS "); - x.getDataType().accept(this); - print(")"); - - return false; - } - - public boolean visit(SQLCharExpr x) { - if ((x.getText() == null) || (x.getText().length() == 0)) { - print("NULL"); - } else { - print("'"); - print(x.getText().replaceAll("'", "''")); - print("'"); - } - - return false; - } - - public boolean visit(SQLDataType x) { - print(x.getName()); - if (x.getArguments().size() > 0) { - print("("); - printAndAccept(x.getArguments(), ", "); - print(")"); - } - - return false; - } - - public boolean visit(SQLCharactorDataType x) { - visit((SQLDataType) x); - return false; - } - - public boolean visit(SQLExistsExpr x) { - if (x.isNot()) { - print("NOT EXISTS ("); - } else { - print("EXISTS ("); - } - incrementIndent(); - x.getSubQuery().accept(this); - decrementIndent(); - print(")"); - return false; - } - - public boolean visit(SQLIdentifierExpr x) { - print(x.getName()); - return false; - } - - public boolean visit(SQLInListExpr x) { - x.getExpr().accept(this); - - if (x.isNot()) { - print(" NOT IN ("); - } else { - print(" IN ("); - } - - printAndAccept(x.getTargetList(), ", "); - print(')'); - return false; - } - - public boolean visit(SQLIntegerExpr x) { - print(x.getNumber().toString()); - return false; - } - - public boolean visit(SQLMethodInvokeExpr x) { - if (x.getOwner() != null) { - x.getOwner().accept(this); - print("."); - } - print(x.getMethodName()); - print("("); - printAndAccept(x.getParameters(), ", "); - print(")"); - return false; - } - - public boolean visit(SQLAggregateExpr x) { - print(x.getMethodName()); - print("("); - - if (x.getOption() != null) { - print(x.getOption().toString()); - print(' '); - } - - printAndAccept(x.getArguments(), ", "); - print(")"); - - if (x.getOver() != null) { - print(" "); - x.getOver().accept(this); - } - return false; - } - - public boolean visit(SQLAllColumnExpr x) { - print("*"); - return true; - } - - public boolean visit(SQLNCharExpr x) { - if ((x.getText() == null) || (x.getText().length() == 0)) { - print("NULL"); - } else { - print("N'"); - print(x.getText().replace("'", "''")); - print("'"); - } - return false; - } - - public boolean visit(SQLNotExpr x) { - print("NOT "); - x.getExpr().accept(this); - return false; - } - - public boolean visit(SQLNullExpr x) { - print("NULL"); - return false; - } - - public boolean visit(SQLNumberExpr x) { - print(x.getNumber().toString()); - return false; - } - - public boolean visit(SQLObjectCreateExpr x) { - throw new UnsupportedOperationException(); - } - - public boolean visit(SQLPropertyExpr x) { - x.getOwner().accept(this); - print("."); - print(x.getName()); - return false; - } - - public boolean visit(SQLQueryExpr x) { - SQLObject parent = x.getParent(); - if (parent instanceof SQLSelect) { - parent = parent.getParent(); - } - - if (parent instanceof SQLStatement) { - incrementIndent(); - - println(); - x.getSubQuery().accept(this); - - decrementIndent(); - } else if (parent instanceof ValuesClause) { - println(); - x.getSubQuery().accept(this); - println(); - } else { - print("("); - incrementIndent(); - println(); - x.getSubQuery().accept(this); - println(); - decrementIndent(); - print(")"); - } - return false; - } - - public boolean visit(SQLSelectGroupByClause x) { - if (x.getItems().size() > 0) { - print("GROUP BY "); - printAndAccept(x.getItems(), ", "); - } - - if (x.getHaving() != null) { - println(); - print("HAVING "); - x.getHaving().accept(this); - } - return false; - } - - public boolean visit(SQLSelect x) { - x.getQuery().setParent(x); - - if (x.getWithSubQuery() != null) { - x.getWithSubQuery().accept(this); - println(); - } - - x.getQuery().accept(this); - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - return false; - } - - public boolean visit(SQLSelectQueryBlock x) { - print("SELECT "); - - if (SQLSetQuantifier.ALL == x.getDistionOption()) { - print("ALL "); - } else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) { - print("DISTINCT "); - } else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) { - print("UNIQUE "); - } - - printSelectList(x.getSelectList()); - - if (x.getFrom() != null) { - println(); - print("FROM "); - x.getFrom().accept(this); - } - - if (x.getWhere() != null) { - println(); - print("WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - if (x.getGroupBy() != null) { - println(); - x.getGroupBy().accept(this); - } - - return false; - } - - public boolean visit(SQLSelectItem x) { - x.getExpr().accept(this); - - if ((x.getAlias() != null) && (x.getAlias().length() > 0)) { - print(" AS "); - print(x.getAlias()); - } - return false; - } - - public boolean visit(SQLOrderBy x) { - if (x.getItems().size() > 0) { - print("ORDER BY "); - - printAndAccept(x.getItems(), ", "); - } - return false; - } - - public boolean visit(SQLSelectOrderByItem x) { - x.getExpr().accept(this); - if (x.getType() != null) { - print(" "); - print(x.getType().name().toUpperCase()); - } - - if (x.getCollate() != null) { - print(" COLLATE "); - print(x.getCollate()); - } - - return false; - } - - public boolean visit(SQLExprTableSource x) { - x.getExpr().accept(this); - - if (x.getAlias() != null) { - print(' '); - print(x.getAlias()); - } - - return false; - } - - public boolean visit(SQLSelectStatement stmt) { - SQLSelect select = stmt.getSelect(); - - select.accept(this); - - return false; - } - - public boolean visit(SQLVariantRefExpr x) { - int index = x.getIndex(); - - if (parameters == null || index >= parameters.size()) { - print(x.getName()); - return false; - } - - Object param = parameters.get(index); - printParameter(param); - return false; - } - - public void printParameter(Object param) { - if (param == null) { - print("NULL"); - return; - } - - if (param instanceof Number // - || param instanceof Boolean) { - print(param.toString()); - return; - } - - if (param instanceof String) { - SQLCharExpr charExpr = new SQLCharExpr((String) param); - visit(charExpr); - return; - } - - if (param instanceof Date) { - print((Date) param); - return; - } - - if (param instanceof InputStream) { - print("'"); - return; - } - - if (param instanceof Reader) { - print("'"); - return; - } - - if (param instanceof Blob) { - print("'"); - return; - } - - if (param instanceof NClob) { - print("'"); - return; - } - - if (param instanceof Clob) { - print("'"); - return; - } - - print("'" + param.getClass().getName() + "'"); - } - - public boolean visit(SQLDropTableStatement x) { - print("DROP TABLE "); - printAndAccept(x.getTableSources(), ", "); - return false; - } - - public boolean visit(SQLDropViewStatement x) { - print("DROP VIEW "); - printAndAccept(x.getTableSources(), ", "); - return false; - } - - public boolean visit(SQLTableElement x) { - if (x instanceof SQLColumnDefinition) { - return visit((SQLColumnDefinition) x); - } - - throw new RuntimeException("TODO"); - } - - public boolean visit(SQLColumnDefinition x) { - x.getName().accept(this); - - if (x.getDataType() != null) { - print(' '); - x.getDataType().accept(this); - } - - if (x.getDefaultExpr() != null) { - visitColumnDefault(x); - } - - for (SQLColumnConstraint item : x.getConstaints()) { - print(' '); - item.accept(this); - } - - if (x.getEnable() != null) { - if (x.getEnable().booleanValue()) { - print(" ENABLE"); - } - } - - return false; - } - - protected void visitColumnDefault(SQLColumnDefinition x) { - print(" DEFAULT "); - x.getDefaultExpr().accept(this); - } - - public boolean visit(SQLDeleteStatement x) { - print("DELETE FROM "); - - x.getTableName().accept(this); - - if (x.getWhere() != null) { - print(" WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - public boolean visit(SQLCurrentOfCursorExpr x) { - print("CURRENT OF "); - x.getCursorName().accept(this); - return false; - } - - public boolean visit(SQLInsertStatement x) { - print("INSERT INTO "); - - x.getTableSource().accept(this); - - if (x.getColumns().size() > 0) { - incrementIndent(); - println(); - print("("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - decrementIndent(); - } - - if (x.getValues() != null) { - println(); - print("VALUES"); - println(); - x.getValues().accept(this); - } else { - if (x.getQuery() != null) { - println(); - x.getQuery().setParent(x); - x.getQuery().accept(this); - } - } - - return false; - } - - public boolean visit(SQLUpdateSetItem x) { - x.getColumn().accept(this); - print(" = "); - x.getValue().accept(this); - return false; - } - - public boolean visit(SQLUpdateStatement x) { - print("UPDATE "); - - x.getTableSource().accept(this); - - println(); - print("SET "); - for (int i = 0, size = x.getItems().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getItems().get(i).accept(this); - } - - if (x.getWhere() != null) { - println(); - print("WHERE "); - x.getWhere().setParent(x); - x.getWhere().accept(this); - } - - return false; - } - - public boolean visit(SQLCreateTableStatement x) { - print("CREATE TABLE "); - if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { - print("GLOBAL TEMPORARY "); - } else if (SQLCreateTableStatement.Type.LOCAL_TEMPORARY.equals(x.getType())) { - print("LOCAL TEMPORARY "); - } - - x.getName().accept(this); - - int size = x.getTableElementList().size(); - - if (size > 0) { - print(" ("); - incrementIndent(); - println(); - for (int i = 0; i < size; ++i) { - if (i != 0) { - print(","); - println(); - } - x.getTableElementList().get(i).accept(this); - } - decrementIndent(); - println(); - print(")"); - } - - return false; - } - - public boolean visit(SQLUniqueConstraint x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - - print("UNIQUE ("); - for (int i = 0, size = x.getColumns().size(); i < size; ++i) { - if (i != 0) { - print(", "); - } - x.getColumns().get(i).accept(this); - } - print(")"); - return false; - } - - public boolean visit(NotNullConstraint x) { - print("NOT NULL"); - return false; - } - - @Override - public boolean visit(SQLUnionQuery x) { - x.getLeft().accept(this); - println(); - print(x.getOperator().name); - println(); - - boolean needParen = false; - - if (x.getOrderBy() != null) { - needParen = true; - } - - if (needParen) { - print('('); - x.getRight().accept(this); - print(')'); - } else { - x.getRight().accept(this); - } - - if (x.getOrderBy() != null) { - println(); - x.getOrderBy().accept(this); - } - - return false; - } - - @Override - public boolean visit(SQLUnaryExpr x) { - print(x.getOperator().name); - - SQLExpr expr = x.getExpr(); - - switch (x.getOperator()) { - case BINARY: - case Prior: - case ConnectByRoot: - print(' '); - expr.accept(this); - return false; - default: - break; - } - - if (expr instanceof SQLBinaryOpExpr) { - print('('); - expr.accept(this); - print(')'); - } else if (expr instanceof SQLUnaryExpr) { - print('('); - expr.accept(this); - print(')'); - } else { - expr.accept(this); - } - return false; - } - - @Override - public boolean visit(SQLHexExpr x) { - print("0x"); - print(x.getHex()); - - String charset = (String) x.getAttribute("USING"); - if (charset != null) { - print(" USING "); - print(charset); - } - - return false; - } - - @Override - public boolean visit(SQLSetStatement x) { - print("SET "); - printAndAccept(x.getItems(), ", "); - return false; - } - - @Override - public boolean visit(SQLAssignItem x) { - x.getTarget().accept(this); - print(" = "); - x.getValue().accept(this); - return false; - } - - @Override - public boolean visit(SQLCallStatement x) { - print("CALL "); - x.getProcedureName().accept(this); - print('('); - printAndAccept(x.getParameters(), ", "); - print(')'); - return false; - } - - @Override - public boolean visit(SQLJoinTableSource x) { - x.getLeft().accept(this); - incrementIndent(); - - if (x.getJoinType() == JoinType.COMMA) { - print(","); - } else { - println(); - print(JoinType.toString(x.getJoinType())); - } - print(" "); - x.getRight().accept(this); - - if (x.getCondition() != null) { - incrementIndent(); - print(" ON "); - x.getCondition().accept(this); - decrementIndent(); - } - - if (x.getUsing().size() > 0) { - print(" USING ("); - printAndAccept(x.getUsing(), ", "); - print(")"); - } - - if (x.getAlias() != null) { - print(" AS "); - print(x.getAlias()); - } - - decrementIndent(); - - return false; - } - - @Override - public boolean visit(ValuesClause x) { - print("("); - incrementIndent(); - for (int i = 0, size = x.getValues().size(); i < size; ++i) { - if (i != 0) { - if (i % 5 == 0) { - println(); - } - print(", "); - } - - SQLExpr expr = x.getValues().get(i); - expr.setParent(x); - expr.accept(this); - } - decrementIndent(); - print(")"); - return false; - } - - @Override - public boolean visit(SQLSomeExpr x) { - print("SOME ("); - - incrementIndent(); - x.getSubQuery().accept(this); - decrementIndent(); - print(")"); - return false; - } - - @Override - public boolean visit(SQLAnyExpr x) { - print("ANY ("); - - incrementIndent(); - x.getSubQuery().accept(this); - decrementIndent(); - print(")"); - return false; - } - - @Override - public boolean visit(SQLAllExpr x) { - print("ALL ("); - - incrementIndent(); - x.getSubQuery().accept(this); - decrementIndent(); - print(")"); - return false; - } - - @Override - public boolean visit(SQLInSubQueryExpr x) { - x.getExpr().accept(this); - if (x.isNot()) { - print(" NOT IN ("); - } else { - print(" IN ("); - } - - incrementIndent(); - x.getSubQuery().accept(this); - decrementIndent(); - print(")"); - - return false; - } - - @Override - public boolean visit(SQLListExpr x) { - print("("); - printAndAccept(x.getItems(), ", "); - print(")"); - - return false; - } - - @Override - public boolean visit(SQLSubqueryTableSource x) { - print("("); - incrementIndent(); - x.getSelect().accept(this); - println(); - decrementIndent(); - print(")"); - - if (x.getAlias() != null) { - print(' '); - print(x.getAlias()); - } - - return false; - } - - @Override - public boolean visit(SQLTruncateStatement x) { - print("TRUNCATE TABLE "); - printAndAccept(x.getTableSources(), ", "); - return false; - } - - @Override - public boolean visit(SQLDefaultExpr x) { - print("DEFAULT"); - return false; - } - - @Override - public void endVisit(SQLCommentStatement x) { - - } - - @Override - public boolean visit(SQLCommentStatement x) { - print("COMMENT ON "); - if (x.getType() != null) { - print(x.getType().name()); - print(" "); - } - x.getOn().accept(this); - - print(" IS "); - x.getComment().accept(this); - - return false; - } - - @Override - public boolean visit(SQLUseStatement x) { - print("USE "); - x.getDatabase().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableAddColumn x) { - print("ADD ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - return false; - } - - @Override - public boolean visit(SQLAlterTableDropColumnItem x) { - print("DROP COLUMN "); - x.getColumnName().accept(this); - return false; - } - - @Override - public void endVisit(SQLAlterTableAddColumn x) { - - } - - @Override - public boolean visit(SQLDropIndexStatement x) { - print("DROP INDEX "); - x.getIndexName().accept(this); - print(" ON "); - x.getTableName().accept(this); - return false; - } - - @Override - public boolean visit(SQLSavePointStatement x) { - print("SAVEPOINT "); - x.getName().accept(this); - return false; - } - - @Override - public boolean visit(SQLReleaseSavePointStatement x) { - print("RELEASE SAVEPOINT "); - x.getName().accept(this); - return false; - } - - @Override - public boolean visit(SQLRollbackStatement x) { - print("ROLLBACK"); - if (x.getTo() != null) { - print(" TO "); - x.getTo().accept(this); - } - return false; - } - - public boolean visit(SQLCommentHint x) { - print("/*"); - print(x.getText()); - print("*/"); - return false; - } - - @Override - public boolean visit(SQLCreateDatabaseStatement x) { - print("CREATE DATABASE "); - x.getName().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableDropIndex x) { - print("DROP INDEX "); - x.getIndexName().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableAddPrimaryKey x) { - print("ADD "); - x.getPrimaryKey().accept(this); - return false; - } - - @Override - public boolean visit(SQLOver x) { - print("OVER ("); - if (x.getPartitionBy().size() > 0) { - printAndAccept(x.getPartitionBy(), ", "); - print(' '); - } - if (x.getOrderBy() != null) { - x.getOrderBy().accept(this); - } - print(")"); - return false; - } - - @Override - public boolean visit(SQLColumnPrimaryKey x) { - print(" PRIMARY KEY"); - return false; - } - - @Override - public boolean visit(SQLColumnCheck x) { - print("CHECK "); - x.getExpr().accept(this); - return false; - } - - @Override - public boolean visit(SQLColumnUniqueIndex x) { - print(" UNIQUE INDEX"); - return false; - } - - @Override - public boolean visit(SQLWithSubqueryClause x) { - print("WITH"); - if (x.getRecursive() == Boolean.TRUE) { - print(" RECURSIVE"); - } - incrementIndent(); - println(); - printlnAndAccept(x.getEntries(), ", "); - decrementIndent(); - return false; - } - - @Override - public boolean visit(SQLWithSubqueryClause.Entry x) { - x.getName().accept(this); - - if (x.getColumns().size() > 0) { - print(" ("); - printAndAccept(x.getColumns(), ", "); - print(")"); - } - println(); - print("AS"); - println(); - print("("); - incrementIndent(); - println(); - x.getSubQuery().accept(this); - decrementIndent(); - println(); - print(")"); - - return false; - } - - @Override - public boolean visit(SQLAlterTableAlterColumn x) { - print("ALTER COLUMN "); - x.getColumn().accept(this); - return false; - } - - @Override - public boolean visit(SQLCheck x) { - if (x.getName() != null) { - print("CONSTRAINT "); - x.getName().accept(this); - print(' '); - } - print("CHECK ("); - x.getExpr().accept(this); - print(')'); - return false; - } - - @Override - public boolean visit(SQLAlterTableDropForeinKey x) { - print("DROP FOREIGN KEY "); - x.getIndexName().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableDropPrimaryKey x) { - print("DROP PRIMARY KEY"); - return false; - } - - @Override - public boolean visit(SQLAlterTableEnableKeys x) { - print("ENABLE KEYS"); - return false; - } - - @Override - public boolean visit(SQLAlterTableDisableKeys x) { - print("DISABLE KEYS"); - return false; - } - - @Override - public boolean visit(SQLAlterTableAddForeignKey x) { - print("ADD "); - x.getForeignKey().accept(this); - return false; - } - - public boolean visit(SQLAlterTableDisableConstraint x) { - print("DISABLE CONSTRAINT "); - x.getConstraintName().accept(this); - return false; - } - - public boolean visit(SQLAlterTableEnableConstraint x) { - print("ENABLE CONSTRAINT "); - x.getConstraintName().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableDropConstraint x) { - print("DROP CONSTRAINT "); - x.getConstraintName().accept(this); - return false; - } - - @Override - public boolean visit(SQLAlterTableStatement x) { - print("ALTER TABLE "); - x.getName().accept(this); - incrementIndent(); - for (int i = 0; i < x.getItems().size(); ++i) { - SQLAlterTableItem item = x.getItems().get(i); - if (i != 0) { - print(','); - } - println(); - item.accept(this); - } - decrementIndent(); - return false; - } - - @Override - public boolean visit(SQLExprHint x) { - x.getExpr().accept(this); - return false; - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.sql.visitor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.NClob; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import com.alibaba.druid.sql.ast.SQLCommentHint; +import com.alibaba.druid.sql.ast.SQLDataType; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.SQLObject; +import com.alibaba.druid.sql.ast.SQLOrderBy; +import com.alibaba.druid.sql.ast.SQLOver; +import com.alibaba.druid.sql.ast.SQLSetQuantifier; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr; +import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr; +import com.alibaba.druid.sql.ast.expr.SQLAllExpr; +import com.alibaba.druid.sql.ast.expr.SQLAnyExpr; +import com.alibaba.druid.sql.ast.expr.SQLBetweenExpr; +import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; +import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator; +import com.alibaba.druid.sql.ast.expr.SQLCaseExpr; +import com.alibaba.druid.sql.ast.expr.SQLCastExpr; +import com.alibaba.druid.sql.ast.expr.SQLCharExpr; +import com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr; +import com.alibaba.druid.sql.ast.expr.SQLDefaultExpr; +import com.alibaba.druid.sql.ast.expr.SQLExistsExpr; +import com.alibaba.druid.sql.ast.expr.SQLHexExpr; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.expr.SQLInListExpr; +import com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr; +import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; +import com.alibaba.druid.sql.ast.expr.SQLListExpr; +import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr; +import com.alibaba.druid.sql.ast.expr.SQLNCharExpr; +import com.alibaba.druid.sql.ast.expr.SQLNotExpr; +import com.alibaba.druid.sql.ast.expr.SQLNullExpr; +import com.alibaba.druid.sql.ast.expr.SQLNumberExpr; +import com.alibaba.druid.sql.ast.expr.SQLObjectCreateExpr; +import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; +import com.alibaba.druid.sql.ast.expr.SQLQueryExpr; +import com.alibaba.druid.sql.ast.expr.SQLSomeExpr; +import com.alibaba.druid.sql.ast.expr.SQLUnaryExpr; +import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr; +import com.alibaba.druid.sql.ast.statement.NotNullConstraint; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddForeignKey; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPrimaryKey; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeinKey; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem; +import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement; +import com.alibaba.druid.sql.ast.statement.SQLAssignItem; +import com.alibaba.druid.sql.ast.statement.SQLCallStatement; +import com.alibaba.druid.sql.ast.statement.SQLCharactorDataType; +import com.alibaba.druid.sql.ast.statement.SQLCheck; +import com.alibaba.druid.sql.ast.statement.SQLColumnCheck; +import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint; +import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; +import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey; +import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueIndex; +import com.alibaba.druid.sql.ast.statement.SQLCommentStatement; +import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement; +import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; +import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement; +import com.alibaba.druid.sql.ast.statement.SQLDropIndexStatement; +import com.alibaba.druid.sql.ast.statement.SQLDropTableStatement; +import com.alibaba.druid.sql.ast.statement.SQLDropViewStatement; +import com.alibaba.druid.sql.ast.statement.SQLExprHint; +import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; +import com.alibaba.druid.sql.ast.statement.SQLInsertStatement; +import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause; +import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource; +import com.alibaba.druid.sql.ast.statement.SQLJoinTableSource.JoinType; +import com.alibaba.druid.sql.ast.statement.SQLReleaseSavePointStatement; +import com.alibaba.druid.sql.ast.statement.SQLRollbackStatement; +import com.alibaba.druid.sql.ast.statement.SQLSavePointStatement; +import com.alibaba.druid.sql.ast.statement.SQLSelect; +import com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause; +import com.alibaba.druid.sql.ast.statement.SQLSelectItem; +import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem; +import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; +import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; +import com.alibaba.druid.sql.ast.statement.SQLSetStatement; +import com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource; +import com.alibaba.druid.sql.ast.statement.SQLTableElement; +import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement; +import com.alibaba.druid.sql.ast.statement.SQLUnionQuery; +import com.alibaba.druid.sql.ast.statement.SQLUniqueConstraint; +import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem; +import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement; +import com.alibaba.druid.sql.ast.statement.SQLUseStatement; +import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause; + +public class SQLASTOutputVisitor extends SQLASTVisitorAdapter { + + protected final Appendable appender; + private String indent = "\t"; + private int indentCount = 0; + private boolean prettyFormat = true; + + private List parameters; + + public SQLASTOutputVisitor(Appendable appender){ + this.appender = appender; + } + + public int getParametersSize() { + if (parameters == null) { + return 0; + } + + return this.parameters.size(); + } + + public List getParameters() { + if (parameters == null) { + parameters = new ArrayList(); + } + + return parameters; + } + + public void setParameters(List parameters) { + this.parameters = parameters; + } + + public int getIndentCount() { + return indentCount; + } + + public Appendable getAppender() { + return appender; + } + + public boolean isPrettyFormat() { + return prettyFormat; + } + + public void setPrettyFormat(boolean prettyFormat) { + this.prettyFormat = prettyFormat; + } + + public void decrementIndent() { + this.indentCount -= 1; + } + + public void incrementIndent() { + this.indentCount += 1; + } + + public void print(char value) { + try { + this.appender.append(value); + } catch (IOException e) { + throw new RuntimeException("println error", e); + } + } + + public void print(int value) { + print(Integer.toString(value)); + } + + public void print(Date date) { + SimpleDateFormat dateFormat; + if (date instanceof java.sql.Timestamp) { + dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + } else { + dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + } + print("'" + dateFormat.format(date) + "'"); + } + + public void print(long value) { + print(Long.toString(value)); + } + + public void print(String text) { + try { + this.appender.append(text); + } catch (IOException e) { + throw new RuntimeException("println error", e); + } + } + + protected void printAlias(String alias) { + if ((alias != null) && (alias.length() > 0)) { + print(" "); + print(alias); + } + } + + protected void printAndAccept(List nodes, String seperator) { + for (int i = 0, size = nodes.size(); i < size; ++i) { + if (i != 0) { + print(seperator); + } + nodes.get(i).accept(this); + } + } + + protected void printSelectList(List selectList) { + incrementIndent(); + for (int i = 0, size = selectList.size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + + print(", "); + } + + selectList.get(i).accept(this); + } + decrementIndent(); + } + + protected void printlnAndAccept(List nodes, String seperator) { + for (int i = 0, size = nodes.size(); i < size; ++i) { + if (i != 0) { + println(seperator); + } + + ((SQLObject) nodes.get(i)).accept(this); + } + } + + public void printIndent() { + for (int i = 0; i < this.indentCount; ++i) { + print(this.indent); + } + } + + public void println() { + if (!isPrettyFormat()) { + print(' '); + return; + } + + print("\n"); + printIndent(); + } + + public void println(String text) { + print(text); + println(); + } + + // //////////////////// + + public boolean visit(SQLBetweenExpr x) { + x.getTestExpr().accept(this); + + if (x.isNot()) { + print(" NOT BETWEEN "); + } else { + print(" BETWEEN "); + } + + x.getBeginExpr().accept(this); + print(" AND "); + x.getEndExpr().accept(this); + + return false; + } + + public boolean visit(SQLBinaryOpExpr x) { + SQLObject parent = x.getParent(); + boolean isRoot = parent instanceof SQLSelectQueryBlock; + boolean relational = x.getOperator() == SQLBinaryOperator.BooleanAnd + || x.getOperator() == SQLBinaryOperator.BooleanOr; + + if (isRoot && relational) { + incrementIndent(); + } + + List groupList = new ArrayList(); + SQLExpr left = x.getLeft(); + for (;;) { + if (left instanceof SQLBinaryOpExpr && ((SQLBinaryOpExpr) left).getOperator() == x.getOperator()) { + SQLBinaryOpExpr binaryLeft = (SQLBinaryOpExpr) left; + groupList.add(binaryLeft.getRight()); + left = binaryLeft.getLeft(); + } else { + groupList.add(left); + break; + } + } + + for (int i = groupList.size() - 1; i >= 0; --i) { + SQLExpr item = groupList.get(i); + visitBinaryLeft(item, x.getOperator()); + + if (relational) { + println(); + } else { + print(" "); + } + print(x.getOperator().name); + print(" "); + } + + visitorBinaryRight(x); + + if (isRoot && relational) { + decrementIndent(); + } + + return false; + } + + private void visitorBinaryRight(SQLBinaryOpExpr x) { + if (x.getRight() instanceof SQLBinaryOpExpr) { + SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight(); + boolean rightRational = right.getOperator() == SQLBinaryOperator.BooleanAnd + || right.getOperator() == SQLBinaryOperator.BooleanOr; + + if (right.getOperator().priority >= x.getOperator().priority) { + if (rightRational) { + incrementIndent(); + } + + print('('); + right.accept(this); + print(')'); + + if (rightRational) { + decrementIndent(); + } + } else { + right.accept(this); + } + } else { + x.getRight().accept(this); + } + } + + private void visitBinaryLeft(SQLExpr left, SQLBinaryOperator op) { + if (left instanceof SQLBinaryOpExpr) { + SQLBinaryOpExpr binaryLeft = (SQLBinaryOpExpr) left; + boolean leftRational = binaryLeft.getOperator() == SQLBinaryOperator.BooleanAnd + || binaryLeft.getOperator() == SQLBinaryOperator.BooleanOr; + + if (binaryLeft.getOperator().priority > op.priority) { + if (leftRational) { + incrementIndent(); + } + print('('); + left.accept(this); + print(')'); + + if (leftRational) { + decrementIndent(); + } + } else { + left.accept(this); + } + } else { + left.accept(this); + } + } + + public boolean visit(SQLCaseExpr x) { + print("CASE "); + if (x.getValueExpr() != null) { + x.getValueExpr().accept(this); + print(" "); + } + + printAndAccept(x.getItems(), " "); + + if (x.getElseExpr() != null) { + print(" ELSE "); + x.getElseExpr().accept(this); + } + + print(" END"); + return false; + } + + public boolean visit(SQLCaseExpr.Item x) { + print("WHEN "); + x.getConditionExpr().accept(this); + print(" THEN "); + x.getValueExpr().accept(this); + return false; + } + + public boolean visit(SQLCastExpr x) { + print("CAST("); + x.getExpr().accept(this); + print(" AS "); + x.getDataType().accept(this); + print(")"); + + return false; + } + + public boolean visit(SQLCharExpr x) { + if ((x.getText() == null) || (x.getText().length() == 0)) { + print("NULL"); + } else { + print("'"); + print(x.getText().replaceAll("'", "''")); + print("'"); + } + + return false; + } + + public boolean visit(SQLDataType x) { + print(x.getName()); + if (x.getArguments().size() > 0) { + print("("); + printAndAccept(x.getArguments(), ", "); + print(")"); + } + + return false; + } + + public boolean visit(SQLCharactorDataType x) { + visit((SQLDataType) x); + return false; + } + + public boolean visit(SQLExistsExpr x) { + if (x.isNot()) { + print("NOT EXISTS ("); + } else { + print("EXISTS ("); + } + incrementIndent(); + x.getSubQuery().accept(this); + decrementIndent(); + print(")"); + return false; + } + + public boolean visit(SQLIdentifierExpr x) { + print(x.getName()); + return false; + } + + public boolean visit(SQLInListExpr x) { + x.getExpr().accept(this); + + if (x.isNot()) { + print(" NOT IN ("); + } else { + print(" IN ("); + } + + printAndAccept(x.getTargetList(), ", "); + print(')'); + return false; + } + + public boolean visit(SQLIntegerExpr x) { + print(x.getNumber().toString()); + return false; + } + + public boolean visit(SQLMethodInvokeExpr x) { + if (x.getOwner() != null) { + x.getOwner().accept(this); + print("."); + } + print(x.getMethodName()); + print("("); + printAndAccept(x.getParameters(), ", "); + print(")"); + return false; + } + + public boolean visit(SQLAggregateExpr x) { + print(x.getMethodName()); + print("("); + + if (x.getOption() != null) { + print(x.getOption().toString()); + print(' '); + } + + printAndAccept(x.getArguments(), ", "); + print(")"); + + if (x.getOver() != null) { + print(" "); + x.getOver().accept(this); + } + return false; + } + + public boolean visit(SQLAllColumnExpr x) { + print("*"); + return true; + } + + public boolean visit(SQLNCharExpr x) { + if ((x.getText() == null) || (x.getText().length() == 0)) { + print("NULL"); + } else { + print("N'"); + print(x.getText().replace("'", "''")); + print("'"); + } + return false; + } + + public boolean visit(SQLNotExpr x) { + print("NOT "); + x.getExpr().accept(this); + return false; + } + + public boolean visit(SQLNullExpr x) { + print("NULL"); + return false; + } + + public boolean visit(SQLNumberExpr x) { + print(x.getNumber().toString()); + return false; + } + + public boolean visit(SQLObjectCreateExpr x) { + throw new UnsupportedOperationException(); + } + + public boolean visit(SQLPropertyExpr x) { + x.getOwner().accept(this); + print("."); + print(x.getName()); + return false; + } + + public boolean visit(SQLQueryExpr x) { + SQLObject parent = x.getParent(); + if (parent instanceof SQLSelect) { + parent = parent.getParent(); + } + + if (parent instanceof SQLStatement) { + incrementIndent(); + + println(); + x.getSubQuery().accept(this); + + decrementIndent(); + } else if (parent instanceof ValuesClause) { + println(); + x.getSubQuery().accept(this); + println(); + } else { + print("("); + incrementIndent(); + println(); + x.getSubQuery().accept(this); + println(); + decrementIndent(); + print(")"); + } + return false; + } + + public boolean visit(SQLSelectGroupByClause x) { + if (x.getItems().size() > 0) { + print("GROUP BY "); + printAndAccept(x.getItems(), ", "); + } + + if (x.getHaving() != null) { + println(); + print("HAVING "); + x.getHaving().accept(this); + } + return false; + } + + public boolean visit(SQLSelect x) { + x.getQuery().setParent(x); + + if (x.getWithSubQuery() != null) { + x.getWithSubQuery().accept(this); + println(); + } + + x.getQuery().accept(this); + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + return false; + } + + public boolean visit(SQLSelectQueryBlock x) { + print("SELECT "); + + if (SQLSetQuantifier.ALL == x.getDistionOption()) { + print("ALL "); + } else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) { + print("DISTINCT "); + } else if (SQLSetQuantifier.UNIQUE == x.getDistionOption()) { + print("UNIQUE "); + } + + printSelectList(x.getSelectList()); + + if (x.getFrom() != null) { + println(); + print("FROM "); + x.getFrom().accept(this); + } + + if (x.getWhere() != null) { + println(); + print("WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + if (x.getGroupBy() != null) { + println(); + x.getGroupBy().accept(this); + } + + return false; + } + + public boolean visit(SQLSelectItem x) { + x.getExpr().accept(this); + + if ((x.getAlias() != null) && (x.getAlias().length() > 0)) { + print(" AS "); + print(x.getAlias()); + } + return false; + } + + public boolean visit(SQLOrderBy x) { + if (x.getItems().size() > 0) { + print("ORDER BY "); + + printAndAccept(x.getItems(), ", "); + } + return false; + } + + public boolean visit(SQLSelectOrderByItem x) { + x.getExpr().accept(this); + if (x.getType() != null) { + print(" "); + print(x.getType().name().toUpperCase()); + } + + if (x.getCollate() != null) { + print(" COLLATE "); + print(x.getCollate()); + } + + return false; + } + + public boolean visit(SQLExprTableSource x) { + x.getExpr().accept(this); + + if (x.getAlias() != null) { + print(' '); + print(x.getAlias()); + } + + return false; + } + + public boolean visit(SQLSelectStatement stmt) { + SQLSelect select = stmt.getSelect(); + + select.accept(this); + + return false; + } + + public boolean visit(SQLVariantRefExpr x) { + int index = x.getIndex(); + + if (parameters == null || index >= parameters.size()) { + print(x.getName()); + return false; + } + + Object param = parameters.get(index); + printParameter(param); + return false; + } + + public void printParameter(Object param) { + if (param == null) { + print("NULL"); + return; + } + + if (param instanceof Number // + || param instanceof Boolean) { + print(param.toString()); + return; + } + + if (param instanceof String) { + SQLCharExpr charExpr = new SQLCharExpr((String) param); + visit(charExpr); + return; + } + + if (param instanceof Date) { + print((Date) param); + return; + } + + if (param instanceof InputStream) { + print("'"); + return; + } + + if (param instanceof Reader) { + print("'"); + return; + } + + if (param instanceof Blob) { + print("'"); + return; + } + + if (param instanceof NClob) { + print("'"); + return; + } + + if (param instanceof Clob) { + print("'"); + return; + } + + print("'" + param.getClass().getName() + "'"); + } + + public boolean visit(SQLDropTableStatement x) { + print("DROP TABLE "); + printAndAccept(x.getTableSources(), ", "); + return false; + } + + public boolean visit(SQLDropViewStatement x) { + print("DROP VIEW "); + printAndAccept(x.getTableSources(), ", "); + return false; + } + + public boolean visit(SQLTableElement x) { + if (x instanceof SQLColumnDefinition) { + return visit((SQLColumnDefinition) x); + } + + throw new RuntimeException("TODO"); + } + + public boolean visit(SQLColumnDefinition x) { + x.getName().accept(this); + + if (x.getDataType() != null) { + print(' '); + x.getDataType().accept(this); + } + + if (x.getDefaultExpr() != null) { + visitColumnDefault(x); + } + + for (SQLColumnConstraint item : x.getConstaints()) { + print(' '); + item.accept(this); + } + + if (x.getEnable() != null) { + if (x.getEnable().booleanValue()) { + print(" ENABLE"); + } + } + + return false; + } + + protected void visitColumnDefault(SQLColumnDefinition x) { + print(" DEFAULT "); + x.getDefaultExpr().accept(this); + } + + public boolean visit(SQLDeleteStatement x) { + print("DELETE FROM "); + + x.getTableName().accept(this); + + if (x.getWhere() != null) { + print(" WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + public boolean visit(SQLCurrentOfCursorExpr x) { + print("CURRENT OF "); + x.getCursorName().accept(this); + return false; + } + + public boolean visit(SQLInsertStatement x) { + print("INSERT INTO "); + + x.getTableSource().accept(this); + + if (x.getColumns().size() > 0) { + incrementIndent(); + println(); + print("("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + decrementIndent(); + } + + if (x.getValues() != null) { + println(); + print("VALUES"); + println(); + x.getValues().accept(this); + } else { + if (x.getQuery() != null) { + println(); + x.getQuery().setParent(x); + x.getQuery().accept(this); + } + } + + return false; + } + + public boolean visit(SQLUpdateSetItem x) { + x.getColumn().accept(this); + print(" = "); + x.getValue().accept(this); + return false; + } + + public boolean visit(SQLUpdateStatement x) { + print("UPDATE "); + + x.getTableSource().accept(this); + + println(); + print("SET "); + for (int i = 0, size = x.getItems().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getItems().get(i).accept(this); + } + + if (x.getWhere() != null) { + println(); + print("WHERE "); + x.getWhere().setParent(x); + x.getWhere().accept(this); + } + + return false; + } + + public boolean visit(SQLCreateTableStatement x) { + print("CREATE TABLE "); + if (SQLCreateTableStatement.Type.GLOBAL_TEMPORARY.equals(x.getType())) { + print("GLOBAL TEMPORARY "); + } else if (SQLCreateTableStatement.Type.LOCAL_TEMPORARY.equals(x.getType())) { + print("LOCAL TEMPORARY "); + } + + x.getName().accept(this); + + int size = x.getTableElementList().size(); + + if (size > 0) { + print(" ("); + incrementIndent(); + println(); + for (int i = 0; i < size; ++i) { + if (i != 0) { + print(","); + println(); + } + x.getTableElementList().get(i).accept(this); + } + decrementIndent(); + println(); + print(")"); + } + + return false; + } + + public boolean visit(SQLUniqueConstraint x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + + print("UNIQUE ("); + for (int i = 0, size = x.getColumns().size(); i < size; ++i) { + if (i != 0) { + print(", "); + } + x.getColumns().get(i).accept(this); + } + print(")"); + return false; + } + + public boolean visit(NotNullConstraint x) { + print("NOT NULL"); + return false; + } + + @Override + public boolean visit(SQLUnionQuery x) { + x.getLeft().accept(this); + println(); + print(x.getOperator().name); + println(); + + boolean needParen = false; + + if (x.getOrderBy() != null) { + needParen = true; + } + + if (needParen) { + print('('); + x.getRight().accept(this); + print(')'); + } else { + x.getRight().accept(this); + } + + if (x.getOrderBy() != null) { + println(); + x.getOrderBy().accept(this); + } + + return false; + } + + @Override + public boolean visit(SQLUnaryExpr x) { + print(x.getOperator().name); + + SQLExpr expr = x.getExpr(); + + switch (x.getOperator()) { + case BINARY: + case Prior: + case ConnectByRoot: + print(' '); + expr.accept(this); + return false; + default: + break; + } + + if (expr instanceof SQLBinaryOpExpr) { + print('('); + expr.accept(this); + print(')'); + } else if (expr instanceof SQLUnaryExpr) { + print('('); + expr.accept(this); + print(')'); + } else { + expr.accept(this); + } + return false; + } + + @Override + public boolean visit(SQLHexExpr x) { + print("0x"); + print(x.getHex()); + + String charset = (String) x.getAttribute("USING"); + if (charset != null) { + print(" USING "); + print(charset); + } + + return false; + } + + @Override + public boolean visit(SQLSetStatement x) { + print("SET "); + printAndAccept(x.getItems(), ", "); + return false; + } + + @Override + public boolean visit(SQLAssignItem x) { + x.getTarget().accept(this); + print(" = "); + x.getValue().accept(this); + return false; + } + + @Override + public boolean visit(SQLCallStatement x) { + print("CALL "); + x.getProcedureName().accept(this); + print('('); + printAndAccept(x.getParameters(), ", "); + print(')'); + return false; + } + + @Override + public boolean visit(SQLJoinTableSource x) { + x.getLeft().accept(this); + incrementIndent(); + + if (x.getJoinType() == JoinType.COMMA) { + print(","); + } else { + println(); + print(JoinType.toString(x.getJoinType())); + } + print(" "); + x.getRight().accept(this); + + if (x.getCondition() != null) { + incrementIndent(); + print(" ON "); + x.getCondition().accept(this); + decrementIndent(); + } + + if (x.getUsing().size() > 0) { + print(" USING ("); + printAndAccept(x.getUsing(), ", "); + print(")"); + } + + if (x.getAlias() != null) { + print(" AS "); + print(x.getAlias()); + } + + decrementIndent(); + + return false; + } + + @Override + public boolean visit(ValuesClause x) { + print("("); + incrementIndent(); + for (int i = 0, size = x.getValues().size(); i < size; ++i) { + if (i != 0) { + if (i % 5 == 0) { + println(); + } + print(", "); + } + + SQLExpr expr = x.getValues().get(i); + expr.setParent(x); + expr.accept(this); + } + decrementIndent(); + print(")"); + return false; + } + + @Override + public boolean visit(SQLSomeExpr x) { + print("SOME ("); + + incrementIndent(); + x.getSubQuery().accept(this); + decrementIndent(); + print(")"); + return false; + } + + @Override + public boolean visit(SQLAnyExpr x) { + print("ANY ("); + + incrementIndent(); + x.getSubQuery().accept(this); + decrementIndent(); + print(")"); + return false; + } + + @Override + public boolean visit(SQLAllExpr x) { + print("ALL ("); + + incrementIndent(); + x.getSubQuery().accept(this); + decrementIndent(); + print(")"); + return false; + } + + @Override + public boolean visit(SQLInSubQueryExpr x) { + x.getExpr().accept(this); + if (x.isNot()) { + print(" NOT IN ("); + } else { + print(" IN ("); + } + + incrementIndent(); + x.getSubQuery().accept(this); + decrementIndent(); + print(")"); + + return false; + } + + @Override + public boolean visit(SQLListExpr x) { + print("("); + printAndAccept(x.getItems(), ", "); + print(")"); + + return false; + } + + @Override + public boolean visit(SQLSubqueryTableSource x) { + print("("); + incrementIndent(); + x.getSelect().accept(this); + println(); + decrementIndent(); + print(")"); + + if (x.getAlias() != null) { + print(' '); + print(x.getAlias()); + } + + return false; + } + + @Override + public boolean visit(SQLTruncateStatement x) { + print("TRUNCATE TABLE "); + printAndAccept(x.getTableSources(), ", "); + return false; + } + + @Override + public boolean visit(SQLDefaultExpr x) { + print("DEFAULT"); + return false; + } + + @Override + public void endVisit(SQLCommentStatement x) { + + } + + @Override + public boolean visit(SQLCommentStatement x) { + print("COMMENT ON "); + if (x.getType() != null) { + print(x.getType().name()); + print(" "); + } + x.getOn().accept(this); + + print(" IS "); + x.getComment().accept(this); + + return false; + } + + @Override + public boolean visit(SQLUseStatement x) { + print("USE "); + x.getDatabase().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableAddColumn x) { + print("ADD ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + return false; + } + + @Override + public boolean visit(SQLAlterTableDropColumnItem x) { + print("DROP COLUMN "); + x.getColumnName().accept(this); + return false; + } + + @Override + public void endVisit(SQLAlterTableAddColumn x) { + + } + + @Override + public boolean visit(SQLDropIndexStatement x) { + print("DROP INDEX "); + x.getIndexName().accept(this); + print(" ON "); + x.getTableName().accept(this); + return false; + } + + @Override + public boolean visit(SQLSavePointStatement x) { + print("SAVEPOINT "); + x.getName().accept(this); + return false; + } + + @Override + public boolean visit(SQLReleaseSavePointStatement x) { + print("RELEASE SAVEPOINT "); + x.getName().accept(this); + return false; + } + + @Override + public boolean visit(SQLRollbackStatement x) { + print("ROLLBACK"); + if (x.getTo() != null) { + print(" TO "); + x.getTo().accept(this); + } + return false; + } + + public boolean visit(SQLCommentHint x) { + print("/*"); + print(x.getText()); + print("*/"); + return false; + } + + @Override + public boolean visit(SQLCreateDatabaseStatement x) { + print("CREATE DATABASE "); + x.getName().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableDropIndex x) { + print("DROP INDEX "); + x.getIndexName().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableAddPrimaryKey x) { + print("ADD "); + x.getPrimaryKey().accept(this); + return false; + } + + @Override + public boolean visit(SQLOver x) { + print("OVER ("); + if (x.getPartitionBy().size() > 0) { + printAndAccept(x.getPartitionBy(), ", "); + print(' '); + } + if (x.getOrderBy() != null) { + x.getOrderBy().accept(this); + } + print(")"); + return false; + } + + @Override + public boolean visit(SQLColumnPrimaryKey x) { + print(" PRIMARY KEY"); + return false; + } + + @Override + public boolean visit(SQLColumnCheck x) { + print("CHECK "); + x.getExpr().accept(this); + return false; + } + + @Override + public boolean visit(SQLColumnUniqueIndex x) { + print(" UNIQUE INDEX"); + return false; + } + + @Override + public boolean visit(SQLWithSubqueryClause x) { + print("WITH"); + if (x.getRecursive() == Boolean.TRUE) { + print(" RECURSIVE"); + } + incrementIndent(); + println(); + printlnAndAccept(x.getEntries(), ", "); + decrementIndent(); + return false; + } + + @Override + public boolean visit(SQLWithSubqueryClause.Entry x) { + x.getName().accept(this); + + if (x.getColumns().size() > 0) { + print(" ("); + printAndAccept(x.getColumns(), ", "); + print(")"); + } + println(); + print("AS"); + println(); + print("("); + incrementIndent(); + println(); + x.getSubQuery().accept(this); + decrementIndent(); + println(); + print(")"); + + return false; + } + + @Override + public boolean visit(SQLAlterTableAlterColumn x) { + print("ALTER COLUMN "); + x.getColumn().accept(this); + return false; + } + + @Override + public boolean visit(SQLCheck x) { + if (x.getName() != null) { + print("CONSTRAINT "); + x.getName().accept(this); + print(' '); + } + print("CHECK ("); + x.getExpr().accept(this); + print(')'); + return false; + } + + @Override + public boolean visit(SQLAlterTableDropForeinKey x) { + print("DROP FOREIGN KEY "); + x.getIndexName().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableDropPrimaryKey x) { + print("DROP PRIMARY KEY"); + return false; + } + + @Override + public boolean visit(SQLAlterTableEnableKeys x) { + print("ENABLE KEYS"); + return false; + } + + @Override + public boolean visit(SQLAlterTableDisableKeys x) { + print("DISABLE KEYS"); + return false; + } + + @Override + public boolean visit(SQLAlterTableAddForeignKey x) { + print("ADD "); + x.getForeignKey().accept(this); + return false; + } + + public boolean visit(SQLAlterTableDisableConstraint x) { + print("DISABLE CONSTRAINT "); + x.getConstraintName().accept(this); + return false; + } + + public boolean visit(SQLAlterTableEnableConstraint x) { + print("ENABLE CONSTRAINT "); + x.getConstraintName().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableDropConstraint x) { + print("DROP CONSTRAINT "); + x.getConstraintName().accept(this); + return false; + } + + @Override + public boolean visit(SQLAlterTableStatement x) { + print("ALTER TABLE "); + x.getName().accept(this); + incrementIndent(); + for (int i = 0; i < x.getItems().size(); ++i) { + SQLAlterTableItem item = x.getItems().get(i); + if (i != 0) { + print(','); + } + println(); + item.accept(this); + } + decrementIndent(); + return false; + } + + @Override + public boolean visit(SQLExprHint x) { + x.getExpr().accept(this); + return false; + } +} diff --git a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java index 9d2ac6a147..1afb0b87db 100644 --- a/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java +++ b/src/main/java/com/alibaba/druid/sql/visitor/SQLEvalVisitorUtils.java @@ -17,6 +17,7 @@ package com.alibaba.druid.sql.visitor; import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_EXPR; import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_VALUE; +import static com.alibaba.druid.sql.visitor.SQLEvalVisitor.EVAL_VALUE_NULL; import java.math.BigDecimal; import java.math.BigInteger; @@ -580,7 +581,7 @@ public class SQLEvalVisitorUtils { } public static boolean visit(SQLEvalVisitor visitor, SQLNullExpr x) { - x.getAttributes().put(EVAL_VALUE, null); + x.getAttributes().put(EVAL_VALUE, EVAL_VALUE_NULL); return false; } @@ -839,6 +840,14 @@ public class SQLEvalVisitorUtils { x.putAttribute(EVAL_VALUE, value); break; case Is: + if (rightValue == EVAL_VALUE_NULL) { + if (leftValue != null) { + value = (leftValue == EVAL_VALUE_NULL); + x.putAttribute(EVAL_VALUE, value); + break; + } + } + break; case Equality: value = eq(leftValue, rightValue); x.putAttribute(EVAL_VALUE, value); @@ -938,6 +947,9 @@ public class SQLEvalVisitorUtils { boolean containsValue = attributes.containsKey(EVAL_VALUE); if (!containsValue) { Object value = visitor.getParameters().get(varIndex); + if (value == null) { + value = EVAL_VALUE_NULL; + } attributes.put(EVAL_VALUE, value); } } diff --git a/src/main/java/com/alibaba/druid/stat/JdbcDataSourceStat.java b/src/main/java/com/alibaba/druid/stat/JdbcDataSourceStat.java index 65a35b1782..f06d26a535 100644 --- a/src/main/java/com/alibaba/druid/stat/JdbcDataSourceStat.java +++ b/src/main/java/com/alibaba/druid/stat/JdbcDataSourceStat.java @@ -66,7 +66,7 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean { // }); - private final ConcurrentMap connections = new ConcurrentHashMap(); + private final ConcurrentMap connections = new ConcurrentHashMap(16, 0.75f, 1); private final AtomicLong clobOpenCount = new AtomicLong(); diff --git a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java index fef5588c3d..61daea15cb 100644 --- a/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java +++ b/src/main/java/com/alibaba/druid/support/http/stat/WebAppStat.java @@ -56,7 +56,7 @@ public class WebAppStat { private final AtomicLong jdbcCommitCount = new AtomicLong(); private final AtomicLong jdbcRollbackCount = new AtomicLong(); - private final ConcurrentMap uriStatMap = new ConcurrentHashMap(); + private final ConcurrentMap uriStatMap = new ConcurrentHashMap(16, 0.75f, 1); private final LRUCache sessionStatMap; private final ReadWriteLock sessionStatLock = new ReentrantReadWriteLock(); diff --git a/src/main/java/com/alibaba/druid/support/ibatis/SqlMapClientImplWrapper.java b/src/main/java/com/alibaba/druid/support/ibatis/SqlMapClientImplWrapper.java index ad7b8cb19d..e1b6f7d8e7 100644 --- a/src/main/java/com/alibaba/druid/support/ibatis/SqlMapClientImplWrapper.java +++ b/src/main/java/com/alibaba/druid/support/ibatis/SqlMapClientImplWrapper.java @@ -39,7 +39,7 @@ public class SqlMapClientImplWrapper extends SqlMapClientImpl { private static Method getLocalSqlMapSessionMethod = null; - private ConcurrentMap statementInfoMap = new ConcurrentHashMap(); + private ConcurrentMap statementInfoMap = new ConcurrentHashMap(16, 0.75f, 1); public SqlMapClientImplWrapper(SqlMapClientImpl raw) { super(raw.getDelegate()); diff --git a/src/main/java/com/alibaba/druid/support/logging/SLF4JImpl.java b/src/main/java/com/alibaba/druid/support/logging/SLF4JImpl.java index 0b4e56fa53..b9e6b4a32e 100644 --- a/src/main/java/com/alibaba/druid/support/logging/SLF4JImpl.java +++ b/src/main/java/com/alibaba/druid/support/logging/SLF4JImpl.java @@ -35,10 +35,10 @@ public class SLF4JImpl implements Log { private int infoCount; private LocationAwareLogger log; - public SLF4JImpl(Class clazz){ - this.log = (LocationAwareLogger) LoggerFactory.getLogger(clazz); + public SLF4JImpl(LocationAwareLogger log){ + this.log = log; } - + public SLF4JImpl(String loggerName){ this.log = (LocationAwareLogger) LoggerFactory.getLogger(loggerName); } diff --git a/src/main/java/com/alibaba/druid/support/spring/stat/SpringStat.java b/src/main/java/com/alibaba/druid/support/spring/stat/SpringStat.java index 5bc9b73472..7c6bd20358 100644 --- a/src/main/java/com/alibaba/druid/support/spring/stat/SpringStat.java +++ b/src/main/java/com/alibaba/druid/support/spring/stat/SpringStat.java @@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap; public class SpringStat { - private ConcurrentMap methodStats = new ConcurrentHashMap(); + private ConcurrentMap methodStats = new ConcurrentHashMap(16, 0.75f, 1); public SpringStat(){ diff --git a/src/main/java/com/alibaba/druid/wall/WallFilter.java b/src/main/java/com/alibaba/druid/wall/WallFilter.java index d4957b8fe3..08e843db7d 100644 --- a/src/main/java/com/alibaba/druid/wall/WallFilter.java +++ b/src/main/java/com/alibaba/druid/wall/WallFilter.java @@ -1,685 +1,685 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.wall; - -import java.sql.DatabaseMetaData; -import java.sql.SQLException; -import java.sql.Wrapper; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.alibaba.druid.DruidRuntimeException; -import com.alibaba.druid.filter.FilterAdapter; -import com.alibaba.druid.filter.FilterChain; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; -import com.alibaba.druid.proxy.jdbc.ConnectionProxy; -import com.alibaba.druid.proxy.jdbc.DataSourceProxy; -import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; -import com.alibaba.druid.proxy.jdbc.ResultSetProxy; -import com.alibaba.druid.proxy.jdbc.StatementProxy; -import com.alibaba.druid.support.logging.Log; -import com.alibaba.druid.support.logging.LogFactory; -import com.alibaba.druid.util.JdbcUtils; -import com.alibaba.druid.wall.spi.MySqlWallProvider; -import com.alibaba.druid.wall.spi.OracleWallProvider; -import com.alibaba.druid.wall.spi.PGWallProvider; -import com.alibaba.druid.wall.spi.SQLServerWallProvider; -import com.alibaba.druid.wall.violation.SyntaxErrorViolation; - -public class WallFilter extends FilterAdapter implements WallFilterMBean { - - private final static Log LOG = LogFactory.getLog(WallFilter.class); - - private boolean inited = false; - - private WallProvider provider; - - private String dbType; - - private WallConfig config; - - private volatile boolean logViolation = false; - private volatile boolean throwException = true; - - public final static String ATTR_SQL_STAT = "wall.sqlStat"; - - @Override - public void init(DataSourceProxy dataSource) { - if (this.dbType == null || this.dbType.trim().length() == 0) { - if (dataSource != null && dataSource.getDbType() != null) { - this.dbType = dataSource.getDbType(); - } else { - this.dbType = JdbcUtils.getDbType(dataSource.getRawJdbcUrl(), ""); - } - } - - if (dbType == null) { - dbType = JdbcUtils.getDbType(dataSource.getUrl(), null); - } - - if (JdbcUtils.MYSQL.equals(dbType) || // - JdbcUtils.MARIADB.equals(dbType) || // - JdbcUtils.H2.equals(dbType)) { - if (config == null) { - config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR); - } - - provider = new MySqlWallProvider(config); - } else if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) { - if (config == null) { - config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR); - } - - provider = new OracleWallProvider(config); - } else if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) { - if (config == null) { - config = new WallConfig(SQLServerWallProvider.DEFAULT_CONFIG_DIR); - } - - provider = new SQLServerWallProvider(config); - } else if (JdbcUtils.POSTGRESQL.equals(dbType)) { - if (config == null) { - config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR); - } - - provider = new PGWallProvider(config); - } else { - throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl()); - } - - this.inited = true; - } - - public String getDbType() { - return dbType; - } - - public void setDbType(String dbType) { - this.dbType = dbType; - } - - public boolean isLogViolation() { - return logViolation; - } - - public void setLogViolation(boolean logViolation) { - this.logViolation = logViolation; - } - - public boolean isThrowException() { - return throwException; - } - - public void setThrowException(boolean throwException) { - this.throwException = throwException; - } - - public void clearProviderCache() { - if (provider != null) { - provider.clearCache(); - } - } - - public Set getProviderWhiteList() { - if (provider == null) { - return Collections.emptySet(); - } - - return provider.getWhiteList(); - } - - public WallProvider getProvider() { - return provider; - } - - public WallConfig getConfig() { - return config; - } - - public void setConfig(WallConfig config) { - this.config = config; - } - - public boolean isInited() { - return inited; - } - - public void checkInit() { - if (inited) { - throw new DruidRuntimeException("wall filter is inited"); - } - } - - @Override - public void statement_addBatch(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - chain.statement_addBatch(statement, sql); - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) - throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int autoGeneratedKeys) throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, autoGeneratedKeys); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int resultSetType, int resultSetConcurrency) - throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, resultSetType, - resultSetConcurrency); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, int[] columnIndexes) throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, columnIndexes); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, - String sql, String[] columnNames) throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, columnNames); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) - throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency) - throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql, resultSetType, - resultSetConcurrency); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - @Override - public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, - int resultSetType, int resultSetConcurrency, - int resultSetHoldability) throws SQLException { - String dbType = connection.getDirectDataSource().getDbType(); - WallContext.create(dbType); - try { - sql = check(sql); - CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql, resultSetType, - resultSetConcurrency, resultSetHoldability); - setSqlStatAttribute(stmt); - return stmt; - } finally { - WallContext.clearContext(); - } - } - - // ////////////// - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - WallContext originalContext = WallContext.current(); - try { - createWallContext(statement); - sql = check(sql); - boolean firstResult = chain.statement_execute(statement, sql); - if (!firstResult) { - int updateCount = statement.getUpdateCount(); - statExecuteUpdate(updateCount); - } - return firstResult; - } finally { - if (originalContext != null) { - WallContext.setContext(originalContext); - } - } - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - boolean firstResult = chain.statement_execute(statement, sql, autoGeneratedKeys); - if (!firstResult) { - int updateCount = statement.getUpdateCount(); - statExecuteUpdate(updateCount); - } - return firstResult; - } finally { - WallContext.clearContext(); - } - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - boolean firstResult = chain.statement_execute(statement, sql, columnIndexes); - if (!firstResult) { - int updateCount = statement.getUpdateCount(); - statExecuteUpdate(updateCount); - } - return firstResult; - } finally { - WallContext.clearContext(); - } - } - - @Override - public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - boolean firstResult = chain.statement_execute(statement, sql, columnNames); - if (!firstResult) { - int updateCount = statement.getUpdateCount(); - statExecuteUpdate(updateCount); - } - return firstResult; - } finally { - WallContext.clearContext(); - } - } - - @Override - public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException { - WallSqlStat sqlStat = (WallSqlStat) statement.getAttributes().get(ATTR_SQL_STAT); - try { - int[] updateCounts = chain.statement_executeBatch(statement); - for (int i = 0; i < updateCounts.length; ++i) { - int updateCount = updateCounts[i]; - statExecuteUpdate(sqlStat, updateCount); - } - return updateCounts; - } finally { - WallContext.clearContext(); - } - } - - @Override - public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - return chain.statement_executeQuery(statement, sql); - } finally { - WallContext.clearContext(); - } - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - int updateCount = chain.statement_executeUpdate(statement, sql); - statExecuteUpdate(updateCount); - return updateCount; - } finally { - WallContext.clearContext(); - } - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - int updateCount = chain.statement_executeUpdate(statement, sql, autoGeneratedKeys); - statExecuteUpdate(updateCount); - return updateCount; - } finally { - WallContext.clearContext(); - } - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - int updateCount = chain.statement_executeUpdate(statement, sql, columnIndexes); - statExecuteUpdate(updateCount); - return updateCount; - } finally { - WallContext.clearContext(); - } - } - - public String getDbType(StatementProxy statement) { - return statement.getConnectionProxy().getDirectDataSource().getDbType(); - } - - private WallContext createWallContext(StatementProxy statement) { - String dbType = getDbType(statement); - WallContext context = WallContext.create(dbType); - return context; - } - - @Override - public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) - throws SQLException { - createWallContext(statement); - try { - sql = check(sql); - int updateCount = chain.statement_executeUpdate(statement, sql, columnNames); - statExecuteUpdate(updateCount); - return updateCount; - } finally { - WallContext.clearContext(); - } - } - - @Override - public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException { - boolean firstResult = chain.preparedStatement_execute(statement); - - if (!firstResult) { - WallSqlStat sqlStat = (WallSqlStat) statement.getAttributes().get(ATTR_SQL_STAT); - int updateCount = statement.getUpdateCount(); - statExecuteUpdate(sqlStat, updateCount); - } - - return firstResult; - } - - @Override - public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) - throws SQLException { - return chain.preparedStatement_executeQuery(statement); - } - - @Override - public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException { - int updateCount = chain.preparedStatement_executeUpdate(statement); - statExecuteUpdate(updateCount); - return updateCount; - } - - public void setSqlStatAttribute(PreparedStatementProxy stmt) { - WallContext context = WallContext.current(); - if (context == null) { - return; - } - - WallSqlStat sqlStat = context.getSqlStat(); - if (sqlStat == null) { - return; - } - - stmt.getAttributes().put(ATTR_SQL_STAT, sqlStat); - } - - public void statExecuteUpdate(int updateCount) { - WallContext context = WallContext.current(); - if (context == null) { - return; - } - - WallSqlStat sqlStat = context.getSqlStat(); - if (sqlStat == null) { - return; - } - - if (updateCount > 0) { - statExecuteUpdate(sqlStat, updateCount); - } - } - - private void statExecuteUpdate(WallSqlStat sqlStat, int updateCount) { - if (sqlStat == null) { - return; - } - - Map sqlTableStats = sqlStat.getTableStats(); - if (sqlTableStats == null) { - return; - } - - for (Map.Entry entry : sqlTableStats.entrySet()) { - String tableName = entry.getKey(); - WallTableStat tableStat = provider.getTableStat(tableName); - if (tableStat == null) { - continue; - } - - WallSqlTableStat sqlTableStat = entry.getValue(); - - if (sqlTableStat.getDeleteCount() > 0) { - tableStat.addDeleteDataCount(updateCount); - } else if (sqlTableStat.getUpdateCount() > 0) { - tableStat.addUpdateDataCount(updateCount); - } - } - } - - public String check(String sql) throws SQLException { - WallCheckResult checkResult = provider.check(sql); - List violations = checkResult.getViolations(); - - if (violations.size() > 0) { - Violation firstViolation = violations.get(0); - if (isLogViolation()) { - LOG.error("sql injection violation, " + firstViolation.getMessage() + " : " + sql); - } - - if (throwException) { - if (violations.get(0) instanceof SyntaxErrorViolation) { - SyntaxErrorViolation violation = (SyntaxErrorViolation) violations.get(0); - throw new SQLException("sql injection violation, " + firstViolation.getMessage() + " : " + sql, - violation.getException()); - } else { - throw new SQLException("sql injection violation, " + firstViolation.getMessage() + " : " + sql); - } - } - } - - //TODO - return sql; - } - - @Override - public boolean isWrapperFor(FilterChain chain, Wrapper wrapper, Class iface) throws SQLException { - if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { - return chain.isWrapperFor(wrapper, iface); - } - - if (!this.provider.getConfig().isWrapAllow()) { - return false; - } - return chain.isWrapperFor(wrapper, iface); - } - - @Override - public T unwrap(FilterChain chain, Wrapper wrapper, Class iface) throws SQLException { - if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { - return chain.unwrap(wrapper, iface); - } - - if (!this.provider.getConfig().isWrapAllow()) { - return null; - } - - return chain.unwrap(wrapper, iface); - } - - @Override - public DatabaseMetaData connection_getMetaData(FilterChain chain, ConnectionProxy connection) throws SQLException { - if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { - return chain.connection_getMetaData(connection); - } - - if (!this.provider.getConfig().isMetadataAllow()) { - if (isLogViolation()) { - LOG.error("not support method : Connection.getMetdataData"); - } - - if (throwException) { - throw new WallSQLException("not support method : Connection.getMetdataData"); - } else { - - } - } - - return chain.connection_getMetaData(connection); - } - - @Override - public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException { - chain.resultSet_close(resultSet); - int fetchRowCount = resultSet.getFetchRowCount(); - - WallSqlStat sqlStat = (WallSqlStat) resultSet.getStatementProxy().getAttributes().get(ATTR_SQL_STAT); - if (sqlStat == null) { - return; - } - - Map sqlTableStats = sqlStat.getTableStats(); - if (sqlTableStats == null) { - return; - } - - for (Map.Entry entry : sqlTableStats.entrySet()) { - String tableName = entry.getKey(); - WallTableStat tableStat = provider.getTableStat(tableName); - if (tableStat == null) { - continue; - } - - WallSqlTableStat sqlTableStat = entry.getValue(); - - if (sqlTableStat.getSelectCount() > 0) { - tableStat.addFetchRowCount(fetchRowCount); - } - } - } - - public long getViolationCount() { - return this.provider.getViolationCount(); - } - - public void resetViolationCount() { - this.provider.reset(); - } - - public void clearWhiteList() { - this.provider.clearCache(); - } - - public boolean checkValid(String sql) { - return provider.checkValid(sql); - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.wall; + +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.sql.Wrapper; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.alibaba.druid.DruidRuntimeException; +import com.alibaba.druid.filter.FilterAdapter; +import com.alibaba.druid.filter.FilterChain; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxy; +import com.alibaba.druid.proxy.jdbc.DataSourceProxy; +import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy; +import com.alibaba.druid.proxy.jdbc.ResultSetProxy; +import com.alibaba.druid.proxy.jdbc.StatementProxy; +import com.alibaba.druid.support.logging.Log; +import com.alibaba.druid.support.logging.LogFactory; +import com.alibaba.druid.util.JdbcUtils; +import com.alibaba.druid.wall.spi.MySqlWallProvider; +import com.alibaba.druid.wall.spi.OracleWallProvider; +import com.alibaba.druid.wall.spi.PGWallProvider; +import com.alibaba.druid.wall.spi.SQLServerWallProvider; +import com.alibaba.druid.wall.violation.SyntaxErrorViolation; + +public class WallFilter extends FilterAdapter implements WallFilterMBean { + + private final static Log LOG = LogFactory.getLog(WallFilter.class); + + private boolean inited = false; + + private WallProvider provider; + + private String dbType; + + private WallConfig config; + + private volatile boolean logViolation = false; + private volatile boolean throwException = true; + + public final static String ATTR_SQL_STAT = "wall.sqlStat"; + + @Override + public void init(DataSourceProxy dataSource) { + if (this.dbType == null || this.dbType.trim().length() == 0) { + if (dataSource != null && dataSource.getDbType() != null) { + this.dbType = dataSource.getDbType(); + } else { + this.dbType = JdbcUtils.getDbType(dataSource.getRawJdbcUrl(), ""); + } + } + + if (dbType == null) { + dbType = JdbcUtils.getDbType(dataSource.getUrl(), null); + } + + if (JdbcUtils.MYSQL.equals(dbType) || // + JdbcUtils.MARIADB.equals(dbType) || // + JdbcUtils.H2.equals(dbType)) { + if (config == null) { + config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR); + } + + provider = new MySqlWallProvider(config); + } else if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) { + if (config == null) { + config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR); + } + + provider = new OracleWallProvider(config); + } else if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) { + if (config == null) { + config = new WallConfig(SQLServerWallProvider.DEFAULT_CONFIG_DIR); + } + + provider = new SQLServerWallProvider(config); + } else if (JdbcUtils.POSTGRESQL.equals(dbType)) { + if (config == null) { + config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR); + } + + provider = new PGWallProvider(config); + } else { + throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl()); + } + + this.inited = true; + } + + public String getDbType() { + return dbType; + } + + public void setDbType(String dbType) { + this.dbType = dbType; + } + + public boolean isLogViolation() { + return logViolation; + } + + public void setLogViolation(boolean logViolation) { + this.logViolation = logViolation; + } + + public boolean isThrowException() { + return throwException; + } + + public void setThrowException(boolean throwException) { + this.throwException = throwException; + } + + public void clearProviderCache() { + if (provider != null) { + provider.clearCache(); + } + } + + public Set getProviderWhiteList() { + if (provider == null) { + return Collections.emptySet(); + } + + return provider.getWhiteList(); + } + + public WallProvider getProvider() { + return provider; + } + + public WallConfig getConfig() { + return config; + } + + public void setConfig(WallConfig config) { + this.config = config; + } + + public boolean isInited() { + return inited; + } + + public void checkInit() { + if (inited) { + throw new DruidRuntimeException("wall filter is inited"); + } + } + + @Override + public void statement_addBatch(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + chain.statement_addBatch(statement, sql); + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) + throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int autoGeneratedKeys) throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, autoGeneratedKeys); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, resultSetType, + resultSetConcurrency); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, int[] columnIndexes) throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, columnIndexes); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, + String sql, String[] columnNames) throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + PreparedStatementProxy stmt = chain.connection_prepareStatement(connection, sql, columnNames); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) + throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency) + throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql, resultSetType, + resultSetConcurrency); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + @Override + public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, + int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + String dbType = connection.getDirectDataSource().getDbType(); + WallContext.create(dbType); + try { + sql = check(sql); + CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql, resultSetType, + resultSetConcurrency, resultSetHoldability); + setSqlStatAttribute(stmt); + return stmt; + } finally { + WallContext.clearContext(); + } + } + + // ////////////// + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + WallContext originalContext = WallContext.current(); + try { + createWallContext(statement); + sql = check(sql); + boolean firstResult = chain.statement_execute(statement, sql); + if (!firstResult) { + int updateCount = statement.getUpdateCount(); + statExecuteUpdate(updateCount); + } + return firstResult; + } finally { + if (originalContext != null) { + WallContext.setContext(originalContext); + } + } + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + boolean firstResult = chain.statement_execute(statement, sql, autoGeneratedKeys); + if (!firstResult) { + int updateCount = statement.getUpdateCount(); + statExecuteUpdate(updateCount); + } + return firstResult; + } finally { + WallContext.clearContext(); + } + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + boolean firstResult = chain.statement_execute(statement, sql, columnIndexes); + if (!firstResult) { + int updateCount = statement.getUpdateCount(); + statExecuteUpdate(updateCount); + } + return firstResult; + } finally { + WallContext.clearContext(); + } + } + + @Override + public boolean statement_execute(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + boolean firstResult = chain.statement_execute(statement, sql, columnNames); + if (!firstResult) { + int updateCount = statement.getUpdateCount(); + statExecuteUpdate(updateCount); + } + return firstResult; + } finally { + WallContext.clearContext(); + } + } + + @Override + public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException { + WallSqlStat sqlStat = (WallSqlStat) statement.getAttribute(ATTR_SQL_STAT); + try { + int[] updateCounts = chain.statement_executeBatch(statement); + for (int i = 0; i < updateCounts.length; ++i) { + int updateCount = updateCounts[i]; + statExecuteUpdate(sqlStat, updateCount); + } + return updateCounts; + } finally { + WallContext.clearContext(); + } + } + + @Override + public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + return chain.statement_executeQuery(statement, sql); + } finally { + WallContext.clearContext(); + } + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql) throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + int updateCount = chain.statement_executeUpdate(statement, sql); + statExecuteUpdate(updateCount); + return updateCount; + } finally { + WallContext.clearContext(); + } + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int autoGeneratedKeys) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + int updateCount = chain.statement_executeUpdate(statement, sql, autoGeneratedKeys); + statExecuteUpdate(updateCount); + return updateCount; + } finally { + WallContext.clearContext(); + } + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, int columnIndexes[]) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + int updateCount = chain.statement_executeUpdate(statement, sql, columnIndexes); + statExecuteUpdate(updateCount); + return updateCount; + } finally { + WallContext.clearContext(); + } + } + + public String getDbType(StatementProxy statement) { + return statement.getConnectionProxy().getDirectDataSource().getDbType(); + } + + private WallContext createWallContext(StatementProxy statement) { + String dbType = getDbType(statement); + WallContext context = WallContext.create(dbType); + return context; + } + + @Override + public int statement_executeUpdate(FilterChain chain, StatementProxy statement, String sql, String columnNames[]) + throws SQLException { + createWallContext(statement); + try { + sql = check(sql); + int updateCount = chain.statement_executeUpdate(statement, sql, columnNames); + statExecuteUpdate(updateCount); + return updateCount; + } finally { + WallContext.clearContext(); + } + } + + @Override + public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException { + boolean firstResult = chain.preparedStatement_execute(statement); + + if (!firstResult) { + WallSqlStat sqlStat = (WallSqlStat) statement.getAttribute(ATTR_SQL_STAT); + int updateCount = statement.getUpdateCount(); + statExecuteUpdate(sqlStat, updateCount); + } + + return firstResult; + } + + @Override + public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) + throws SQLException { + return chain.preparedStatement_executeQuery(statement); + } + + @Override + public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException { + int updateCount = chain.preparedStatement_executeUpdate(statement); + statExecuteUpdate(updateCount); + return updateCount; + } + + public void setSqlStatAttribute(PreparedStatementProxy stmt) { + WallContext context = WallContext.current(); + if (context == null) { + return; + } + + WallSqlStat sqlStat = context.getSqlStat(); + if (sqlStat == null) { + return; + } + + stmt.putAttribute(ATTR_SQL_STAT, sqlStat); + } + + public void statExecuteUpdate(int updateCount) { + WallContext context = WallContext.current(); + if (context == null) { + return; + } + + WallSqlStat sqlStat = context.getSqlStat(); + if (sqlStat == null) { + return; + } + + if (updateCount > 0) { + statExecuteUpdate(sqlStat, updateCount); + } + } + + private void statExecuteUpdate(WallSqlStat sqlStat, int updateCount) { + if (sqlStat == null) { + return; + } + + Map sqlTableStats = sqlStat.getTableStats(); + if (sqlTableStats == null) { + return; + } + + for (Map.Entry entry : sqlTableStats.entrySet()) { + String tableName = entry.getKey(); + WallTableStat tableStat = provider.getTableStat(tableName); + if (tableStat == null) { + continue; + } + + WallSqlTableStat sqlTableStat = entry.getValue(); + + if (sqlTableStat.getDeleteCount() > 0) { + tableStat.addDeleteDataCount(updateCount); + } else if (sqlTableStat.getUpdateCount() > 0) { + tableStat.addUpdateDataCount(updateCount); + } + } + } + + public String check(String sql) throws SQLException { + WallCheckResult checkResult = provider.check(sql); + List violations = checkResult.getViolations(); + + if (violations.size() > 0) { + Violation firstViolation = violations.get(0); + if (isLogViolation()) { + LOG.error("sql injection violation, " + firstViolation.getMessage() + " : " + sql); + } + + if (throwException) { + if (violations.get(0) instanceof SyntaxErrorViolation) { + SyntaxErrorViolation violation = (SyntaxErrorViolation) violations.get(0); + throw new SQLException("sql injection violation, " + firstViolation.getMessage() + " : " + sql, + violation.getException()); + } else { + throw new SQLException("sql injection violation, " + firstViolation.getMessage() + " : " + sql); + } + } + } + + //TODO + return sql; + } + + @Override + public boolean isWrapperFor(FilterChain chain, Wrapper wrapper, Class iface) throws SQLException { + if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { + return chain.isWrapperFor(wrapper, iface); + } + + if (!this.provider.getConfig().isWrapAllow()) { + return false; + } + return chain.isWrapperFor(wrapper, iface); + } + + @Override + public T unwrap(FilterChain chain, Wrapper wrapper, Class iface) throws SQLException { + if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { + return chain.unwrap(wrapper, iface); + } + + if (!this.provider.getConfig().isWrapAllow()) { + return null; + } + + return chain.unwrap(wrapper, iface); + } + + @Override + public DatabaseMetaData connection_getMetaData(FilterChain chain, ConnectionProxy connection) throws SQLException { + if (config.isDoPrivilegedAllow() && WallProvider.ispPivileged()) { + return chain.connection_getMetaData(connection); + } + + if (!this.provider.getConfig().isMetadataAllow()) { + if (isLogViolation()) { + LOG.error("not support method : Connection.getMetdataData"); + } + + if (throwException) { + throw new WallSQLException("not support method : Connection.getMetdataData"); + } else { + + } + } + + return chain.connection_getMetaData(connection); + } + + @Override + public void resultSet_close(FilterChain chain, ResultSetProxy resultSet) throws SQLException { + chain.resultSet_close(resultSet); + int fetchRowCount = resultSet.getFetchRowCount(); + + WallSqlStat sqlStat = (WallSqlStat) resultSet.getStatementProxy().getAttribute(ATTR_SQL_STAT); + if (sqlStat == null) { + return; + } + + Map sqlTableStats = sqlStat.getTableStats(); + if (sqlTableStats == null) { + return; + } + + for (Map.Entry entry : sqlTableStats.entrySet()) { + String tableName = entry.getKey(); + WallTableStat tableStat = provider.getTableStat(tableName); + if (tableStat == null) { + continue; + } + + WallSqlTableStat sqlTableStat = entry.getValue(); + + if (sqlTableStat.getSelectCount() > 0) { + tableStat.addFetchRowCount(fetchRowCount); + } + } + } + + public long getViolationCount() { + return this.provider.getViolationCount(); + } + + public void resetViolationCount() { + this.provider.reset(); + } + + public void clearWhiteList() { + this.provider.clearCache(); + } + + public boolean checkValid(String sql) { + return provider.checkValid(sql); + } +} diff --git a/src/main/java/com/alibaba/druid/wall/WallProvider.java b/src/main/java/com/alibaba/druid/wall/WallProvider.java index e0360277b1..d69a530dce 100644 --- a/src/main/java/com/alibaba/druid/wall/WallProvider.java +++ b/src/main/java/com/alibaba/druid/wall/WallProvider.java @@ -59,8 +59,8 @@ public abstract class WallProvider { private static final ThreadLocal privileged = new ThreadLocal(); - private final ConcurrentMap functionStats = new ConcurrentHashMap(); - private final ConcurrentMap tableStats = new ConcurrentHashMap(); + private final ConcurrentMap functionStats = new ConcurrentHashMap(16, 0.75f, 1); + private final ConcurrentMap tableStats = new ConcurrentHashMap(16, 0.75f, 1); public final WallDenyStat commentDeniedStat = new WallDenyStat(); diff --git a/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_Clob_2.java b/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_Clob_2.java index ac84aa6446..77406ec8fa 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_Clob_2.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_Clob_2.java @@ -30,6 +30,7 @@ import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; import com.alibaba.druid.proxy.jdbc.ClobProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; import com.alibaba.druid.util.JdbcUtils; public class FilterChainTest_Clob_2 extends TestCase { @@ -51,7 +52,7 @@ public class FilterChainTest_Clob_2 extends TestCase { } }; - statement = new CallableStatementProxyImpl(null, mockStmt, "", 1); + statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1); } @@ -69,16 +70,15 @@ public class FilterChainTest_Clob_2 extends TestCase { Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } - + public void test_getClob_1() throws Exception { FilterChainImpl chain = new FilterChainImpl(dataSource); - + Clob clob = chain.callableStatement_getClob(statement, "1"); - + Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } - public void test_getObject() throws Exception { FilterChainImpl chain = new FilterChainImpl(dataSource); @@ -88,30 +88,30 @@ public class FilterChainTest_Clob_2 extends TestCase { Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } - + public void test_getObject_1() throws Exception { FilterChainImpl chain = new FilterChainImpl(dataSource); - + Clob clob = (Clob) chain.callableStatement_getObject(statement, "1"); - + Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } - + public void test_getObject_2() throws Exception { FilterChainImpl chain = new FilterChainImpl(dataSource); - Clob clob = (Clob) chain.callableStatement_getObject(statement, 1, Collections.>emptyMap()); + Clob clob = (Clob) chain.callableStatement_getObject(statement, 1, Collections.> emptyMap()); Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } - + public void test_getObject_3() throws Exception { FilterChainImpl chain = new FilterChainImpl(dataSource); - - Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.>emptyMap()); - + + Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.> emptyMap()); + Assert.assertTrue(clob instanceof ClobProxy); Assert.assertEquals(1, invokeCount); } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_NClob_2.java b/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_NClob_2.java index daad72853e..fd80455918 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_NClob_2.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/FilterChainTest_NClob_2.java @@ -29,6 +29,7 @@ import com.alibaba.druid.mock.MockNClob; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.proxy.jdbc.CallableStatementProxy; import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; +import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; import com.alibaba.druid.proxy.jdbc.NClobProxy; import com.alibaba.druid.util.JdbcUtils; @@ -51,7 +52,7 @@ public class FilterChainTest_NClob_2 extends TestCase { } }; - statement = new CallableStatementProxyImpl(null, mockStmt, "", 1); + statement = new CallableStatementProxyImpl(new ConnectionProxyImpl(null, null, null, 0), mockStmt, "", 1); } diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest71.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest71.java index 9a12c31cbf..8a8c1b9700 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest71.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/MySqlWallTest71.java @@ -1,56 +1,56 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.bvt.filter.wall; - -import junit.framework.TestCase; - -import org.junit.Assert; - -import com.alibaba.druid.wall.WallProvider; -import com.alibaba.druid.wall.spi.MySqlWallProvider; - -/** - * SQLServerWallTest - * - * @author RaymondXiu - * @version 1.0, 2012-3-18 - * @see - */ -public class MySqlWallTest71 extends TestCase { - - public void test_false() throws Exception { - WallProvider provider = new MySqlWallProvider(); - - provider.getConfig().setCommentAllow(true); - - Assert.assertTrue(provider.checkValid(// - "update order_return set return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00 where id=1319")); - - Assert.assertEquals(1, provider.getTableStats().size()); - } - - public void test_false1() throws Exception { - WallProvider provider = new MySqlWallProvider(); - - provider.getConfig().setCommentAllow(true); - - Assert.assertFalse(provider.checkValid(// - "select * from order_return where return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00")); - - Assert.assertEquals(1, provider.getTableStats().size()); - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.MySqlWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class MySqlWallTest71 extends TestCase { + + public void test_false() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setCommentAllow(true); + + Assert.assertFalse(provider.checkValid(// + "update order_return set return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00 where id=1319")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + + public void test_false1() throws Exception { + WallProvider provider = new MySqlWallProvider(); + + provider.getConfig().setCommentAllow(true); + + Assert.assertFalse(provider.checkValid(// + "select * from order_return where return_goods_money =0.00 ,return_other_money = 8--149.00, return_total_fee = ifnull(return_shipping,0)+ifnull(return_other_discount,0)+0.00--149.00-0.00,return_goods_amount=1,return_real_money=0.00")); + + Assert.assertEquals(1, provider.getTableStats().size()); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_0.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_0.java index 731a310cbd..30408dfa45 100644 --- a/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_0.java +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_0.java @@ -1,143 +1,143 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.bvt.filter.wall; - -import junit.framework.TestCase; - -import org.junit.Assert; - -import com.alibaba.druid.wall.WallProvider; -import com.alibaba.druid.wall.spi.SQLServerWallProvider; - -/** - * SQLServerWallTest - * - * @author RaymondXiu - * @version 1.0, 2012-3-18 - * @see - */ -public class SQLServerWallTest_0 extends TestCase { - - private WallProvider initWallProvider() { - WallProvider provider = new SQLServerWallProvider(); - - provider.getConfig().setUseAllow(true); - provider.getConfig().setStrictSyntaxCheck(false); - provider.getConfig().setMultiStatementAllow(true); - provider.getConfig().setConditionAndAlwayTrueAllow(true); - provider.getConfig().setNoneBaseStatementAllow(true); - provider.getConfig().setSelectUnionCheck(false); - provider.getConfig().setSchemaCheck(true); - provider.getConfig().setLimitZeroAllow(true); - provider.getConfig().setCommentAllow(true); - - return provider; - } - - public void test_false() { - WallProvider provider = initWallProvider(); - { - String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 And (Select Top 1 unicode(substring(isNull(cast(name as varchar(8000)),char(32)),7,1)) From (Select Top 9 [dbid],[name] From master..sysdatabases Order by [dbid] desc) T Order by [dbid]) between 105 and 105"; - Assert.assertFalse(provider.checkValid(sql)); - } - { - String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 and (select unicode(substring(isNull(cast(db_name() as varchar(8000)),char(32)),1,1))) between 105 and 108"; - Assert.assertFalse(provider.checkValid(sql)); - } - } - - public void test_false1() throws Exception { - WallProvider provider = initWallProvider(); - { - String sql = "select OrderId,Order_Time,oResult,oState,show_Exp_Num,Is_Exp_Print,sel_Exp_Id,Order_Th,Th_Audit_Time,Th_Delay_Days from Pro_Order_List where OrderId='2012110125252' AND HOST_NAME()=HOST_NAME() AND 'kbwg'='kbwg'"; - Assert.assertFalse(provider.checkValid(sql)); - } - } - - public void test_true1() throws Exception { - WallProvider provider = initWallProvider(); - { - String sql = "select Fg.name as TableFg, dsp.name as TexImageFg, FtCat.name as FulltextCatalog, OBJECTPROPERTY(tbl.object_id, 'TableTextInRowLimit') as TextInrowLimit, OBJECTPROPERTY(tbl.object_id, 'IsIndexable'), user_name(tbl.principal_id) as DirectOwner, tbl.is_replicated, tbl.lock_escalation_desc from sys.tables tbl left outer join sys.data_spaces dsp on dsp.data_space_id = tbl.lob_data_space_id left outer join (sys.fulltext_indexes fti inner join sys.fulltext_catalogs FtCat on FtCat.fulltext_catalog_id = fti.fulltext_catalog_id ) on fti.object_id = tbl.object_id inner join (sys.indexes idx inner join sys.data_spaces Fg on (idx.index_id = 0 or idx.index_id = 1) and Fg.data_space_id = idx.data_space_id) on idx.object_id = tbl.object_id and (idx.index_id = 0 or idx.index_id = 1) where tbl.object_id = object_id(N'dbo.nqh_TelOrder') "; - Assert.assertTrue(provider.checkValid(sql)); - } - } - - public void test_true() throws Exception { - WallProvider provider = initWallProvider(); - { - String sql = "SELECT 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Collation[@Name=' + quotename(cl.name,'''') + ']' AS [Urn], cl.name AS [Name], CAST(COLLATIONPROPERTY(name, 'CodePage') AS int) AS [CodePage], CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID], CAST(COLLATIONPROPERTY(name, 'ComparisonStyle') AS int) AS [ComparisonStyle], cl.description AS [Description], CAST(COLLATIONPROPERTY(name, 'Version') AS int) AS [CollationVersion] FROM sys.fn_helpcollations() cl ORDER BY [Name] ASC"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "SELECT bp.Class_desc, bp.Permission_name, bp.Type, bp.Covering_permission_name, bp.Parent_class_desc, bp.Parent_covering_permission_name FROM sys.fn_builtin_permissions(null) as bp order by bp.class_desc"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select isExist = case when exists(select * from dbo.sysobjects where id = object_id ('SYS_LOG_2005')) then 1 else 0 end"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select length from syscolumns(nolock) where id = object_id('boat') and (name in ('boat_bag','skill_state'))"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from INFORMATION_SCHEMA.KEY_COLUMN_USAGE c join INFORMATION_SCHEMA.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_0 and SCHEMA_NAME(tbl.schema_id)=@_msparam_1)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_2 and SCHEMA_NAME(tbl.schema_id)=@_msparam_3)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_4 and SCHEMA_NAME(tbl.schema_id)=@_msparam_5)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_6 and SCHEMA_NAME(tbl.schema_id)=@_msparam_7)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_8 and SCHEMA_NAME(tbl.schema_id)=@_msparam_9)"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from sys.KEY_COLUMN_USAGE c join sys.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'"; - Assert.assertTrue(provider.checkValid(sql)); - } - - { - String sql = "SELECT user_name(), @@MAX_PRECISION, is_member('db_owner'), permissions(), DatabasePropertyEx(db_name(), N'collation'), SERVERPROPERTY('IsFullTextInstalled'), schema_name()"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select col.name, col.column_id, st.name as DT_name, schema_name(st.schema_id) as DT_schema, col.max_length, col.precision, col.scale, bt.name as BT_name, col.collation_name, col.is_nullable, col.is_ansi_padded, col.is_rowguidcol, col.is_identity, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.seed_value) end, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.increment_value) end, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, convert(bit, ColumnProperty(col.object_id, col.name, N'IsIdNotForRepl')) as IsIdNotForRepl, col.is_replicated, col.is_non_sql_subscribed, col.is_merge_published, col.is_dts_replicated, col.rule_object_id, robj.name as Rul_name, schema_name(robj.schema_id) as Rul_schema, col.default_object_id, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, dobj.name as def_name, schema_name(dobj.schema_id) as def_schema, CONVERT(bit, case when (ftc.column_id is null) then 0 else 1 end) as is_FullTextCol, col_name(col.object_id, ftc.type_column_id) FT_type_column, ftc.language_id as FT_language_id, case when(cmc.column_id is null) then null else cmc.definition end as formular, case when(cmc.column_id is null) then null else cmc.is_persisted end as is_persisted, defCst.definition, COLUMNPROPERTY(col.object_id, col.name, 'IsDeterministic') as IsDeterministic, xmlcoll.name as xmlSchema_name, schema_name(xmlcoll.schema_id) as xmlSchema_schema, col.is_xml_document, col.is_sparse, col.is_column_set from sys.columns col left outer join sys.types st on st.user_type_id = col.user_type_id left outer join sys.types bt on bt.user_type_id = col.system_type_id left outer join sys.objects robj on robj.object_id = col.rule_object_id and robj.type = 'R' left outer join sys.objects dobj on dobj.object_id = col.default_object_id and dobj.type = 'D' left outer join sys.default_constraints defCst on defCst.parent_object_id = col.object_id and defCst.parent_column_id = col.column_id left outer join sys.identity_columns idc o"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "SELECT * FROM `www_subject` WHERE subject like '哎%' or subject like '%' ORDER BY aid desc LIMIT 30 "; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "SELECT COUNT(*) FROM syscolumns WHERE id=OBJECT_ID(N'taobao_order') AND name='r3_billtype'"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "update master.dbo.dml_health_check set id=1"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "select col.name, st.name as DT_name, case when (st.name in ('nchar', 'nvarchar') and (col.max_length > 0)) then col.max_length / 2 else col.max_length end, col.precision, col.scale, bt.name as BT_name, col.is_nullable, col.is_identity,col.is_rowguidcol, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, case when(cmc.column_id is null) then null else cmc.definition end as formular, col.collation_name, col.system_type_id from nowshop.sys.all_columns col left outer join nowshop.sys.types st on st.user_type_id = col.user_type_id left outer join nowshop.sys.types bt on bt.user_type_id = col.system_type_id left outer join nowshop.sys.identity_columns idc on idc.object_id = col.object_id and idc.column_id = col.column_id left outer join nowshop.sys.computed_columns cmc on cmc.object_id = col.object_id and cmc.column_id = col.column_id where col.object_id = object_id(N'nowshop.dbo.hr_shop') order by col.column_id"; - Assert.assertTrue(provider.checkValid(sql)); - } - { - String sql = "update dbo.dml_health_check set name='123' where id=OBJECT_ID(N'taobao_order')"; - Assert.assertFalse(provider.checkValid(sql)); - } - { - String sql = "select * from tb_product_word where name='' or CONCAT(name,style)='' or CONCAT(shop,style)='' or CONCAT(ename,style)=''"; - Assert.assertTrue(provider.checkValid(sql)); - } - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.SQLServerWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class SQLServerWallTest_0 extends TestCase { + + private WallProvider initWallProvider() { + WallProvider provider = new SQLServerWallProvider(); + + provider.getConfig().setUseAllow(true); + provider.getConfig().setStrictSyntaxCheck(false); + provider.getConfig().setMultiStatementAllow(true); + provider.getConfig().setConditionAndAlwayTrueAllow(true); + provider.getConfig().setNoneBaseStatementAllow(true); + provider.getConfig().setSelectUnionCheck(false); + provider.getConfig().setSchemaCheck(true); + provider.getConfig().setLimitZeroAllow(true); + provider.getConfig().setCommentAllow(true); + + return provider; + } + + public void test_false() { + WallProvider provider = initWallProvider(); + { + String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 And (Select Top 1 unicode(substring(isNull(cast(name as varchar(8000)),char(32)),7,1)) From (Select Top 9 [dbid],[name] From master..sysdatabases Order by [dbid] desc) T Order by [dbid]) between 105 and 105"; + Assert.assertFalse(provider.checkValid(sql)); + } + { + String sql = "SELECT KL_ArticleContent,KL_ArticleTitle FROM dbo.KL_Article WHERE KL_ArticleId =13 and (select unicode(substring(isNull(cast(db_name() as varchar(8000)),char(32)),1,1))) between 105 and 108"; + Assert.assertFalse(provider.checkValid(sql)); + } + } + + public void test_false1() throws Exception { + WallProvider provider = initWallProvider(); + { + String sql = "select OrderId,Order_Time,oResult,oState,show_Exp_Num,Is_Exp_Print,sel_Exp_Id,Order_Th,Th_Audit_Time,Th_Delay_Days from Pro_Order_List where OrderId='2012110125252' AND HOST_NAME()=HOST_NAME() AND 'kbwg'='kbwg'"; + Assert.assertFalse(provider.checkValid(sql)); + } + { + String sql = "update dbo.dml_health_check set name='123' where id=OBJECT_ID(N'taobao_order')"; + Assert.assertFalse(provider.checkValid(sql)); + } + } + + public void test_true1() throws Exception { + WallProvider provider = initWallProvider(); + { + String sql = "select Fg.name as TableFg, dsp.name as TexImageFg, FtCat.name as FulltextCatalog, OBJECTPROPERTY(tbl.object_id, 'TableTextInRowLimit') as TextInrowLimit, OBJECTPROPERTY(tbl.object_id, 'IsIndexable'), user_name(tbl.principal_id) as DirectOwner, tbl.is_replicated, tbl.lock_escalation_desc from sys.tables tbl left outer join sys.data_spaces dsp on dsp.data_space_id = tbl.lob_data_space_id left outer join (sys.fulltext_indexes fti inner join sys.fulltext_catalogs FtCat on FtCat.fulltext_catalog_id = fti.fulltext_catalog_id ) on fti.object_id = tbl.object_id inner join (sys.indexes idx inner join sys.data_spaces Fg on (idx.index_id = 0 or idx.index_id = 1) and Fg.data_space_id = idx.data_space_id) on idx.object_id = tbl.object_id and (idx.index_id = 0 or idx.index_id = 1) where tbl.object_id = object_id(N'dbo.nqh_TelOrder') "; + Assert.assertTrue(provider.checkValid(sql)); + } + } + + public void test_true() throws Exception { + WallProvider provider = initWallProvider(); + { + String sql = "SELECT 'Server[@Name=' + quotename(CAST(serverproperty(N'Servername') AS sysname),'''') + ']' + '/Collation[@Name=' + quotename(cl.name,'''') + ']' AS [Urn], cl.name AS [Name], CAST(COLLATIONPROPERTY(name, 'CodePage') AS int) AS [CodePage], CAST(COLLATIONPROPERTY(name, 'LCID') AS int) AS [LocaleID], CAST(COLLATIONPROPERTY(name, 'ComparisonStyle') AS int) AS [ComparisonStyle], cl.description AS [Description], CAST(COLLATIONPROPERTY(name, 'Version') AS int) AS [CollationVersion] FROM sys.fn_helpcollations() cl ORDER BY [Name] ASC"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "SELECT bp.Class_desc, bp.Permission_name, bp.Type, bp.Covering_permission_name, bp.Parent_class_desc, bp.Parent_covering_permission_name FROM sys.fn_builtin_permissions(null) as bp order by bp.class_desc"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select isExist = case when exists(select * from dbo.sysobjects where id = object_id ('SYS_LOG_2005')) then 1 else 0 end"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select length from syscolumns(nolock) where id = object_id('boat') and (name in ('boat_bag','skill_state'))"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from INFORMATION_SCHEMA.KEY_COLUMN_USAGE c join INFORMATION_SCHEMA.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_0 and SCHEMA_NAME(tbl.schema_id)=@_msparam_1)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_2 and SCHEMA_NAME(tbl.schema_id)=@_msparam_3)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_4 and SCHEMA_NAME(tbl.schema_id)=@_msparam_5)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_6 and SCHEMA_NAME(tbl.schema_id)=@_msparam_7)INSERT INTO tempdep SELECT tbl.object_id AS [ID], tbl.name AS [Name], SCHEMA_NAME(tbl.schema_id) AS [Schema], db_name(), 3 FROM sys.tables AS tbl WHERE (tbl.name=@_msparam_8 and SCHEMA_NAME(tbl.schema_id)=@_msparam_9)"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select c.COLUMN_NAME, COLUMNPROPERTY(OBJECT_ID(c.TABLE_SCHEMA + '.' + c.TABLE_NAME), c.COLUMN_NAME, 'IsIdentity') from sys.KEY_COLUMN_USAGE c join sys.TABLE_CONSTRAINTS p on p.CONSTRAINT_NAME = c.CONSTRAINT_NAME where c.TABLE_NAME = @p1 and c.TABLE_SCHEMA = @p2 and p.TABLE_SCHEMA = @p2 and p.CONSTRAINT_TYPE = 'PRIMARY KEY'"; + Assert.assertTrue(provider.checkValid(sql)); + } + + { + String sql = "SELECT user_name(), @@MAX_PRECISION, is_member('db_owner'), permissions(), DatabasePropertyEx(db_name(), N'collation'), SERVERPROPERTY('IsFullTextInstalled'), schema_name()"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select col.name, col.column_id, st.name as DT_name, schema_name(st.schema_id) as DT_schema, col.max_length, col.precision, col.scale, bt.name as BT_name, col.collation_name, col.is_nullable, col.is_ansi_padded, col.is_rowguidcol, col.is_identity, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.seed_value) end, case when(idc.column_id is null) then null else CONVERT(nvarchar(40), idc.increment_value) end, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, convert(bit, ColumnProperty(col.object_id, col.name, N'IsIdNotForRepl')) as IsIdNotForRepl, col.is_replicated, col.is_non_sql_subscribed, col.is_merge_published, col.is_dts_replicated, col.rule_object_id, robj.name as Rul_name, schema_name(robj.schema_id) as Rul_schema, col.default_object_id, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, dobj.name as def_name, schema_name(dobj.schema_id) as def_schema, CONVERT(bit, case when (ftc.column_id is null) then 0 else 1 end) as is_FullTextCol, col_name(col.object_id, ftc.type_column_id) FT_type_column, ftc.language_id as FT_language_id, case when(cmc.column_id is null) then null else cmc.definition end as formular, case when(cmc.column_id is null) then null else cmc.is_persisted end as is_persisted, defCst.definition, COLUMNPROPERTY(col.object_id, col.name, 'IsDeterministic') as IsDeterministic, xmlcoll.name as xmlSchema_name, schema_name(xmlcoll.schema_id) as xmlSchema_schema, col.is_xml_document, col.is_sparse, col.is_column_set from sys.columns col left outer join sys.types st on st.user_type_id = col.user_type_id left outer join sys.types bt on bt.user_type_id = col.system_type_id left outer join sys.objects robj on robj.object_id = col.rule_object_id and robj.type = 'R' left outer join sys.objects dobj on dobj.object_id = col.default_object_id and dobj.type = 'D' left outer join sys.default_constraints defCst on defCst.parent_object_id = col.object_id and defCst.parent_column_id = col.column_id left outer join sys.identity_columns idc o"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "SELECT * FROM `www_subject` WHERE subject like '哎%' or subject like '%' ORDER BY aid desc LIMIT 30 "; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "SELECT COUNT(*) FROM syscolumns WHERE id=OBJECT_ID(N'taobao_order') AND name='r3_billtype'"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "update master.dbo.dml_health_check set id=1"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select col.name, st.name as DT_name, case when (st.name in ('nchar', 'nvarchar') and (col.max_length > 0)) then col.max_length / 2 else col.max_length end, col.precision, col.scale, bt.name as BT_name, col.is_nullable, col.is_identity,col.is_rowguidcol, OBJECTPROPERTY(col.default_object_id, N'IsDefaultCnst') as is_defcnst, CONVERT(bit, case when(cmc.column_id is null) then 0 else 1 end) as is_computed, case when(cmc.column_id is null) then null else cmc.definition end as formular, col.collation_name, col.system_type_id from nowshop.sys.all_columns col left outer join nowshop.sys.types st on st.user_type_id = col.user_type_id left outer join nowshop.sys.types bt on bt.user_type_id = col.system_type_id left outer join nowshop.sys.identity_columns idc on idc.object_id = col.object_id and idc.column_id = col.column_id left outer join nowshop.sys.computed_columns cmc on cmc.object_id = col.object_id and cmc.column_id = col.column_id where col.object_id = object_id(N'nowshop.dbo.hr_shop') order by col.column_id"; + Assert.assertTrue(provider.checkValid(sql)); + } + { + String sql = "select * from tb_product_word where name='' or CONCAT(name,style)='' or CONCAT(shop,style)='' or CONCAT(ename,style)=''"; + Assert.assertTrue(provider.checkValid(sql)); + } + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_7.java b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_7.java new file mode 100644 index 0000000000..865e489d08 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/filter/wall/SQLServerWallTest_7.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.filter.wall; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.wall.WallProvider; +import com.alibaba.druid.wall.spi.SQLServerWallProvider; + +/** + * SQLServerWallTest + * + * @author RaymondXiu + * @version 1.0, 2012-3-18 + * @see + */ +public class SQLServerWallTest_7 extends TestCase { + + public void test_true() throws Exception { + WallProvider provider = new SQLServerWallProvider(); + + provider.getConfig().setSelectHavingAlwayTrueCheck(true); + + Assert.assertTrue(provider.checkValid(// + "select * from (select top 3000 jol.id as primaryKeyIds, jo.orderNo as 委托单号, bm.custname as 委托方名称, manuCustInfo.custname as 出证方, jo.chkerDate as 委托日期, bcc.connectName as 联系人, bcc.mobile as 电话,jol.barcode as 样品条码, jol.name as 样品名称, jol.qtysub as 套件数量,jol.OnlyCode as 唯一识别码,jol.manufacture as 制造厂商,jol.sprc as 规格型号, jol.outno as 出厂编号, djod.name as 任务状态, djoc.name 委托类别, dct.name as 证书类型,bdp.organ_name as 分配室组, jol.task_id as 任务ID, be.user_name as 检定人员, verifyUser.user_name as 核验员, checkUser.user_name as 批准员, jol.ddate 交款日期,cjcs.name as 缴款状态, jc.moneys as 应收费, jc.moneystotal as 实收费, be.organ_id from jl_OrderList jol left outer join jl_CheckList jc on jol.checkList_id = jc.id left outer join jl_Order jo on jol.orderid = jo.id left outer join ba_dptinfo bdp on jol.dptid = bdp.id left outer join jl_Task jt on jol.task_id = jt.id left outer join ba_manucustinfo bm on jo.entrustCustId = bm.id left outer join ba_manucustinfo manuCustInfo on jo.custid = manuCustInfo.id left outer join ba_custconnect bcc on jo.linkPerson = bcc.id left outer join ba_employeeinfo be on jt.jdUserId = be.id left outer join ba_employeeinfo verifyUser on jt.verifyUser = verifyUser.id left outer join ba_employeeinfo checkUser on jt.checkUser = checkUser.id left outer join dict_jl_order_doType djod on jol.dotypeid = djod.id left outer join dict_jl_order_class djoc on jo.orderclassid = djoc.id left outer join dict_certificate_type dct on jt.certificatetype = dct.id left outer join dict_jl_chargestatus cjcs on jol.chargestatus = cjcs.id where jol.id >= (select min(primaryKeyId) from (select top 3000 jol.id as primaryKeyId from jl_OrderList jol left outer join jl_CheckList jc on jol.checkList_id = jc.id left outer join jl_Order jo on jol.orderid = jo.id left outer join ba_dptinfo bdp on jol.dptid = bdp.id left outer join jl_Task jt on jol.task_id = jt.id left outer join ba_manucustinfo bm on jo.entrustCustId = bm.id left outer join ba_manucustinfo manuCustInfo on jo.custid = manuCustInfo.id left outer join ba_custconnect bcc on jo.linkPerson = bcc.id left outer join ba_employeeinfo be on jt.jdUserId = be.id left outer join ba_employeeinfo verifyUser on jt.verifyUser = verifyUser.id left outer join ba_employeeinfo checkUser on jt.checkUser = checkUser.id left outer join dict_jl_order_doType djod on jol.dotypeid = djod.id left outer join dict_jl_order_class djoc on jo.orderclassid = djoc.id left outer join dict_certificate_type dct on jt.certificatetype = dct.id left outer join dict_jl_chargestatus cjcs on jol.chargestatus = cjcs.id where jo.chkerDate >= ? and jo.chkerDate <= ? and jol.ddate >= ? order by jol.id desc, jo.id DESC) as T) and jo.chkerDate >= ? and jo.chkerDate <= ? and jol.ddate >= ? order by jol.id asc, jo.id DESC) as T1 order by T1.primaryKeyIds desc")); + +// Assert.assertEquals(12, provider.getTableStats().size()); +// Assert.assertTrue(provider.getTableStats().containsKey("jl_OrderList")); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/pool/PreparedStatementProxyImplTest.java b/src/test/java/com/alibaba/druid/bvt/pool/PreparedStatementProxyImplTest.java index 5e0da955d0..2aa429e7df 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/PreparedStatementProxyImplTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/PreparedStatementProxyImplTest.java @@ -37,40 +37,40 @@ public class PreparedStatementProxyImplTest extends TestCase { stmt.setObject(3, (int) 1); stmt.setObject(4, (long) 1); stmt.setObject(5, (float) 1); - + stmt.setObject(6, (double) 1); stmt.setObject(7, new BigDecimal(1)); stmt.setObject(8, true); stmt.setObject(9, "xxx"); stmt.setObject(10, new java.sql.Date(System.currentTimeMillis())); - + stmt.setObject(11, new java.util.Date(System.currentTimeMillis())); stmt.setObject(12, new java.sql.Timestamp(System.currentTimeMillis())); stmt.setObject(13, new java.sql.Time(System.currentTimeMillis())); - + stmt.execute(); - + PreparedStatementProxy stmtProxy = stmt.unwrap(PreparedStatementProxy.class); Assert.assertNotNull(stmtProxy); - - Assert.assertEquals(Types.TINYINT, stmtProxy.getParameters().get(1).getSqlType()); - Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameters().get(2).getSqlType()); - Assert.assertEquals(Types.INTEGER, stmtProxy.getParameters().get(3).getSqlType()); - Assert.assertEquals(Types.BIGINT, stmtProxy.getParameters().get(4).getSqlType()); - Assert.assertEquals(Types.FLOAT, stmtProxy.getParameters().get(5).getSqlType()); - - Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameters().get(6).getSqlType()); - Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameters().get(7).getSqlType()); - Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameters().get(8).getSqlType()); - Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameters().get(9).getSqlType()); - Assert.assertEquals(Types.DATE, stmtProxy.getParameters().get(10).getSqlType()); - Assert.assertEquals(Types.DATE, stmtProxy.getParameters().get(11).getSqlType()); - Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameters().get(12).getSqlType()); - Assert.assertEquals(Types.TIME, stmtProxy.getParameters().get(13).getSqlType()); - + Assert.assertEquals(Types.TINYINT, stmtProxy.getParameter(0).getSqlType()); + Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameter(1).getSqlType()); + Assert.assertEquals(Types.INTEGER, stmtProxy.getParameter(2).getSqlType()); + Assert.assertEquals(Types.BIGINT, stmtProxy.getParameter(3).getSqlType()); + Assert.assertEquals(Types.FLOAT, stmtProxy.getParameter(4).getSqlType()); + + Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameter(5).getSqlType()); + Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameter(6).getSqlType()); + Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameter(7).getSqlType()); + Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameter(8).getSqlType()); + Assert.assertEquals(Types.DATE, stmtProxy.getParameter(9).getSqlType()); + + Assert.assertEquals(Types.DATE, stmtProxy.getParameter(10).getSqlType()); + Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameter(11).getSqlType()); + Assert.assertEquals(Types.TIME, stmtProxy.getParameter(12).getSqlType()); + stmt.close(); - + conn.close(); } } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/ConnectionTest4.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/ConnectionTest4.java index e61fe21727..dc74b89f38 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/ConnectionTest4.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/ConnectionTest4.java @@ -22,9 +22,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Assert; + import com.alibaba.druid.mock.MockDriver; import com.alibaba.druid.mock.MockPreparedStatement; import com.alibaba.druid.pool.DruidDataSource; @@ -264,7 +265,7 @@ public class ConnectionTest4 extends TestCase { PreparedStatement stmt = conn.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); - Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class)); + Assert.assertSame(raw, stmt.unwrap(MockPreparedStatement.class)); stmt.close(); } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java index 49b29b825c..7d521eac8b 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java @@ -32,19 +32,29 @@ import junit.framework.Assert; import junit.framework.TestCase; import com.alibaba.druid.mock.MockCallableStatement; +import com.alibaba.druid.mock.MockConnection; +import com.alibaba.druid.pool.DruidConnectionHolder; +import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidPooledCallableStatement; +import com.alibaba.druid.pool.DruidPooledConnection; import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey; import com.alibaba.druid.pool.PreparedStatementHolder; public class PoolableCallableStatementTest extends TestCase { - protected MockCallableStatement raw; + private DruidDataSource dataSource = new DruidDataSource(); + protected DruidPooledConnection conn; + protected MockCallableStatement raw; protected DruidPooledCallableStatement stmt; protected void setUp() throws Exception { + MockConnection mockConn = new MockConnection(); + DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn); + conn = new DruidPooledConnection(connHolder); raw = new MockCallableStatement(null, null); - stmt = new DruidPooledCallableStatement(null, - new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) { + stmt = new DruidPooledCallableStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, + null, 0, 0, + 0), raw)) { protected SQLException checkException(Throwable error) throws SQLException { if (error instanceof SQLException) { diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolablePreparedStatementTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolablePreparedStatementTest.java index 46804e7704..e5fb07d887 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolablePreparedStatementTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolablePreparedStatementTest.java @@ -24,23 +24,34 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Arrays; -import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Assert; + +import com.alibaba.druid.mock.MockConnection; import com.alibaba.druid.mock.MockPreparedStatement; +import com.alibaba.druid.pool.DruidConnectionHolder; +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.pool.DruidPooledConnection; import com.alibaba.druid.pool.DruidPooledPreparedStatement; import com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey; import com.alibaba.druid.pool.PreparedStatementHolder; public class PoolablePreparedStatementTest extends TestCase { - protected MockPreparedStatement raw; + protected MockPreparedStatement raw; protected DruidPooledPreparedStatement stmt; protected void setUp() throws Exception { + DruidDataSource dataSource = new DruidDataSource(); + MockConnection mockConn = new MockConnection(); + DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn); + DruidPooledConnection conn = new DruidPooledConnection(connHolder); + raw = new MockPreparedStatement(null, null); - stmt = new DruidPooledPreparedStatement(null, - new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) { + stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, + null, 0, 0, + 0), raw)) { protected SQLException checkException(Throwable error) throws SQLException { if (error instanceof SQLException) { diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest3.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest3.java index cd23cccb21..91f0a36075 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest3.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableStatementTest3.java @@ -1,45 +1,45 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.bvt.pool.basic; - -import java.sql.SQLException; - -import junit.framework.TestCase; - -import com.alibaba.druid.mock.MockResultSet; -import com.alibaba.druid.pool.DruidPooledStatement; - -public class PoolableStatementTest3 extends TestCase { - - public void test_clearResultSetError() throws Exception { - final MockResultSet rs = new MockResultSet(null) { - - public void close() throws SQLException { - throw new SQLException(); - } - }; - - DruidPooledStatement stmt = new DruidPooledStatement(null, null) { - - public void close() throws SQLException { - resultSetTrace.add(rs); - clearResultSet(); - } - }; - stmt.close(); - - } -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.pool.basic; + +import java.sql.SQLException; + +import junit.framework.TestCase; + +import com.alibaba.druid.mock.MockResultSet; +import com.alibaba.druid.pool.DruidPooledStatement; + +public class PoolableStatementTest3 extends TestCase { + + public void test_clearResultSetError() throws Exception { + final MockResultSet rs = new MockResultSet(null) { + + public void close() throws SQLException { + throw new SQLException(); + } + }; + + DruidPooledStatement stmt = new DruidPooledStatement(null, null) { + + public void close() throws SQLException { + addResultSetTrace(rs); + clearResultSet(); + } + }; + stmt.close(); + + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/CallableStatementProxyImplTest.java b/src/test/java/com/alibaba/druid/bvt/proxy/CallableStatementProxyImplTest.java index bf5490ce8a..f6abac8ea5 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/CallableStatementProxyImplTest.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/CallableStatementProxyImplTest.java @@ -1,609 +1,609 @@ -/* - * Copyright 1999-2011 Alibaba Group Holding Ltd. - * - * 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.alibaba.druid.bvt.proxy; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Array; -import java.sql.Blob; -import java.sql.CallableStatement; -import java.sql.Clob; -import java.sql.NClob; -import java.sql.Ref; -import java.sql.ResultSet; -import java.sql.RowId; -import java.sql.SQLException; -import java.sql.SQLXML; -import java.sql.Types; -import java.util.Calendar; -import java.util.Properties; - -import org.junit.Assert; - -import junit.framework.TestCase; - -import com.alibaba.druid.filter.FilterEventAdapter; -import com.alibaba.druid.proxy.DruidDriver; -import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; -import com.alibaba.druid.proxy.jdbc.ConnectionProxy; -import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; -import com.alibaba.druid.proxy.jdbc.DataSourceProxy; -import com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig; -import com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl; -import com.alibaba.druid.stat.JdbcStatManager; - -public class CallableStatementProxyImplTest extends TestCase { - protected void tearDown() throws Exception { - DruidDriver.getProxyDataSources().clear(); - Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); - } - - public void test_call() throws Exception { - DataSourceProxyConfig config = new DataSourceProxyConfig(); - DataSourceProxy dataSource = new DataSourceProxyImpl(null, config); - - FilterEventAdapter filter = new FilterEventAdapter() { - }; - filter.init(dataSource); - - config.getFilters().add(filter); - - String sql = "CALL P_0(?, ?)"; - CallableStatementProxyImpl rawCallStatement = new FakeCallableStatement(null, null, sql, 1001); - - ConnectionProxy connection = new ConnectionProxyImpl(dataSource, null, new Properties(), 1001); - CallableStatementProxyImpl cstmt = new CallableStatementProxyImpl(connection, rawCallStatement, sql, 2001); - - cstmt.registerOutParameter(1, Types.VARCHAR); - cstmt.registerOutParameter(1, Types.VARCHAR, "VARCHAR"); - cstmt.registerOutParameter(1, Types.VARCHAR, 3); - - cstmt.registerOutParameter("1", Types.VARCHAR); - cstmt.registerOutParameter("1", Types.VARCHAR, "VARCHAR"); - cstmt.registerOutParameter("1", Types.VARCHAR, 3); - - cstmt.setBoolean("1", true); - cstmt.setByte("1", (byte) 0); - cstmt.setShort("1", (short) 0); - cstmt.setInt("1", 0); - cstmt.setLong("1", 0); - cstmt.setFloat("1", 0); - cstmt.setDouble("1", 0); - cstmt.setBigDecimal("1", new BigDecimal("111")); - cstmt.setString("1", "X"); - cstmt.setURL("1", null); - cstmt.setSQLXML("1", null); - cstmt.setBytes("1", null); - cstmt.setDate("1", null); - cstmt.setDate("1", null, Calendar.getInstance()); - cstmt.setTime("1", null); - cstmt.setTime("1", null, Calendar.getInstance()); - cstmt.setTimestamp("1", null); - cstmt.setTimestamp("1", null, Calendar.getInstance()); - cstmt.setAsciiStream("1", null); - cstmt.setAsciiStream("1", null, 0); - cstmt.setAsciiStream("1", null, 0L); - cstmt.setBinaryStream("1", null); - cstmt.setBinaryStream("1", null, 0); - cstmt.setBinaryStream("1", null, 0L); - cstmt.setObject("1", null); - cstmt.setObject("1", null, Types.VARCHAR); - cstmt.setObject("1", null, Types.VARCHAR, 3); - cstmt.setCharacterStream("1", null); - cstmt.setCharacterStream("1", null, 0); - cstmt.setCharacterStream("1", null, 0L); - cstmt.setNull("1", Types.VARCHAR); - cstmt.setNull("1", Types.VARCHAR, "VARCHAR"); - cstmt.setRowId("1", null); - cstmt.setNString("1", null); - cstmt.setNCharacterStream("1", null); - cstmt.setNCharacterStream("1", null, 0); - cstmt.setNClob("1", (NClob) null); - cstmt.setNClob("1", (Reader) null); - cstmt.setNClob("1", (Reader) null, 0); - cstmt.setClob("1", (Clob) null); - cstmt.setClob("1", (Reader) null); - cstmt.setClob("1", (Reader) null, 0); - cstmt.setBlob("1", (Blob) null); - cstmt.setBlob("1", (InputStream) null); - cstmt.setBlob("1", (InputStream) null, 0); - - cstmt.setURL(1, null); - cstmt.setSQLXML(1, null); - - cstmt.setArray(1, null); - cstmt.setNCharacterStream(1, null); - cstmt.setNCharacterStream(1, null, 0); - cstmt.setNClob(1, (NClob) null); - cstmt.setNClob(1, (Reader) null); - cstmt.setNClob(1, (Reader) null, 0); - cstmt.setNString(1, null); - cstmt.setObject(1, null); - cstmt.setRef(1, null); - cstmt.setRowId(1, null); - cstmt.setUnicodeStream(1, null, 0); - - cstmt.getClob(1); - cstmt.getClob("1"); - cstmt.cancel(); - - cstmt.getResultSet(); - } - - private static final class FakeCallableStatement extends CallableStatementProxyImpl { - - private FakeCallableStatement(ConnectionProxy connection, CallableStatement statement, String sql, long id){ - super(connection, statement, sql, id); - } - - @Override - public ResultSet getResultSet() throws SQLException { - return null; - } - - @Override - public void cancel() throws SQLException { - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { - - } - - @Override - public void registerOutParameter(String parameterIndex, int sqlType, String typeName) throws SQLException { - - } - - @Override - public void registerOutParameter(String parameterIndex, int sqlType) throws SQLException { - } - - @Override - public void registerOutParameter(String parameterIndex, int sqlType, int scale) throws SQLException { - - } - - @Override - public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { - - } - - @Override - public Clob getClob(int parameterIndex) throws SQLException { - return null; - } - - @Override - public void setRowId(int parameterIndex, RowId x) throws SQLException { - } - - @Override - public void setRef(int parameterIndex, Ref x) throws SQLException { - } - - @Override - public void setObject(int parameterIndex, Object x) throws SQLException { - } - - @Override - public void setNString(int parameterIndex, String x) throws SQLException { - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException { - } - - @Override - public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { - } - - @Override - public void setNClob(int parameterIndex, NClob x) throws SQLException { - } - - @Override - public void setNClob(int parameterIndex, Reader x) throws SQLException { - } - - @Override - public void setNClob(int parameterIndex, Reader x, long length) throws SQLException { - } - - @Override - public void setArray(int parameterIndex, Array x) throws SQLException { - } - - @Override - public void setURL(int parameterIndex, URL x) throws SQLException { - } - - @Override - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - } - - @Override - public java.net.URL getURL(int parameterIndex) throws SQLException { - return null; - } - - @Override - public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException { - } - - @Override - public void setURL(String parameterName, java.net.URL val) throws SQLException { - } - - @Override - public void setNull(String parameterName, int sqlType) throws SQLException { - } - - @Override - public void setBoolean(String parameterName, boolean x) throws SQLException { - } - - @Override - public void setByte(String parameterName, byte x) throws SQLException { - } - - @Override - public void setShort(String parameterName, short x) throws SQLException { - } - - @Override - public void setInt(String parameterName, int x) throws SQLException { - } - - @Override - public void setLong(String parameterName, long x) throws SQLException { - } - - @Override - public void setFloat(String parameterName, float x) throws SQLException { - } - - @Override - public void setDouble(String parameterName, double x) throws SQLException { - } - - @Override - public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { - } - - @Override - public void setString(String parameterName, String x) throws SQLException { - } - - @Override - public void setBytes(String parameterName, byte[] x) throws SQLException { - } - - @Override - public void setDate(String parameterName, java.sql.Date x) throws SQLException { - } - - @Override - public void setTime(String parameterName, java.sql.Time x) throws SQLException { - } - - @Override - public void setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x, int length) throws SQLException { - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x, int length) throws SQLException { - } - - @Override - public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { - } - - @Override - public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { - } - - @Override - public void setObject(String parameterName, Object x) throws SQLException { - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader, int length) throws SQLException { - } - - @Override - public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException { - } - - @Override - public void setTime(String parameterName, java.sql.Time x, Calendar cal) throws SQLException { - } - - @Override - public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) throws SQLException { - } - - @Override - public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { - } - - @Override - public String getString(String parameterName) throws SQLException { - return null; - } - - @Override - public boolean getBoolean(String parameterName) throws SQLException { - return true; - } - - @Override - public byte getByte(String parameterName) throws SQLException { - return 0; - } - - @Override - public short getShort(String parameterName) throws SQLException { - return 0; - } - - @Override - public int getInt(String parameterName) throws SQLException { - return 0; - } - - @Override - public long getLong(String parameterName) throws SQLException { - return 0; - } - - @Override - public float getFloat(String parameterName) throws SQLException { - return 0; - } - - @Override - public double getDouble(String parameterName) throws SQLException { - return 0; - } - - @Override - public byte[] getBytes(String parameterName) throws SQLException { - return null; - } - - @Override - public java.sql.Date getDate(String parameterName) throws SQLException { - return null; - } - - @Override - public java.sql.Time getTime(String parameterName) throws SQLException { - return null; - } - - @Override - public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException { - return null; - } - - @Override - public Object getObject(String parameterName) throws SQLException { - return null; - } - - @Override - public BigDecimal getBigDecimal(String parameterName) throws SQLException { - return null; - } - - @Override - public Object getObject(String parameterName, java.util.Map> map) throws SQLException { - return null; - } - - @Override - public Ref getRef(String parameterName) throws SQLException { - return null; - } - - @Override - public Blob getBlob(String parameterName) throws SQLException { - return null; - } - - @Override - public Clob getClob(String parameterName) throws SQLException { - return null; - } - - @Override - public Array getArray(String parameterName) throws SQLException { - return null; - } - - @Override - public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException { - return null; - } - - @Override - public java.sql.Time getTime(String parameterName, Calendar cal) throws SQLException { - return null; - } - - @Override - public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - return null; - } - - @Override - public java.net.URL getURL(String parameterName) throws SQLException { - return null; - } - - @Override - public RowId getRowId(int parameterIndex) throws SQLException { - return null; - } - - @Override - public RowId getRowId(String parameterName) throws SQLException { - return null; - } - - @Override - public void setRowId(String parameterName, RowId x) throws SQLException { - } - - @Override - public void setNString(String parameterName, String value) throws SQLException { - } - - @Override - public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { - } - - @Override - public void setNClob(String parameterName, NClob value) throws SQLException { - } - - @Override - public void setClob(String parameterName, Reader reader, long length) throws SQLException { - } - - @Override - public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { - } - - @Override - public void setNClob(String parameterName, Reader reader, long length) throws SQLException { - } - - @Override - public NClob getNClob(int parameterIndex) throws SQLException { - return null; - } - - @Override - public NClob getNClob(String parameterName) throws SQLException { - return null; - } - - @Override - public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { - } - - @Override - public SQLXML getSQLXML(int parameterIndex) throws SQLException { - return null; - } - - @Override - public SQLXML getSQLXML(String parameterName) throws SQLException { - return null; - } - - @Override - public String getNString(int parameterIndex) throws SQLException { - return null; - } - - @Override - public String getNString(String parameterName) throws SQLException { - return null; - } - - @Override - public java.io.Reader getNCharacterStream(int parameterIndex) throws SQLException { - return null; - } - - @Override - public java.io.Reader getNCharacterStream(String parameterName) throws SQLException { - return null; - } - - @Override - public java.io.Reader getCharacterStream(int parameterIndex) throws SQLException { - return null; - } - - @Override - public java.io.Reader getCharacterStream(String parameterName) throws SQLException { - return null; - } - - @Override - public void setBlob(String parameterName, Blob x) throws SQLException { - } - - @Override - public void setClob(String parameterName, Clob x) throws SQLException { - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x, long length) throws SQLException { - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x, long length) throws SQLException { - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader, long length) throws SQLException { - } - - @Override - public void setAsciiStream(String parameterName, java.io.InputStream x) throws SQLException { - } - - @Override - public void setBinaryStream(String parameterName, java.io.InputStream x) throws SQLException { - } - - @Override - public void setCharacterStream(String parameterName, java.io.Reader reader) throws SQLException { - } - - @Override - public void setNCharacterStream(String parameterName, Reader value) throws SQLException { - } - - @Override - public void setClob(String parameterName, Reader reader) throws SQLException { - } - - @Override - public void setBlob(String parameterName, InputStream inputStream) throws SQLException { - } - - @Override - public void setNClob(String parameterName, Reader reader) throws SQLException { - } - } - -} +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.proxy; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Array; +import java.sql.Blob; +import java.sql.CallableStatement; +import java.sql.Clob; +import java.sql.NClob; +import java.sql.Ref; +import java.sql.ResultSet; +import java.sql.RowId; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Types; +import java.util.Calendar; +import java.util.Properties; + +import org.junit.Assert; + +import junit.framework.TestCase; + +import com.alibaba.druid.filter.FilterEventAdapter; +import com.alibaba.druid.proxy.DruidDriver; +import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl; +import com.alibaba.druid.proxy.jdbc.ConnectionProxy; +import com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl; +import com.alibaba.druid.proxy.jdbc.DataSourceProxy; +import com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig; +import com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl; +import com.alibaba.druid.stat.JdbcStatManager; + +public class CallableStatementProxyImplTest extends TestCase { + protected void tearDown() throws Exception { + DruidDriver.getProxyDataSources().clear(); + Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); + } + + public void test_call() throws Exception { + DataSourceProxyConfig config = new DataSourceProxyConfig(); + DataSourceProxy dataSource = new DataSourceProxyImpl(null, config); + + FilterEventAdapter filter = new FilterEventAdapter() { + }; + filter.init(dataSource); + + config.getFilters().add(filter); + + String sql = "CALL P_0(?, ?)"; + CallableStatementProxyImpl rawCallStatement = new FakeCallableStatement(new ConnectionProxyImpl(null, null, null, 0), null, sql, 1001); + + ConnectionProxy connection = new ConnectionProxyImpl(dataSource, null, new Properties(), 1001); + CallableStatementProxyImpl cstmt = new CallableStatementProxyImpl(connection, rawCallStatement, sql, 2001); + + cstmt.registerOutParameter(1, Types.VARCHAR); + cstmt.registerOutParameter(1, Types.VARCHAR, "VARCHAR"); + cstmt.registerOutParameter(1, Types.VARCHAR, 3); + + cstmt.registerOutParameter("1", Types.VARCHAR); + cstmt.registerOutParameter("1", Types.VARCHAR, "VARCHAR"); + cstmt.registerOutParameter("1", Types.VARCHAR, 3); + + cstmt.setBoolean("1", true); + cstmt.setByte("1", (byte) 0); + cstmt.setShort("1", (short) 0); + cstmt.setInt("1", 0); + cstmt.setLong("1", 0); + cstmt.setFloat("1", 0); + cstmt.setDouble("1", 0); + cstmt.setBigDecimal("1", new BigDecimal("111")); + cstmt.setString("1", "X"); + cstmt.setURL("1", null); + cstmt.setSQLXML("1", null); + cstmt.setBytes("1", null); + cstmt.setDate("1", null); + cstmt.setDate("1", null, Calendar.getInstance()); + cstmt.setTime("1", null); + cstmt.setTime("1", null, Calendar.getInstance()); + cstmt.setTimestamp("1", null); + cstmt.setTimestamp("1", null, Calendar.getInstance()); + cstmt.setAsciiStream("1", null); + cstmt.setAsciiStream("1", null, 0); + cstmt.setAsciiStream("1", null, 0L); + cstmt.setBinaryStream("1", null); + cstmt.setBinaryStream("1", null, 0); + cstmt.setBinaryStream("1", null, 0L); + cstmt.setObject("1", null); + cstmt.setObject("1", null, Types.VARCHAR); + cstmt.setObject("1", null, Types.VARCHAR, 3); + cstmt.setCharacterStream("1", null); + cstmt.setCharacterStream("1", null, 0); + cstmt.setCharacterStream("1", null, 0L); + cstmt.setNull("1", Types.VARCHAR); + cstmt.setNull("1", Types.VARCHAR, "VARCHAR"); + cstmt.setRowId("1", null); + cstmt.setNString("1", null); + cstmt.setNCharacterStream("1", null); + cstmt.setNCharacterStream("1", null, 0); + cstmt.setNClob("1", (NClob) null); + cstmt.setNClob("1", (Reader) null); + cstmt.setNClob("1", (Reader) null, 0); + cstmt.setClob("1", (Clob) null); + cstmt.setClob("1", (Reader) null); + cstmt.setClob("1", (Reader) null, 0); + cstmt.setBlob("1", (Blob) null); + cstmt.setBlob("1", (InputStream) null); + cstmt.setBlob("1", (InputStream) null, 0); + + cstmt.setURL(1, null); + cstmt.setSQLXML(1, null); + + cstmt.setArray(1, null); + cstmt.setNCharacterStream(1, null); + cstmt.setNCharacterStream(1, null, 0); + cstmt.setNClob(1, (NClob) null); + cstmt.setNClob(1, (Reader) null); + cstmt.setNClob(1, (Reader) null, 0); + cstmt.setNString(1, null); + cstmt.setObject(1, null); + cstmt.setRef(1, null); + cstmt.setRowId(1, null); + cstmt.setUnicodeStream(1, null, 0); + + cstmt.getClob(1); + cstmt.getClob("1"); + cstmt.cancel(); + + cstmt.getResultSet(); + } + + private static final class FakeCallableStatement extends CallableStatementProxyImpl { + + private FakeCallableStatement(ConnectionProxy connection, CallableStatement statement, String sql, long id){ + super(connection, statement, sql, id); + } + + @Override + public ResultSet getResultSet() throws SQLException { + return null; + } + + @Override + public void cancel() throws SQLException { + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType) throws SQLException { + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException { + + } + + @Override + public void registerOutParameter(String parameterIndex, int sqlType, String typeName) throws SQLException { + + } + + @Override + public void registerOutParameter(String parameterIndex, int sqlType) throws SQLException { + } + + @Override + public void registerOutParameter(String parameterIndex, int sqlType, int scale) throws SQLException { + + } + + @Override + public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException { + + } + + @Override + public Clob getClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + } + + @Override + public void setNString(int parameterIndex, String x) throws SQLException { + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader x) throws SQLException { + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader x, long length) throws SQLException { + } + + @Override + public void setNClob(int parameterIndex, NClob x) throws SQLException { + } + + @Override + public void setNClob(int parameterIndex, Reader x) throws SQLException { + } + + @Override + public void setNClob(int parameterIndex, Reader x, long length) throws SQLException { + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + } + + @Override + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + } + + @Override + public java.net.URL getURL(int parameterIndex) throws SQLException { + return null; + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML x) throws SQLException { + } + + @Override + public void setURL(String parameterName, java.net.URL val) throws SQLException { + } + + @Override + public void setNull(String parameterName, int sqlType) throws SQLException { + } + + @Override + public void setBoolean(String parameterName, boolean x) throws SQLException { + } + + @Override + public void setByte(String parameterName, byte x) throws SQLException { + } + + @Override + public void setShort(String parameterName, short x) throws SQLException { + } + + @Override + public void setInt(String parameterName, int x) throws SQLException { + } + + @Override + public void setLong(String parameterName, long x) throws SQLException { + } + + @Override + public void setFloat(String parameterName, float x) throws SQLException { + } + + @Override + public void setDouble(String parameterName, double x) throws SQLException { + } + + @Override + public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException { + } + + @Override + public void setString(String parameterName, String x) throws SQLException { + } + + @Override + public void setBytes(String parameterName, byte[] x) throws SQLException { + } + + @Override + public void setDate(String parameterName, java.sql.Date x) throws SQLException { + } + + @Override + public void setTime(String parameterName, java.sql.Time x) throws SQLException { + } + + @Override + public void setTimestamp(String parameterName, java.sql.Timestamp x) throws SQLException { + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x, int length) throws SQLException { + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x, int length) throws SQLException { + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType, int scale) throws SQLException { + } + + @Override + public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException { + } + + @Override + public void setObject(String parameterName, Object x) throws SQLException { + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader, int length) throws SQLException { + } + + @Override + public void setDate(String parameterName, java.sql.Date x, Calendar cal) throws SQLException { + } + + @Override + public void setTime(String parameterName, java.sql.Time x, Calendar cal) throws SQLException { + } + + @Override + public void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal) throws SQLException { + } + + @Override + public void setNull(String parameterName, int sqlType, String typeName) throws SQLException { + } + + @Override + public String getString(String parameterName) throws SQLException { + return null; + } + + @Override + public boolean getBoolean(String parameterName) throws SQLException { + return true; + } + + @Override + public byte getByte(String parameterName) throws SQLException { + return 0; + } + + @Override + public short getShort(String parameterName) throws SQLException { + return 0; + } + + @Override + public int getInt(String parameterName) throws SQLException { + return 0; + } + + @Override + public long getLong(String parameterName) throws SQLException { + return 0; + } + + @Override + public float getFloat(String parameterName) throws SQLException { + return 0; + } + + @Override + public double getDouble(String parameterName) throws SQLException { + return 0; + } + + @Override + public byte[] getBytes(String parameterName) throws SQLException { + return null; + } + + @Override + public java.sql.Date getDate(String parameterName) throws SQLException { + return null; + } + + @Override + public java.sql.Time getTime(String parameterName) throws SQLException { + return null; + } + + @Override + public java.sql.Timestamp getTimestamp(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(String parameterName) throws SQLException { + return null; + } + + @Override + public Object getObject(String parameterName, java.util.Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String parameterName) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String parameterName) throws SQLException { + return null; + } + + @Override + public Clob getClob(String parameterName) throws SQLException { + return null; + } + + @Override + public Array getArray(String parameterName) throws SQLException { + return null; + } + + @Override + public java.sql.Date getDate(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public java.sql.Time getTime(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public java.sql.Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { + return null; + } + + @Override + public java.net.URL getURL(String parameterName) throws SQLException { + return null; + } + + @Override + public RowId getRowId(int parameterIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String parameterName) throws SQLException { + return null; + } + + @Override + public void setRowId(String parameterName, RowId x) throws SQLException { + } + + @Override + public void setNString(String parameterName, String value) throws SQLException { + } + + @Override + public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { + } + + @Override + public void setNClob(String parameterName, NClob value) throws SQLException { + } + + @Override + public void setClob(String parameterName, Reader reader, long length) throws SQLException { + } + + @Override + public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { + } + + @Override + public void setNClob(String parameterName, Reader reader, long length) throws SQLException { + } + + @Override + public NClob getNClob(int parameterIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String parameterName) throws SQLException { + return null; + } + + @Override + public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException { + } + + @Override + public SQLXML getSQLXML(int parameterIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String parameterName) throws SQLException { + return null; + } + + @Override + public String getNString(int parameterIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String parameterName) throws SQLException { + return null; + } + + @Override + public java.io.Reader getNCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public java.io.Reader getNCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public java.io.Reader getCharacterStream(int parameterIndex) throws SQLException { + return null; + } + + @Override + public java.io.Reader getCharacterStream(String parameterName) throws SQLException { + return null; + } + + @Override + public void setBlob(String parameterName, Blob x) throws SQLException { + } + + @Override + public void setClob(String parameterName, Clob x) throws SQLException { + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x, long length) throws SQLException { + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x, long length) throws SQLException { + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader, long length) throws SQLException { + } + + @Override + public void setAsciiStream(String parameterName, java.io.InputStream x) throws SQLException { + } + + @Override + public void setBinaryStream(String parameterName, java.io.InputStream x) throws SQLException { + } + + @Override + public void setCharacterStream(String parameterName, java.io.Reader reader) throws SQLException { + } + + @Override + public void setNCharacterStream(String parameterName, Reader value) throws SQLException { + } + + @Override + public void setClob(String parameterName, Reader reader) throws SQLException { + } + + @Override + public void setBlob(String parameterName, InputStream inputStream) throws SQLException { + } + + @Override + public void setNClob(String parameterName, Reader reader) throws SQLException { + } + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest.java index f41437716e..7b14fe7d19 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest.java @@ -18,7 +18,7 @@ package com.alibaba.druid.bvt.proxy.filter; import java.sql.Connection; import java.sql.Statement; -import junit.framework.Assert; +import org.junit.Assert; import junit.framework.TestCase; import com.alibaba.druid.pool.DruidDataSource; diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest2.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest2.java index e737aef849..00a7a03a29 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest2.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest2.java @@ -18,9 +18,10 @@ package com.alibaba.druid.bvt.proxy.filter; import java.sql.Connection; import java.sql.Statement; -import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Assert; + import com.alibaba.druid.pool.DruidDataSource; public class MergeStatFilterTest2 extends TestCase { diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest3.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest3.java index 30f7cbe255..53678876e1 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest3.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest3.java @@ -19,9 +19,10 @@ import java.io.InputStreamReader; import java.sql.Connection; import java.sql.Statement; -import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Assert; + import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.util.IOUtils; diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl.java index a07e759202..7638a10633 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl.java @@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter; import java.sql.Connection; import java.sql.Statement; -import java.util.Set; import javax.management.openmbean.TabularData; @@ -26,7 +25,6 @@ import junit.framework.TestCase; import org.junit.Assert; import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.stat.DruidDataSourceStatManager; import com.alibaba.druid.stat.JdbcStatManager; import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.druid.util.JdbcUtils; diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_1.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_1.java index 2e598dd871..30858d02b6 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_1.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_1.java @@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter; import java.sql.Connection; import java.sql.Statement; -import java.util.Set; import javax.management.openmbean.TabularData; @@ -26,7 +25,6 @@ import junit.framework.TestCase; import org.junit.Assert; import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.stat.DruidDataSourceStatManager; import com.alibaba.druid.stat.JdbcStatManager; import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.druid.util.JdbcUtils; diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_2.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_2.java index 7918fe4e3b..5fb0fb39b0 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_2.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_2.java @@ -17,7 +17,6 @@ package com.alibaba.druid.bvt.proxy.filter; import java.sql.Connection; import java.sql.Statement; -import java.util.Set; import javax.management.openmbean.TabularData; @@ -26,7 +25,6 @@ import junit.framework.TestCase; import org.junit.Assert; import com.alibaba.druid.pool.DruidDataSource; -import com.alibaba.druid.stat.DruidDataSourceStatManager; import com.alibaba.druid.stat.JdbcStatManager; import com.alibaba.druid.support.json.JSONUtils; import com.alibaba.druid.util.JdbcUtils; diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_3.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_3.java new file mode 100644 index 0000000000..cc2783f357 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_3.java @@ -0,0 +1,80 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.proxy.filter; + +import java.sql.Connection; +import java.sql.PreparedStatement; + +import javax.management.openmbean.TabularData; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.stat.JdbcStatManager; +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.druid.util.JdbcUtils; + +public class MergeStatFilterTest_tddl_3 extends TestCase { + + private DruidDataSource dataSource; + + protected void setUp() throws Exception { + TabularData sqlList = JdbcStatManager.getInstance().getSqlList(); + if (sqlList.size() > 0) { + for (Object item : JdbcStatManager.getInstance().getSqlList().values()) { + String text = JSONUtils.toJSONString(item); + System.out.println(text); + } + } + + Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); + + dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:mock:xx"); + dataSource.setFilters("mergeStat"); + dataSource.setDbType("mysql"); + dataSource.setConnectionProperties("druid.useGloalDataSourceStat"); + } + + protected void tearDown() throws Exception { + JdbcUtils.close(dataSource); + + Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); + } + + public void test_merge() throws Exception { + for (int i = 1000; i < 2000; ++i) { + String tableName = "t_" + i; + + Connection conn = dataSource.getConnection(); + + String sql = "update " + tableName + " SET a = ? WHERE b = ?"; + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, "aaa"); + stmt.setInt(1, 2); + stmt.execute(); + stmt.close(); + + conn.close(); + } + + Assert.assertEquals(1, dataSource.getDataSourceStat().getSqlStatMap().size()); + + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_4.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_4.java new file mode 100644 index 0000000000..0cca94b87f --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/MergeStatFilterTest_tddl_4.java @@ -0,0 +1,81 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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.alibaba.druid.bvt.proxy.filter; + +import java.sql.Connection; +import java.sql.PreparedStatement; + +import javax.management.openmbean.TabularData; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.stat.JdbcStatManager; +import com.alibaba.druid.support.json.JSONUtils; +import com.alibaba.druid.util.JdbcUtils; + +public class MergeStatFilterTest_tddl_4 extends TestCase { + + private DruidDataSource dataSource; + + protected void setUp() throws Exception { + TabularData sqlList = JdbcStatManager.getInstance().getSqlList(); + if (sqlList.size() > 0) { + for (Object item : JdbcStatManager.getInstance().getSqlList().values()) { + String text = JSONUtils.toJSONString(item); + System.out.println(text); + } + } + + Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); + + dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:mock:xx"); + dataSource.setFilters("mergeStat"); + dataSource.setDbType("mysql"); + dataSource.setConnectionProperties("druid.useGloalDataSourceStat"); + dataSource.setPoolPreparedStatements(true); + } + + protected void tearDown() throws Exception { + JdbcUtils.close(dataSource); + + Assert.assertEquals(0, JdbcStatManager.getInstance().getSqlList().size()); + } + + public void test_merge() throws Exception { + for (int i = 1000; i < 2000; ++i) { + String tableName = "t_" + i; + + Connection conn = dataSource.getConnection(); + + String sql = "update " + tableName + " SET a = ? WHERE b = ?"; + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, "aaa"); + stmt.setInt(1, 2); + stmt.execute(); + stmt.close(); + + conn.close(); + } + + Assert.assertEquals(1, dataSource.getDataSourceStat().getSqlStatMap().size()); + + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest3.java b/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest3.java index 5f9c636f58..9ce9f486a0 100644 --- a/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest3.java +++ b/src/test/java/com/alibaba/druid/bvt/proxy/filter/StatFilterTest3.java @@ -1,11 +1,13 @@ package com.alibaba.druid.bvt.proxy.filter; -import junit.framework.Assert; import junit.framework.TestCase; +import org.junit.Assert; + import com.alibaba.druid.filter.stat.StatFilter; public class StatFilterTest3 extends TestCase { + @SuppressWarnings("deprecation") public void test_dbType() throws Exception { StatFilter filter = new StatFilter();