com.ptc.windchill.upgrade.history
Class JdbcIUHPersistenceDelegate

java.lang.Object
  extended bycom.ptc.windchill.upgrade.history.IUHPersistenceDelegate
      extended bycom.ptc.windchill.upgrade.history.JdbcIUHPersistenceDelegate
All Implemented Interfaces:
ReleaseId.AssemblyIdResolver

public class JdbcIUHPersistenceDelegate
extends IUHPersistenceDelegate
implements ReleaseId.AssemblyIdResolver


Field Summary
private static String ASSEMBLY_ID_COLUMN
           
private static String ASSEMBLY_INSTALLATIONID_COLUMN
           
private static String ASSEMBLY_RELEASEID_COLUMN
           
private static String ASSEMBLY_TABLE
           
private  ConnectionProvider connectionProvider_
           
private static String DDL_ASSEMBLY_ID
           
private static int FIRST_INSTALLATION
           
private static String INSTALLATION_COMPLETE_COLUMN
           
private static String INSTALLATION_ID_COLUMN
           
private static String INSTALLATION_TABLE
           
private static String INSTALLATION_TIMESTAMP_COLUMN
           
private static String IU_NAME_COLUMN
           
private static String IU_TABLE
           
private static String IU_UPGRADEPHASEID_COLUMN
           
private static String IU_UUID_COLUMN
           
private static String MARK_INSTALLATION_COMPLETE
           
private static String MARK_UPGRADE_PHASE_COMPLETE
           
private static String PJL_ASSEMBLY_ID
           
private static String SELECT_ALL_FROM_INSTALLATION
           
private static String SELECT_INSTALLATION_ASSEMBLIES
           
private static String SELECT_INSTALLATION_UPGRADE_PHASES
           
private static String SELECT_IS_INSTALLATION_COMPLETE
           
private static String SELECT_IS_UPGRADE_PHASE_COMPLETE
           
private static String SELECT_IU_APPLICATIONS
           
private static HashMap tableToDefMaps__
           
private static String UPGRADE_PHASE_COMPLETE_COLUMN
           
private static String UPGRADE_PHASE_ID_COLUMN
           
private static String UPGRADE_PHASE_INSTALLATIONID_COLUMN
           
private static String UPGRADE_PHASE_PHASETYPE_COLUMN
           
private static String UPGRADE_PHASE_TABLE
           
private static String WNC_ASSEMBLY_ID
           
 
Fields inherited from class com.ptc.windchill.upgrade.history.IUHPersistenceDelegate
 
Constructor Summary
JdbcIUHPersistenceDelegate(ConnectionProvider connection_provider)
          Creates a new JdbcIUHPersistenceDelegate object.
 
Method Summary
protected  boolean areAssembliesDirty(Installation installation)
           
protected  boolean areInstallationsDirty()
           
protected  boolean areIUApplicationsDirty(UpgradePhase upgrade_phase)
           
protected  boolean areUpgradePhasesDirty(Installation installation)
           
protected  void clear()
          Removes all contents from the history.
protected  void clearNewHistoryTables(Connection connection)
          Removes all contents from the history.
private  Transaction commitTransaction(Transaction transaction)
           
protected  Assembly createAssembly(Installation installation, ReleaseId release_identifier)
          Adding a new entry to the WTUPGINST_VERSIONEDASSEMBLY table
protected  Installation createInstallation(Date timestamp)
          Adding an installation to the WTUPGINST_INSTALLATION table.
protected  IUApplication createIUApplication(UpgradePhase upgrade_phase, UUID uuid, String name)
          Adding an entry to the table WTUPGINST_INCREMENTALUPDATE after a migrator was successfully completed.
private  String createTableFor(String table_name)
           
private  void createTableIfNecessary(String table_name)
           
protected  UpgradePhase createUpgradePhase(Installation installation, UpgradePhaseType phase_type)
          Adding an UpgradePhase to the table WTUPGINST_UPGRADEPHASE corresponding to an installation
private  String deleteAllFor(String table_name)
           
private  void ensureTablesExist()
           
protected  void flush()
          Saves uncommitted work done in the current thread.
protected  ArrayList getAssemblies(Installation installation)
           
private  Connection getConnection()
           
private static String[][] getDefFor(String table_name)
           
protected  ArrayList getInstallations()
          Retrieves the installation that are stored in the database.
protected  ArrayList getIUApplications(UpgradePhase upgrade_phase)
          Retrieves all the IncrementalUpdates that have been executed for a specific UpgradePhase that is in the table.
