git-svn-id: http://code.alibabatech.com/svn/druid/trunk@2 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-05-11 01:35:21 +00:00
parent 239363b62e
commit 0e60b7d988
524 changed files with 67045 additions and 0 deletions
@@ -0,0 +1,309 @@
/**
* Project: druid
*
* File Created at 2010-12-2
* $Id$
*
* Copyright 1999-2100 Alibaba.com Corporation Limited.
* All rights reserved.
*
* This software is the confidential and proprietary information of
* Alibaba Company. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Alibaba.com.
*/
package com.alibaba.druid.proxy.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.FilterChainImpl;
/**
*
* @author shaojin.wensj
*
*/
public class StatementProxyImpl extends WrapperProxyImpl implements StatementProxy {
private final ConnectionProxy connection;
private final Statement statement;
// 通过CounterEventListener来维护
protected long lastExecuteStartTime;
protected long lastExecuteStartNano;
protected long lastExecuteCompleteTime;
protected long lastExecuteCompleteNano;
protected String lastExecuteSql;
protected ArrayList<String> batchSqlList;
public StatementProxyImpl(ConnectionProxy connection, Statement statement, long id) {
super(statement, id);
this.connection = connection;
this.statement = statement;
}
public ConnectionProxy getConnectionProxy() {
return connection;
}
public Statement getStatementRaw() {
return this.statement;
}
public FilterChain createChain() {
return new FilterChainImpl(this.connection.getDirectDataSource());
}
@Override
public void addBatch(String sql) throws SQLException {
if (batchSqlList == null) {
batchSqlList = new ArrayList<String>();
}
createChain().statement_addBatch(this, sql);
batchSqlList.add(sql);
}
@Override
public void cancel() throws SQLException {
createChain().statement_cancel(this);
}
@Override
public void clearBatch() throws SQLException {
if (batchSqlList == null) {
batchSqlList = new ArrayList<String>();
}
createChain().statement_clearBatch(this);
batchSqlList.clear();
}
@Override
public void clearWarnings() throws SQLException {
createChain().statement_clearWarnings(this);
}
@Override
public void close() throws SQLException {
createChain().statement_close(this);
}
@Override
public boolean execute(String sql) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_execute(this, sql);
}
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_execute(this, sql, autoGeneratedKeys);
}
@Override
public boolean execute(String sql, int[] columnIndexes) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_execute(this, sql, columnIndexes);
}
@Override
public boolean execute(String sql, String[] columnNames) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_execute(this, sql, columnNames);
}
@Override
public int[] executeBatch() throws SQLException {
return createChain().statement_executeBatch(this);
}
@Override
public ResultSet executeQuery(String sql) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_executeQuery(this, sql);
}
@Override
public int executeUpdate(String sql) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_executeUpdate(this, sql);
}
@Override
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_executeUpdate(this, sql, autoGeneratedKeys);
}
@Override
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_executeUpdate(this, sql, columnIndexes);
}
@Override
public int executeUpdate(String sql, String[] columnNames) throws SQLException {
lastExecuteSql = sql;
return createChain().statement_executeUpdate(this, sql, columnNames);
}
@Override
public Connection getConnection() throws SQLException {
return createChain().statement_getConnection(this);
}
@Override
public int getFetchDirection() throws SQLException {
return createChain().statement_getFetchDirection(this);
}
@Override
public int getFetchSize() throws SQLException {
return createChain().statement_getFetchSize(this);
}
@Override
public ResultSet getGeneratedKeys() throws SQLException {
return createChain().statement_getGeneratedKeys(this);
}
@Override
public int getMaxFieldSize() throws SQLException {
return createChain().statement_getMaxFieldSize(this);
}
@Override
public int getMaxRows() throws SQLException {
return createChain().statement_getMaxRows(this);
}
@Override
public boolean getMoreResults() throws SQLException {
return createChain().statement_getMoreResults(this);
}
@Override
public boolean getMoreResults(int current) throws SQLException {
return createChain().statement_getMoreResults(this, current);
}
@Override
public int getQueryTimeout() throws SQLException {
return createChain().statement_getQueryTimeout(this);
}
@Override
public ResultSet getResultSet() throws SQLException {
return createChain().statement_getResultSet(this);
}
@Override
public int getResultSetConcurrency() throws SQLException {
return createChain().statement_getResultSetConcurrency(this);
}
@Override
public int getResultSetHoldability() throws SQLException {
return createChain().statement_getResultSetHoldability(this);
}
@Override
public int getResultSetType() throws SQLException {
return createChain().statement_getResultSetType(this);
}
@Override
public int getUpdateCount() throws SQLException {
return createChain().statement_getUpdateCount(this);
}
@Override
public SQLWarning getWarnings() throws SQLException {
return createChain().statement_getWarnings(this);
}
@Override
public boolean isClosed() throws SQLException {
return createChain().statement_isClosed(this);
}
@Override
public boolean isPoolable() throws SQLException {
return createChain().statement_isPoolable(this);
}
@Override
public void setCursorName(String name) throws SQLException {
createChain().statement_setCursorName(this, name);
}
@Override
public void setEscapeProcessing(boolean enable) throws SQLException {
createChain().statement_setEscapeProcessing(this, enable);
}
@Override
public void setFetchDirection(int direction) throws SQLException {
createChain().statement_setFetchDirection(this, direction);
}
@Override
public void setFetchSize(int rows) throws SQLException {
createChain().statement_setFetchSize(this, rows);
}
@Override
public void setMaxFieldSize(int max) throws SQLException {
createChain().statement_setMaxFieldSize(this, max);
}
@Override
public void setMaxRows(int max) throws SQLException {
createChain().statement_setMaxRows(this, max);
}
@Override
public void setPoolable(boolean poolable) throws SQLException {
createChain().statement_setPoolable(this, poolable);
}
@Override
public void setQueryTimeout(int seconds) throws SQLException {
createChain().statement_setQueryTimeout(this, seconds);
}
@Override
public List<String> getBatchSqlList() {
if (batchSqlList == null) {
batchSqlList = new ArrayList<String>();
}
return batchSqlList;
}
@Override
public String getBatchSql() {
List<String> 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;
}
}