Search in sources :

Example 21 with WallTableStat

use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.

the class WallStatTest_update method testMySql.

public void testMySql() throws Exception {
    WallProvider provider = new MySqlWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(1, tableStat.getUpdateCount());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) OracleWallProvider(com.alibaba.druid.wall.spi.OracleWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 22 with WallTableStat

use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.

the class WallStatTest_update method testSQLServer.

public void testSQLServer() throws Exception {
    WallProvider provider = new SQLServerWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(1, tableStat.getUpdateCount());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) OracleWallProvider(com.alibaba.druid.wall.spi.OracleWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider)

Example 23 with WallTableStat

use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.

the class WallStatTest_whiteList_syntaxError method testMySql.

public void testMySql() throws Exception {
    WallProvider provider = new MySqlWallProvider();
    provider.getConfig().setStrictSyntaxCheck(false);
    String sql = "select xx * x *";
    Assert.assertTrue(provider.checkValid(sql));
    {
        WallTableStat tableStat = provider.getTableStat("t");
        Assert.assertEquals(0, tableStat.getSelectCount());
        Assert.assertEquals(0, provider.getBlackListHitCount());
        Assert.assertEquals(0, provider.getWhiteListHitCount());
        Assert.assertEquals(0, provider.getWhiteList().size());
        Assert.assertEquals(0, provider.getBlackList().size());
        Assert.assertEquals(1, provider.getCheckCount());
        Assert.assertEquals(1, provider.getSyntaxErrorCount());
        Assert.assertEquals(1, provider.getHardCheckCount());
    }
    Assert.assertTrue(provider.checkValid(sql));
    {
        WallTableStat tableStat = provider.getTableStat("t");
        Assert.assertEquals(0, tableStat.getSelectCount());
        Assert.assertEquals(0, provider.getBlackListHitCount());
        Assert.assertEquals(0, provider.getWhiteListHitCount());
        Assert.assertEquals(0, provider.getWhiteList().size());
        Assert.assertEquals(0, provider.getBlackList().size());
        Assert.assertEquals(2, provider.getCheckCount());
        Assert.assertEquals(2, provider.getSyntaxErrorCount());
        Assert.assertEquals(2, provider.getHardCheckCount());
    }
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Example 24 with WallTableStat

use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.

the class WallProviderTest method test_getSqlStat.

public void test_getSqlStat() throws Exception {
    String whiteSql_1 = "select * from t1 where fid = 1";
    String whiteSql_2 = "select * from t1 where fid = 2";
    String blackSql_1 = "select * from t2 where len(fid) = 1 OR 1 = 1";
    String blackSql_2 = "select * from t2 where len(fid) = 2 OR 1 = 1";
    MySqlWallProvider provider = new MySqlWallProvider();
    Assert.assertTrue(provider.checkValid(whiteSql_1));
    Assert.assertTrue(provider.checkValid(whiteSql_2));
    Assert.assertEquals(1, provider.getSqlList().size());
    Assert.assertFalse(provider.checkValid(blackSql_1));
    Assert.assertFalse(provider.checkValid(blackSql_2));
    Assert.assertEquals(2, provider.getSqlList().size());
    Assert.assertNotNull(provider.getSqlStat(whiteSql_1));
    Assert.assertNotNull(provider.getSqlStat(blackSql_1));
    Assert.assertSame(provider.getSqlStat(blackSql_1), provider.getSqlStat(blackSql_2));
    WallSqlStat whiteStat_1 = provider.getSqlStat(whiteSql_1);
    WallSqlStat whiteStat_2 = provider.getSqlStat(whiteSql_2);
    Assert.assertSame(whiteStat_1, whiteStat_2);
    provider.addFetchRowCount(whiteStat_1, 3);
    WallTableStat wallTableStat = provider.getTableStat("t1");
    Assert.assertNotNull(wallTableStat);
    Assert.assertEquals(3, wallTableStat.getFetchRowCount());
    Assert.assertTrue(provider.checkValid(whiteSql_1));
    Assert.assertTrue(provider.checkValid(whiteSql_2));
    Assert.assertFalse(provider.checkValid(blackSql_1));
    Assert.assertFalse(provider.checkValid(blackSql_2));
    for (int i = 1000; i < 1000 * 2; ++i) {
        String sql_x = "select * from t1 where fid = " + i;
        Assert.assertTrue(provider.checkValid(sql_x));
        Assert.assertSame(whiteStat_1, provider.getSqlStat(sql_x));
    }
    Assert.assertEquals(1, provider.getWhiteList().size());
    Assert.assertEquals(2, provider.getSqlList().size());
    Assert.assertFalse(provider.checkValid("slelc"));
    {
        WallProviderStatValue statValue = provider.getStatValue(true);
        Assert.assertNotNull(statValue);
        Assert.assertEquals(2, statValue.getTables().size());
        Assert.assertEquals(1, statValue.getFunctions().size());
        Assert.assertEquals(1009, statValue.getCheckCount());
        Assert.assertEquals(2, statValue.getBlackListHitCount());
        Assert.assertEquals(4, statValue.getHardCheckCount());
        Assert.assertEquals(1, statValue.getSyntaxErrorCount());
        Assert.assertEquals(5, statValue.getViolationCount());
        Assert.assertEquals(1003, statValue.getWhiteListHitCount());
        Assert.assertEquals(1, statValue.getWhiteList().size());
        Assert.assertEquals(2, statValue.getBlackList().size());
    }
    {
        WallProviderStatValue statValue = provider.getStatValue(true);
        Assert.assertNotNull(statValue);
        Assert.assertEquals(0, statValue.getTables().size());
        Assert.assertEquals(0, statValue.getFunctions().size());
        Assert.assertEquals(0, statValue.getCheckCount());
        Assert.assertEquals(0, statValue.getBlackListHitCount());
        Assert.assertEquals(0, statValue.getHardCheckCount());
        Assert.assertEquals(0, statValue.getSyntaxErrorCount());
        Assert.assertEquals(0, statValue.getViolationCount());
        Assert.assertEquals(0, statValue.getWhiteListHitCount());
        Assert.assertEquals(0, statValue.getWhiteList().size());
        Assert.assertEquals(0, statValue.getBlackList().size());
    }
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) WallSqlStat(com.alibaba.druid.wall.WallSqlStat) WallProviderStatValue(com.alibaba.druid.wall.WallProviderStatValue)

Example 25 with WallTableStat

use of com.alibaba.druid.wall.WallTableStat in project druid by alibaba.

the class WallStatTest_WhiteList method testMySql.

public void testMySql() throws Exception {
    WallProvider provider = new MySqlWallProvider();
    for (int i = 0; i < 3001; ++i) {
        String sql = "select * from t where id = " + i;
        Assert.assertTrue(provider.checkValid(sql));
    }
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(3001, tableStat.getSelectCount());
    Assert.assertEquals(0, provider.getBlackListHitCount());
    Assert.assertEquals(3000, provider.getWhiteListHitCount());
    Assert.assertEquals(1, provider.getWhiteList().size());
    Assert.assertEquals(3001, provider.getCheckCount());
}
Also used : WallTableStat(com.alibaba.druid.wall.WallTableStat) WallProvider(com.alibaba.druid.wall.WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider)

Aggregations

WallTableStat (com.alibaba.druid.wall.WallTableStat)42 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)42 WallProvider (com.alibaba.druid.wall.WallProvider)41 OracleWallProvider (com.alibaba.druid.wall.spi.OracleWallProvider)34 PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)34 SQLServerWallProvider (com.alibaba.druid.wall.spi.SQLServerWallProvider)34 WallFunctionStat (com.alibaba.druid.wall.WallFunctionStat)1 WallProviderStatValue (com.alibaba.druid.wall.WallProviderStatValue)1 WallSqlStat (com.alibaba.druid.wall.WallSqlStat)1