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


Java SelectItem类代码示例

本文整理汇总了Java中net.sf.jsqlparser.statement.select.SelectItem的典型用法代码示例。如果您正苦于以下问题:Java SelectItem类的具体用法?Java SelectItem怎么用?Java SelectItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: countSelectItem

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
/**
 * 获取jsqlparser中count的SelectItem
 *
 * @return
 */
private static List<SelectItem> countSelectItem() {
    if (CollectionUtils.isNotEmpty(countSelectItem)) {
        return countSelectItem;
    }
    Function function = new Function();
    function.setName("COUNT");
    List<Expression> expressions = new ArrayList<>();
    LongValue longValue = new LongValue(1);
    ExpressionList expressionList = new ExpressionList();
    expressions.add(longValue);
    expressionList.setExpressions(expressions);
    function.setParameters(expressionList);
    countSelectItem = new ArrayList<>();
    SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
    countSelectItem.add(selectExpressionItem);
    return countSelectItem;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:23,代码来源:JsqlParserUtils.java

示例2: visit

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
@Override
public void visit(PlainSelect plainSelect) {
	for (SelectItem item : plainSelect.getSelectItems()) {
		item.accept(this);
	}

	if (itemsExpr.size() > 1) {
		BinaryExpression binExpr = createBinaryExpression();
		binExpr.setLeftExpression(itemsExpr.get(0).getExpression());
		for (int i = 1; i < itemsExpr.size() - 1; i++) {
			binExpr.setRightExpression(itemsExpr.get(i).getExpression());
			BinaryExpression binExpr2 = createBinaryExpression();
			binExpr2.setLeftExpression(binExpr);
			binExpr = binExpr2;
		}
		binExpr.setRightExpression(itemsExpr.get(itemsExpr.size() - 1).getExpression());

		SelectExpressionItem sei = new SelectExpressionItem();
		sei.setExpression(binExpr);

		plainSelect.getSelectItems().clear();
		plainSelect.getSelectItems().add(sei);
	}

	((SelectExpressionItem) plainSelect.getSelectItems().get(0)).setAlias(new Alias(alias));
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:27,代码来源:ConnectExpressionsVisitor.java

示例3: visit

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
@Override
public void visit(PlainSelect plainSelect) {
    if (plainSelect.getSelectItems() != null) {
        for (SelectItem item : plainSelect.getSelectItems()) {
            item.accept(this);
        }
    }

    if (plainSelect.getFromItem() != null) {
        plainSelect.getFromItem().accept(this);
    }

    if (plainSelect.getJoins() != null) {
        for (Join join : plainSelect.getJoins()) {
            join.getRightItem().accept(this);
        }
    }
    if (plainSelect.getWhere() != null) {
        plainSelect.getWhere().accept(this);
    }
    if (plainSelect.getOracleHierarchical() != null) {
        plainSelect.getOracleHierarchical().accept(this);
    }
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:25,代码来源:TablesNamesFinder.java

示例4: sqlCountOptimize

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
/**
 * 获取select的count语句
 *
 * @param originalSql
 *            selectSQL
 * @return
 */
public static String sqlCountOptimize(String originalSql) {
    Assert.hasLength(originalSql);
    String sqlCount;
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(originalSql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        // 优化Order by
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();
        // 添加包含groupby 不去除orderby
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
        }
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            return String.format(SQL_BASE_COUNT, selectStatement.toString());
        }
        List<SelectItem> selectCount = countSelectItem();
        plainSelect.setSelectItems(selectCount);
        sqlCount = selectStatement.toString();
    } catch (Exception e) {
        sqlCount = String.format(SQL_BASE_COUNT, originalSql);
    }
    return sqlCount;
}
 
开发者ID:baomidou,项目名称:hibernate-plus,代码行数:33,代码来源:SqlUtils.java

示例5: SelectItemsList

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
final public List SelectItemsList() throws ParseException {
      ArrayList selectItemsList = new ArrayList();
      SelectItem selectItem = null;
  selectItem = SelectItem();
                            selectItemsList.add(selectItem);
  label_10:
  while (true) {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 79:
      ;
      break;
    default:
      jj_la1[52] = jj_gen;
      break label_10;
    }
    jj_consume_token(79);
    selectItem = SelectItem();
                                                                                              selectItemsList.add(selectItem);
  }
    {if (true) return selectItemsList;}
  throw new Error("Missing return statement in function");
}
 
开发者ID:UBOdin,项目名称:jsqlparser,代码行数:23,代码来源:CCJSqlParser.java

