Package org.alfresco.repo.domain.schema
Class SchemaBootstrap
java.lang.Object
org.springframework.extensions.surf.util.AbstractLifecycleBean
org.alfresco.repo.domain.schema.SchemaBootstrap
- All Implemented Interfaces:
EventListener,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener
public class SchemaBootstrap
extends org.springframework.extensions.surf.util.AbstractLifecycleBean
Bootstraps the schema and schema update. The schema is considered missing if the applied patch table
is not present, and the schema is considered empty if the applied patch table is empty.
- Author:
- Derek Hulley
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassAConnectionwrapper that delegates all calls to the wrapped class except for the close methods, which are ignored. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intFields inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPostCreateScriptUrl(String postUpdateScriptUrl) Register a new script for execution after the Hibernate schema creation phase.voidaddPostUpdateScriptPatch(SchemaUpgradeScriptPatch scriptPatch) Register a new SQL-based patch for consideration against the instance (after Hibernate execution)voidaddPreCreateScriptUrl(String preCreateScriptUrl) Register a new script for execution when creating a clean schema.voidaddPreUpdateScriptPatch(SchemaUpgradeScriptPatch scriptPatch) Register a new SQL-based patch for consideration against the instance (before Hibernate execution)voidaddUpdateActivitiScriptPatch(SchemaUpgradeScriptPatch scriptPatch) Register a new SQL-based patch for consideration against the Activiti instanceProduces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if changes are made to the schema) and can made upon demand via JMX.dumpSchema(String[] dbPrefixes) Produces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if changes are made to the schema) and can made upon demand via JMX.static final intvoidonBootstrap(org.springframework.context.ApplicationEvent event) protected voidonShutdown(org.springframework.context.ApplicationEvent event) voidsetAppliedPatchDAO(AppliedPatchDAO appliedPatchDAO) voidsetDatabaseMetaDataHelper(DatabaseMetaDataHelper databaseMetaDataHelper) Defines the DatabaseMetaDataHelper to be usedvoidsetDataSource(DataSource dataSource) voidsetDbSchemaName(String dbSchemaName) Set db.schema.name to be usedvoidsetDescriptorService(DescriptorService descriptorService) Provide a reference to the DescriptorService, used to provide information about the repository such as the database schema version number.voidsetDialect(Dialect dialect) Sets the previously auto-detected Hibernate dialect.voidsetDifferenceHelper(SchemaDifferenceHelper differenceHelper) voidsetGlobalProperties(Properties globalProperties) Sets the properties map from which we look up some configuration settings.voidsetMaximumStringLength(int maximumStringLength) Optionally override the system's default maximum string length.static final voidsetMaxStringLength(int length, Dialect dialect) voidsetSchemaOuputFilename(String schemaOuputFilename) Set this to output the full database creation scriptvoidsetSchemaReferenceUrls(List<String> schemaReferenceUrls) Specifies the schema reference files that will be used to validate the repository schema whenever changes have been made.voidsetSchemaUpdateLockRetryCount(int schemaUpdateLockRetryCount) Set the number times that the DB must be checked for the presence of the table indicating that a schema change is in progress.voidsetSchemaUpdateLockRetryWaitSeconds(int schemaUpdateLockRetryWaitSeconds) Set the wait time (seconds) between checks for the schema update lock.voidsetStopAfterSchemaBootstrap(boolean stopAfterSchemaBootstrap) Set whether this component should terminate the bootstrap process after running all the usual checks and scripts.voidsetUpdateSchema(boolean updateSchema) Set whether to modify the schema or not.static final StringtrimStringForTextFields(String value) Truncates or returns a string that will fit into the string columns in the schema.intvalidateSchema(String outputFileNameTemplate, PrintWriter out) Collate differences and validation problems with the schema with respect to an appropriate reference schema.Methods inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
getApplicationContext, onApplicationEvent, setApplicationContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Field Details
-
DEFAULT_LOCK_RETRY_COUNT
public static final int DEFAULT_LOCK_RETRY_COUNT- See Also:
-
DEFAULT_LOCK_RETRY_WAIT_SECONDS
public static final int DEFAULT_LOCK_RETRY_WAIT_SECONDS- See Also:
-
DEFAULT_MAX_STRING_LENGTH
public static final int DEFAULT_MAX_STRING_LENGTH- See Also:
-
DEFAULT_MAX_STRING_LENGTH_NDB
public static final int DEFAULT_MAX_STRING_LENGTH_NDB- See Also:
-
-
Constructor Details
-
SchemaBootstrap
public SchemaBootstrap()
-
-
Method Details
-
setMaxStringLength
- See Also:
-
getMaxStringLength
public static final int getMaxStringLength()- Returns:
- Returns the maximum number of characters that a string field can be
-
trimStringForTextFields
Truncates or returns a string that will fit into the string columns in the schema. Text fields can either cope with arbitrarily long text fields or have the default limit,DEFAULT_MAX_STRING_LENGTH.- Parameters:
value- the string to check- Returns:
- Returns a string that is short enough for
getMaxStringLength() - Since:
- 3.2
-
setDescriptorService
Provide a reference to the DescriptorService, used to provide information about the repository such as the database schema version number.- Parameters:
descriptorService- the descriptorService to set
-
setDatabaseMetaDataHelper
Defines the DatabaseMetaDataHelper to be used- Parameters:
databaseMetaDataHelper- DatabaseMetaDataHelper
-
setDialect
Sets the previously auto-detected Hibernate dialect.- Parameters:
dialect- the dialect
-
setDifferenceHelper
-
setDataSource
-
setAppliedPatchDAO
-
setSchemaOuputFilename
Set this to output the full database creation script- Parameters:
schemaOuputFilename- the name of a file to dump the schema to, or null to ignore
-
setUpdateSchema
public void setUpdateSchema(boolean updateSchema) Set whether to modify the schema or not. Either way, the schema will be validated.- Parameters:
updateSchema- true to update and validate the schema, otherwise false to just validate the schema. Default is true.
-
setStopAfterSchemaBootstrap
public void setStopAfterSchemaBootstrap(boolean stopAfterSchemaBootstrap) Set whether this component should terminate the bootstrap process after running all the usual checks and scripts. This has the additional effect of dumping a final schema structure file just before exiting.WARNING: USE FOR DEBUG AND UPGRADE TESTING ONLY
- Parameters:
stopAfterSchemaBootstrap- true to terminate (with exception) after running all the usual schema updates and checks.
-
setSchemaReferenceUrls
Specifies the schema reference files that will be used to validate the repository schema whenever changes have been made. The database dialect placeholder will be resolved so that the correct reference files are loaded for the current database type (e.g. PostgreSQL)- Parameters:
schemaReferenceUrls- the schemaReferenceUrls to set
-
setSchemaUpdateLockRetryCount
public void setSchemaUpdateLockRetryCount(int schemaUpdateLockRetryCount) Set the number times that the DB must be checked for the presence of the table indicating that a schema change is in progress.- Parameters:
schemaUpdateLockRetryCount- the number of times to retry (default 24)
-
setSchemaUpdateLockRetryWaitSeconds
public void setSchemaUpdateLockRetryWaitSeconds(int schemaUpdateLockRetryWaitSeconds) Set the wait time (seconds) between checks for the schema update lock.- Parameters:
schemaUpdateLockRetryWaitSeconds- the number of seconds between checks (default 5 seconds)
-
setMaximumStringLength
public void setMaximumStringLength(int maximumStringLength) Optionally override the system's default maximum string length. Some databases have limitations on how long the string_value columns can be while other do not. Some parts of the persistence have alternatives when the string values exceed this length while others do not. Either way, it is possible to adjust the text column sizes and adjust this value manually to override the default associated with the database being used.The system - as of V2.1.2 - will attempt to adjust the maximum string length size automatically and therefore this method is not normally required. But it is possible to manually override the value if, for example, the system doesn't guess the correct maximum length or if the dialect is not explicitly catered for.
All negative or zero values are ignored and the system defaults to its best guess based on the dialect being used.
- Parameters:
maximumStringLength- the maximum length of the string_value columns
-
setDbSchemaName
Set db.schema.name to be used -
setGlobalProperties
Sets the properties map from which we look up some configuration settings.- Parameters:
globalProperties- the global properties
-
addPreCreateScriptUrl
Register a new script for execution when creating a clean schema. The order of registration determines the order of execution.- Parameters:
preCreateScriptUrl- the script URL, possibly containing the ${db.script.dialect} placeholder
-
addPostCreateScriptUrl
Register a new script for execution after the Hibernate schema creation phase. The order of registration determines the order of execution.- Parameters:
postUpdateScriptUrl- the script URL, possibly containing the ${db.script.dialect} placeholder
-
addPreUpdateScriptPatch
Register a new SQL-based patch for consideration against the instance (before Hibernate execution)- Parameters:
scriptPatch- the patch that will be examined for execution
-
addPostUpdateScriptPatch
Register a new SQL-based patch for consideration against the instance (after Hibernate execution)- Parameters:
scriptPatch- the patch that will be examined for execution
-
addUpdateActivitiScriptPatch
Register a new SQL-based patch for consideration against the Activiti instance- Parameters:
scriptPatch- the patch that will be examined for execution
-
onBootstrap
public void onBootstrap(org.springframework.context.ApplicationEvent event) - Specified by:
onBootstrapin classorg.springframework.extensions.surf.util.AbstractLifecycleBean
-
validateSchema
Collate differences and validation problems with the schema with respect to an appropriate reference schema.- Parameters:
outputFileNameTemplate- Stringout- PrintWriter- Returns:
- the number of potential problems found.
-
dumpSchema
Produces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if changes are made to the schema) and can made upon demand via JMX.- Returns:
- List of output files.
-
dumpSchema
Produces schema dump in XML format: this is performed pre- and post-upgrade (i.e. if changes are made to the schema) and can made upon demand via JMX.- Parameters:
dbPrefixes- Array of database object prefixes to produce the dump for, e.g. "alf_".- Returns:
- List of output files.
-
onShutdown
protected void onShutdown(org.springframework.context.ApplicationEvent event) - Specified by:
onShutdownin classorg.springframework.extensions.surf.util.AbstractLifecycleBean
-