Search in sources :

Example 1 with OrderByElement

use of org.dbflute.cbean.sqlclause.orderby.OrderByElement in project dbflute-core by dbflute.

the class AbstractSqlClause method doRegisterOrderBy.

protected void doRegisterOrderBy(String orderByProperty, boolean ascOrDesc, ColumnInfo columnInfo, boolean derived) {
    try {
        _orderByEffective = true;
        final List<String> orderByList = new ArrayList<String>();
        {
            final StringTokenizer st = new StringTokenizer(orderByProperty, "/");
            while (st.hasMoreElements()) {
                orderByList.add(st.nextToken());
            }
        }
        for (String orderBy : orderByList) {
            _orderByEffective = true;
            final String aliasName;
            final String columnName;
            if (orderBy.indexOf(".") < 0) {
                aliasName = null;
                columnName = orderBy;
            } else {
                aliasName = orderBy.substring(0, orderBy.lastIndexOf("."));
                columnName = orderBy.substring(orderBy.lastIndexOf(".") + 1);
            }
            final OrderByElement element = newOrderByElement(columnInfo, derived, aliasName, columnName);
            if (ascOrDesc) {
                element.setupAsc();
            } else {
                element.setupDesc();
            }
            element.setGearedCipherManager(_gearedCipherManager);
            getOrderBy().addOrderByElement(element);
        }
    } catch (RuntimeException e) {
        String msg = "Failed to register order-by:";
        msg = msg + " orderByProperty=" + orderByProperty + " ascOrDesc=" + ascOrDesc;
        msg = msg + " table=" + _tableDbName;
        throw new IllegalStateException(msg, e);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement)

Example 2 with OrderByElement

use of org.dbflute.cbean.sqlclause.orderby.OrderByElement in project dbflute-core by dbflute.

the class AbstractBehaviorReadable method helpSelectCursorCheckingOrderByPK.

protected void helpSelectCursorCheckingOrderByPK(CB cb, CursorSelectOption option) {
    if (option.isOrderByPK()) {
        final OrderByClause orderByClause = cb.getOrderByComponent();
        final OrderByElement orderByFirstElement = orderByClause.getOrderByFirstElement();
        if (orderByFirstElement == null || !orderByFirstElement.getColumnInfo().isPrimary()) {
            String msg = "The cursor select by paging needs order by primary key: " + cb.asTableDbName();
            throw new IllegalConditionBeanOperationException(msg);
        }
    }
}
Also used : OrderByClause(org.dbflute.cbean.sqlclause.orderby.OrderByClause) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement)

Example 3 with OrderByElement

use of org.dbflute.cbean.sqlclause.orderby.OrderByElement in project dbflute-core by dbflute.

the class AbstractConditionQuery method xdoWithManualOrder.

protected void xdoWithManualOrder(ManualOrderOption mob) {
    assertObjectNotNull("withManualOrder(mob)", mob);
    final OrderByElement lastElement = xgetSqlClause().getOrderByLastElement();
    xcheckManualOrderState(mob, lastElement);
    xcheckManualOrderUnique(mob, lastElement);
    mob.bind((themeKey, orderValue) -> {
        return xregisterManualOrderParameterToThemeList(themeKey, orderValue);
    });
    if (mob.hasOrderByCalculation()) {
        final ConditionBean dreamCruiseCB = xgetBaseCB().xcreateDreamCruiseCB();
        dreamCruiseCB.overTheWaves(xcreateManualOrderSpecifiedColumn(dreamCruiseCB));
        mob.xinitOrderByCalculation(xgetBaseCB(), dreamCruiseCB);
    }
    mob.validate();
    xgetSqlClause().addManualOrderToPreviousOrderByElement(mob);
}
Also used : OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement)

Example 4 with OrderByElement

use of org.dbflute.cbean.sqlclause.orderby.OrderByElement in project dbflute-core by dbflute.

the class AbstractConditionQuery method xcreateManualOrderSpecifiedColumn.

protected SpecifiedColumn xcreateManualOrderSpecifiedColumn(ConditionBean dreamCruiseCB) {
    final OrderByElement orderByLastElement = xgetSqlClause().getOrderByLastElement();
    final String aliasName = orderByLastElement.getAliasName();
    final String columnName = orderByLastElement.getColumnName();
    final ColumnInfo columnInfo = orderByLastElement.getColumnInfo();
    final boolean derived = orderByLastElement.isDerivedOrderBy();
    return new SpecifiedColumn(aliasName, columnInfo, dreamCruiseCB, columnName, derived);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) OrderByElement(org.dbflute.cbean.sqlclause.orderby.OrderByElement) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Aggregations

OrderByElement (org.dbflute.cbean.sqlclause.orderby.OrderByElement)4 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)1 OrderByClause (org.dbflute.cbean.sqlclause.orderby.OrderByClause)1 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)1 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)1