Search in sources :

Example 1 with DataSourceProxyImpl

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

the class DruidDriver method connect.

@Override
public Connection connect(String url, Properties info) throws SQLException {
    if (!acceptsURL(url)) {
        return null;
    }
    connectCount.incrementAndGet();
    DataSourceProxyImpl dataSource = getDataSource(url, info);
    return dataSource.connect(info);
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)

Example 2 with DataSourceProxyImpl

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

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

the class JdbcStatManager method reset.

@Override
public void reset() {
    resetCount.incrementAndGet();
    connectionStat.reset();
    statementStat.reset();
    resultSetStat.reset();
    final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
    for (DataSourceProxyImpl dataSource : dataSources.values()) {
        dataSource.getDataSourceStat().reset();
    }
    for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        instance.getDataSourceStat().reset();
    }
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 4 with DataSourceProxyImpl

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

the class JdbcStatManager method getConnectionList.

public TabularData getConnectionList() throws JMException {
    CompositeType rowType = JdbcConnectionStat.Entry.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("ConnectionList", "ConnectionList", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
    for (DataSourceProxyImpl dataSource : dataSources.values()) {
        JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
        ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
        for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
            data.put(entry.getValue().getCompositeData());
        }
    }
    for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcDataSourceStat dataSourceStat = instance.getDataSourceStat();
        ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
        for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
            data.put(entry.getValue().getCompositeData());
        }
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularType(javax.management.openmbean.TabularType) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

Example 5 with DataSourceProxyImpl

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

the class JdbcStatManager method getSqlList.

@Override
public TabularData getSqlList() throws JMException {
    CompositeType rowType = JdbcSqlStat.getCompositeType();
    String[] indexNames = rowType.keySet().toArray(new String[rowType.keySet().size()]);
    TabularType tabularType = new TabularType("SqlListStatistic", "SqlListStatistic", rowType, indexNames);
    TabularData data = new TabularDataSupport(tabularType);
    JdbcDataSourceStat globalStat = JdbcDataSourceStat.getGlobal();
    if (globalStat != null) {
        Map<String, JdbcSqlStat> statMap = globalStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", globalStat.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DataSourceProxyImpl dataSource : DruidDriver.getProxyDataSources().values()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcDataSourceStat druidDataSourceStat = dataSource.getDataSourceStat();
        if (druidDataSourceStat == globalStat) {
            continue;
        }
        Map<String, JdbcSqlStat> statMap = druidDataSourceStat.getSqlStatMap();
        for (Map.Entry<String, JdbcSqlStat> entry : statMap.entrySet()) {
            if (entry.getValue().getExecuteCount() == 0 && entry.getValue().getRunningCount() == 0) {
                continue;
            }
            Map<String, Object> map = entry.getValue().getData();
            map.put("URL", dataSource.getUrl());
            data.put(new CompositeDataSupport(JdbcSqlStat.getCompositeType(), map));
        }
    }
    return data;
}
Also used : DataSourceProxyImpl(com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl) TabularType(javax.management.openmbean.TabularType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) TabularData(javax.management.openmbean.TabularData) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) CompositeType(javax.management.openmbean.CompositeType)

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