Search in sources :

Example 1 with SqlViewSelectionQueryBuilder

use of de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder in project metasfresh-webui-api by metasfresh.

the class SqlViewRowIdsOrderedSelectionFactory method deleteSelection.

@Override
public void deleteSelection(@NonNull final ViewId viewId) {
    final String selectionId = viewId.getViewId();
    final SqlViewSelectionQueryBuilder viewQueryBuilder = newSqlViewSelectionQueryBuilder();
    // Delete selection lines
    {
        final String sql = viewQueryBuilder.buildSqlDeleteSelectionLines(selectionId);
        final int countDeleted = DB.executeUpdateEx(sql, ITrx.TRXNAME_ThreadInherited);
        logger.trace("Delete {} selection lines for {}", countDeleted, selectionId);
    }
    // Delete selection rows
    {
        final String sql = viewQueryBuilder.buildSqlDeleteSelection(selectionId);
        final int countDeleted = DB.executeUpdateEx(sql, ITrx.TRXNAME_ThreadInherited);
        logger.trace("Delete {} selection rows for {}", countDeleted, selectionId);
    }
}
Also used : SqlViewSelectionQueryBuilder(de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder)

Example 2 with SqlViewSelectionQueryBuilder

use of de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder in project metasfresh-webui-api by metasfresh.

the class SqlViewRowIdsOrderedSelectionFactory method createOrderedSelectionFromSelection.

@Override
public ViewRowIdsOrderedSelection createOrderedSelectionFromSelection(final ViewEvaluationCtx viewEvalCtx, final ViewRowIdsOrderedSelection fromSelection, final List<DocumentQueryOrderBy> orderBys) {
    final WindowId windowId = fromSelection.getWindowId();
    final String fromSelectionId = fromSelection.getSelectionId();
    final ViewId newViewId = ViewId.random(windowId);
    final int rowsCount;
    final SqlViewSelectionQueryBuilder viewQueryBuilder = newSqlViewSelectionQueryBuilder();
    if (viewQueryBuilder.hasGroupingFields()) {
        final SqlAndParams sqlCreateSelectionLines = viewQueryBuilder.buildSqlCreateSelectionLinesFromSelectionLines(viewEvalCtx, newViewId, fromSelectionId);
        final int linesCount = DB.executeUpdateEx(sqlCreateSelectionLines.getSql(), sqlCreateSelectionLines.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
        if (linesCount > 0) {
            final SqlAndParams sqlCreateSelection = viewQueryBuilder.buildSqlCreateSelectionFromSelectionLines(viewEvalCtx, newViewId, orderBys);
            rowsCount = DB.executeUpdateEx(sqlCreateSelection.getSql(), sqlCreateSelection.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
        } else {
            rowsCount = 0;
        }
    } else {
        final SqlAndParams sqlCreateSelection = viewQueryBuilder.buildSqlCreateSelectionFromSelection(viewEvalCtx, newViewId, fromSelectionId, orderBys);
        rowsCount = DB.executeUpdateEx(sqlCreateSelection.getSql(), sqlCreateSelection.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
    }
    return ViewRowIdsOrderedSelection.builder().setViewId(newViewId).setSize(rowsCount).setOrderBys(orderBys).setQueryLimit(fromSelection.getQueryLimit()).build();
}
Also used : SqlViewSelectionQueryBuilder(de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder) WindowId(de.metas.ui.web.window.datatypes.WindowId) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) WindowMaxQueryRecordsConstraint(org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)

Aggregations

SqlViewSelectionQueryBuilder (de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder)2 SqlAndParams (de.metas.ui.web.view.descriptor.SqlAndParams)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 WindowMaxQueryRecordsConstraint (org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)1