protected  ArrayList getUpgradePhases(Installation installation)
          Retrieves all the entries of Installation in the table WTUPGINST_INSTALLATION
private  String insertFor(String table_name)
           
protected  boolean isComplete(Installation installation)
          Able to find out if the Installation is complete or not
protected  boolean isComplete(UpgradePhase upgrade_phase)
          Able to check if an UpgradePhase is complete or not complete.
private  boolean isSchema62()
          The schema is 6.2
private  boolean isSchema623()
          The schema is 6.2.3
private  boolean isSchemaPre62()
          The schema is pre-6.2
protected  void markComplete(Installation installation, boolean complete)
          Marks the installation complete
protected  void markComplete(UpgradePhase upgrade_phase, boolean complete)
          Marking the Upgrade Phase as complete.
private  void migrate623To7()
           
private  void migrate623WtUpgInstAssemblyTo7(Connection conn)
           
private  void migrate623WTVersionStepTo7(Connection conn)
           
private  void migrate62To7()
          select versions add assembly id insert into assembly table with new release identifiers drop version column from versionstep
private  void migrate62WTVersionStepTo7(Connection conn)
           
private  void migratePre62To7()
           
private  void migratePre62WTVersionStepTo7(Connection conn)
           
private  void migrateWtIncrementalUpdateTo7(Connection conn)
           
private  void migrationInsertInstallation(int installation_id, boolean complete, Date timestamp, Connection conn)
           
private  void migrationInsertInstallation(int installation_id, boolean complete, Date timestamp, ReleaseId release_id, Connection conn)
           
private  boolean needTable(String table_name)
           
private  int nextAssemblyId()
          Looks up the next sequential installation OID based on the maximum id from the Assembly table.
private  int nextId(String col_name, String table_name, String type_description)
          Looks up the next sequential installation OID based on the maximum id from the specified column on the specified table.
private  int nextInstallationId()
          Looks up the next sequential installation OID based on the maximum id from the Installation table.
private  int nextUpgradePhaseId()
          Looks up the next sequential installation OID based on the maximum id from the UpgradePhase table.
 String resolveAssemblyIdFor(int major, int minor, int service_pack, int dsu, int build)
          For any version other than 6.1 assume WNC.
private  void rollbackTransaction(Transaction trans)
           
private  Transaction startTransaction()
           
 
Methods inherited from class com.ptc.windchill.upgrade.history.IUHPersistenceDelegate
addInvalidateable, invalidate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIRST_INSTALLATION

private static final int FIRST_INSTALLATION
See Also:
Constant Field Values

WNC_ASSEMBLY_ID

private static final String WNC_ASSEMBLY_ID
See Also:
Constant Field Values

PJL_ASSEMBLY_ID

private static final String PJL_ASSEMBLY_ID
See Also:
Constant Field Values

DDL_ASSEMBLY_ID

private static final String DDL_ASSEMBLY_ID
See Also:
Constant Field Values

INSTALLATION_TABLE

private static final String INSTALLATION_TABLE
See Also:
Constant Field Values

INSTALLATION_ID_COLUMN

private static final String INSTALLATION_ID_COLUMN
See Also:
Constant Field Values

INSTALLATION_COMPLETE_COLUMN

private static final String INSTALLATION_COMPLETE_COLUMN
See Also:
Constant Field Values

INSTALLATION_TIMESTAMP_COLUMN

private static final String INSTALLATION_TIMESTAMP_COLUMN
See Also:
Constant Field Values

ASSEMBLY_TABLE

private static final String ASSEMBLY_TABLE
See Also:
Constant Field Values

ASSEMBLY_ID_COLUMN

private static final String ASSEMBLY_ID_COLUMN
See Also:
Constant Field Values

ASSEMBLY_RELEASEID_COLUMN

private static final String ASSEMBLY_RELEASEID_COLUMN
See Also:
Constant Field Values

ASSEMBLY_INSTALLATIONID_COLUMN

private static final String ASSEMBLY_INSTALLATIONID_COLUMN
See Also:
Constant Field Values

UPGRADE_PHASE_TABLE

private static final String UPGRADE_PHASE_TABLE
See Also:
Constant Field Values

UPGRADE_PHASE_ID_COLUMN

private static final String UPGRADE_PHASE_ID_COLUMN
See Also:
Constant Field Values

UPGRADE_PHASE_PHASETYPE_COLUMN

private static final String UPGRADE_PHASE_PHASETYPE_COLUMN
See Also:
Constant Field Values

