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 java.lang.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
Fields Modifier and Type Field Description protected org.springframework.context.ApplicationEventPublisherapplicationEventPublisherPublishes batch event notifications for JMX viewingprotected AuthenticationContextauthenticationContextstatic java.lang.StringERR_PROPERTY_NOT_SETI18N message when properties not set.protected org.alfresco.service.namespace.NamespaceServicenamespaceServiceprotected org.alfresco.service.cmr.repository.NodeServicenodeServiceprotected PatchServicepatchServicethe service to register ourselves withprotected org.alfresco.service.cmr.search.SearchServicesearchServiceprotected TenantAdminServicetenantAdminServiceprotected RetryingTransactionHelpertransactionHelperUse this helper to ensure that patches can execute even on a read-only systemprotected TransactionServicetransactionServiceused to ensure a unique transaction per execution
-
Constructor Summary
Constructors Constructor Description AbstractPatch()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanapplies(int version)Check if the patch is applicable to a given schema version.java.lang.Stringapply()Sets up the transaction and ensures thread-safety.java.lang.StringapplyAsync()Apply the patch, regardless of the deferred flag.protected abstract java.lang.StringapplyInternal()This method does the work.protected voidcheckProperties()Check that the schema version properties have been set appropriately.protected voidcheckPropertyNotNull(java.lang.Object value, java.lang.String name)Performs a null check on the supplied value.java.util.List<Patch>getAlternatives()Get patches that could have done the work alreadyjava.util.List<Patch>getDependsOn()Get patches that this patch depends onjava.lang.StringgetDescription()intgetFixesFromSchema()intgetFixesToSchema()java.lang.StringgetId()intgetTargetSchema()voidinit()This ensures that this bean gets registered with the appropriateservice.booleanisDeferred()Indicates whether the patch must be deferred (not to be executed in bootstrap) or notbooleanisForce()booleanisIgnored()Is this patch just ignored - never considered for applicationprotected voidreportProgress(long estimatedTotal, long currentInteration)Support to report patch completion and estimated completion time.booleanrequiresTransaction()Does the patch need to be wrapped in a transaction?voidsetAlternatives(java.util.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(java.util.List<Patch> dependsOn)Set all the dependencies for this patch.voidsetDescription(java.lang.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.voidsetId(java.lang.String id)voidsetIgnored(boolean ignored)voidsetNamespaceService(org.alfresco.service.namespace.NamespaceService namespaceService)voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)voidsetPatchService(PatchService patchService)Set the service that this patch will register with for execution.voidsetRequiresTransaction(boolean requiresTransaction)voidsetSearchService(org.alfresco.service.cmr.search.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 transactionjava.lang.StringtoString()
-
-
-
Field Detail
-
ERR_PROPERTY_NOT_SET
public static final java.lang.String ERR_PROPERTY_NOT_SET
I18N message when properties not set.- {0} = property name
- {1} = patch instance
- See Also:
- Constant Field Values
-
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 org.alfresco.service.namespace.NamespaceService namespaceService
-
nodeService
protected org.alfresco.service.cmr.repository.NodeService nodeService
-
searchService
protected org.alfresco.service.cmr.search.SearchService searchService
-
authenticationContext
protected AuthenticationContext authenticationContext
-
tenantAdminService
protected TenantAdminService tenantAdminService
-
applicationEventPublisher
protected org.springframework.context.ApplicationEventPublisher applicationEventPublisher
Publishes batch event notifications for JMX viewing
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.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(org.alfresco.service.namespace.NamespaceService namespaceService)
-
setNodeService
public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
-
setSearchService
public void setSearchService(org.alfresco.service.cmr.search.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:
setApplicationEventPublisherin interfaceorg.springframework.context.ApplicationEventPublisherAware
-
init
public void init()
This ensures that this bean gets registered with the appropriateservice.
-
setId
public void setId(java.lang.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:
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
public java.lang.String getDescription()
- Specified by:
getDescriptionin interfacePatch
-
setDescription
public void setDescription(java.lang.String description)
- 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
public java.util.List<Patch> getDependsOn()
Description copied from interface:PatchGet patches that this patch depends on- Specified by:
getDependsOnin interfacePatch- Returns:
- Returns a list of patches
-
setDependsOn
public void setDependsOn(java.util.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 java.util.List<Patch> 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
public void setAlternatives(java.util.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:PatchCheck if the patch is applicable to a given schema version.
-
checkPropertyNotNull
protected final void checkPropertyNotNull(java.lang.Object value, java.lang.String name)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
public java.lang.String applyAsync() throws PatchExceptionApply 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
public java.lang.String apply() throws PatchExceptionSets 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()
-
applyInternal
protected abstract java.lang.String applyInternal() throws java.lang.ExceptionThis 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:
java.lang.Exception- anything can be thrown. This must be used for all failures.- See Also:
apply()
-
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
-
-