本文整理汇总了Java中net.sf.jsqlparser.statement.select.SelectExpressionItem类的典型用法代码示例。如果您正苦于以下问题:Java SelectExpressionItem类的具体用法?Java SelectExpressionItem怎么用?Java SelectExpressionItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelectExpressionItem类属于net.sf.jsqlparser.statement.select包,在下文中一共展示了SelectExpressionItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
@Override
public void visit(SelectExpressionItem selectExpressionItem) {
if (firstRun) {
if (selectExpressionItem.getAlias() != null) {
aliases.add(selectExpressionItem.getAlias().getName().toUpperCase());
}
} else {
if (selectExpressionItem.getAlias() == null) {
while (true) {
String alias = getNextAlias().toUpperCase();
if (!aliases.contains(alias)) {
aliases.add(alias);
selectExpressionItem.setAlias(new Alias(alias));
break;
}
}
}
}
}
示例2: countSelectItem
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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;
}
示例3: visit
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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));
}
示例4: addExpression
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
/**
* Adds an expression to select statements. E.g. a simple column is an
* expression.
*
* @param select
* @param expr
*/
public static void addExpression(Select select, final Expression expr) {
select.getSelectBody().accept(new SelectVisitor() {
@Override
public void visit(PlainSelect plainSelect) {
plainSelect.getSelectItems().add(new SelectExpressionItem(expr));
}
@Override
public void visit(SetOperationList setOpList) {
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
@Override
public void visit(WithItem withItem) {
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
});
}
示例5: processPlainSelect
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
/**
* <p>
* 处理 PlainSelect
* </p>
*
* @param plainSelect
* @param addColumn 是否添加租户列,insert into select语句中需要
*/
protected void processPlainSelect(PlainSelect plainSelect, boolean addColumn) {
FromItem fromItem = plainSelect.getFromItem();
if (fromItem instanceof Table) {
Table fromTable = (Table) fromItem;
if (this.tenantHandler.doTableFilter(fromTable.getName())) {
// 过滤退出执行
return;
}
plainSelect.setWhere(builderExpression(plainSelect.getWhere(), fromTable));
if (addColumn) {
plainSelect.getSelectItems().add(new SelectExpressionItem(new Column(this.tenantHandler.getTenantIdColumn())));
}
} else {
processFromItem(fromItem);
}
List<Join> joins = plainSelect.getJoins();
if (joins != null && joins.size() > 0) {
for (Join join : joins) {
processJoin(join);
processFromItem(join.getRightItem());
}
}
}
示例6: createProjections
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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;
}
示例7: test
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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());
}
}
}
示例8: visit
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
@Override
public void visit(SelectExpressionItem selectExpressionItem) {
selectExpressionItem.getExpression().accept(expressionVisitor);
if (selectExpressionItem.getAlias() != null) {
buffer.append(selectExpressionItem.getAlias().toString());
}
}
示例9: buildSelectFromTableAndExpressions
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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);
}
示例10: SQLAggregator
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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");
}
}
}
示例11: countSelectItem
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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;
}
示例12: countSelectItem
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的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<Expression>();
LongValue longValue = new LongValue(0);
ExpressionList expressionList = new ExpressionList();
expressions.add(longValue);
expressionList.setExpressions(expressions);
function.setParameters(expressionList);
countSelectItem = new ArrayList<SelectItem>();
SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
countSelectItem.add(selectExpressionItem);
return countSelectItem;
}
示例13: testDistinct
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
public void testDistinct() throws JSQLParserException {
String statement = "SELECT DISTINCT ON (myid) myid, mycol FROM mytable WHERE mytable.col = 9";
PlainSelect plainSelect = (PlainSelect) ((Select) parserManager.parse(new StringReader(statement))).getSelectBody();
assertEquals(
"myid",
((Column) ((SelectExpressionItem) plainSelect.getDistinct().getOnSelectItems().get(0)).getExpression()).getColumnName());
assertEquals("mycol", ((Column) ((SelectExpressionItem) plainSelect.getSelectItems().get(1)).getExpression()).getColumnName());
assertEquals(statement.toUpperCase(), plainSelect.toString().toUpperCase());
}
示例14: visit
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
@Override
public void visit(SelectExpressionItem item) {
ColumnParser columnParser = new ColumnParser();
item.getExpression().accept(columnParser);
if (columnParser.isSimple()) {
String columnName = columnParser.getColumnName();
simpleColumnNames.add(columnName);
if(item.getAlias() != null){
aliases.put(columnName, StringUtils.strip(item.getAlias().getName(), "`").toUpperCase());
}
}
}
示例15: visit
import net.sf.jsqlparser.statement.select.SelectExpressionItem; //导入依赖的package包/类
public void visit(SelectExpressionItem selectExpressionItem) {
selectExpressionItem.getExpression().accept(expressionVisitor);
if (selectExpressionItem.getAlias() != null) {
buffer.append(" ").append(selectExpressionItem.getAlias().toString());
}
}