Search in sources :

Example 6 with ITrxManager

use of org.adempiere.ad.trx.api.ITrxManager in project metasfresh-webui-api by metasfresh.

the class DocumentCacheInvalidationDispatcher method reset.

@Override
public int reset(@NonNull final CacheInvalidateMultiRequest request) {
    final ITrxManager trxManager = Services.get(ITrxManager.class);
    final ITrx currentTrx = trxManager.getThreadInheritedTrx(OnTrxMissingPolicy.ReturnTrxNone);
    if (trxManager.isNull(currentTrx)) {
        async.execute(() -> resetNow(request));
    } else {
        final CacheInvalidateMultiRequestsCollector collector = currentTrx.getProperty(TRXPROP_Requests, trx -> {
            final CacheInvalidateMultiRequestsCollector c = new CacheInvalidateMultiRequestsCollector();
            trx.getTrxListenerManager().newEventListener(TrxEventTiming.AFTER_COMMIT).registerHandlingMethod(innerTrx -> {
                final CacheInvalidateMultiRequest aggregatedRequest = c.aggregateOrNull();
                if (aggregatedRequest == null) {
                    return;
                }
                async.execute(() -> resetNow(aggregatedRequest));
            });
            return c;
        });
        collector.add(request);
    }
    // not relevant
    return 1;
}
Also used : ITrx(org.adempiere.ad.trx.api.ITrx) CacheInvalidateMultiRequest(org.adempiere.ad.dao.cache.CacheInvalidateMultiRequest) ITrxManager(org.adempiere.ad.trx.api.ITrxManager)

Aggregations

ITrxManager (org.adempiere.ad.trx.api.ITrxManager)6 ITrx (org.adempiere.ad.trx.api.ITrx)4 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 ApiOperation (io.swagger.annotations.ApiOperation)1 CacheInvalidateMultiRequest (org.adempiere.ad.dao.cache.CacheInvalidateMultiRequest)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1