Package org.alfresco.repo.admin.patch
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 Summary
FieldsModifier and TypeFieldDescriptionprotected org.springframework.context.ApplicationEventPublisherPublishes batch event notifications for JMX viewingprotected AuthenticationContextstatic final StringI18N message when properties not set.protected NamespaceServiceprotected NodeServiceprotected PatchServicethe service to register ourselves withprotected SearchServiceprotected TenantAdminServiceprotected RetryingTransactionHelperUse this helper to ensure that patches can execute even on a read-only systemprotected TransactionServiceused to ensure a unique transaction per execution -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanapplies(int version) Check if the patch is applicable to a given schema version.apply()Sets up the transaction and ensures thread-safety.Apply the patch, regardless of the deferred flag.protected abstract StringThis method does the work.protected voidCheck that the schema version properties have been set appropriately.protected final voidcheckPropertyNotNull(Object value, String name) Performs a null check on the supplied value.Get patches that could have done the work alreadyGet patches that this patch depends onintintgetId()intvoidinit()This ensures that this bean gets registered with the appropriateservice.booleanIndicates whether the patch must be deferred (not to be executed in bootstrap) or notbooleanisForce()booleanIs this patch just ignored - never considered for applicationprotected voidreportProgress(long estimatedTotal, long currentInteration) Support to report patch completion and estimated completion time.booleanDoes the patch need to be wrapped in a transaction?voidsetAlternatives(List<Patch> alternatives) Set all anti-dependencies.voidsetApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) Set automaticallyvoidsetApplyToTenants(boolean applyToTenants) voidsetAuthenticationContext(AuthenticationContext authenticationContext) voidsetDeferred(boolean deferred) Should the patch be deferred? And not run at bootstrap.voidsetDependsOn(List<Patch> dependsOn) Set all the dependencies for this patch.voidsetDescription(String description) voidsetFixesFromSchema(int version) Set the smallest schema number that this patch may be applied to.voidsetFixesToSchema(int version) Set the largest schema version number that this patch may be applied to.voidsetForce(boolean force) Set the flag that forces the patch to be forcefully applied.voidvoidsetIgnored(boolean ignored) voidsetNamespaceService(NamespaceService namespaceService) voidsetNodeService(NodeService nodeService) voidsetPatchService(PatchService patchService) Set the service that this patch will register with for execution.voidsetRequiresTransaction(boolean requiresTransaction) voidsetSearchService(SearchService searchService) voidsetTargetSchema(int version) Set the schema version that this patch attempts to take the existing schema to.voidsetTenantAdminService(TenantAdminService tenantAdminService) voidsetTransactionService(TransactionService transactionService) Set the transaction provider so that each execution can be performed within a transactiontoString()
-
Field Details
-
ERR_PROPERTY_NOT_SET
I18N message when properties not set.- {0} = property name
- {1} = patch instance
- See Also:
-
patchService
the service to register ourselves with -
transactionService
used to ensure a unique transaction per execution -
transactionHelper
Use this helper to ensure that patches can execute even on a read-only system -
namespaceService
-
nodeService
-
searchService
-
authenticationContext
-
tenantAdminService
-
applicationEventPublisher
protected org.springframework.context.ApplicationEventPublisher applicationEventPublisherPublishes batch event notifications for JMX viewing
-
-
Constructor Details
-
AbstractPatch
public AbstractPatch()
-
-
Method Details
-
toString
-
setPatchService
Set the service that this patch will register with for execution. -
setTransactionService
Set the transaction provider so that each execution can be performed within a transaction -
setNamespaceService
-
setNodeService
-
setSearchService
-
setAuthenticationContext
-
setTenantAdminService
-
setApplicationEventPublisher
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) Set automatically- Specified by:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
init
public void init()This ensures that this bean gets registered with the appropriateservice. -
getId
-
setId
- Parameters:
id- the unique ID of the patch. This dictates the order in which patches are applied.
-
getFixesFromSchema
public int getFixesFromSchema()- Specified by:
getFixesFromSchemain interfacePatch- 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:PatchDoes the patch need to be wrapped in a transaction?- Specified by:
requiresTransactionin interfacePatch- 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:
getFixesToSchemain interfacePatch- 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 thefrom versionnumber.
-
getTargetSchema
public int getTargetSchema()- Specified by:
getTargetSchemain interfacePatch- 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 themax fix schema number
-
isForce
public boolean isForce() -
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
- Specified by:
getDescriptionin interfacePatch
-
setDescription
- Parameters:
description- a thorough description of the patch
-
isIgnored
public boolean isIgnored()Description copied from interface:PatchIs this patch just ignored - never considered for application -
setIgnored
public void setIgnored(boolean ignored) - Parameters:
ignored- the ignored to set
-
getDependsOn
Description copied from interface:PatchGet patches that this patch depends on- Specified by:
getDependsOnin interfacePatch- Returns:
- Returns a list of patches
-
setDependsOn
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
Description copied from interface:PatchGet patches that could have done the work already- Specified by:
getAlternativesin interfacePatch- Returns:
- Returns a list of patches
-
setAlternatives
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:PatchCheck if the patch is applicable to a given schema version. -
checkPropertyNotNull
Performs a null check on the supplied value.- Parameters:
value- value to checkname- 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
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:
applyAsyncin interfacePatch- Returns:
- the patch report
- Throws:
PatchException- if the patch failed to be applied
-
apply
Sets up the transaction and ensures thread-safety.- Specified by:
applyin interfacePatch- Returns:
- Returns the patch execution report
- Throws:
PatchException- if the patch failed to be applied- See Also:
-
applyInternal
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. -
reportProgress
protected void reportProgress(long estimatedTotal, long currentInteration) Support to report patch completion and estimated completion time.- Parameters:
estimatedTotal- longcurrentInteration- 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:PatchIndicates whether the patch must be deferred (not to be executed in bootstrap) or not- Specified by:
isDeferredin interfacePatch- Returns:
- true if the patch must be deferred, false otherwise
-