org.opencms.setup.update6to7.generic
Class CmsUpdateDBProjectId

java.lang.Object
  extended by org.opencms.setup.update6to7.A_CmsUpdateDBPart
      extended by org.opencms.setup.update6to7.generic.CmsUpdateDBProjectId
All Implemented Interfaces:
I_CmsUpdateDBPart
Direct Known Subclasses:
CmsUpdateDBProjectId, CmsUpdateDBProjectId

public class CmsUpdateDBProjectId
extends A_CmsUpdateDBPart

This class updates the project ids from integer values to CmsUUIDs in all existing database tables.

It creates new UUIDs for each existing project and stores it into a temporary table.

For each table using a project id a new column for the UUID is added and the according data is transferred.

After that the original indexes and the column for the project id index is dropped and the new column with the project uuid becomes the primary key.

Since:
7.0.0
Version:
$Revision: 1.2 $
Author:
Roland Metzler

Field Summary
protected static java.lang.String COLUMN_PROJECT_ID
          Constant for the sql column PROJECT_ID.
protected static java.lang.String COLUMN_PROJECT_LASTMODIFIED
          Constant for the sql query to use the column PROJECT_LASTMODIFIED.
protected static java.lang.String COLUMN_PROJECT_UUID
          Constant for the sql column PROJECT_UUID.
protected static java.lang.String COLUMN_TEMP_PROJECT_UUID
          Constant for the sql column TEMP_PROJECT_UUID.
protected static java.lang.String HISTORY_PROJECTS_TABLE
          Constant for the table name of the CMS_HISTORY_PROJECTS table.
protected static java.lang.String QUERY_ADD_PRIMARY_KEY
          Constant for the sql query to add a new primary key.
protected static java.lang.String QUERY_ADD_TEMP_UUID_COLUMN
          Constant for the sql query to add a new column to the table.
protected static java.lang.String QUERY_CREATE_HISTORY_PROJECTS_TABLE
          Constant for the sql query to create the new CMS_HISTORY_PROJECTS table.
protected static java.lang.String QUERY_CREATE_TEMP_TABLE_UUIDS
          Constant for the sql query to create the temporary table.
protected static java.lang.String QUERY_DESCRIBE_TABLE
          Constant for the sql query to describe the given table.
protected static java.lang.String QUERY_READ_MAX_PUBTAG
          Constant for the sql query to read max publish tag.
protected static java.lang.String REPLACEMENT_COLUMN
          Constant for the replacement in the SQL query for the columnname.
protected static java.lang.String REPLACEMENT_NEW_COLUMN
          Constant for the replacement in the SQL query for the new columnname.
protected static java.lang.String REPLACEMENT_OLDID
          Constant for the replacement in the SQL query for old id to update.
protected static java.lang.String REPLACEMENT_PRIMARY_KEY
          Constant for the replacement in the SQL query for the primary key.
protected static java.lang.String REPLACEMENT_TABLENAME
          Constant for the replacement in the SQL query for the tablename.
protected static java.lang.String[] RESOURCE_TABLES
          Array of the online and offline resources tables.
protected static java.util.List RESOURCES_TABLES_LIST
          Arraylist for the online and offline resources tables that shall be updated.
protected static java.lang.String[] TABLES
          Array of the tables that are to be updated.
protected static java.util.List TABLES_LIST
          Arraylist for the tables that shall be updated.
protected static java.lang.String TEMP_UUID_COLUMN
          Constant for the temporary UUID column in the tables.
protected static java.lang.String TEMPORARY_TABLE_NAME
          Constant for the name of temporary table containing the project ids and uuids.
 
Fields inherited from class org.opencms.setup.update6to7.A_CmsUpdateDBPart
m_poolData, m_queries, QUERY_PROPERTIES_PREFIX
 
Constructor Summary
CmsUpdateDBProjectId()
          Constructor.
 
Method Summary
protected  void addPrimaryKey(CmsSetupDb dbCon, java.lang.String tablename, java.lang.String primaryKey)
          Adds a new primary key to the given table.
protected  void addUUIDColumnToTable(CmsSetupDb dbCon, java.lang.String tablename, java.lang.String column)
          Adds the new column for the uuids to a table.
protected  boolean checkColumnTypeProjectId(int type)
          Check if the column type of the project id is incorrect.
