Search in sources :

Example 6 with DataSourceProxyImpl

use of com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl in project druid by alibaba.

the class CallableStatementProxyImplTest method test_call.

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();
}
Also used : DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) FilterEventAdapter(com.alibaba.druid.filter.FilterEventAdapter) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) CallableStatementProxyImpl(com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl) Properties(java.util.Properties) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) BigDecimal(java.math.BigDecimal)

Example 7 with DataSourceProxyImpl

use of com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl in project druid by alibaba.

the class ConnectionProxyImplTest method test_connection.

public void test_connection() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    DataSourceProxy dataSource = new DataSourceProxyImpl(null, config);
    FilterEventAdapter filter = new FilterEventAdapter() {
    };
    filter.init(dataSource);
    ConnectionProxyImpl rawConnection = new ConnectionProxyImpl(null, null, new Properties(), 0) {

        public void setClientInfo(String name, String value) throws SQLClientInfoException {
        }
    };
    ConnectionProxyImpl connection = new ConnectionProxyImpl(dataSource, rawConnection, new Properties(), 1001);
    connection.setClientInfo("name", null);
}
Also used : DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) FilterEventAdapter(com.alibaba.druid.filter.FilterEventAdapter) ConnectionProxyImpl(com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl) Properties(java.util.Properties)

Example 8 with DataSourceProxyImpl

use of com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl in project druid by alibaba.

the class LogFilterTest method test_logFilter_1.

public void test_logFilter_1() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    config.setRawUrl("jdbc:mock:");
    DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
    Log4jFilter log4jFilter = new Log4jFilter();
    log4jFilter.init(dataSource);
    config.getFilters().add(log4jFilter);
    setLogDisableAll(log4jFilter, true);
    CommonsLogFilter commonLogFilter = new CommonsLogFilter() {

        @Override
        public boolean isDataSourceLogEnabled() {
            return false;
        }

        @Override
        public boolean isConnectionLogEnabled() {
            return false;
        }

        @Override
        public boolean isStatementLogEnabled() {
            return false;
        }

        @Override
        public boolean isResultSetLogEnabled() {
            return false;
        }

        @Override
        public boolean isResultSetLogErrorEnabled() {
            return false;
        }

        @Override
        public boolean isResultSetNextAfterLogEnabled() {
            return false;
        }
    };
    commonLogFilter.init(dataSource);
    config.getFilters().add(commonLogFilter);
    setLogDisableAll(commonLogFilter, true);
    executeSQL(dataSource);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CommonsLogFilter(com.alibaba.druid.filter.logging.CommonsLogFilter) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter)

Example 9 with DataSourceProxyImpl

use of com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl in project druid by alibaba.

the class LogFilterTest method test_logFilter_0.

public void test_logFilter_0() throws Exception {
    DataSourceProxyConfig config = new DataSourceProxyConfig();
    config.setRawUrl("jdbc:mock:");
    DataSourceProxyImpl dataSource = new DataSourceProxyImpl(new MockDriver(), config);
    Log4jFilter log4jFilter = new Log4jFilter();
    log4jFilter.init(dataSource);
    config.getFilters().add(log4jFilter);
    setLogDisableAll(log4jFilter, true);
    CommonsLogFilter commonLogFilter = new CommonsLogFilter() {

        @Override
        public boolean isDataSourceLogEnabled() {
            return true;
        }

        @Override
        public boolean isConnectionLogEnabled() {
            return true;
        }

        @Override
        public boolean isStatementLogEnabled() {
            return true;
        }

        @Override
        public boolean isResultSetLogEnabled() {
            return true;
        }

        @Override
        public boolean isResultSetLogErrorEnabled() {
            return true;
        }

        @Override
        public boolean isResultSetNextAfterLogEnabled() {
            return true;
        }
    };
    commonLogFilter.init(dataSource);
    config.getFilters().add(commonLogFilter);
    setLogDisableAll(commonLogFilter, false);
    executeSQL(dataSource);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) CommonsLogFilter(com.alibaba.druid.filter.logging.CommonsLogFilter) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter)

Example 10 with DataSourceProxyImpl

use of com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl 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);
}
Also used : MockDriver(com.alibaba.druid.mock.MockDriver) DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) Statement(java.sql.Statement) Log4jFilter(com.alibaba.druid.filter.logging.Log4jFilter) StatFilter(com.alibaba.druid.filter.stat.StatFilter) Connection(java.sql.Connection) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy)

Aggregations

DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)16 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)10 Properties (java.util.Properties)6 MockDriver (com.alibaba.druid.mock.MockDriver)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)5 Log4jFilter (com.alibaba.druid.filter.logging.Log4jFilter)4 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)4 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)4 FilterChain (com.alibaba.druid.filter.FilterChain)3 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)3 FilterEventAdapter (com.alibaba.druid.filter.FilterEventAdapter)3 CommonsLogFilter (com.alibaba.druid.filter.logging.CommonsLogFilter)3 StatFilter (com.alibaba.druid.filter.stat.StatFilter)3 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)3 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)3 SQLException (java.sql.SQLException)3 Statement (java.sql.Statement)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 CompositeType (javax.management.openmbean.CompositeType)3 TabularData (javax.management.openmbean.TabularData)3