示例6: visit

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
public void visit(PlainSelect plainSelect) {
	List<SelectItem> cols = plainSelect.getSelectItems();
	for(SelectItem col : cols){
		col.accept(this);
	}

	if(plainSelect.getFromItem()!=null){
		plainSelect.getFromItem().accept(this);
	}

	if (plainSelect.getJoins() != null) {
		for (Iterator joinsIt = plainSelect.getJoins().iterator(); joinsIt.hasNext();) {
			Join join = (Join) joinsIt.next();
			join.getRightItem().accept(this);
		}
	}
	if (plainSelect.getWhere() != null)
		plainSelect.getWhere().accept(this);

}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:21,代码来源:TableFinder.java

示例7: SelectItemsList

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
final public List SelectItemsList(List commas) throws ParseException {ArrayList selectItemsList = new ArrayList();
        SelectItem selectItem = null;
        Token tk = null;
    selectItem = SelectItem();
selectItemsList.add(selectItem);
    label_10:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case COMMA:{
        ;
        break;
        }
      default:
        jj_la1[56] = jj_gen;
        break label_10;
      }
      tk = jj_consume_token(COMMA);
if (tk.specialToken != null) {
      commas.add(tk.specialToken.image);
     } else {commas.add("");}
      selectItem = SelectItem();
selectItemsList.add(selectItem);
    }
{if ("" != null) return selectItemsList;}
    throw new Error("Missing return statement in function");
  }
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:27,代码来源:CCJSqlParser.java

示例8: createProjections

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
private List<ProjectionItem> createProjections(PlainSelect plainSelect, List<ProjectionItem> fromProjections) throws AmbiguousCoalesceException {
	List<ProjectionItem> projections = Lists.newArrayList();

	List<SelectItem> selectItems = plainSelect.getSelectItems();

	for (SelectItem selectItem : selectItems) {
		if (selectItem instanceof AllColumns) {
			addAllFromProjections(fromProjections, projections);
		} else if (selectItem instanceof AllTableColumns) {
			AllTableColumns allTableColumns = (AllTableColumns) selectItem;
			Table table = allTableColumns.getTable();

			addAllFromProjectionsOfTable(fromProjections, projections, table);
		} else if (selectItem instanceof SelectExpressionItem) {
			SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem;
			Expression expression = selectExpressionItem.getExpression();

			addExpressionProjection(fromProjections, projections, expression, selectExpressionItem.getAlias());
		}
	}
	
	return projections;
}
 
开发者ID:sebastianoe,项目名称:s4j,代码行数:24,代码来源:QueryTypeExtractor.java

示例9: test

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
@Test
public void test() {
    Select select = select("select max(name),code,min(aa),nvl(ab,0),heh from user where a > 100");
    List<SelectItem> selectItems = ((PlainSelect) select.getSelectBody()).getSelectItems();
    for (SelectItem item : selectItems) {
        if (item instanceof SelectExpressionItem) {
            Expression exp = ((SelectExpressionItem) item).getExpression();
            if (exp instanceof Function) {
                System.out.println("Function:" + item.toString());
            } else {
                System.out.println("Not a function:" + exp.toString());
            }
        } else {
            System.out.println("Not a function:" + item.toString());
        }
    }
}
 
开发者ID:pagehelper,项目名称:Mybatis-PageHelper,代码行数:18,代码来源:FunctionCountTest.java

示例10: jsqlparserCount

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
/**
 * jsqlparser方式获取select的count语句
 *
 * @param originalSql selectSQL
 * @return
 */
public static String jsqlparserCount(String originalSql) {
    String sqlCount;
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(originalSql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        // 优化Order by
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();
        // 添加包含groupby 不去除orderby
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
        }
        // 包含 distinct、groupBy不优化
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            sqlCount = String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString());
            return sqlCount;
        }
        List<SelectItem> selectCount = countSelectItem();
        plainSelect.setSelectItems(selectCount);
        sqlCount = selectStatement.toString();
    } catch (Exception e) {
        sqlCount = String.format(SqlUtils.SQL_BASE_COUNT, originalSql);
    }
    return sqlCount;
}
 
开发者ID:Caratacus,项目名称:mybatis-plus-mini,代码行数:33,代码来源:JsqlParserUtils.java

示例11: buildSelectFromTableAndExpressions

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
/**
 * Builds select expr1, expr2 from table.
 * @param table
 * @param expr
 * @return 
 */