UPGRADE_PHASE_COMPLETE_COLUMN

private static final String UPGRADE_PHASE_COMPLETE_COLUMN
See Also:
Constant Field Values

UPGRADE_PHASE_INSTALLATIONID_COLUMN

private static final String UPGRADE_PHASE_INSTALLATIONID_COLUMN
See Also:
Constant Field Values

IU_TABLE

private static final String IU_TABLE
See Also:
Constant Field Values

IU_UUID_COLUMN

private static final String IU_UUID_COLUMN
See Also:
Constant Field Values

IU_NAME_COLUMN

private static final String IU_NAME_COLUMN
See Also:
Constant Field Values

IU_UPGRADEPHASEID_COLUMN

private static final String IU_UPGRADEPHASEID_COLUMN
See Also:
Constant Field Values

tableToDefMaps__

private static HashMap tableToDefMaps__

SELECT_ALL_FROM_INSTALLATION

private static final String SELECT_ALL_FROM_INSTALLATION
See Also:
Constant Field Values

SELECT_INSTALLATION_ASSEMBLIES

private static final String SELECT_INSTALLATION_ASSEMBLIES
See Also:
Constant Field Values

SELECT_INSTALLATION_UPGRADE_PHASES

private static final String SELECT_INSTALLATION_UPGRADE_PHASES
See Also:
Constant Field Values

SELECT_IU_APPLICATIONS

private static final String SELECT_IU_APPLICATIONS
See Also:
Constant Field Values

SELECT_IS_INSTALLATION_COMPLETE

private static final String SELECT_IS_INSTALLATION_COMPLETE
See Also:
Constant Field Values

SELECT_IS_UPGRADE_PHASE_COMPLETE

private static final String SELECT_IS_UPGRADE_PHASE_COMPLETE
See Also:
Constant Field Values

MARK_INSTALLATION_COMPLETE

private static final String MARK_INSTALLATION_COMPLETE
See Also:
Constant Field Values

MARK_UPGRADE_PHASE_COMPLETE

private static final String MARK_UPGRADE_PHASE_COMPLETE
See Also:
Constant Field Values

connectionProvider_

private ConnectionProvider connectionProvider_
Constructor Detail

JdbcIUHPersistenceDelegate

public JdbcIUHPersistenceDelegate(ConnectionProvider connection_provider)
                           throws IUHException
Creates a new JdbcIUHPersistenceDelegate object.

Parameters:
connection_provider - Connection is needed to the database to make use of this class.
Throws:
IUHException
Method Detail

getDefFor

private static String[][] getDefFor(String table_name)

createTableFor

private String createTableFor(String table_name)

insertFor

private String insertFor(String table_name)

deleteAllFor

private String deleteAllFor(String table_name)

startTransaction

private Transaction startTransaction()
                              throws IUHException
Throws:
IUHException

commitTransaction

private Transaction commitTransaction(Transaction transaction)
                               throws IUHException
Throws:
IUHException

rollbackTransaction

private void rollbackTransaction(Transaction trans)

areInstallationsDirty

protected boolean areInstallationsDirty()
Specified by:
areInstallationsDirty in class IUHPersistenceDelegate
Returns:
false

getInstallations

protected ArrayList getInstallations()
                              throws IUHException
Retrieves the installation that are stored in the database.

Specified by:
getInstallations in class IUHPersistenceDelegate
Returns:
ret an ArrayList of the installations in the db
Throws:
IUHException - If an SQLException occurs

createInstallation

protected Installation createInstallation(Date timestamp)
                                   throws IUHException
Adding an installation to the WTUPGINST_INSTALLATION table.

Specified by:
createInstallation in class IUHPersistenceDelegate
Parameters:
timestamp -
Returns:
Installation
Throws:
IUHException - Unable to add an installation to the table

markComplete

protected void markComplete(Installation installation,
                            boolean complete)
                     throws IUHException
Marks the installation complete

Specified by:
markComplete in class IUHPersistenceDelegate
Parameters:
installation - Installation
complete - boolean
Throws:
IUHException - If all the phases in the database are not marked complete

markComplete

protected void markComplete(UpgradePhase upgrade_phase,
                            boolean complete)
                     throws IUHException
Marking the Upgrade Phase as complete.

Specified by:
markComplete in class IUHPersistenceDelegate
Parameters:
upgrade_phase - UpgradePhase
complete - boolean
Throws:
IUHException

areAssembliesDirty

