use of de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder.SqlCreateSelection in project metasfresh-webui-api by metasfresh.
the class SqlViewRowIdsOrderedSelectionFactory method createOrderedSelection.
@Override
public ViewRowIdsOrderedSelection createOrderedSelection(final ViewEvaluationCtx viewEvalCtx, final ViewId viewId, final List<DocumentFilter> filters, final List<DocumentQueryOrderBy> orderBys) {
final UserRolePermissionsKey permissionsKey = viewEvalCtx.getPermissionsKey();
final IUserRolePermissions permissions = Services.get(IUserRolePermissionsDAO.class).retrieveUserRolePermissions(permissionsKey);
final int queryLimit = permissions.getConstraint(WindowMaxQueryRecordsConstraint.class).or(WindowMaxQueryRecordsConstraint.DEFAULT).getMaxQueryRecordsPerRole();
//
//
final SqlCreateSelection sqlCreates = newSqlViewSelectionQueryBuilder().buildSqlCreateSelectionFrom(viewEvalCtx, viewId, filters, orderBys, queryLimit);
logger.trace("Creating selection using {}", sqlCreates);
// Create selection lines if any => insert into T_WEBUI_ViewSelectionLine
if (sqlCreates.getSqlCreateSelectionLines() != null) {
final SqlAndParams sqlCreateSelectionLines = sqlCreates.getSqlCreateSelectionLines();
final Stopwatch stopwatch = Stopwatch.createStarted();
final long linesCount = DB.executeUpdateEx(sqlCreateSelectionLines.getSql(), sqlCreateSelectionLines.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
logger.trace("Created selection lines {}, linesCount={}, duration={}", viewId, linesCount, stopwatch);
}
//
// Create selection rows => insert into T_WEBUI_ViewSelection
final long rowsCount;
{
final SqlAndParams sqlCreateSelection = sqlCreates.getSqlCreateSelection();
final Stopwatch stopwatch = Stopwatch.createStarted();
rowsCount = DB.executeUpdateEx(sqlCreateSelection.getSql(), sqlCreateSelection.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
logger.trace("Created selection {}, rowsCount={}, duration={}", viewId, rowsCount, stopwatch);
}
return ViewRowIdsOrderedSelection.builder().setViewId(viewId).setSize(rowsCount).setOrderBys(orderBys).setQueryLimit(queryLimit).build();
}
Aggregations