use of com.alibaba.druid.proxy.jdbc.ResultSetProxy in project druid by alibaba.
the class DruidDataSourceTest6 method setUp.
protected void setUp() throws Exception {
returnEmptyCount.set(0);
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(true);
dataSource.setInitialSize(1);
dataSource.setValidationQuery("select 1");
dataSource.setValidationQueryTimeout(10);
dataSource.setQueryTimeout(100);
dataSource.setUserCallback(new NameCallback("xx") {
});
dataSource.setPasswordCallback(new DruidPasswordCallback() {
@Override
public char[] getPassword() {
return "xx".toCharArray();
}
});
dataSource.getProxyFilters().add(new FilterAdapter() {
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
if (errorCount.get() > 0) {
errorCount.decrementAndGet();
throw new RuntimeException();
}
if (returnEmptyCount.get() > 0) {
returnEmptyCount.decrementAndGet();
return new ResultSetProxyImpl(statement, new MockResultSet(statement), 0, sql);
}
return chain.statement_executeQuery(statement, sql);
}
});
}
use of com.alibaba.druid.proxy.jdbc.ResultSetProxy in project druid by alibaba.
the class DruidPooledPreparedStatementTest1 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(false);
dataSource.setInitialSize(1);
dataSource.getProxyFilters().add(new FilterAdapter() {
@Override
public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
public void preparedStatement_clearParameters(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException {
throw new SQLException();
}
@Override
public ParameterMetaData preparedStatement_getParameterMetaData(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
throw new SQLException();
}
});
}
use of com.alibaba.druid.proxy.jdbc.ResultSetProxy in project druid by alibaba.
the class ResultSetProxyImplTest method test_resultset.
public void test_resultset() throws Exception {
MockDriver driver = new MockDriver();
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
config.setRawUrl("jdbc:mock:");
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);
{
StatFilter filter = new StatFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
{
Log4jFilter filter = new Log4jFilter();
filter.init(dataSource);
config.getFilters().add(filter);
}
Connection conn = dataSource.connect(null);
conn.setClientInfo("name", null);
Statement stmt = conn.createStatement();
ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
rs.insertRow();
rs.refreshRow();
rs.moveToInsertRow();
rs.moveToCurrentRow();
rs.next();
rs.updateRef(1, null);
rs.updateArray(1, null);
rs.updateRowId(1, null);
rs.updateNString(1, null);
rs.updateNClob(1, (NClob) null);
rs.updateNClob(1, (Reader) null);
rs.updateNClob(1, (Reader) null, 0);
rs.updateSQLXML(1, null);
rs.updateNCharacterStream(1, null);
rs.updateNCharacterStream(1, null, 0);
rs.getArray("1");
rs.updateRef("1", null);
rs.updateArray("1", null);
rs.updateRowId("1", null);
rs.updateNString("1", null);
rs.updateNClob("1", (NClob) null);
rs.updateNClob("1", (Reader) null);
rs.updateNClob("1", (Reader) null, 0);
rs.updateSQLXML("1", null);
rs.updateNCharacterStream("1", null);
rs.updateNCharacterStream("1", null, 0);
}
use of com.alibaba.druid.proxy.jdbc.ResultSetProxy in project druid by alibaba.
the class CounterFilterTest method test_count_filter.
public void test_count_filter() throws Exception {
DataSourceProxyConfig config = new DataSourceProxyConfig();
config.setUrl("");
config.setRawUrl("jdbc:mock:");
StatFilter filter = new StatFilter();
MockDriver driver = new MockDriver();
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(driver, config);
filter.init(dataSource);
config.getFilters().add(filter);
Connection conn = dataSource.connect(null);
Statement stmt = conn.createStatement();
ResultSetProxy rs = (ResultSetProxy) stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();
conn.close();
dataSource.getCompositeData();
dataSource.getProperties();
dataSource.getDataSourceMBeanDomain();
}
use of com.alibaba.druid.proxy.jdbc.ResultSetProxy in project druid by alibaba.
the class FilterEventAdapter method preparedStatement_executeQuery.
@Override
public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
try {
statementExecuteQueryBefore(statement, statement.getSql());
ResultSetProxy resultSet = chain.preparedStatement_executeQuery(statement);
if (resultSet != null) {
statementExecuteQueryAfter(statement, statement.getSql(), resultSet);
resultSetOpenAfter(resultSet);
}
return resultSet;
} catch (SQLException error) {
statement_executeErrorAfter(statement, statement.getSql(), error);
throw error;
} catch (RuntimeException error) {
statement_executeErrorAfter(statement, statement.getSql(), error);
throw error;
} catch (Error error) {
statement_executeErrorAfter(statement, statement.getSql(), error);
throw error;
}
}
Aggregations