本文整理汇总了Java中com.alibaba.druid.sql.ast.SQLExpr.toString方法的典型用法代码示例。如果您正苦于以下问题:Java SQLExpr.toString方法的具体用法?Java SQLExpr.toString怎么用?Java SQLExpr.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.druid.sql.ast.SQLExpr
的用法示例。
在下文中一共展示了SQLExpr.toString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: opSQLExpr
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private void opSQLExpr(SQLBinaryOpExpr expr,String Operator) {
if (expr==null) {
return;
}
SQLExpr exprL=expr.getLeft();
if (!(exprL instanceof SQLBinaryOpExpr))
{
String field=exprL.toString();
String value=getExpValue(expr.getRight()).toString();
if (expr.getOperator()==SQLBinaryOperator.Equality) {
if (checkJoinField(value)) {
//joinLkey=field;
//joinRkey=value;
tableFilter.setJoinKey(field,value);
}
else {
tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator);
}
}
else {
tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator);
}
}
}
示例2: buildOrderByCols
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
protected LinkedHashMap<String, Integer> buildOrderByCols(List<SQLSelectOrderByItem> orderByItems,Map<String, String> aliaColumns) {
LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
for(int i= 0; i < orderByItems.size(); i++) {
SQLOrderingSpecification type = orderByItems.get(i).getType();
//orderColumn只记录字段名称,因为返回的结果集是不带表名的。
SQLExpr expr = orderByItems.get(i).getExpr();
String col;
if (expr instanceof SQLName) {
col = ((SQLName)expr).getSimpleName();
}
else {
col =expr.toString();
}
if(type == null) {
type = SQLOrderingSpecification.ASC;
}
col=getAliaColumn(aliaColumns,col);//此步骤得到的col必须是不带.的,有别名的用别名,无别名的用字段名
map.put(col, type == SQLOrderingSpecification.ASC ? OrderCol.COL_ORDER_TYPE_ASC : OrderCol.COL_ORDER_TYPE_DESC);
}
return map;
}
示例3: genIndexName
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
public static String genIndexName(SQLName srcIndexName, List<SQLExpr> columnExprs, Set<String> indexNames) {
String indexName;
if (srcIndexName != null) {
indexName = StringUtil.removeBackQuote(srcIndexName.getSimpleName());
} else {
SQLExpr firstColumn = columnExprs.get(0);
String columnName = firstColumn.toString();
if (firstColumn instanceof SQLIdentifierExpr) {
columnName = StringUtil.removeBackQuote(((SQLIdentifierExpr) firstColumn).getName());
} else if (firstColumn instanceof SQLMethodInvokeExpr) {
columnName = StringUtil.removeBackQuote(((SQLMethodInvokeExpr) firstColumn).getMethodName());
}
indexName = columnName;
int indexNum = 1;
while (indexNames.contains(indexName)) {
indexNum++;
indexName = columnName + "_" + indexNum;
}
}
indexNames.add(indexName);
return indexName;
}
示例4: parseProcedureForCall
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private void parseProcedureForCall(Procedure procedure, Set<String> outSet, String query, SQLCallStatement statement) {
procedure.setName(statement.getProcedureName().getSimpleName());
List<SQLExpr> parameterList = statement.getParameters();
for (int i1 = 0; i1 < parameterList.size(); i1++) {
SQLExpr sqlExpr = parameterList.get(i1);
String pName = sqlExpr.toString();
String pType = outSet.contains(pName) ? ProcedureParameter.OUT : ProcedureParameter.IN;
ProcedureParameter parameter = new ProcedureParameter();
parameter.setIndex(i1 + 1);
parameter.setName(pName);
parameter.setParameterType(pType);
if (pName.startsWith("@")) {
procedure.getParameterMap().put(pName, parameter);
} else {
procedure.getParameterMap().put(String.valueOf(i1 + 1), parameter);
}
}
procedure.setCallSql(query);
}
示例5: parseProcedureForCall
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private void parseProcedureForCall(Procedure procedure, String query, SQLCallStatement statement) {
SQLCallStatement sqlCallStatement = statement;
procedure.setName(sqlCallStatement.getProcedureName().getSimpleName());
List<SQLExpr> parameterList = sqlCallStatement.getParameters();
for (int i1 = 0; i1 < parameterList.size(); i1++) {
SQLExpr sqlExpr = parameterList.get(i1);
String pName = sqlExpr.toString();
ProcedureParameter parameter = new ProcedureParameter();
parameter.setIndex(i1 + 1);
parameter.setName(pName);
parameter.setParameterType(ProcedureParameter.IN);
if (pName.startsWith("@")) {
procedure.getParameterMap().put(pName, parameter);
} else {
procedure.getParameterMap().put(String.valueOf(i1 + 1), parameter);
}
}
procedure.setCallSql(query);
}
示例6: isMycatSeq
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private static boolean isMycatSeq(String stmt, SchemaConfig schema)
{
if(pattern.matcher(stmt).find()) {
return true;
}
SQLStatementParser parser =new MySqlStatementParser(stmt);
MySqlInsertStatement statement = (MySqlInsertStatement) parser.parseStatement();
String tableName= statement.getTableName().getSimpleName();
TableConfig tableConfig= schema.getTables().get(tableName.toUpperCase());
if(tableConfig==null) {
return false;
}
if(tableConfig.isAutoIncrement())
{
boolean isHasIdInSql=false;
String primaryKey = tableConfig.getPrimaryKey();
List<SQLExpr> columns = statement.getColumns();
for (SQLExpr column : columns)
{
String columnName = column.toString();
if(primaryKey.equalsIgnoreCase(columnName))
{
isHasIdInSql = true;
break;
}
}
if(!isHasIdInSql) {
return true;
}
}
return false;
}
示例7: getExprFieldName
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private String getExprFieldName(SQLAggregateExpr expr){
String field="";
for (SQLExpr item :expr.getArguments()){
field+=item.toString();
}
return expr.getMethodName()+"("+field+")";
}
示例8: buildGroupByHaving
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private HavingCols buildGroupByHaving(SQLExpr having){
if (having == null) {
return null;
}
SQLBinaryOpExpr expr = ((SQLBinaryOpExpr) having);
SQLExpr left = expr.getLeft();
SQLBinaryOperator operator = expr.getOperator();
SQLExpr right = expr.getRight();
String leftValue = null;;
if (left instanceof SQLAggregateExpr) {
leftValue = ((SQLAggregateExpr) left).getMethodName() + "("
+ ((SQLAggregateExpr) left).getArguments().get(0) + ")";
} else if (left instanceof SQLIdentifierExpr) {
leftValue = ((SQLIdentifierExpr) left).getName();
}
String rightValue = null;
if (right instanceof SQLNumericLiteralExpr) {
rightValue = right.toString();
}else if(right instanceof SQLTextLiteralExpr){
rightValue = StringUtil.removeBackquote(right.toString());
}
return new HavingCols(leftValue,rightValue,operator.getName());
}
示例9: parseInsertColumns
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
@Override
protected void parseInsertColumns(SQLInsertInto insert) {
if (lexer.token() == Token.RPAREN ) {
return;
}
for (;;) {
SQLName expr = this.exprParser.name();
expr.setParent(insert);
insert.getColumns().add(expr);
if (lexer.token() == Token.IDENTIFIER) {
String text = lexer.stringVal();
if (text.equalsIgnoreCase("TINYINT")
|| text.equalsIgnoreCase("BIGINT")
|| text.equalsIgnoreCase("INTEGER")
|| text.equalsIgnoreCase("DOUBLE")
|| text.equalsIgnoreCase("DATE")
|| text.equalsIgnoreCase("VARCHAR")) {
expr.getAttributes().put("dataType", text);
lexer.nextToken();
} else if (text.equalsIgnoreCase("CHAR")) {
String dataType = text;
lexer.nextToken();
accept(Token.LPAREN);
SQLExpr char_len = this.exprParser.primary();
accept(Token.RPAREN);
dataType += ("(" + char_len.toString() + ")");
expr.getAttributes().put("dataType", dataType);
}
}
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
}
示例10: SQLServerObjectReferenceExpr
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
public SQLServerObjectReferenceExpr(SQLExpr owner){
if (owner instanceof SQLIdentifierExpr) {
this.database = ((SQLIdentifierExpr) owner).getName();
} else if (owner instanceof SQLPropertyExpr) {
SQLPropertyExpr propExpr = (SQLPropertyExpr) owner;
this.server = ((SQLIdentifierExpr) propExpr.getOwner()).getName();
this.database = propExpr.getName();
} else {
throw new IllegalArgumentException(owner.toString());
}
}
示例11: shardingValueToSting
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
protected static String shardingValueToSting(SQLExpr valueExpr) throws SQLNonTransientException {
String shardingValue = null;
if (valueExpr instanceof SQLIntegerExpr) {
SQLIntegerExpr intExpr = (SQLIntegerExpr) valueExpr;
shardingValue = intExpr.getNumber() + "";
} else if (valueExpr instanceof SQLCharExpr) {
SQLCharExpr charExpr = (SQLCharExpr) valueExpr;
shardingValue = charExpr.getText();
}
if (shardingValue == null) {
throw new SQLNonTransientException("Not Supported of Sharding Value EXPR :" + valueExpr.toString());
}
return shardingValue;
}
示例12: getFieldName2
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private String getFieldName2(SQLExpr item){
return item.toString();
}
示例13: buildGroupByCols
import com.alibaba.druid.sql.ast.SQLExpr; //导入方法依赖的package包/类
private String[] buildGroupByCols(List<SQLExpr> groupByItems,Map<String, String> aliaColumns) {
String[] groupByCols = new String[groupByItems.size()];
for(int i= 0; i < groupByItems.size(); i++) {
SQLExpr sqlExpr = groupByItems.get(i);
String column = null;
if(sqlExpr instanceof SQLIdentifierExpr )
{
column=((SQLIdentifierExpr) sqlExpr).getName();
} else if(sqlExpr instanceof SQLMethodInvokeExpr){
column = ((SQLMethodInvokeExpr) sqlExpr).toString();
} else if(sqlExpr instanceof MySqlOrderingExpr){
//todo czn
SQLExpr expr = ((MySqlOrderingExpr) sqlExpr).getExpr();
if (expr instanceof SQLName)
{
column = StringUtil.removeBackquote(((SQLName) expr).getSimpleName());//不要转大写 2015-2-10 sohudo StringUtil.removeBackquote(expr.getSimpleName().toUpperCase());
} else
{
column = StringUtil.removeBackquote(expr.toString());
}
} else if(sqlExpr instanceof SQLPropertyExpr){
/**
* 针对子查询别名,例如select id from (select h.id from hotnews h union select h.title from hotnews h ) as t1 group by t1.id;
*/
column = sqlExpr.toString();
}
if(column == null){
column = sqlExpr.toString();
}
int dotIndex=column.indexOf(".") ;
int bracketIndex=column.indexOf("(") ;
//通过判断含有括号来决定是否为函数列
if(dotIndex!=-1&&bracketIndex==-1)
{
//此步骤得到的column必须是不带.的,有别名的用别名,无别名的用字段名
column=column.substring(dotIndex+1) ;
}
groupByCols[i] = getAliaColumn(aliaColumns,column);//column;
}
return groupByCols;
}