Search in sources :

Example 11 with SqlAndParams

use of de.metas.ui.web.view.descriptor.SqlAndParams 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

SqlAndParams (de.metas.ui.web.view.descriptor.SqlAndParams)11 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 WindowMaxQueryRecordsConstraint (org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)5 DBException (org.adempiere.exceptions.DBException)5 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)1 SqlViewSelectionQueryBuilder (de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder)1 SqlCreateSelection (de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder.SqlCreateSelection)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 LinkedHashSet (java.util.LinkedHashSet)1 IUserRolePermissions (org.adempiere.ad.security.IUserRolePermissions)1 IUserRolePermissionsDAO (org.adempiere.ad.security.IUserRolePermissionsDAO)1 UserRolePermissionsKey (org.adempiere.ad.security.UserRolePermissionsKey)1