protected boolean areAssembliesDirty(Installation installation)
Specified by:
areAssembliesDirty in class IUHPersistenceDelegate
Parameters:
installation - Installation
Returns:
false

getAssemblies

protected ArrayList getAssemblies(Installation installation)
                           throws IUHException
Specified by:
getAssemblies in class IUHPersistenceDelegate
Parameters:
installation - Installation
Returns:
ArrayList
Throws:
IUHException

createAssembly

protected Assembly createAssembly(Installation installation,
                                  ReleaseId release_identifier)
                           throws IUHException
Adding a new entry to the WTUPGINST_VERSIONEDASSEMBLY table

Specified by:
createAssembly in class IUHPersistenceDelegate
Parameters:
installation - Installation
release_identifier - Version
Returns:
Assembly
Throws:
IUHException

isComplete

protected boolean isComplete(Installation installation)
                      throws IUHException
Able to find out if the Installation is complete or not

Specified by:
isComplete in class IUHPersistenceDelegate
Parameters:
installation - Installation
Returns:
boolean
Throws:
IUHException

areUpgradePhasesDirty

protected boolean areUpgradePhasesDirty(Installation installation)
Specified by:
areUpgradePhasesDirty in class IUHPersistenceDelegate
Parameters:
installation - Installation
Returns:
false

getUpgradePhases

protected ArrayList getUpgradePhases(Installation installation)
                              throws IUHException
Retrieves all the entries of Installation in the table WTUPGINST_INSTALLATION

Specified by:
getUpgradePhases in class IUHPersistenceDelegate
Parameters:
installation - Installation
Returns:
ArrayList of Installation entries in the database
Throws:
IUHException

createUpgradePhase

protected UpgradePhase createUpgradePhase(Installation installation,
                                          UpgradePhaseType phase_type)
                                   throws IUHException
Adding an UpgradePhase to the table WTUPGINST_UPGRADEPHASE corresponding to an installation

Specified by:
createUpgradePhase in class IUHPersistenceDelegate
Parameters:
installation - Installation
phase_type - UpgradePhaseType
Returns:
UpgradePhase
Throws:
IUHException

isComplete

protected boolean isComplete(UpgradePhase upgrade_phase)
                      throws IUHException
Able to check if an UpgradePhase is complete or not complete.

Specified by:
isComplete in class IUHPersistenceDelegate
Parameters:
upgrade_phase - UpgradePhase
Returns:
boolean
Throws:
IUHException - Thrown if unable to determine what the phase is

areIUApplicationsDirty

protected boolean areIUApplicationsDirty(UpgradePhase upgrade_phase)
Specified by:
areIUApplicationsDirty in class IUHPersistenceDelegate
Parameters:
upgrade_phase - UpgradePhase
Returns:
false

getIUApplications

protected ArrayList getIUApplications(UpgradePhase upgrade_phase)
                               throws IUHException
Retrieves all the IncrementalUpdates that have been executed for a specific UpgradePhase that is in the table.

Specified by:
getIUApplications in class IUHPersistenceDelegate
Parameters:
upgrade_phase - UpgradePhase
Returns:
ArrayList of IUApplications
Throws:
IUHException - Problems with the SQL statement

createIUApplication

protected IUApplication createIUApplication(UpgradePhase upgrade_phase,
                                            UUID uuid,
                                            String name)
                                     throws IUHException
Adding an entry to the table WTUPGINST_INCREMENTALUPDATE after a migrator was successfully completed.

Specified by:
createIUApplication in class IUHPersistenceDelegate
Parameters:
upgrade_phase - UpgradePhase
uuid - The generated number of the IncrementalUpdate executed successfully
name - The name of the IncrementalUpdate that was just executed
Returns:
IUApplication
Throws:
IUHException - Thrown when unable to add an entry

clear

protected void clear()
              throws IUHException
Description copied from class: IUHPersistenceDelegate
Removes all contents from the history.

Specified by:
clear in class IUHPersistenceDelegate
Throws:
IUHException

clearNewHistoryTables

protected void clearNewHistoryTables(Connection connection)
                              throws IUHException
Removes all contents from the history.

Throws:
IUHException

flush

protected final void flush()
                    throws IUHException
Saves uncommitted work done in the current thread.

Overrides:
flush in class IUHPersistenceDelegate
Throws:
IUHException

nextInstallationId

private int nextInstallationId()
                        throws IUHException
Looks up the next sequential installation OID based on the maximum id from the Installation table.

