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();
}
Aggregations