org.alfresco.repo.domain.schema
Class SchemaBootstrap

java.lang.Object
  extended by org.springframework.extensions.surf.util.AbstractLifecycleBean
      extended by org.alfresco.repo.domain.schema.SchemaBootstrap
All Implemented Interfaces:
java.util.EventListener, 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.


Nested Class Summary
static class SchemaBootstrap.SchemaBootstrapConnectionProvider
          This is a workaround for the odd Spring-Hibernate interaction during configuration.
 class SchemaBootstrap.UnclosableConnection
          A Connection wrapper that delegates all calls to the wrapped class except for the close methods, which are ignored.
 
Field Summary
static int DEFAULT_LOCK_RETRY_COUNT
           
static int DEFAULT_LOCK_RETRY_WAIT_SECONDS
           
static int DEFAULT_MAX_STRING_LENGTH
           
 
Fields inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
log
 
Constructor Summary
SchemaBootstrap()
           
 
Method Summary
 int getHibernateMaxExecutions()
          Get the limit for the hibernate executions queue
 org.springframework.orm.hibernate3.LocalSessionFactoryBean getLocalSessionFactory()
           
static int getMaxStringLength()
           
protected  void onBootstrap(org.springframework.context.ApplicationEvent event)
           
protected  void onShutdown(org.springframework.context.ApplicationEvent event)
           
 void setDataSource(javax.sql.DataSource dataSource)
           
 void setDialect(org.hibernate.dialect.Dialect dialect)
          Sets the previously auto-detected Hibernate dialect.
 void setGlobalProperties(java.util.Properties globalProperties)
          Sets the properties map from which we look up some configuration settings.
 void setHibernateMaxExecutions(int hibernateMaxExecutions)
          Set the limit for the hibernate executions queue Less than zero always uses event amalgamation
 void setLocalSessionFactory(org.springframework.orm.hibernate3.LocalSessionFactoryBean localSessionFactory)
           
 void setMaximumStringLength(int maximumStringLength)
          Optionally override the system's default maximum string length.
 void setPostCreateScriptUrls(java.util.List postUpdateScriptUrls)
          Set the scripts that must be executed after the schema has been created.
 void setPostUpdateScriptPatches(java.util.List scriptPatches)
          Set the schema script patches that may be applied after the auto-update process.
 void setPreCreateScriptUrls(java.util.List preUpdateScriptUrls)
          Set the scripts that must be executed before the schema has been created.
 void setPreUpdateScriptPatches(java.util.List scriptPatches)
          Set the schema script patches that may be applied prior to the auto-update process.
 void setSchemaOuputFilename(java.lang.String schemaOuputFilename)
          Set this to output the full database creation script
 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.
 void setSchemaUpdateLockRetryWaitSeconds(int schemaUpdateLockRetryWaitSeconds)
          Set the wait time (seconds) between checks for the schema update lock.
 void setStopAfterSchemaBootstrap(boolean stopAfterSchemaBootstrap)
          Set whether this component should terminate the bootstrap process after running all the usual checks and scripts.
 void setUpdateSchema(boolean updateSchema)
          Set whether to modify the schema or not.
 void setValidateUpdateScriptPatches(java.util.List scriptPatches)
          Set the schema script patches that must have been applied.
static java.lang.String trimStringForTextFields(java.lang.String value)
          Truncates or returns a string that will fit into the string columns in the schema.
 
Methods inherited from class org.springframework.extensions.surf.util.AbstractLifecycleBean
getApplicationContext, onApplicationEvent, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCK_RETRY_COUNT

public static final int DEFAULT_LOCK_RETRY_COUNT
See Also:
Constant Field Values

DEFAULT_LOCK_RETRY_WAIT_SECONDS

public static final int DEFAULT_LOCK_RETRY_WAIT_SECONDS
See Also:
Constant Field Values

DEFAULT_MAX_STRING_LENGTH

public static final int DEFAULT_MAX_STRING_LENGTH
See Also:
Constant Field Values
Constructor Detail

SchemaBootstrap

public SchemaBootstrap()
Method Detail

getMaxStringLength

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

trimStringForTextFields

public static final java.lang.String trimStringForTextFields(java.lang.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, SchemaBootstrap.DEFAULT_MAX_STRING_LENGTH.

Parameters:
value - the string to check
Returns:
Returns a string that is short enough for SchemaBootstrap.getMaxStringLength()
Since:
3.2

setDialect

public void setDialect(org.hibernate.dialect.Dialect dialect)
Sets the previously auto-detected Hibernate dialect.

Parameters:
dialect - the dialect

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)

setLocalSessionFactory

public void setLocalSessionFactory(org.springframework.orm.hibernate3.LocalSessionFactoryBean localSessionFactory)

getLocalSessionFactory

public org.springframework.orm.hibernate3.LocalSessionFactoryBean getLocalSessionFactory()

setSchemaOuputFilename

public void setSchemaOuputFilename(java.lang.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.

setPreCreateScriptUrls

public void setPreCreateScriptUrls(java.util.List preUpdateScriptUrls)
Set the scripts that must be executed before the schema has been created.

Parameters:
postCreateScriptUrls - file URLs
See Also:
SchemaBootstrap.PLACEHOLDER_SCRIPT_DIALECT

setPostCreateScriptUrls

public void setPostCreateScriptUrls(java.util.List postUpdateScriptUrls)
Set the scripts that must be executed after the schema has been created.

Parameters:
postCreateScriptUrls - file URLs
See Also:
SchemaBootstrap.PLACEHOLDER_SCRIPT_DIALECT

setValidateUpdateScriptPatches

public void setValidateUpdateScriptPatches(java.util.List scriptPatches)
Set the schema script patches that must have been applied. These will not be applied to the database. These can be used where the script cannot be applied automatically or where a particular upgrade path is no longer supported. For example, at version 3.0, the upgrade scripts for version 1.4 may be considered unsupported - this doesn't prevent the manual application of the scripts, though.

Parameters:
scriptPatches - a list of schema patches to check

setPreUpdateScriptPatches

public void setPreUpdateScriptPatches(java.util.List scriptPatches)
Set the schema script patches that may be applied prior to the auto-update process.

Parameters:
scriptPatches - a list of schema patches to check

setPostUpdateScriptPatches

public void setPostUpdateScriptPatches(java.util.List scriptPatches)
Set the schema script patches that may be applied after the auto-update process.

Parameters:
postUpdateScriptPatches - a list of schema patches to check

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

getHibernateMaxExecutions

public int getHibernateMaxExecutions()
Get the limit for the hibernate executions queue


setHibernateMaxExecutions

public void setHibernateMaxExecutions(int hibernateMaxExecutions)
Set the limit for the hibernate executions queue Less than zero always uses event amalgamation


setGlobalProperties

public void setGlobalProperties(java.util.Properties globalProperties)
Sets the properties map from which we look up some configuration settings.

Parameters:
globalProperties - the global properties

onBootstrap

protected void onBootstrap(org.springframework.context.ApplicationEvent event)
Specified by:
onBootstrap in class org.springframework.extensions.surf.util.AbstractLifecycleBean

onShutdown

protected void onShutdown(org.springframework.context.ApplicationEvent event)
Specified by:
onShutdown in class org.springframework.extensions.surf.util.AbstractLifecycleBean


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