Class UserPreferenceWriter

java.lang.Object
fr.becpg.repo.helper.UserPreferenceWriter

@Service("userPreferenceWriter") public class UserPreferenceWriter extends Object
Saves best-effort user preferences, such as UI history, without putting the calling request at risk.

Every preference write rewrites the whole cm:preferenceValues content of the person node. When another transaction holds a lock on that node or on alf_content_url, the write fails with a ConcurrencyFailureException that the content service wraps into a ContentIOException. Run inside the caller's transaction, that failure either aborts the whole transaction or makes the web script container replay the request, each attempt waiting for the database lock timeout again. The write therefore runs in a transaction of its own and is skipped when the cause chain reveals a lock conflict.

Author:
matthieu
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
    • preferenceService

      private final org.alfresco.service.cmr.preference.PreferenceService preferenceService
    • transactionService

      private final org.alfresco.service.transaction.TransactionService transactionService
  • Constructor Details

    • UserPreferenceWriter

      @Autowired public UserPreferenceWriter(@Qualifier("PreferenceService") org.alfresco.service.cmr.preference.PreferenceService preferenceService, @Qualifier("TransactionService") org.alfresco.service.transaction.TransactionService transactionService)

      Constructor for UserPreferenceWriter.

      Parameters:
      preferenceService - the service storing the user preferences
      transactionService - the service providing the dedicated write transaction
  • Method Details

    • savePreferencesUnlessLocked

      public void savePreferencesUnlessLocked(String userName, Map<String,Serializable> preferences)
      Saves the preferences in a dedicated transaction, and skips the write when it loses a lock conflict.
      Parameters:
      userName - the user owning the preferences
      preferences - the preferences to add or replace
      Throws:
      BeCPGException - if the write fails for any reason other than a lock conflict
    • isLockConflict

      private boolean isLockConflict(Throwable e)
    • rollbackQuietly

      private void rollbackQuietly(jakarta.transaction.UserTransaction transaction)