net.sf.jsqlparser.statement.select.OrderByElement Java Examples

The following examples show how to use net.sf.jsqlparser.statement.select.OrderByElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlServer2012Dialect.java    From hasor with Apache License 2.0 6 votes vote down vote up
@Override
public BoundSql getCountSql(FxQuery fxSql, Map<String, Object> paramMap) {
    String buildSqlString = fxSql.buildQueryString(paramMap);
    List<Object> paramArrays = fxSql.buildParameterSource(paramMap);
    //
    // .含有 order by 去掉它
    if (buildSqlString.toLowerCase().contains("order by")) {
        Select selectStatement = parseSelect(buildSqlString, fxSql);
        PlainSelect plainSelect = (PlainSelect) selectStatement.getSelectBody();
        if (plainSelect.getOrderByElements() != null) {
            List<OrderByElement> orderByElements = plainSelect.getOrderByElements();
            plainSelect.setOrderByElements(null);
            buildSqlString = selectStatement.toString();
            plainSelect.setOrderByElements(orderByElements);
        }
    }
    // .拼 count 语句
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("SELECT COUNT(*) FROM (");
    sqlBuilder.append(buildSqlString);
    sqlBuilder.append(") as TEMP_T");
    return new BoundSql(sqlBuilder.toString(), paramArrays.toArray());
}
 
Example #2
Source File: QueryConverter.java    From sql-to-mongo-db-query-converter with Apache License 2.0 5 votes vote down vote up
/**
 * Erase table base alias
 * @param lord
 * @param tholder
 * @return
 */
private List<OrderByElement> preprocessOrderBy(List<OrderByElement> lord, FromHolder tholder){
	for(OrderByElement ord : lord) {
		ord.getExpression().accept(new ExpVisitorEraseAliasTableBaseBuilder(tholder.getBaseAliasTable()));
	}
	return lord;
}
 
Example #3
Source File: SelectVisitorImpl.java    From DataPermissionHelper with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(PlainSelect plainSelect) {

    // 访问 select
    if (plainSelect.getSelectItems() != null) {
        for (SelectItem item : plainSelect.getSelectItems()) {
            item.accept(new SelectItemVisitorImpl());
        }
    }

    // 访问from
    FromItem fromItem = plainSelect.getFromItem();
    FromItemVisitorImpl fromItemVisitorImpl = new FromItemVisitorImpl();
    fromItem.accept(fromItemVisitorImpl);

    if (fromItemVisitorImpl.getSubSelect() != null) {
        plainSelect.setFromItem(fromItemVisitorImpl.getSubSelect());
        if (!DPHelper.getChangeTable()) {
            DPHelper.setChangeTable(true);
        }
    }

    // 访问where
    if (plainSelect.getWhere() != null) {
        plainSelect.getWhere().accept(new ExpressionVisitorImpl());
    }

    // 访问join
    if (plainSelect.getJoins() != null) {
        for (Join join : plainSelect.getJoins()) {
            FromItemVisitorImpl fromItemVisitorImplTemp = new FromItemVisitorImpl();
            join.getRightItem().accept(fromItemVisitorImplTemp);
            if (fromItemVisitorImplTemp.getSubSelect() != null) {
                join.setRightItem(fromItemVisitorImplTemp.getSubSelect());
                if (!DPHelper.getChangeTable()) {
                    DPHelper.setChangeTable(true);
                }
            }
        }
    }

    // 访问 order by
    if (plainSelect.getOrderByElements() != null) {
        for (OrderByElement orderByElement : plainSelect
                .getOrderByElements()) {
            orderByElement.getExpression().accept(
                    new ExpressionVisitorImpl());
        }
    }

    // 访问group by having
    if (plainSelect.getHaving() != null) {
        plainSelect.getHaving().accept(new ExpressionVisitorImpl());
    }

}
 
Example #4
Source File: ObjPD.java    From openprodoc with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Search in ANY object using SQL Syntax subset, similar to CMIS SQL
 * @param SQL complete query
 * @return and opened @Cursor
 * @throws PDException In any Error
 */
public Cursor SearchSelect(String SQL) throws PDException
{
if (PDLog.isDebug())
    PDLog.Debug("ObjPD.SearchSelect>:"+SQL);
Query QBE=null;
try {
Select ParsedSQL = (Select) CCJSqlParserUtil.parse(SQL);
//-- Calculate Table Names ------------
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();
List<String> TableListSQL = tablesNamesFinder.getTableList(ParsedSQL);
Vector <String> OPDTabs=CalculateTabs(TableListSQL);
//-- Calculate Fields -------------
List<SelectItem> selectItems = ((PlainSelect)ParsedSQL.getSelectBody()).getSelectItems();
Vector<String> Fields=new Vector<String>();
if (!( selectItems.get(0) instanceof AllColumns))
    for (int i = 0; i < selectItems.size(); i++)
        Fields.add(((SelectExpressionItem)selectItems.get(i)).getExpression().toString());      
Record Rec=CalculateRec(Fields, OPDTabs);
//-- Calculate Conds in Select ------------
Expression When = ((PlainSelect)ParsedSQL.getSelectBody()).getWhere();
Conditions CondSel=EvalExpr(When);

//-- Check Additional-Security Conditions ----
Conditions FinalConds;
Conditions AddedConds=NeededMoreConds(TableListSQL, OPDTabs);
if (AddedConds==null)
    FinalConds=CondSel;
else
    {
    FinalConds=new Conditions();
    FinalConds.addCondition(AddedConds);
    FinalConds.addCondition(CondSel);
    }
//-- Calculate Order ------------
Vector <String> Order=new Vector<String>();
Vector <Boolean> OrderAsc=new Vector<Boolean>();
List<OrderByElement> orderByElements = ((PlainSelect)ParsedSQL.getSelectBody()).getOrderByElements(); 
if (orderByElements!=null)
    for (int i = 0; i < orderByElements.size(); i++)
        {
        Order.add(orderByElements.get(i).getExpression().toString());
        OrderAsc.add(orderByElements.get(i).isAsc());
        }
//-- Create Query --------------
QBE=new Query(OPDTabs, Rec, FinalConds, Order, OrderAsc);
if (PDLog.isDebug())
    PDLog.Debug("ObjPD.SearchSelect <");
} catch (Exception Ex)
    {
    Ex.printStackTrace();
    PDException.GenPDException("Processing_SQL", Ex.getLocalizedMessage());
    }
return(getDrv().OpenCursor(QBE));
}
 
Example #5
Source File: CTEToNestedQueryConverter.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
public List<OrderByElement> getOrderByElements() {
	return setOp.getOrderByElements();
}
 
Example #6
Source File: CTEToNestedQueryConverter.java    From quetzal with Eclipse Public License 2.0 2 votes vote down vote up
public void setOrderByElements(List<OrderByElement> orderByElements) {
	setOp.setOrderByElements(orderByElements);
	
}