use of com.dangdang.ddframe.rdb.sharding.parser.visitor.basic.mysql.MySQLEvalVisitor in project sharding-jdbc by dangdangdotcom.
the class ParseContext method evalExpression.
private ValuePair evalExpression(final DatabaseType databaseType, final SQLObject sqlObject, final List<Object> parameters) {
if (sqlObject instanceof SQLMethodInvokeExpr) {
// TODO 解析函数中的sharingValue不支持
return null;
}
SQLEvalVisitor visitor;
switch(databaseType.name().toLowerCase()) {
case JdbcUtils.MYSQL:
case JdbcUtils.H2:
visitor = new MySQLEvalVisitor();
break;
default:
visitor = SQLEvalVisitorUtils.createEvalVisitor(databaseType.name());
}
visitor.setParameters(parameters);
sqlObject.accept(visitor);
Object value = SQLEvalVisitorUtils.getValue(sqlObject);
if (null == value) {
// TODO 对于NULL目前解析为空字符串,此处待考虑解决方法
return null;
}
Comparable<?> finalValue;
if (value instanceof Comparable<?>) {
finalValue = (Comparable<?>) value;
} else {
finalValue = "";
}
Integer index = (Integer) sqlObject.getAttribute(MySQLEvalVisitor.EVAL_VAR_INDEX);
if (null == index) {
index = -1;
}
return new ValuePair(finalValue, index);
}
Aggregations