本文整理汇总了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;
}
示例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));
}
示例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);
}
}
示例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;
}
示例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");
}
示例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);
}
示例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");
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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");
}
}
}
示例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;
}
}
示例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;
}