protected  void createHistProjectsTable(CmsSetupDb dbCon)
          Creates the CMS_HISTORY_PROJECTS table if it does not exist yet.
protected  void createTempTable(CmsSetupDb dbCon)
          Creates the temp table for project ids if it does not exist yet.
protected  java.lang.String getColumnProjectIdResourcePath()
          Returns the columns for the primary key of the project resources table.
protected  void internalExecute(CmsSetupDb dbCon)
          Does the hard work.
protected  boolean needsUpdating(CmsSetupDb dbCon, java.lang.String tablename)
          Checks if the given table needs an update of the uuids.
protected  void transferDataToHistoryTable(CmsSetupDb dbCon)
          Transfers the data from the CMS_BACKUP_PROJECTS to the CMS_HISTORY_PROJECTS table.
 
Methods inherited from class org.opencms.setup.update6to7.A_CmsUpdateDBPart
execute, getDbInstance, getPoolData, isKeepHistory, loadQueryProperties, readQuery, setPoolData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLUMN_PROJECT_ID

protected static final java.lang.String COLUMN_PROJECT_ID
Constant for the sql column PROJECT_ID.

See Also:
Constant Field Values

COLUMN_PROJECT_LASTMODIFIED

protected static final java.lang.String COLUMN_PROJECT_LASTMODIFIED
Constant for the sql query to use the column PROJECT_LASTMODIFIED.

See Also:
Constant Field Values

COLUMN_PROJECT_UUID

protected static final java.lang.String COLUMN_PROJECT_UUID
Constant for the sql column PROJECT_UUID.

See Also:
Constant Field Values

COLUMN_TEMP_PROJECT_UUID

protected static final java.lang.String COLUMN_TEMP_PROJECT_UUID
Constant for the sql column TEMP_PROJECT_UUID.

See Also:
Constant Field Values

HISTORY_PROJECTS_TABLE

protected static final java.lang.String HISTORY_PROJECTS_TABLE
Constant for the table name of the CMS_HISTORY_PROJECTS table.

See Also:
Constant Field Values

QUERY_ADD_PRIMARY_KEY

protected static final java.lang.String QUERY_ADD_PRIMARY_KEY
Constant for the sql query to add a new primary key.

See Also:
Constant Field Values

QUERY_ADD_TEMP_UUID_COLUMN

protected static final java.lang.String QUERY_ADD_TEMP_UUID_COLUMN
Constant for the sql query to add a new column to the table.

See Also:
Constant Field Values

QUERY_CREATE_HISTORY_PROJECTS_TABLE

protected static final java.lang.String QUERY_CREATE_HISTORY_PROJECTS_TABLE
Constant for the sql query to create the new CMS_HISTORY_PROJECTS table.

See Also:
Constant Field Values

QUERY_CREATE_TEMP_TABLE_UUIDS

protected static final java.lang.String QUERY_CREATE_TEMP_TABLE_UUIDS
Constant for the sql query to create the temporary table.

See Also:
Constant Field Values

QUERY_DESCRIBE_TABLE

protected static final java.lang.String QUERY_DESCRIBE_TABLE
Constant for the sql query to describe the given table.

See Also:
Constant Field Values

QUERY_READ_MAX_PUBTAG

protected static final java.lang.String QUERY_READ_MAX_PUBTAG
Constant for the sql query to read max publish tag.

See Also:
Constant Field Values

REPLACEMENT_COLUMN

protected static final java.lang.String REPLACEMENT_COLUMN
Constant for the replacement in the SQL query for the columnname.

See Also:
Constant Field Values

REPLACEMENT_NEW_COLUMN

protected static final java.lang.String REPLACEMENT_NEW_COLUMN
Constant for the replacement in the SQL query for the new columnname.

See Also:
Constant Field Values

REPLACEMENT_OLDID

protected static final java.lang.String REPLACEMENT_OLDID
Constant for the replacement in the SQL query for old id to update.

See Also:
Constant Field Values

REPLACEMENT_PRIMARY_KEY

protected static final java.lang.String REPLACEMENT_PRIMARY_KEY
Constant for the replacement in the SQL query for the primary key.

See Also:
Constant Field Values

REPLACEMENT_TABLENAME

protected static final java.lang.String REPLACEMENT_TABLENAME
Constant for the replacement in the SQL query for the tablename.