public static Select buildSelectFromTableAndExpressions(Table table, Expression ... expr) {
	SelectItem[] list = new SelectItem[expr.length];
	for (int i=0;i<expr.length;i++) {
		list[i]=new SelectExpressionItem(expr[i]);
	}
	return buildSelectFromTableAndSelectItems(table, list);
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:14,代码来源:SelectUtils.java

示例12: buildSelectFromTableAndSelectItems

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
public static Select buildSelectFromTableAndSelectItems(Table table, SelectItem ... selectItems) {
	Select select = new Select();
	PlainSelect body = new PlainSelect();
	body.addSelectItems(selectItems);
	body.setFromItem(table);
	select.setSelectBody(body);
	return select;
}
 
开发者ID:WeiMei-Tian,项目名称:editor-sql,代码行数:9,代码来源:SelectUtils.java

示例13: SQLAggregator

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
public SQLAggregator(List<SelectItem> selectItems, List<Expression> groupByColumnReferences, RecordSetFactory recordSetFactory) throws StatementExecutionException {
    this.recordSetFactory = recordSetFactory;
    this.selectItems = selectItems;
    this.groupByColumnReferences = groupByColumnReferences != null ? groupByColumnReferences : Collections.emptyList();

    for (SelectItem item : selectItems) {
        boolean done = false;
        if (item instanceof SelectExpressionItem) {
            SelectExpressionItem sei = (SelectExpressionItem) item;
            Expression expression = sei.getExpression();
            if (expression instanceof Function) {
                Function f = (Function) expression;
                if (BuiltinFunctions.isAggregateFunction(f.getName())) {
                    done = true;
                }
            } else if (expression instanceof net.sf.jsqlparser.schema.Column) {
                net.sf.jsqlparser.schema.Column c = (net.sf.jsqlparser.schema.Column) expression;
                for (Expression ex : this.groupByColumnReferences) {
                    if (ex instanceof net.sf.jsqlparser.schema.Column) {
                        net.sf.jsqlparser.schema.Column cex = (net.sf.jsqlparser.schema.Column) ex;
                        if (cex.getColumnName().equals(c.getColumnName())) {
                            done = true;
                            break;
                        }
                    }
                }
            }
        }
        if (!done) {
            throw new StatementExecutionException("field " + item + " MUST appear in GROUP BY clause");
        }
    }

}
 
开发者ID:diennea,项目名称:herddb,代码行数:35,代码来源:SQLAggregator.java

示例14: optimizeSql

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
@Override
public SqlInfo optimizeSql(MetaObject metaObject, String sql) {
    if (logger.isDebugEnabled()) {
        logger.debug(" JsqlParserCountOptimize sql=" + sql);
    }
    SqlInfo sqlInfo = SqlInfo.newInstance();
    try {
        Select selectStatement = (Select) CCJSqlParserUtil.parse(sql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        Distinct distinct = plainSelect.getDistinct();
        List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
        List<OrderByElement> orderBy = plainSelect.getOrderByElements();

        // 添加包含groupBy 不去除orderBy
        if (CollectionUtils.isEmpty(groupBy) && CollectionUtils.isNotEmpty(orderBy)) {
            plainSelect.setOrderByElements(null);
            sqlInfo.setOrderBy(false);
        }
        //#95 Github, selectItems contains #{} ${}, which will be translated to ?, and it may be in a function: power(#{myInt},2)
        for (SelectItem item : plainSelect.getSelectItems()) {
            if (item.toString().contains("?")) {
                sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString()));
                return sqlInfo;
            }
        }
        // 包含 distinct、groupBy不优化
        if (distinct != null || CollectionUtils.isNotEmpty(groupBy)) {
            sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, selectStatement.toString()));
            return sqlInfo;
        }
        // 优化 SQL
        plainSelect.setSelectItems(countSelectItem);
        sqlInfo.setSql(selectStatement.toString());
        return sqlInfo;
    } catch (Throwable e) {
        // 无法优化使用原 SQL
        sqlInfo.setSql(String.format(SqlUtils.SQL_BASE_COUNT, sql));
        return sqlInfo;
    }
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:41,代码来源:JsqlParserCountOptimize.java

示例15: countSelectItem

import net.sf.jsqlparser.statement.select.SelectItem; //导入依赖的package包/类
/**
 * <p>
 * 获取jsqlparser中count的SelectItem
 * </p>
 */
private static List<SelectItem> countSelectItem() {
    Function function = new Function();
    function.setName("COUNT");
    List<Expression> expressions = new ArrayList<>();
    LongValue longValue = new LongValue(1);
    ExpressionList expressionList = new ExpressionList();
    expressions.add(longValue);
    expressionList.setExpressions(expressions);
    function.setParameters(expressionList);
    List<SelectItem> selectItems = new ArrayList<>();
    SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
    selectItems.add(selectExpressionItem);
    return selectItems;
}
 
开发者ID:baomidou,项目名称:mybatis-plus,代码行数:20,代码来源:JsqlParserCountOptimize.java


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