本文整理了Java中net.sf.jsqlparser.statement.select.Select.getSelectBody()
方法的一些代码示例,展示了Select.getSelectBody()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.getSelectBody()
方法的具体详情如下:
包路径:net.sf.jsqlparser.statement.select.Select
类名称:Select
方法名:getSelectBody
暂无
代码示例来源:origin: JSQLParser/JSqlParser
/**
* 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);
}
@Override
public void visit(ValuesStatement aThis) {
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
});
}
代码示例来源:origin: JSQLParser/JSqlParser
select.getSelectBody().accept(new SelectVisitor() {
代码示例来源:origin: JSQLParser/JSqlParser
/**
* Adds a simple join to a select statement. The introduced join is returned for more
* configuration settings on it (e.g. left join, right join).
*
* @param select
* @param table
* @param onExpression
* @return
*/
public static Join addJoin(Select select, final Table table, final Expression onExpression) {
if (select.getSelectBody() instanceof PlainSelect) {
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
List<Join> joins = plainSelect.getJoins();
if (joins == null) {
joins = new ArrayList<Join>();
plainSelect.setJoins(joins);
}
Join join = new Join();
join.setRightItem(table);
join.setOnExpression(onExpression);
joins.add(join);
return join;
}
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}
代码示例来源:origin: alibaba/mdrill
public void visit(Select select) {
SelectDeParser selectDeParser = new SelectDeParser();
selectDeParser.setBuffer(buffer);
ExpressionDeParser expressionDeParser = new ExpressionDeParser(selectDeParser, buffer);
selectDeParser.setExpressionVisitor(expressionDeParser);
if (select.getWithItemsList() != null && !select.getWithItemsList().isEmpty()) {
buffer.append("WITH ");
for (Iterator iter = select.getWithItemsList().iterator(); iter.hasNext();) {
WithItem withItem = (WithItem)iter.next();
buffer.append(withItem);
if (iter.hasNext())
buffer.append(",");
buffer.append(" ");
}
}
select.getSelectBody().accept(selectDeParser);
}
代码示例来源:origin: JSQLParser/JSqlParser
@Override
public void visit(Select select) {
selectDeParser.setBuffer(buffer);
expressionDeParser.setSelectVisitor(selectDeParser);
expressionDeParser.setBuffer(buffer);
selectDeParser.setExpressionVisitor(expressionDeParser);
if (select.getWithItemsList() != null && !select.getWithItemsList().isEmpty()) {
buffer.append("WITH ");
for (Iterator<WithItem> iter = select.getWithItemsList().iterator(); iter.hasNext();) {
WithItem withItem = iter.next();
withItem.accept(selectDeParser);
if (iter.hasNext()) {
buffer.append(",");
}
buffer.append(" ");
}
}
select.getSelectBody().accept(selectDeParser);
}
代码示例来源:origin: JSQLParser/JSqlParser
@Override
public void visit(Select select) {
if (select.getWithItemsList() != null) {
for (WithItem withItem : select.getWithItemsList()) {
withItem.accept(this);
}
}
select.getSelectBody().accept(this);
}
代码示例来源:origin: JSQLParser/JSqlParser
private void appendSelect(Upsert upsert) {
buffer.append(" ");
if (upsert.isUseSelectBrackets()) {
buffer.append("(");
}
if (upsert.getSelect().getWithItemsList() != null) {
buffer.append("WITH ");
for (WithItem with : upsert.getSelect().getWithItemsList()) {
with.accept(selectVisitor);
}
buffer.append(" ");
}
upsert.getSelect().getSelectBody().accept(selectVisitor);
if (upsert.isUseSelectBrackets()) {
buffer.append(")");
}
}
代码示例来源:origin: baomidou/mybatis-plus
/**
* 执行 SQL 解析
*
* @param statement JsqlParser Statement
* @return
*/
public SqlInfo processParser(Statement statement) {
if (statement instanceof Insert) {
this.processInsert((Insert) statement);
} else if (statement instanceof Select) {
this.processSelectBody(((Select) statement).getSelectBody());
} else if (statement instanceof Update) {
this.processUpdate((Update) statement);
} else if (statement instanceof Delete) {
this.processDelete((Delete) statement);
}
logger.debug("parser sql: " + statement.toString());
return SqlInfo.newInstance().setSql(statement.toString());
}
代码示例来源:origin: baomidou/mybatis-plus
@Test
void parser() throws Exception {
Select select = (Select) CCJSqlParserUtil.parse("SELECT a,b,c FROM tableName t WHERE t.col = 9 and b=c LIMIT 3, ?");
PlainSelect ps = (PlainSelect) select.getSelectBody();
System.out.println(ps.getWhere().toString());
System.out.println(ps.getSelectItems().get(1).toString());
AndExpression e = (AndExpression) ps.getWhere();
System.out.println(e.getLeftExpression());
}
代码示例来源:origin: pagehelper/Mybatis-PageHelper
/**
* convert to order by sql
*
* @param sql
* @param orderBy
* @return
*/
public static String converToOrderBySql(String sql, String orderBy) {
//解析SQL
Statement stmt = null;
try {
stmt = CCJSqlParserUtil.parse(sql);
Select select = (Select) stmt;
SelectBody selectBody = select.getSelectBody();
//处理body-去最外层order by
List<OrderByElement> orderByElements = extraOrderBy(selectBody);
String defaultOrderBy = PlainSelect.orderByToString(orderByElements);
if (defaultOrderBy.indexOf('?') != -1) {
throw new PageException("原SQL[" + sql + "]中的order by包含参数,因此不能使用OrderBy插件进行修改!");
}
//新的sql
sql = select.toString();
} catch (Throwable e) {
throw new PageException("处理排序失败: " + e, e);
}
return sql + " order by " + orderBy;
}
代码示例来源:origin: JSQLParser/JSqlParser
createView.getSelect().getSelectBody().accept(selectVisitor);
代码示例来源:origin: JSQLParser/JSqlParser
insert.getSelect().getSelectBody().accept(selectVisitor);
if (insert.isUseSelectBrackets()) {
buffer.append(")");
代码示例来源:origin: JSQLParser/JSqlParser
buffer.append("(");
Select select = update.getSelect();
select.getSelectBody().accept(selectVisitor);
buffer.append(")");
代码示例来源:origin: pagehelper/Mybatis-PageHelper
/**
* 将sql转换为count查询
*
* @param select
*/
public void sqlToCount(Select select, String name) {
SelectBody selectBody = select.getSelectBody();
// 是否能简化count查询
List<SelectItem> COUNT_ITEM = new ArrayList<SelectItem>();
COUNT_ITEM.add(new SelectExpressionItem(new Column("count(" + name +")")));
if (selectBody instanceof PlainSelect && isSimpleCount((PlainSelect) selectBody)) {
((PlainSelect) selectBody).setSelectItems(COUNT_ITEM);
} else {
PlainSelect plainSelect = new PlainSelect();
SubSelect subSelect = new SubSelect();
subSelect.setSelectBody(selectBody);
subSelect.setAlias(TABLE_ALIAS);
plainSelect.setFromItem(subSelect);
plainSelect.setSelectItems(COUNT_ITEM);
select.setSelectBody(plainSelect);
}
}
代码示例来源:origin: baomidou/mybatis-plus
/**
* insert 语句处理
*/
@Override
public void processInsert(Insert insert) {
if (tenantHandler.doTableFilter(insert.getTable().getName())) {
// 过滤退出执行
return;
}
insert.getColumns().add(new Column(tenantHandler.getTenantIdColumn()));
if (insert.getSelect() != null) {
processPlainSelect((PlainSelect) insert.getSelect().getSelectBody(), true);
} else if (insert.getItemsList() != null) {
// fixed github pull/295
ItemsList itemsList = insert.getItemsList();
if (itemsList instanceof MultiExpressionList) {
((MultiExpressionList) itemsList).getExprList().forEach(el -> el.getExpressions().add(tenantHandler.getTenantId()));
} else {
((ExpressionList) insert.getItemsList()).getExpressions().add(tenantHandler.getTenantId());
}
} else {
throw ExceptionUtils.mpe("Failed to process multiple-table update, please exclude the tableName or statementId");
}
}
代码示例来源:origin: pagehelper/Mybatis-PageHelper
SelectBody selectBody = select.getSelectBody();
try {
代码示例来源:origin: codingapi/tx-lcn
if (!(lockableSelect.statement().getSelectBody() instanceof PlainSelect)) {
throw new SQLException("non support this query when use control lock.");
PlainSelect plainSelect = (PlainSelect) lockableSelect.statement().getSelectBody();
代码示例来源:origin: pagehelper/Mybatis-PageHelper
SelectBody selectBody = select.getSelectBody();
if (selectBody instanceof SetOperationList) {
selectBody = wrapSetOperationList((SetOperationList) selectBody);
代码示例来源:origin: baomidou/mybatis-plus
try {
Select selectStatement = (Select) CCJSqlParserUtil.parse(sql);
PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
Distinct distinct = plainSelect.getDistinct();
List<Expression> groupBy = plainSelect.getGroupByColumnReferences();
代码示例来源:origin: baomidou/mybatis-plus
List<Join> joins = null;
if (statement instanceof Select) {
PlainSelect plainSelect = (PlainSelect) ((Select) statement).getSelectBody();
where = plainSelect.getWhere();
table = (Table) plainSelect.getFromItem();
内容来源于网络,如有侵权,请联系作者删除!