Returns:
an integer greater than 0 (1 for the first time it's called against a database).
Throws:
IUHException - wrapping a SQLException if there's a problem performing the query.

nextAssemblyId

private int nextAssemblyId()
                    throws IUHException
Looks up the next sequential installation OID based on the maximum id from the Assembly table.

Returns:
an integer greater than 0 (1 for the first time it's called against a database).
Throws:
IUHException - wrapping a SQLException if there's a problem performing the query.

nextUpgradePhaseId

private int nextUpgradePhaseId()
                        throws IUHException
Looks up the next sequential installation OID based on the maximum id from the UpgradePhase table.

Returns:
an integer greater than 0 (1 for the first time it's called against a database).
Throws:
IUHException - wrapping a SQLException if there's a problem performing the query.

nextId

private int nextId(String col_name,
                   String table_name,
                   String type_description)
            throws IUHException
Looks up the next sequential installation OID based on the maximum id from the specified column on the specified table.

Returns:
an integer greater than 0 (1 for the first time it's called against a database).
Throws:
IUHException - wrapping a SQLException if there's a problem performing the query.

getConnection

private Connection getConnection()
                          throws IUHException
Throws:
IUHException

needTable

private boolean needTable(String table_name)
                   throws SQLException,
                          IUHException
Throws:
SQLException
IUHException

createTableIfNecessary

private void createTableIfNecessary(String table_name)
                             throws SQLException,
                                    IUHException
Throws:
SQLException
IUHException

ensureTablesExist

private void ensureTablesExist()
                        throws IUHException
Throws:
IUHException

isSchemaPre62

private boolean isSchemaPre62()
                       throws SQLException,
                              IUHException
The schema is pre-6.2

Throws:
SQLException
IUHException

isSchema62

private boolean isSchema62()
                    throws SQLException,
                           IUHException
The schema is 6.2

Throws:
SQLException
IUHException

isSchema623

private boolean isSchema623()
                     throws SQLException,
                            IUHException
The schema is 6.2.3

Throws:
SQLException
IUHException

migratePre62To7

private void migratePre62To7()
                      throws SQLException,
                             IUHException
Throws:
SQLException
IUHException

migrate62To7

private void migrate62To7()
                   throws SQLException,
                          IUHException
select versions add assembly id insert into assembly table with new release identifiers drop version column from versionstep

Throws:
SQLException
IUHException

migrate623To7

private void migrate623To7()
                    throws SQLException,
                           IUHException
Throws:
SQLException
IUHException

migrationInsertInstallation

private void migrationInsertInstallation(int installation_id,
                                         boolean complete,
                                         Date timestamp,
                                         Connection conn)
                                  throws SQLException
Throws:
SQLException

migrationInsertInstallation

private void migrationInsertInstallation(int installation_id,
                                         boolean complete,
                                         Date timestamp,
                                         ReleaseId release_id,
                                         Connection conn)
                                  throws SQLException,
                                         IUHException
Throws:
SQLException
IUHException

migratePre62WTVersionStepTo7

private void migratePre62WTVersionStepTo7(Connection conn)
                                   throws SQLException,
                                          IUHException
Throws:
SQLException
IUHException

migrate62WTVersionStepTo7

private void migrate62WTVersionStepTo7(Connection conn)
                                throws SQLException,
                                       IUHException
Throws:
SQLException
IUHException

migrate623WTVersionStepTo7

private void migrate623WTVersionStepTo7(Connection conn)
                                 throws SQLException,
                                        IUHException
Throws:
SQLException
IUHException

migrate623WtUpgInstAssemblyTo7

private void migrate623WtUpgInstAssemblyTo7(Connection conn)
                                     throws SQLException
Throws:
SQLException

migrateWtIncrementalUpdateTo7

private void migrateWtIncrementalUpdateTo7(Connection conn)
                                    throws SQLException
Throws:
SQLException

resolveAssemblyIdFor

public String resolveAssemblyIdFor(int major,
                                   int minor,
                                   int service_pack,
                                   int dsu,
                                   int build)
                            throws ReleaseIdException
For any version other than 6.1 assume WNC. If we encounter a 6.1 version number, then we don't automatically know if it's PJL or DDL. Resolve to one or the other based on if PJL or DDL is installed on the target system. If neither PJL nor DDL is installed, or if both are installed then a ReleaseIdException will be thrown.

Specified by:
resolveAssemblyIdFor in interface ReleaseId.AssemblyIdResolver
Returns:
a non-null String that is at least two characters long.
Throws:
ReleaseIdException - if the assembly id cannot be resolved