See Also:
Constant Field Values

RESOURCE_TABLES

protected static final java.lang.String[] RESOURCE_TABLES
Array of the online and offline resources tables.


RESOURCES_TABLES_LIST

protected static final java.util.List RESOURCES_TABLES_LIST
Arraylist for the online and offline resources tables that shall be updated.


TABLES

protected static final java.lang.String[] TABLES
Array of the tables that are to be updated.


TABLES_LIST

protected static final java.util.List TABLES_LIST
Arraylist for the tables that shall be updated.


TEMP_UUID_COLUMN

protected static final java.lang.String TEMP_UUID_COLUMN
Constant for the temporary UUID column in the tables.

See Also:
Constant Field Values

TEMPORARY_TABLE_NAME

protected static final java.lang.String TEMPORARY_TABLE_NAME
Constant for the name of temporary table containing the project ids and uuids.

See Also:
Constant Field Values
Constructor Detail

CmsUpdateDBProjectId

public CmsUpdateDBProjectId()
                     throws java.io.IOException
Constructor.

Throws:
java.io.IOException - if the query properties cannot be read
Method Detail

addPrimaryKey

protected void addPrimaryKey(CmsSetupDb dbCon,
                             java.lang.String tablename,
                             java.lang.String primaryKey)
                      throws java.sql.SQLException
Adds a new primary key to the given table.

Parameters:
dbCon - the db connection interface
tablename - the table to add the primary key to
primaryKey - the new primary key
Throws:
java.sql.SQLException - if something goes wrong

addUUIDColumnToTable

protected void addUUIDColumnToTable(CmsSetupDb dbCon,
                                    java.lang.String tablename,
                                    java.lang.String column)
                             throws java.sql.SQLException
Adds the new column for the uuids to a table.

Parameters:
dbCon - the db connection interface
tablename - the table to add the column to
column - the new colum to add
Throws:
java.sql.SQLException - if something goes wrong

checkColumnTypeProjectId

protected boolean checkColumnTypeProjectId(int type)
Check if the column type of the project id is incorrect.

Parameters:
type - the type of the column from the meta data
Returns:
true if the type is incorrect

createHistProjectsTable

protected void createHistProjectsTable(CmsSetupDb dbCon)
                                throws java.sql.SQLException
Creates the CMS_HISTORY_PROJECTS table if it does not exist yet.

Parameters:
dbCon - the db connection interface
Throws:
java.sql.SQLException - if soemthing goes wrong

createTempTable

protected void createTempTable(CmsSetupDb dbCon)
                        throws java.sql.SQLException
Creates the temp table for project ids if it does not exist yet.

Parameters:
dbCon - the db connection interface
Throws:
java.sql.SQLException - if soemthing goes wrong

getColumnProjectIdResourcePath

protected java.lang.String getColumnProjectIdResourcePath()
Returns the columns for the primary key of the project resources table.

Returns:
the columns for the primary key of the project resources table

internalExecute

protected void internalExecute(CmsSetupDb dbCon)
                        throws java.sql.SQLException
Description copied from class: A_CmsUpdateDBPart
Does the hard work.

Specified by:
internalExecute in class A_CmsUpdateDBPart
Parameters:
dbCon - the db connection interface
Throws:
java.sql.SQLException - if somethign goes wrong
See Also:
A_CmsUpdateDBPart.internalExecute(org.opencms.setup.CmsSetupDb)

needsUpdating

protected boolean needsUpdating(CmsSetupDb dbCon,
                                java.lang.String tablename)
                         throws java.sql.SQLException
Checks if the given table needs an update of the uuids.

Parameters:
dbCon - the db connection interface
tablename - the table to check
Returns:
true if the project ids are not yet updated, false if nothing needs to be done
Throws:
java.sql.SQLException - if something goes wrong

transferDataToHistoryTable

protected void transferDataToHistoryTable(CmsSetupDb dbCon)
                                   throws java.sql.SQLException
Transfers the data from the CMS_BACKUP_PROJECTS to the CMS_HISTORY_PROJECTS table.

The datetime type for the column PROJECT_PUBLISHDATE is converted to the new long value.

Parameters:
dbCon - the db connection interface
Throws:
java.sql.SQLException - if something goes wrong