From e4f45cd23cf88d0960307e4bf381be28940bb509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=B0=91?= Date: Sat, 17 Mar 2012 23:12:48 +0800 Subject: [PATCH] refactor --- .../druid/filter/wall/WallProvider.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/alibaba/druid/filter/wall/WallProvider.java b/src/main/java/com/alibaba/druid/filter/wall/WallProvider.java index 99f589b058..8f4309b584 100644 --- a/src/main/java/com/alibaba/druid/filter/wall/WallProvider.java +++ b/src/main/java/com/alibaba/druid/filter/wall/WallProvider.java @@ -6,7 +6,7 @@ import java.util.LinkedHashMap; import java.util.List; import com.alibaba.druid.sql.ast.SQLStatement; -import com.alibaba.druid.sql.parser.NotAllowCommentException; +import com.alibaba.druid.sql.parser.ParserException; import com.alibaba.druid.sql.parser.SQLStatementParser; import com.alibaba.druid.sql.parser.Token; @@ -51,11 +51,6 @@ public abstract class WallProvider { public abstract WallVisitor createWallVisitor(); - public boolean check(String sql, boolean throwException) throws WallRuntimeException { - List violations = check(sql); - return violations.size() > 0; - } - public List check(String sql) { // first step, check whiteList boolean isWhite = whiteContains(sql); @@ -63,7 +58,6 @@ public abstract class WallProvider { return Collections.emptyList(); } - SQLStatementParser parser = createParser(sql); parser.getLexer().setAllowComment(false); // permit comment @@ -71,23 +65,27 @@ public abstract class WallProvider { try { parser.parseStatementList(statementList); - } catch (NotAllowCommentException e) { - return Collections.singletonList(new IllegalSQLObjectViolation(sql)); + } catch (ParserException e) { + return Collections. singletonList(new IllegalSQLObjectViolation(sql)); } if (parser.getLexer().token() != Token.EOF) { - return Collections.singletonList(new IllegalSQLObjectViolation(sql)); + return Collections. singletonList(new IllegalSQLObjectViolation(sql)); } if (statementList.size() > 1) { - return Collections.singletonList(new IllegalSQLObjectViolation(sql)); + return Collections. singletonList(new IllegalSQLObjectViolation(sql)); } SQLStatement stmt = statementList.get(0); WallVisitor visitor = createWallVisitor(); - stmt.accept(visitor); + try { + stmt.accept(visitor); + } catch (ParserException e) { + return Collections. singletonList(new IllegalSQLObjectViolation(sql)); + } if (visitor.getViolations().size() == 0) { if (sql.length() < whiteSqlMaxLength) {