org.alfresco.repo.admin.patch
Class AbstractPatch

java.lang.Object
  extended by org.alfresco.repo.admin.patch.AbstractPatch
All Implemented Interfaces:
Patch, org.springframework.context.ApplicationEventPublisherAware
Direct Known Subclasses:
AbstractPermissionChangePatch, ActivitiesTemplatesUpdatePatch, AuthorityDefaultZonesPatch, AuthorityMigrationPatch, AVMToADMRemoteStorePatch, AVMWebProjectInheritPermissionsPatch, BaseReindexingPatch, CalendarModelUriPatch, ClearOldImapMessgesPatch, ClearOldImapTemplatesPatch2, ContentUrlConverterPatch, CopiedFromAspectPatch, DeploymentMigrationPatch, DmPermissionsPatch, EmailTemplatesInviteAndNotifyFoldersPatch, FixAclInheritancePatch, FixAuthoritiesCrcValuesPatch, FixNameCrcValuesPatch, FixUserQNamesPatch, GenericBootstrapPatch, GenericMimetypeRenamePatch, GenericWorkflowPatch, ImapFoldersPatch, InvitationMigrationPatch, LinkNodeFileExtensionPatch, MigrateAttrAVMLocksPatch, MigrateAttrChainingURSPatch, MigrateAttrDropOldTablesPatch, MigrateAttrPropBackedBeanPatch, MigrateAttrTenantsPatch, MigrateVersionStorePatch, MoveWCMToGroupBasedPermissionsPatch, MultiTFixAdminExistingTenantsPatch, MultiTShareExistingTenantsPatch, NoLongerSupportedPatch, NoOpPatch, PersonUsagePatch, QNamePatch, SamplePatch, SchemaUpgradeScriptPatch, SimplePatch, SiteLoadPatch, SitePermissionRefactorPatch, SitesSpacePermissionsPatch, SiteStorePatch, SpacesStoreGuestPermissionPatch, WCMFoldersPatch, WCMPostPermissionSnapshotPatch, WebSiteAddModeratedPatch

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.


Field Summary
protected  org.springframework.context.ApplicationEventPublisher applicationEventPublisher
          Publishes batch event notifications for JMX viewing
protected  AuthenticationContext authenticationContext
           
static java.lang.String ERR_PROPERTY_NOT_SET
          I18N message when properties not set.
protected  org.alfresco.service.namespace.NamespaceService namespaceService
           
protected  org.alfresco.service.cmr.repository.NodeService nodeService
           
protected  org.alfresco.service.cmr.search.SearchService searchService
           
protected  TenantAdminService tenantAdminService
           
protected  RetryingTransactionHelper transactionHelper
          Use this helper to ensure that patches can execute even on a read-only system
protected  TransactionService transactionService
          used to ensure a unique transaction per execution
 
Constructor Summary
AbstractPatch()
           
 
Method Summary
 boolean applies(int version)
          Check if the patch is applicable to a given schema version.
 java.lang.String apply()
          Sets up the transaction and ensures thread-safety.
protected abstract  java.lang.String applyInternal()
          This method does the work.
protected  void checkProperties()
          Check that the schema version properties have been set appropriately.
protected  void checkPropertyNotNull(java.lang.Object value, java.lang.String name)
          Performs a null check on the supplied value.
 java.util.List getAlternatives()
          Get patches that could have done the work already
 java.util.List getDependsOn()
          Get patches that this patch depends on
 java.lang.String getDescription()
           
 int getFixesFromSchema()
           
 int getFixesToSchema()
           
 java.lang.String getId()
           
 int getTargetSchema()
           
 void init()
          This ensures that this bean gets registered with the appropriate service.
 boolean isForce()
          
protected  void reportProgress(long estimatedTotal, long currentInteration)
          Support to report patch completion and estimated completion time.
 boolean requiresTransaction()
          Does the patch need to be wrapped in a transaction?
 void setAlternatives(java.util.List alternatives)
          Set all anti-dependencies.
 void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
          Set automatically
 void setApplyToTenants(boolean applyToTenants)
           
 void setAuthenticationContext(AuthenticationContext authenticationContext)
           
 void setDependsOn(java.util.List dependsOn)
          Set all the dependencies for this patch.
 void setDescription(java.lang.String description)
           
 void setFixesFromSchema(int version)
          Set the smallest schema number that this patch may be applied to.
 void setFixesToSchema(int version)
          Set the largest schema version number that this patch may be applied to.
 void setForce(boolean force)
          Set the flag that forces the patch to be forcefully applied.
 void setId(java.lang.String id)
           
 void setNamespaceService(org.alfresco.service.namespace.NamespaceService namespaceService)
           
 void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)
           
 void setPatchService(PatchService patchService)
          Set the service that this patch will register with for execution.
 void setRequiresTransaction(boolean requiresTransaction)
           
 void setSearchService(org.alfresco.service.cmr.search.SearchService searchService)
           
 void setTargetSchema(int version)
          Set the schema version that this patch attempts to take the existing schema to.
 void setTenantAdminService(TenantAdminService tenantAdminService)
           
 void setTransactionService(TransactionService transactionService)
          Set the transaction provider so that each execution can be performed within a transaction
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ERR_PROPERTY_NOT_SET

public static final java.lang.String ERR_PROPERTY_NOT_SET
I18N message when properties not set.

See Also:
Constant Field Values

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

Constructor Detail

AbstractPatch

public AbstractPatch()
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.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:
setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware

init

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


getId

public java.lang.String getId()
Specified by:
getId in interface Patch

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:
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 java.lang.String getDescription()
Specified by:
getDescription in interface Patch

setDescription

public void setDescription(java.lang.String description)
Parameters:
description - a thorough description of the patch

getDependsOn

public java.util.List 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(java.util.List 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 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(java.util.List 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(java.lang.Object value,
                                          java.lang.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.


apply

public java.lang.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:
AbstractPatch.applyInternal()

applyInternal

protected abstract java.lang.String applyInternal()
                                           throws java.lang.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:
java.lang.Exception - anything can be thrown. This must be used for all failures.
See Also:
AbstractPatch.apply()

reportProgress

protected void reportProgress(long estimatedTotal,
                              long currentInteration)
Support to report patch completion and estimated completion time.

Parameters:
estimatedTotal -
currentInteration -


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.