mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbse sql support
This commit is contained in:
+14
-3
@@ -11,9 +11,11 @@ import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
|
||||
|
||||
public class MySqlEvalVisitorImpl extends MySqlASTVisitorAdapter implements SQLEvalVisitor {
|
||||
|
||||
private List<Object> parameters = new ArrayList<Object>();
|
||||
private List<Object> parameters = new ArrayList<Object>();
|
||||
|
||||
private int variantIndex = -1;
|
||||
private int variantIndex = -1;
|
||||
|
||||
private boolean markVariantIndex = true;
|
||||
|
||||
public MySqlEvalVisitorImpl(){
|
||||
this(new ArrayList<Object>(1));
|
||||
@@ -46,8 +48,17 @@ public class MySqlEvalVisitorImpl extends MySqlASTVisitorAdapter implements SQLE
|
||||
public boolean visit(SQLVariantRefExpr x) {
|
||||
return SQLEvalVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
return SQLEvalVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean isMarkVariantIndex() {
|
||||
return markVariantIndex;
|
||||
}
|
||||
|
||||
public void setMarkVariantIndex(boolean markVariantIndex) {
|
||||
this.markVariantIndex = markVariantIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,4 +13,8 @@ public interface SQLEvalVisitor extends SQLASTVisitor {
|
||||
void setParameters(List<Object> parameters);
|
||||
|
||||
int incrementAndGetVariantIndex();
|
||||
|
||||
boolean isMarkVariantIndex();
|
||||
|
||||
void setMarkVariantIndex(boolean markVariantIndex);
|
||||
}
|
||||
|
||||
@@ -9,9 +9,11 @@ import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
|
||||
public class SQLEvalVisitorImpl extends SQLASTVisitorAdapter implements SQLEvalVisitor {
|
||||
|
||||
private List<Object> parameters = new ArrayList<Object>();
|
||||
private List<Object> parameters = new ArrayList<Object>();
|
||||
|
||||
private int variantIndex = -1;
|
||||
private int variantIndex = -1;
|
||||
|
||||
private boolean markVariantIndex = true;
|
||||
|
||||
public SQLEvalVisitorImpl(){
|
||||
this(new ArrayList<Object>(1));
|
||||
@@ -48,4 +50,13 @@ public class SQLEvalVisitorImpl extends SQLASTVisitorAdapter implements SQLEvalV
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
return SQLEvalVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean isMarkVariantIndex() {
|
||||
return markVariantIndex;
|
||||
}
|
||||
|
||||
public void setMarkVariantIndex(boolean markVariantIndex) {
|
||||
this.markVariantIndex = markVariantIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,24 +67,24 @@ public class SQLEvalVisitorUtils {
|
||||
x.putAttribute(EVAL_VALUE, x.getText());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static boolean visit(SQLEvalVisitor visitor, SQLBinaryOpExpr x) {
|
||||
x.getLeft().accept(visitor);
|
||||
x.getRight().accept(visitor);
|
||||
|
||||
|
||||
if (!x.getLeft().getAttributes().containsKey(EVAL_VALUE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (!x.getRight().getAttributes().containsKey(EVAL_VALUE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (SQLBinaryOperator.Add.equals(x.getOperator())) {
|
||||
Object value = _add(x.getLeft().getAttribute(EVAL_VALUE), x.getRight().getAttributes().get(EVAL_VALUE));
|
||||
x.putAttribute(EVAL_VALUE, value);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,10 +96,12 @@ public class SQLEvalVisitorUtils {
|
||||
x.putAttribute(EVAL_VAR_INDEX, varIndex);
|
||||
}
|
||||
|
||||
boolean containsValue = attributes.containsKey(EVAL_VALUE);
|
||||
if (!containsValue) {
|
||||
Object value = visitor.getParameters().get(varIndex.intValue());
|
||||
attributes.put(EVAL_VALUE, value);
|
||||
if (visitor.getParameters().size() > 0) {
|
||||
boolean containsValue = attributes.containsKey(EVAL_VALUE);
|
||||
if (!containsValue) {
|
||||
Object value = visitor.getParameters().get(varIndex.intValue());
|
||||
attributes.put(EVAL_VALUE, value);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user