mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for null contextClassLoader
This commit is contained in:
@@ -19,7 +19,6 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQuery;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLExprParser;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (statementList.size() == 0) {
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
SQLStatement stmt = statementList.get(0);
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
@@ -62,7 +62,7 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (JdbcUtils.MYSQL.equals(dbType)) {
|
||||
return new MySqlParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.MARIADB.equals(dbType)) {
|
||||
return new MySqlParameterizedOutputVisitor(out);
|
||||
}
|
||||
@@ -74,11 +74,11 @@ public class ParameterizedOutputVisitorUtils {
|
||||
if (JdbcUtils.POSTGRESQL.equals(dbType)) {
|
||||
return new PGParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.SQL_SERVER.equals(dbType) || JdbcUtils.JTDS.equals(dbType)) {
|
||||
return new SQLServerParameterizedOutputVisitor(out);
|
||||
}
|
||||
|
||||
|
||||
if (JdbcUtils.DB2.equals(dbType)) {
|
||||
return new DB2ParameterizedOutputVisitor(out);
|
||||
}
|
||||
@@ -99,16 +99,19 @@ public class ParameterizedOutputVisitorUtils {
|
||||
}
|
||||
|
||||
public static SQLBinaryOpExpr merge(SQLBinaryOpExpr x) {
|
||||
SQLExpr left = x.getLeft();
|
||||
SQLExpr right = x.getRight();
|
||||
SQLObject parent = x.getParent();
|
||||
if (x.getLeft() instanceof SQLLiteralExpr && x.getRight() instanceof SQLLiteralExpr) {
|
||||
|
||||
if (left instanceof SQLLiteralExpr && right instanceof SQLLiteralExpr) {
|
||||
if (x.getOperator() == SQLBinaryOperator.Equality || x.getOperator() == SQLBinaryOperator.NotEqual) {
|
||||
x.getLeft().getAttributes().put(ATTR_PARAMS_SKIP, true);
|
||||
x.getRight().getAttributes().put(ATTR_PARAMS_SKIP, true);
|
||||
left.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
right.putAttribute(ATTR_PARAMS_SKIP, true);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
if (x.getRight() instanceof SQLLiteralExpr) {
|
||||
if (right instanceof SQLLiteralExpr) {
|
||||
x = new SQLBinaryOpExpr(x.getLeft(), x.getOperator(), new SQLVariantRefExpr("?"));
|
||||
x.setParent(parent);
|
||||
}
|
||||
@@ -141,17 +144,17 @@ public class ParameterizedOutputVisitorUtils {
|
||||
|
||||
// ID = ? OR ID = ? => ID = ?
|
||||
if (x.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
if ((x.getLeft() instanceof SQLBinaryOpExpr) && (x.getRight() instanceof SQLBinaryOpExpr)) {
|
||||
SQLBinaryOpExpr left = (SQLBinaryOpExpr) x.getLeft();
|
||||
SQLBinaryOpExpr right = (SQLBinaryOpExpr) x.getRight();
|
||||
if ((left instanceof SQLBinaryOpExpr) && (right instanceof SQLBinaryOpExpr)) {
|
||||
SQLBinaryOpExpr leftBinary = (SQLBinaryOpExpr) x.getLeft();
|
||||
SQLBinaryOpExpr rightBinary = (SQLBinaryOpExpr) x.getRight();
|
||||
|
||||
if (mergeEqual(left, right)) {
|
||||
return left;
|
||||
if (mergeEqual(leftBinary, rightBinary)) {
|
||||
return leftBinary;
|
||||
}
|
||||
|
||||
if (isLiteralExpr(left.getLeft()) && left.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
if (mergeEqual(left.getRight(), right)) {
|
||||
return left;
|
||||
if (isLiteralExpr(leftBinary.getLeft()) && leftBinary.getOperator() == SQLBinaryOperator.BooleanOr) {
|
||||
if (mergeEqual(leftBinary.getRight(), right)) {
|
||||
return leftBinary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,20 +53,23 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
|
||||
static {
|
||||
try {
|
||||
for (Enumeration<URL> e = Thread.currentThread().getContextClassLoader().getResources("META-INF/druid-driver.properties"); e.hasMoreElements();) {
|
||||
URL url = e.nextElement();
|
||||
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (ctxClassLoader != null) {
|
||||
for (Enumeration<URL> e = ctxClassLoader.getResources("META-INF/druid-driver.properties"); e.hasMoreElements();) {
|
||||
URL url = e.nextElement();
|
||||
|
||||
Properties property = new Properties();
|
||||
Properties property = new Properties();
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = url.openStream();
|
||||
property.load(is);
|
||||
} finally {
|
||||
JdbcUtils.close(is);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = url.openStream();
|
||||
property.load(is);
|
||||
} finally {
|
||||
JdbcUtils.close(is);
|
||||
}
|
||||
|
||||
driverUrlMapping.putAll(property);
|
||||
}
|
||||
|
||||
driverUrlMapping.putAll(property);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("load druid-driver.properties error", e);
|
||||
@@ -486,7 +489,7 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (clazz == null) {
|
||||
try {
|
||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||
@@ -637,10 +640,13 @@ public final class JdbcUtils implements JdbcConstants {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (ctxClassLoader != null) {
|
||||
try {
|
||||
clazz = ctxClassLoader.loadClass(className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
if (clazz != null) {
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.db2.visitor.DB2ASTVisitorAdapter;
|
||||
import com.alibaba.druid.wall.Violation;
|
||||
import com.alibaba.druid.wall.WallConfig;
|
||||
@@ -128,6 +129,13 @@ public class DB2WallVisitor extends DB2ASTVisitorAdapter implements WallVisitor
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(DB2SelectQueryBlock x) {
|
||||
WallVisitorUtils.checkSelelct(this, x);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLUnionQuery x) {
|
||||
@@ -222,4 +230,5 @@ public class DB2WallVisitor extends DB2ASTVisitorAdapter implements WallVisitor
|
||||
public boolean visit(SQLCallStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user