Search in sources :

Example 6 with PGWallProvider

use of com.alibaba.druid.wall.spi.PGWallProvider in project druid by alibaba.

the class WallStatTest_delete method testPG.

public void testPG() throws Exception {
    WallProvider provider = new PGWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(1, tableStat.getDeleteCount());
}
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) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider)

Example 7 with PGWallProvider

use of com.alibaba.druid.wall.spi.PGWallProvider in project druid by alibaba.

the class PGShowTest method test_0.

public void test_0() throws Exception {
    String sql = "SHOW max_identifier_length";
    PGSQLStatementParser parser = new PGSQLStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLStatement statemen = statementList.get(0);
    //        print(statementList);
    Assert.assertEquals(1, statementList.size());
    PGSchemaStatVisitor visitor = new PGSchemaStatVisitor();
    statemen.accept(visitor);
    //        System.out.println("Tables : " + visitor.getTables());
    //        System.out.println("fields : " + visitor.getColumns());
    {
        WallProvider provider = new PGWallProvider();
        Assert.assertTrue(provider.checkValid(sql));
    }
// Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("reviews")));
//Assert.assertTrue(visitor.getTables().get(new TableStat.Name("reviews")).getAlterCount() == 1);
//Assert.assertTrue(visitor.getColumns().size() == 1);
}
Also used : WallProvider(com.alibaba.druid.wall.WallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) PGSchemaStatVisitor(com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) PGSQLStatementParser(com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)

Example 8 with PGWallProvider

use of com.alibaba.druid.wall.spi.PGWallProvider in project druid by alibaba.

the class WallFilter method init.

@Override
public synchronized void init(DataSourceProxy dataSource) {
    if (null == dataSource) {
        LOG.error("dataSource should not be null");
        return;
    }
    if (this.dbType == null || this.dbType.trim().length() == 0) {
        if (dataSource.getDbType() != null) {
            this.dbType = dataSource.getDbType();
        } else {
            this.dbType = JdbcUtils.getDbType(dataSource.getRawJdbcUrl(), "");
        }
    }
    if (dbType == null) {
        dbType = JdbcUtils.getDbType(dataSource.getUrl(), null);
    }
    if (//
    JdbcUtils.MYSQL.equals(dbType) || //
    JdbcUtils.MARIADB.equals(dbType) || JdbcUtils.H2.equals(dbType)) {
        if (config == null) {
            config = new WallConfig(MySqlWallProvider.DEFAULT_CONFIG_DIR);
        }
        provider = new MySqlWallProvider(config);
    } else if (JdbcUtils.ORACLE.equals(dbType) || JdbcUtils.ALI_ORACLE.equals(dbType)) {
        if (config == null) {
            config = new WallConfig(OracleWallProvider.DEFAULT_CONFIG_DIR);
        }
        provider = new OracleWallProvider(config);
    } else if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) {
        if (config == null) {
            config = new WallConfig(SQLServerWallProvider.DEFAULT_CONFIG_DIR);
        }
        provider = new SQLServerWallProvider(config);
    } else if (JdbcUtils.POSTGRESQL.equals(dbType) || JdbcUtils.ENTERPRISEDB.equals(dbType)) {
        if (config == null) {
            config = new WallConfig(PGWallProvider.DEFAULT_CONFIG_DIR);
        }
        provider = new PGWallProvider(config);
    } else if (JdbcUtils.DB2.equals(dbType)) {
        if (config == null) {
            config = new WallConfig(DB2WallProvider.DEFAULT_CONFIG_DIR);
        }
        provider = new DB2WallProvider(config);
    } else {
        throw new IllegalStateException("dbType not support : " + dbType + ", url " + dataSource.getUrl());
    }
    provider.setName(dataSource.getName());
    this.inited = true;
}
Also used : OracleWallProvider(com.alibaba.druid.wall.spi.OracleWallProvider) DB2WallProvider(com.alibaba.druid.wall.spi.DB2WallProvider) MySqlWallProvider(com.alibaba.druid.wall.spi.MySqlWallProvider) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider) SQLServerWallProvider(com.alibaba.druid.wall.spi.SQLServerWallProvider)

Example 9 with PGWallProvider

use of com.alibaba.druid.wall.spi.PGWallProvider in project druid by alibaba.

the class WallStatTest_update method testPG.

public void testPG() throws Exception {
    WallProvider provider = new PGWallProvider();
    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) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider)

Example 10 with PGWallProvider

use of com.alibaba.druid.wall.spi.PGWallProvider in project druid by alibaba.

the class WallStatTest_select method testPG.

public void testPG() throws Exception {
    WallProvider provider = new PGWallProvider();
    Assert.assertTrue(provider.checkValid(sql));
    WallTableStat tableStat = provider.getTableStat("t");
    Assert.assertEquals(1, tableStat.getSelectCount());
}
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) PGWallProvider(com.alibaba.druid.wall.spi.PGWallProvider)

Aggregations

PGWallProvider (com.alibaba.druid.wall.spi.PGWallProvider)11 WallProvider (com.alibaba.druid.wall.WallProvider)10 MySqlWallProvider (com.alibaba.druid.wall.spi.MySqlWallProvider)9 OracleWallProvider (com.alibaba.druid.wall.spi.OracleWallProvider)9 SQLServerWallProvider (com.alibaba.druid.wall.spi.SQLServerWallProvider)9 WallTableStat (com.alibaba.druid.wall.WallTableStat)8 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 PGSQLStatementParser (com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser)1 PGSchemaStatVisitor (com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor)1 WallCheckResult (com.alibaba.druid.wall.WallCheckResult)1 WallConfig (com.alibaba.druid.wall.WallConfig)1 DB2WallProvider (com.alibaba.druid.wall.spi.DB2WallProvider)1 Test (org.junit.Test)1