Class CollectedProductPersistedDomainContext

java.lang.Object
com.broadleafcommerce.catalog.service.product.mapper.CollectedProductPersistedDomainContext

public class CollectedProductPersistedDomainContext extends Object
Thread-local used by ProductPersistedDomainCollectingMapperMember to store the persisted domain instances.
Since:
Catalog Service 2.3.0, Release Train 2.3.0
  • Constructor Details

    • CollectedProductPersistedDomainContext

      public CollectedProductPersistedDomainContext()
  • Method Details

    • get

      @Nullable public static CollectedProductPersistedDomainContext get()
    • clear

      public static void clear()
    • doWithCollectionEnabled

      public static <V> V doWithCollectionEnabled(Supplier<V> supplier)
    • setCollectionEnabled

      public void setCollectionEnabled(boolean collectionEnabled)
    • putIfMissingOrNewerAuditTime

      public void putIfMissingOrNewerAuditTime(com.broadleafcommerce.data.tracking.core.Trackable trackable)
      This component is only intended to track the persisted domain instances after they've been successfully created/updated in the system (ex: after repository.save()). However, during any standard create/update/etc flow, there may be multiple attempts to read the same product instance (ex: for validation against the existing state, etc). Because ProductPersistedDomainCollectingMapperMember runs on all 'fromRepositoryDomain' requests, we don't want to collect the instances from those extra reads. Thus, we only collect an instance if it was either already missing in the map, or if it has a higher last-created/last-updated audit time than the existing collected value. The create/update flows naturally assign these updated audit values on the persisted domain instance, so it's a fairly reliable way to know we're dealing with the latest state of the item.
      Parameters:
      trackable - the candidate instance to collect
    • getLastUpdateOrCreateAuditTime

      @Nullable protected Instant getLastUpdateOrCreateAuditTime(com.broadleafcommerce.data.tracking.core.Trackable trackable)
    • getCollectedInstancesByContextId

      public Map<String,com.broadleafcommerce.data.tracking.core.Trackable> getCollectedInstancesByContextId()