本文整理汇总了Java中net.sf.jsqlparser.statement.select.PlainSelect.getOrderByElements方法的典型用法代码示例。如果您正苦于以下问题:Java PlainSelect.getOrderByElements方法的具体用法?Java PlainSelect.getOrderByElements怎么用?Java PlainSelect.getOrderByElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.jsqlparser.statement.select.PlainSelect
的用法示例。
在下文中一共展示了PlainSelect.getOrderByElements方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sqlCountOptimize
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的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;
}
示例2: jsqlparserCount
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的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;
}
示例3: visit
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
@Override
public void visit(PlainSelect plainSelect) {
if (plainSelect.getDistinct() != null && plainSelect.getDistinct().getOnSelectItems() != null) {
plainSelect.getDistinct().getOnSelectItems().forEach(s -> s.accept(this));
}
if (plainSelect.getFromItem() != null) {
plainSelect.getFromItem().accept(this);
}
if (plainSelect.getGroupByColumnReferences() != null) {
plainSelect.getGroupByColumnReferences().forEach(s -> s.accept(this));
}
if (plainSelect.getHaving() != null) {
plainSelect.getHaving().accept(this);
}
if (plainSelect.getJoins() != null) {
plainSelect.getJoins().forEach(
j -> {
visitJoin(j);
}
);
}
if (plainSelect.getOrderByElements() != null) {
plainSelect.getOrderByElements().forEach(s -> s.accept(this));
}
if (plainSelect.getSelectItems() != null) {
plainSelect.getSelectItems().forEach(s -> s.accept(this));
}
if (plainSelect.getTop() != null) {
plainSelect.getTop().getExpression().accept(this);
}
if (plainSelect.getWhere() != null) {
plainSelect.getWhere().accept(this);
}
if (plainSelect.getLimit() != null) {
visitLimit(plainSelect.getLimit());
}
}
示例4: optimizeSql
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的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;
}
}
示例5: visit
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
@Override
public void visit(PlainSelect ps) {
// First collect FROM and JOIN items
ps.getFromItem().accept(this);
if (ps.getJoins() != null) {
for (Join j : ps.getJoins()) {
j.getRightItem().accept(this);
if (j.getOnExpression() != null) {
j.getOnExpression().accept(this);
}
if (j.getUsingColumns() != null) {
for (Iterator it1 = j.getUsingColumns().iterator(); it1.hasNext();) {
((Expression) it1.next()).accept(this);
}
}
}
}
// Next iterate over SELECT, WHERE and ORDER BY items
for (Iterator it = ps.getSelectItems().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof SelectExpressionItem) {
((SelectExpressionItem) o).accept(this);
}
if (o instanceof AllColumns) {
((AllColumns) o).accept(this);
}
if (o instanceof AllTableColumns) {
((AllTableColumns) o).accept(this);
}
}
if (ps.getWhere() != null) {
ps.getWhere().accept(this);
}
if (ps.getOrderByElements() != null) {
for (Iterator it = ps.getOrderByElements().iterator(); it.hasNext();) {
((OrderByElement) it.next()).accept(this);
}
}
if (ps.getOracleHierarchical() != null) {
ps.getOracleHierarchical().accept(this);
}
}
示例6: visit
import net.sf.jsqlparser.statement.select.PlainSelect; //导入方法依赖的package包/类
/**
* SelectVisitor
* @param ps
*/
@Override
public void visit(PlainSelect ps) {
// First collect FROM and JOIN items
ps.getFromItem().accept(this);
if (ps.getJoins() != null) {
for (Join j : ps.getJoins()) {
j.getRightItem().accept(this);
if (j.getOnExpression() != null) {
j.getOnExpression().accept(expParser);
}
if (j.getUsingColumns() != null) {
for (Iterator<?> it1 = j.getUsingColumns().iterator(); it1.hasNext();) {
((Expression) it1.next()).accept(expParser);
}
}
}
}
// Next iterate over SELECT, WHERE and ORDER BY items
for (Object o: ps.getSelectItems()) {
if (o instanceof SelectExpressionItem) {
((SelectExpressionItem) o).accept(this);
}
if (o instanceof AllColumns) {
((AllColumns) o).accept(this);
}
if (o instanceof AllTableColumns) {
((AllTableColumns) o).accept(this);
}
}
if (ps.getWhere() != null) {
ps.getWhere().accept(expParser);
}
if (ps.getOrderByElements() != null) {
for (Iterator<?> it = ps.getOrderByElements().iterator(); it.hasNext();) {
((OrderByElement) it.next()).accept(this);
}
}
if (ps.getOracleHierarchical() != null) {
ps.getOracleHierarchical().accept(expParser);
}
}