Search in sources :

Example 1 with DataSourceProxy

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

the class RandomDataSourceValidateFilter method recordTime.

private void recordTime(StatementProxy statement) {
    ConnectionProxy conn = statement.getConnectionProxy();
    if (conn != null) {
        DataSourceProxy dataSource = conn.getDirectDataSource();
        RandomDataSourceValidateThread.logSuccessTime(dataSource);
    }
}
Also used : DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 2 with DataSourceProxy

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

the class DruidDriver method getDataSource.

/**
 * 参数定义: com.alibaba.druid.log.LogFilter=filter com.alibaba.druid.log.LogFilter.p1=prop-value
 * com.alibaba.druid.log.LogFilter.p2=prop-value
 *
 * @param url
 * @return
 * @throws SQLException
 */
private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
    DataSourceProxyImpl dataSource = proxyDataSources.get(url);
    if (dataSource == null) {
        DataSourceProxyConfig config = parseConfig(url, info);
        Driver rawDriver = createDriver(config.getRawDriverClassName());
        DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);
        {
            String property = System.getProperty("druid.filters");
            if (property != null && property.length() > 0) {
                for (String filterItem : property.split(",")) {
                    FilterManager.loadFilter(config.getFilters(), filterItem);
                }
            }
        }
        {
            int dataSourceId = createDataSourceId();
            newDataSource.setId(dataSourceId);
            for (Filter filter : config.getFilters()) {
                filter.init(newDataSource);
            }
        }
        DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
        if (oldDataSource == null) {
            if (config.isJmxOption()) {
                JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
            }
        }
        dataSource = proxyDataSources.get(url);
    }
    return dataSource;
}
Also used : DataSourceProxyConfig(com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig) DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) Filter(com.alibaba.druid.filter.Filter) Driver(java.sql.Driver)

Example 3 with DataSourceProxy

use of com.alibaba.druid.proxy.jdbc.DataSourceProxy 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 4 with DataSourceProxy

use of com.alibaba.druid.proxy.jdbc.DataSourceProxy 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 5 with DataSourceProxy

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

the class StatFilter method createSqlStat.

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 {
        DbType dbType = this.dbType;
        if (dbType == null) {
            dbType = DbType.of(dataSource.getDbType());
        }
        sql = mergeSql(sql, dbType);
        return dataSourceStat.createSqlStat(sql);
    }
}
Also used : DataSourceProxy(com.alibaba.druid.proxy.jdbc.DataSourceProxy) JdbcDataSourceStat(com.alibaba.druid.stat.JdbcDataSourceStat) JdbcStatContext(com.alibaba.druid.stat.JdbcStatContext) DbType(com.alibaba.druid.DbType)

Aggregations

DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)7 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)4 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)4 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)4 Properties (java.util.Properties)4 FilterEventAdapter (com.alibaba.druid.filter.FilterEventAdapter)3 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)3 Driver (java.sql.Driver)2 DbType (com.alibaba.druid.DbType)1 Filter (com.alibaba.druid.filter.Filter)1 FilterChain (com.alibaba.druid.filter.FilterChain)1 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)1 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 DruidDriver (com.alibaba.druid.proxy.DruidDriver)1 CallableStatementProxyImpl (com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl)1 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)1 PreparedStatementProxyImpl (com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl)1 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)1 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)1