Class AbstractPatch

java.lang.Object
org.alfresco.repo.admin.patch.AbstractPatch
All Implemented Interfaces:
Patch, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationEventPublisherAware
Direct Known Subclasses:
AbstractPermissionChangePatch, AddGroupAuthorityPatch, AddSurfConfigFoldersPatch, AdminUserPatch, AliasableAspectPatch, AsynchronousPatch, CalendarAllDayEventDatesCorrectingPatch, FixBpmPackagesPatch, FixPersonSizeCurrentTypePatch, FixTemplatePatch, GenericBootstrapPatch, GenericDeleteAspectForTypePatch, GenericEMailTemplateUpdatePatch, GenericMimetypeRenamePatch, GenericWorkflowPatch, ImapFoldersPatch, ImapUnsubscribedAspectPatch, MigrateTenantsFromAttrsToTablePatch, NoLongerSupportedPatch, NoOpPatch, QNamePatch, RenameSiteAuthorityDisplayName, SamplePatch, SchemaUpgradeScriptPatch, SimplePatch, SiteLoadPatch, SWSDPPatch, UpdateAuditTemplatePatch

public abstract class AbstractPatch extends Object implements Patch, org.springframework.context.ApplicationEventPublisherAware
Base implementation of the patch. This class ensures that the patch is thread- and transaction-safe.
Author:
Derek Hulley
  • Field Details

    • ERR_PROPERTY_NOT_SET

      public static final String ERR_PROPERTY_NOT_SET
      I18N message when properties not set.
      • {0} = property name
      • {1} = patch instance
      See Also:
    • patchService

      protected PatchService patchService
      the service to register ourselves with
    • transactionService

      protected TransactionService transactionService
      used to ensure a unique transaction per execution
    • transactionHelper

      protected RetryingTransactionHelper transactionHelper
      Use this helper to ensure that patches can execute even on a read-only system
    • namespaceService

      protected NamespaceService namespaceService
    • nodeService

      protected NodeService nodeService
    • searchService

      protected SearchService searchService
    • authenticationContext

      protected AuthenticationContext authenticationContext
    • tenantAdminService

      protected TenantAdminService tenantAdminService
    • applicationEventPublisher

      protected org.springframework.context.ApplicationEventPublisher applicationEventPublisher
      Publishes batch event notifications for JMX viewing
  • Constructor Details

    • AbstractPatch

      public AbstractPatch()
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setPatchService

      public void setPatchService(PatchService patchService)
      Set the service that this patch will register with for execution.
    • setTransactionService

      public void setTransactionService(TransactionService transactionService)
      Set the transaction provider so that each execution can be performed within a transaction
    • setNamespaceService

      public void setNamespaceService(NamespaceService namespaceService)
    • setNodeService

      public void setNodeService(NodeService nodeService)
    • setSearchService

      public void setSearchService(SearchService searchService)
    • setAuthenticationContext

      public void setAuthenticationContext(AuthenticationContext authenticationContext)
    • setTenantAdminService

      public void setTenantAdminService(TenantAdminService tenantAdminService)
    • setApplicationEventPublisher

      public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
      Set automatically
      Specified by:
      setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
    • init

      public void init()
      This ensures that this bean gets registered with the appropriate service.
    • getId

      public String getId()
      Specified by:
      getId in interface Patch
    • setId

      public void setId(String id)
      Parameters:
      id - the unique ID of the patch. This dictates the order in which patches are applied.
    • getFixesFromSchema

      public int getFixesFromSchema()
      Specified by:
      getFixesFromSchema in interface Patch
      Returns:
      Returns the smallest schema number that this patch may be applied to
    • setRequiresTransaction

      public void setRequiresTransaction(boolean requiresTransaction)
    • requiresTransaction

      public boolean requiresTransaction()
      Description copied from interface: Patch
      Does the patch need to be wrapped in a transaction?
      Specified by:
      requiresTransaction in interface Patch
      Returns:
      Returns true if the patch needs to be wrapped, false otherwise
    • setFixesFromSchema

      public void setFixesFromSchema(int version)
      Set the smallest schema number that this patch may be applied to.
      Parameters:
      version - a schema number not smaller than 0
    • getFixesToSchema

      public int getFixesToSchema()
      Specified by:
      getFixesToSchema in interface Patch
      Returns:
      Returns the largest schema number that this patch may be applied to
    • setFixesToSchema

      public void setFixesToSchema(int version)
      Set the largest schema version number that this patch may be applied to.
      Parameters:
      version - a schema version number not smaller than the from version number.
    • getTargetSchema

      public int getTargetSchema()
      Specified by:
      getTargetSchema in interface Patch
      Returns:
      Returns the schema number that this patch attempts to bring the repo up to
    • setTargetSchema

      public void setTargetSchema(int version)
      Set the schema version that this patch attempts to take the existing schema to. This is for informational purposes only, acting as an indicator of intention rather than having any specific effect.
      Parameters:
      version - a schema version number that must be greater than the max fix schema number
    • isForce

      public boolean isForce()
      Specified by:
      isForce in interface Patch
      Returns:
      Returns true if the patch must forcefully run regardless of any other state
    • setForce

      public void setForce(boolean force)
      Set the flag that forces the patch to be forcefully applied. This allows patches to be overridden to induce execution regardless of the upgrade or installation versions, or even if the patch has been executed before.
      Parameters:
      force - true to force the patch to be applied
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface Patch
    • setDescription

      public void setDescription(String description)
      Parameters:
      description - a thorough description of the patch
    • isIgnored

      public boolean isIgnored()
      Description copied from interface: Patch
      Is this patch just ignored - never considered for application
      Specified by:
      isIgnored in interface Patch
      Returns:
      the ignored
    • setIgnored

      public void setIgnored(boolean ignored)
      Parameters:
      ignored - the ignored to set
    • getDependsOn

      public List<Patch> getDependsOn()
      Description copied from interface: Patch
      Get patches that this patch depends on
      Specified by:
      getDependsOn in interface Patch
      Returns:
      Returns a list of patches
    • setDependsOn

      public void setDependsOn(List<Patch> dependsOn)
      Set all the dependencies for this patch. It should not be executed before all the dependencies have been applied.
      Parameters:
      dependsOn - a list of dependencies
    • getAlternatives

      public List<Patch> getAlternatives()
      Description copied from interface: Patch
      Get patches that could have done the work already
      Specified by:
      getAlternatives in interface Patch
      Returns:
      Returns a list of patches
    • setAlternatives

      public void setAlternatives(List<Patch> alternatives)
      Set all anti-dependencies. If any of the patches in the list have already been executed, then this one need not be.
      Parameters:
      alternatives - a list of alternative patches
    • applies

      public boolean applies(int version)
      Description copied from interface: Patch
      Check if the patch is applicable to a given schema version.
      Specified by:
      applies in interface Patch
      Parameters:
      version - a schema version number
      Returns:
      Returns (fixesFromVersion <= version <= fixesToVersion)
    • checkPropertyNotNull

      protected final void checkPropertyNotNull(Object value, String name)
      Performs a null check on the supplied value.
      Parameters:
      value - value to check
      name - name of the property to report
    • setApplyToTenants

      public void setApplyToTenants(boolean applyToTenants)
    • checkProperties

      protected void checkProperties()
      Check that the schema version properties have been set appropriately. Derived classes can override this method to perform their own validation provided that this method is called by the derived class.
    • applyAsync

      public String applyAsync() throws PatchException
      Apply the patch, regardless of the deferred flag. So if the patch has not run due to it being deferred earlier then this will run it now. Also ignores the "applied" lock. So the patch can be executed many times.
      Specified by:
      applyAsync in interface Patch
      Returns:
      the patch report
      Throws:
      PatchException - if the patch failed to be applied
    • apply

      public String apply() throws PatchException
      Sets up the transaction and ensures thread-safety.
      Specified by:
      apply in interface Patch
      Returns:
      Returns the patch execution report
      Throws:
      PatchException - if the patch failed to be applied
      See Also:
    • applyInternal

      protected abstract String applyInternal() throws Exception
      This method does the work. All transactions and thread-safety will be taken care of by this class. Any exception will result in the transaction being rolled back. Integrity checks are downgraded for the duration of the transaction.
      Returns:
      Returns the report (only success messages).
      Throws:
      Exception - anything can be thrown. This must be used for all failures.
      See Also:
    • reportProgress

      protected void reportProgress(long estimatedTotal, long currentInteration)
      Support to report patch completion and estimated completion time.
      Parameters:
      estimatedTotal - long
      currentInteration - long
    • setDeferred

      public void setDeferred(boolean deferred)
      Should the patch be deferred? And not run at bootstrap.
      Parameters:
      deferred - boolean
    • isDeferred

      public boolean isDeferred()
      Description copied from interface: Patch
      Indicates whether the patch must be deferred (not to be executed in bootstrap) or not
      Specified by:
      isDeferred in interface Patch
      Returns:
      true if the patch must be deferred, false otherwise