add wall filter

This commit is contained in:
温少
2012-03-14 20:52:21 +08:00
parent 70b0664815
commit b98361ffd7
4 changed files with 142 additions and 8 deletions
@@ -0,0 +1,8 @@
package com.alibaba.druid.filter.wall;
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVIsitorAdapter;
public class OracleWallVisitor extends OracleASTVIsitorAdapter implements WallVisitor {
}
@@ -0,0 +1,102 @@
package com.alibaba.druid.filter.wall;
import java.sql.SQLException;
import com.alibaba.druid.filter.FilterAdapter;
import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
import com.alibaba.druid.sql.dialect.oracle.parser.OracleStatementParser;
import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser;
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
import com.alibaba.druid.sql.parser.SQLStatementParser;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import com.alibaba.druid.util.JdbcUtils;
public class WallFilter extends FilterAdapter {
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql)
throws SQLException {
return chain.connection_prepareStatement(connection, sql);
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection,
String sql, int autoGeneratedKeys) throws SQLException {
return chain.connection_prepareStatement(connection, sql, autoGeneratedKeys);
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection,
String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
return chain.connection_prepareStatement(connection, sql, resultSetType, resultSetConcurrency);
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection,
String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
return chain.connection_prepareStatement(connection, sql, resultSetType, resultSetConcurrency,
resultSetHoldability);
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection,
String sql, int[] columnIndexes) throws SQLException {
return chain.connection_prepareStatement(connection, sql, columnIndexes);
}
@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection,
String sql, String[] columnNames) throws SQLException {
return chain.connection_prepareStatement(connection, sql, columnNames);
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql)
throws SQLException {
return chain.connection_prepareCall(connection, sql);
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql,
int resultSetType, int resultSetConcurrency)
throws SQLException {
return chain.connection_prepareCall(connection, sql, resultSetType, resultSetConcurrency);
}
@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql,
int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
return chain.connection_prepareCall(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability);
}
public SQLASTVisitor createWallVisitor(String dbType) throws SQLException {
throw new SQLException("dbType not support : " + dbType);
}
public SQLStatementParser createParser(String dbType, String sql) throws SQLException {
if (JdbcUtils.ORACLE.equals(dbType)) {
return new OracleStatementParser(sql);
}
if (JdbcUtils.MYSQL.equals(dbType)) {
return new MySqlStatementParser(sql);
}
if (JdbcUtils.POSTGRESQL.equals(dbType)) {
return new PGSQLStatementParser(sql);
}
if (JdbcUtils.SQL_SERVER.equals(dbType)) {
return new SQLServerStatementParser(sql);
}
throw new SQLException("dbType not support : " + dbType);
}
}
@@ -0,0 +1,8 @@
package com.alibaba.druid.filter.wall;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
public interface WallVisitor extends SQLASTVisitor {
}
@@ -50,6 +50,22 @@ import com.alibaba.druid.mapping.DruidMappingException;
*/
public final class JdbcUtils {
public static final String HSQL = "hsql";
public static final String DB2 = "db2";
public static final String POSTGRESQL = "postgresql";
public static final String SYBASE = "sybase";
public static final String SQL_SERVER = "sqlserver";
public static final String ORACLE = "oracle";
public static final String MYSQL = "mysql";
public static final String DERBY = "derby";
private final static Log LOG = LogFactory.getLog(JdbcUtils.class);
private static final Properties driverUrlMapping = new Properties();
@@ -444,25 +460,25 @@ public final class JdbcUtils {
}
if (rawUrl.startsWith("jdbc:derby:")) {
return "derby";
return DERBY;
} else if (rawUrl.startsWith("jdbc:mysql:")) {
return "mysql";
return MYSQL;
} else if (rawUrl.startsWith("jdbc:oracle:")) {
return "oracle";
return ORACLE;
} else if (rawUrl.startsWith("jdbc:microsoft:")) {
return "sqlserver";
return SQL_SERVER;
} else if (rawUrl.startsWith("jdbc:sybase:Tds:")) {
return "sybase";
return SYBASE;
} else if (rawUrl.startsWith("jdbc:jtds:")) {
return "jtds";
} else if (rawUrl.startsWith("jdbc:fake:") || rawUrl.startsWith("jdbc:mock:")) {
return "mock";
} else if (rawUrl.startsWith("jdbc:postgresql:")) {
return "postgresql";
return POSTGRESQL;
} else if (rawUrl.startsWith("jdbc:hsqldb:")) {
return "hsql";
return HSQL;
} else if (rawUrl.startsWith("jdbc:db2:")) {
return "db2";
return DB2;
} else if (rawUrl.startsWith("jdbc:sqlite:")) {
return "sqlite";
} else if (rawUrl.startsWith("jdbc:ingres:")) {