Package com.alibaba.druid.filter.stat

Examples of com.alibaba.druid.filter.stat.StatFilter


    public Properties getConnectProperties() {
        return properties;
    }

    public CompositeDataSupport getCompositeData() throws JMException {
        StatFilter statFilter = null;
        JdbcDataSourceStat stat = null;
        for (Filter filter : this.getProxyFilters()) {
            if (filter instanceof StatFilter) {
                statFilter = (StatFilter) filter;
            }
        }
        if (statFilter != null) {
            stat = statFilter.getDataSourceStat();
        }

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("ID", id);
View Full Code Here


        config.setUrl("");

        DataSourceProxyImpl dataSource = new DataSourceProxyImpl(null, config);
        JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
       
        StatFilter filter = new StatFilter();
        filter.init(dataSource);

        dataSourceStat.reset();

        Assert.assertNull(StatFilter.getStatFilter(dataSource));
        Assert.assertNull(dataSourceStat.getSqlStat(Integer.MAX_VALUE));
        Assert.assertNull(dataSourceStat.getConnectionStat().getConnectLastTime());

        FilterChain chain = new FilterChainImpl(dataSource) {

            public ConnectionProxy connection_connect(Properties info) throws SQLException {
                throw new SQLException();
            }
        };

        Exception error = null;
        try {
            filter.connection_connect(chain, new Properties());
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectErrorCount());
View Full Code Here

    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();
View Full Code Here

import com.alibaba.druid.filter.stat.StatFilter;

public class StatFilterTest3 extends TestCase {
    @SuppressWarnings("deprecation")
    public void test_dbType() throws Exception {
        StatFilter filter = new StatFilter();
       
        Assert.assertFalse(filter.isMergeSql());
       
        filter.setDbType("mysql");
        filter.setMergeSql(true);
       
        Assert.assertTrue(filter.isMergeSql());
        Assert.assertEquals("mysql", filter.getDbType());
       
        Assert.assertEquals("SELECT ?\nLIMIT ?" , filter.mergeSql("select 'x' limit 1"));
    }
View Full Code Here

       
        Assert.assertEquals("SELECT ?\nLIMIT ?" , filter.mergeSql("select 'x' limit 1"));
    }
   
    public void test_dbType_error() throws Exception {
        StatFilter filter = new StatFilter();
        filter.setDbType("mysql");
        filter.setMergeSql(true);
       
        Assert.assertEquals("mysql", filter.getDbType());
       
        Assert.assertEquals("sdafawer asf " , filter.mergeSql("sdafawer asf "));
    }
View Full Code Here

       
        Assert.assertEquals("sdafawer asf " , filter.mergeSql("sdafawer asf "));
    }
   
    public void test_merge() throws Exception {
        StatFilter filter = new StatFilter();
        filter.setDbType("mysql");
        filter.setMergeSql(false);
       
        Assert.assertEquals("mysql", filter.getDbType());
       
        Assert.assertEquals("select 'x' limit 1" , filter.mergeSql("select 'x' limit 1"));
    }
View Full Code Here

    public void setUp() throws Exception {
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setMaxActive(100);

        statFilter = new StatFilter();
        dataSource.getProxyFilters().add(statFilter);
        dataSource.setConnectionProperties("executeSleep=1");
    }
View Full Code Here

        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);
View Full Code Here

                          PropertiesContent.get("jdbc.password")
                          ,PropertiesContent.get("jdbc.driver"));
//    WallFilter wall = new WallFilter();
//    wall.setDbType(PropertiesContent.get("jdbc.dbType"));
//    druidPlugin.addFilter(wall);
    druidPlugin.addFilter(new StatFilter());
    me.add(druidPlugin);
    // 配置ActiveRecord插件
    /**
    ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
    me.add(arp);
View Full Code Here

TOP

Related Classes of com.alibaba.druid.filter.stat.StatFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.