Search in sources :

Example 1 with SqlCreateSelection

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();
}
Also used : UserRolePermissionsKey(org.adempiere.ad.security.UserRolePermissionsKey) SqlCreateSelection(de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder.SqlCreateSelection) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) Stopwatch(com.google.common.base.Stopwatch) IUserRolePermissionsDAO(org.adempiere.ad.security.IUserRolePermissionsDAO) IUserRolePermissions(org.adempiere.ad.security.IUserRolePermissions) WindowMaxQueryRecordsConstraint(org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 SqlAndParams (de.metas.ui.web.view.descriptor.SqlAndParams)1 SqlCreateSelection (de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder.SqlCreateSelection)1 IUserRolePermissions (org.adempiere.ad.security.IUserRolePermissions)1 IUserRolePermissionsDAO (org.adempiere.ad.security.IUserRolePermissionsDAO)1 UserRolePermissionsKey (org.adempiere.ad.security.UserRolePermissionsKey)1 WindowMaxQueryRecordsConstraint (org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)1