当前位置: 首页>>代码示例>>Java>>正文


Java SQLObject类代码示例

本文整理汇总了Java中com.alibaba.druid.sql.ast.SQLObject的典型用法代码示例。如果您正苦于以下问题:Java SQLObject类的具体用法?Java SQLObject怎么用?Java SQLObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SQLObject类属于com.alibaba.druid.sql.ast包,在下文中一共展示了SQLObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: eval

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public static Object eval(String dbType, SQLObject sqlObject, List<Object> parameters, boolean throwError) {
    SQLEvalVisitor visitor = createEvalVisitor(dbType);
    visitor.setParameters(parameters);

    Object value;
    if (sqlObject instanceof SQLValuableExpr) {
        value = ((SQLValuableExpr) sqlObject).getValue();
    } else {
        sqlObject.accept(visitor);

        value = getValue(sqlObject);

        if (value == null) {
            if (throwError && !sqlObject.getAttributes().containsKey(EVAL_VALUE)) {
                throw new DruidRuntimeException("eval error : " + SQLUtils.toSQLString(sqlObject, dbType));
            }
        }
    }

    return value;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:22,代码来源:SQLEvalVisitorUtils.java

示例2: evalExpression

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
private Comparable<?> evalExpression(final DatabaseType databaseType, final SQLObject sqlObject,
		final List<Object> parameters) {
	if (sqlObject instanceof SQLMethodInvokeExpr) {
		// TODO 解析函数中的sharingValue不支持
		return null;
	}
	Object result = SQLEvalVisitorUtils.eval(databaseType.name().toLowerCase(), sqlObject, parameters, false);
	if (null == result) {
		return null;
	}
	if (result instanceof Comparable<?>) {
		return (Comparable<?>) result;
	}
	// TODO 对于NULL目前解析为空字符串,此处待考虑解决方法
	return "";
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:17,代码来源:SQLParsedResult.java

示例3: visit

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public boolean visit(SQLPropertyExpr x) {
    String ownerName = x.getOwnernName();
    if (ownerName == null) {
        return super.visit(x);
    }

    for (SQLObject parent = x.getParent(); parent != null; parent = parent.getParent()) {
        if (parent instanceof SQLSelectQueryBlock) {
            SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) parent;
            SQLTableSource tableSource = queryBlock.findTableSource(ownerName);
            if (tableSource == null) {
                continue;
            }

            String alias = tableSource.computeAlias();
            if (tableSource != null
                    && ownerName.equalsIgnoreCase(alias)
                    && !ownerName.equals(alias)) {
                x.setOwner(alias);
            }

            break;
        }
    }

    return super.visit(x);
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:28,代码来源:NameResolveVisitor.java

示例4: visit

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public boolean visit(SQLSubqueryTableSource x) {
    String subViewName = generateSubViewName();

    SQLObject parent = x.getParent();
    if(parent instanceof SQLSelectQueryBlock) {
        SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) parent;
        queryBlock.setFrom(subViewName, x.getAlias());
    } else if(parent instanceof SQLJoinTableSource) {
        SQLJoinTableSource join = (SQLJoinTableSource) parent;
        if (join.getLeft() == x) {
            join.setLeft(subViewName, x.getAlias());
        } else if (join.getRight() == x) {
            join.setRight(subViewName, x.getAlias());
        }
    }

    SQLCreateViewStatement stmt = new SQLCreateViewStatement();

    stmt.setName(generateSubViewName());

    SQLSelect select = x.getSelect();
    stmt.setSubQuery(select);

    targetList.add(0, stmt);

    stmt.accept(new FromSubqueryResolver(targetList, viewName));

    return false;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:30,代码来源:FromSubqueryResolver.java

示例5: getValue

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public static Object getValue(SQLObject sqlObject) {
    if (sqlObject instanceof SQLNumericLiteralExpr) {
        return ((SQLNumericLiteralExpr) sqlObject).getNumber();
    }

    return sqlObject.getAttributes().get(EVAL_VALUE);
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:8,代码来源:SQLEvalVisitorUtils.java

示例6: getColumnByExpr

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
private Column getColumnByExpr(SQLBetweenExpr betweenExpr, Map<String, String> aliasMap) {
    if (betweenExpr.getTestExpr() != null) {
        String tableName = null;
        String column = null;
        if (betweenExpr.getTestExpr() instanceof SQLPropertyExpr) { //field has alias
            tableName = ((SQLIdentifierExpr) ((SQLPropertyExpr) betweenExpr.getTestExpr()).getOwner()).getName();
            column = ((SQLPropertyExpr) betweenExpr.getTestExpr()).getName();
            SQLObject query = this.subQueryMap.get(tableName);
            if (query == null) {
                if (aliasMap.containsKey(tableName)) {
                    tableName = aliasMap.get(tableName);
                }
                return new Column(tableName, column);
            }
            return handleSubQueryColumn(tableName, column);
        } else if (betweenExpr.getTestExpr() instanceof SQLIdentifierExpr) {
            column = ((SQLIdentifierExpr) betweenExpr.getTestExpr()).getName();
            tableName = getOwnerTableName(betweenExpr, column);
        }
        String table = tableName;
        if (aliasMap.containsKey(table)) {
            table = aliasMap.get(table);
        }

        if (variants.containsKey(table)) {
            return null;
        }

        if (table != null && !"".equals(table)) {
            return new Column(table, column);
        }
    }
    return null;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:35,代码来源:ServerSchemaStatVisitor.java

示例7: getOwnerTableName

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
/**
 * get table name of field in between expr
 *
 * @param betweenExpr
 * @param column
 * @return
 */
private String getOwnerTableName(SQLBetweenExpr betweenExpr, String column) {
    if (tableStats.size() == 1) { //only has 1 table
        return tableStats.keySet().iterator().next().getName();
    } else if (tableStats.size() == 0) { //no table
        return "";
    } else { // multi tables
        for (Column col : columns.keySet()) {
            if (col.getName().equals(column)) {
                return col.getTable();
            }
        }

        //parser from parent
        SQLObject parent = betweenExpr.getParent();
        if (parent instanceof SQLBinaryOpExpr) {
            parent = parent.getParent();
        }

        if (parent instanceof MySqlSelectQueryBlock) {
            MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
            if (select.getFrom() instanceof SQLJoinTableSource) {
                SQLJoinTableSource joinTableSource = (SQLJoinTableSource) select.getFrom();
                //FIXME :left as driven table
                return joinTableSource.getLeft().toString();
            } else if (select.getFrom() instanceof SQLExprTableSource) {
                return select.getFrom().toString();
            }
        } else if (parent instanceof SQLUpdateStatement) {
            SQLUpdateStatement update = (SQLUpdateStatement) parent;
            return update.getTableName().getSimpleName();
        } else if (parent instanceof SQLDeleteStatement) {
            SQLDeleteStatement delete = (SQLDeleteStatement) parent;
            return delete.getTableName().getSimpleName();
        }
    }
    return "";
}
 
开发者ID:actiontech,项目名称:dble,代码行数:45,代码来源:ServerSchemaStatVisitor.java

示例8: eval

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public static Object eval(String dbType, SQLObject sqlObject, List<Object> parameters, boolean throwError) {
    ActionMySqlEvalVisitorImpl visitor = new ActionMySqlEvalVisitorImpl();
    visitor.setParameters(parameters);
    sqlObject.accept(visitor);
    Object value = getValue(sqlObject);
    if (value == null && throwError && !sqlObject.getAttributes().containsKey("eval.value")) {
        throw new DruidRuntimeException("eval error : " + SQLUtils.toSQLString(sqlObject, dbType));
    } else {
        return value;
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:12,代码来源:ActionSQLEvalVisitorUtils.java

示例9: visitHandle

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
/**
 * 进行OR表达式的访问.
 *
 * @param sqlObject SQL对象
 * @return OR访问节点
 */
public Optional<AbstractOrASTNode> visitHandle(final SQLObject sqlObject) {
    reset();
    sqlObject.accept(this);
    postVisitHandle();
    return Optional.fromNullable(orASTNode);
}
 
开发者ID:balancebeam,项目名称:sherlock,代码行数:13,代码来源:OrPgsqlVisitor.java

示例10: getOwnerTableName

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
/**
     * 从between语句中获取字段所属的表名。
     * 对于容易出现ambiguous的(字段不知道到底属于哪个表),实际应用中必须使用别名来避免歧义
     * @param betweenExpr
     * @param column
     * @return
     */
    private String getOwnerTableName(SQLBetweenExpr betweenExpr,String column) {
        if(tableStats.size() == 1) {//只有一个表,直接返回这一个表名
            return tableStats.keySet().iterator().next().getName();
        } else if(tableStats.size() == 0) {//一个表都没有,返回空串
            return "";
        } else {//多个表名
            for (Column col : columns.keySet())
            {
                if(col.getName().equals(column)) {
                    return col.getTable();
                }
            }
//            for(Column col : columns) {//从columns中找表名
//                if(col.getName().equals(column)) {
//                    return col.getTable();
//                }
//            }

            //前面没找到表名的,自己从parent中解析

            SQLObject parent = betweenExpr.getParent();
            if(parent instanceof SQLBinaryOpExpr)
            {
                parent=parent.getParent();
            }

            if(parent instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock select = (MySqlSelectQueryBlock) parent;
                if(select.getFrom() instanceof SQLJoinTableSource) {//多表连接
                    SQLJoinTableSource joinTableSource = (SQLJoinTableSource)select.getFrom();
                    return joinTableSource.getLeft().toString();//将left作为主表,此处有不严谨处,但也是实在没有办法,如果要准确,字段前带表名或者表的别名即可
                } else if(select.getFrom() instanceof SQLExprTableSource) {//单表
                    return select.getFrom().toString();
                }
            }
            else if(parent instanceof SQLUpdateStatement) {
                SQLUpdateStatement update = (SQLUpdateStatement) parent;
                return update.getTableName().getSimpleName();
            } else if(parent instanceof SQLDeleteStatement) {
                SQLDeleteStatement delete = (SQLDeleteStatement) parent;
                return delete.getTableName().getSimpleName();
            } else {
                
            }
        }
        return "";
    }
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:55,代码来源:MycatSchemaStatVisitor.java

示例11: getOn

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public SQLObject getOn() {
    return on;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:4,代码来源:SQLGrantStatement.java

示例12: setOn

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public void setOn(SQLObject on) {
    this.on = on;
    on.setParent(this);
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:5,代码来源:SQLGrantStatement.java

示例13: getStorage

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public SQLObject getStorage() {
    return storage;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:4,代码来源:SQLCreateMaterializedViewStatement.java

示例14: setStorage

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public void setStorage(SQLObject storage) {
    if (storage != null) {
        storage.setParent(this);
    }
    this.storage = storage;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:7,代码来源:SQLCreateMaterializedViewStatement.java

示例15: getTableOptions

import com.alibaba.druid.sql.ast.SQLObject; //导入依赖的package包/类
public Map<String, SQLObject> getTableOptions() {
    return tableOptions;
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:4,代码来源:SQLAlterTableStatement.java


注:本文中的com.alibaba.druid.sql.ast.SQLObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。