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
  • 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

      public static final void setMaxStringLength(int length, Dialect dialect)
      See Also:
    • getMaxStringLength

      public static final int getMaxStringLength()
      Returns:
      Returns the maximum number of characters that a string field can be
    • trimStringForTextFields

      public static final String trimStringForTextFields(String value)
      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

      public void setDescriptorService(DescriptorService descriptorService)
      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

      public void setDatabaseMetaDataHelper(DatabaseMetaDataHelper databaseMetaDataHelper)
      Defines the DatabaseMetaDataHelper to be used
      Parameters:
      databaseMetaDataHelper - DatabaseMetaDataHelper
    • setDialect

      public void setDialect(Dialect dialect)
      Sets the previously auto-detected Hibernate dialect.
      Parameters:
      dialect - the dialect
    • setDifferenceHelper

      public void setDifferenceHelper(SchemaDifferenceHelper differenceHelper)
    • setDataSource

      public void setDataSource(DataSource dataSource)
    • setAppliedPatchDAO

      public void setAppliedPatchDAO(AppliedPatchDAO appliedPatchDAO)
    • setSchemaOuputFilename

      public void setSchemaOuputFilename(String schemaOuputFilename)
      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

      public void setSchemaReferenceUrls(List<String> schemaReferenceUrls)
      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

      public void setDbSchemaName(String dbSchemaName)
      Set db.schema.name to be used
    • setGlobalProperties

      public void setGlobalProperties(Properties globalProperties)
      Sets the properties map from which we look up some configuration settings.
      Parameters:
      globalProperties - the global properties
    • addPreCreateScriptUrl

      public void addPreCreateScriptUrl(String preCreateScriptUrl)
      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

      public void addPostCreateScriptUrl(String postUpdateScriptUrl)
      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

      public void addPreUpdateScriptPatch(SchemaUpgradeScriptPatch scriptPatch)
      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

      public void addPostUpdateScriptPatch(SchemaUpgradeScriptPatch scriptPatch)
      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

      public void addUpdateActivitiScriptPatch(SchemaUpgradeScriptPatch scriptPatch)
      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:
      onBootstrap in class org.springframework.extensions.surf.util.AbstractLifecycleBean
    • validateSchema

      public int validateSchema(String outputFileNameTemplate, PrintWriter out)
      Collate differences and validation problems with the schema with respect to an appropriate reference schema.
      Parameters:
      outputFileNameTemplate - String
      out - PrintWriter
      Returns:
      the number of potential problems found.
    • dumpSchema

      public List<File> 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

      public List<File> 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.
      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:
      onShutdown in class org.springframework.extensions.surf.util.AbstractLifecycleBean