net.sf.farrago.ddl
Class DdlAlterTableStructureStmt

java.lang.Object
  extended by net.sf.farrago.ddl.DdlStmt
      extended by net.sf.farrago.ddl.DdlReloadTableStmt
          extended by net.sf.farrago.ddl.DdlAlterTableStructureStmt
All Implemented Interfaces:
DdlMultipleTransactionStmt, FarragoSessionDdlStmt

public class DdlAlterTableStructureStmt
extends DdlReloadTableStmt

DdlAlterTableStructureStmt represents an ALTER TABLE statement which adds/drops columns or changes their datatype, implying that stored tuples may need to be reshaped. Currently it can only handle addition of a new column at the end. It extends DdlRebuildTableStmt since the default implementation for the reshape is to rebuild the entire table by copying from the old structure to the new.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/ddl/DdlAlterTableStructureStmt.java#6 $
Author:
John Sichi

Field Summary
private  CwmTable origTable
           
 
Constructor Summary
DdlAlterTableStructureStmt(FarragoRepos repos, CwmTable table)
           
 
Method Summary
private  RefObject cloneRefObj(JmiModelGraph oldModelGraph, JmiModelGraph newModelGraph, RefObject oldObj)
          Clones an object from one repository to another, sort of.
 void completeAfterExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session, boolean success)
          Provides access to the repository after execution of the DDL.
private static void deleteGrants(FarragoRepos repos, CwmModelElement element)
           
private static void deleteModelElement(FarragoRepos repos, CwmModelElement element)
           
protected  CwmTable getOldTableStructureForIndexMap()
           
protected  String getReloadDml(SqlPrettyWriter writer)
          Generates the SQL to be used to reload the table.
 void prepForExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
          Provides access to the repository in preparation for the execution of DdlStmt.
 void preValidate(FarragoSessionDdlValidator ddlValidator)
          Called before generic validation.
static void recover(FarragoRepos repos, CwmTable failedTable)
          Recovers after a problem (either execution failure or system crash) while a table was being altered.
protected  void recoverFromFailure(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
          Called after an exception is thrown during the execution phase.
protected  boolean shouldRebuildIndexes(FarragoSessionDdlValidator ddlValidator)
          Determines whether statement execution should rebuild all indexes on the table.
 
Methods inherited from class net.sf.farrago.ddl.DdlReloadTableStmt
completeRequiresWriteTxn, executeUnlocked, getTable, setRecoveryRef, visit
 
Methods inherited from class net.sf.farrago.ddl.DdlStmt
getModelElement, isDropRestricted, postCommit, postExecute, preExecute, requiresCommit, runsAsDml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.farrago.session.FarragoSessionDdlStmt
getModelElement, isDropRestricted, postCommit, postExecute, preExecute, requiresCommit, runsAsDml
 

Field Detail

origTable

private CwmTable origTable
Constructor Detail

DdlAlterTableStructureStmt

public DdlAlterTableStructureStmt(FarragoRepos repos,
                                  CwmTable table)
Method Detail

cloneRefObj

private RefObject cloneRefObj(JmiModelGraph oldModelGraph,
                              JmiModelGraph newModelGraph,
                              RefObject oldObj)
Clones an object from one repository to another, sort of.

TODO jvs 4-Dec-2008: make this handle more cases generically and then promote it to JmiObjUtil.

Parameters:
oldModelGraph - model graph for the old repository
newModelGraph - model graph for the new repository
oldObj - object to be cloned
Returns:
result of cloning

prepForExecuteUnlocked

public void prepForExecuteUnlocked(FarragoSessionDdlValidator ddlValidator,
                                   FarragoSession session)
Description copied from interface: DdlMultipleTransactionStmt
Provides access to the repository in preparation for the execution of DdlStmt. This method is invoked within the context the original repository transaction for the DDL statement. Whether that transaction is a write transaction depends on the DDL statement being executed.

Specified by:
prepForExecuteUnlocked in interface DdlMultipleTransactionStmt
Overrides:
prepForExecuteUnlocked in class DdlReloadTableStmt
Parameters:
ddlValidator - DDL validator for this statement
See Also:
FarragoReposTxnContext

getOldTableStructureForIndexMap

protected CwmTable getOldTableStructureForIndexMap()
Overrides:
getOldTableStructureForIndexMap in class DdlReloadTableStmt
Returns:
the old table structure if the table structure is being altered, or null if no change is taking place

preValidate

public void preValidate(FarragoSessionDdlValidator ddlValidator)
Description copied from interface: FarragoSessionDdlStmt
Called before generic validation.

Specified by:
preValidate in interface FarragoSessionDdlStmt
Overrides:
preValidate in class DdlStmt
Parameters:
ddlValidator - the object validating this stmt

shouldRebuildIndexes

protected boolean shouldRebuildIndexes(FarragoSessionDdlValidator ddlValidator)
Description copied from class: DdlReloadTableStmt
Determines whether statement execution should rebuild all indexes on the table. Some ooptimzed reloads may be able to avoid this.

Overrides:
shouldRebuildIndexes in class DdlReloadTableStmt
Parameters:
ddlValidator - validator for this DDL statement
Returns:
whether to rebuild

recover

public static void recover(FarragoRepos repos,
                           CwmTable failedTable)
Recovers after a problem (either execution failure or system crash) while a table was being altered.

Parameters:
repos - repository containing table definition
failedTable - table to recover

deleteModelElement

private static void deleteModelElement(FarragoRepos repos,
                                       CwmModelElement element)

deleteGrants

private static void deleteGrants(FarragoRepos repos,
                                 CwmModelElement element)

recoverFromFailure

protected void recoverFromFailure(FarragoSessionDdlValidator ddlValidator,
                                  FarragoSession session)
Description copied from class: DdlReloadTableStmt
Called after an exception is thrown during the execution phase.

Overrides:
recoverFromFailure in class DdlReloadTableStmt
Parameters:
ddlValidator - DDL validator for this statement
session - reentrant Farrago session

completeAfterExecuteUnlocked

public void completeAfterExecuteUnlocked(FarragoSessionDdlValidator ddlValidator,
                                         FarragoSession session,
                                         boolean success)
Description copied from interface: DdlMultipleTransactionStmt
Provides access to the repository after execution of the DDL. Typically implementations of this method modify the repository to store the results of DdlMultipleTransactionStmt.executeUnlocked(FarragoSessionDdlValidator, FarragoSession). This method is invoked in a locked repository transaction. The method DdlMultipleTransactionStmt.completeRequiresWriteTxn() controls whether the transaction read-only or not. This method may not access and/or modify repository objects loaded in a previous transaction unless they are reloaded by MOF ID. Be aware that objects may have been modified by another session unless some external mechanism (for instance, the "table-in-use" collection) guarantees that they have not been modified by another statement.

Note that any repository modifications made during the execution of this method will not be post-processed by DdlValidator. For instance, DdlValidator.checkJmiConstraints(RefObject) is not called, and therefore any mandatory default primitives are not automatically set, which will cause errors later if the attributes have not been explicitly initialized. See JmiObjUtil.setMandatoryPrimitiveDefaults(javax.jmi.reflect.RefObject).

Specified by:
completeAfterExecuteUnlocked in interface DdlMultipleTransactionStmt
Overrides:
completeAfterExecuteUnlocked in class DdlReloadTableStmt
Parameters:
ddlValidator - DDL validator for this statement
session - reentrant Farrago session which may be used to execute DML statements
success - whether the execution succeeded; detection of failure can be used to recover

getReloadDml

protected String getReloadDml(SqlPrettyWriter writer)
Description copied from class: DdlReloadTableStmt
Generates the SQL to be used to reload the table. Note that this is called from prepForExecuteUnlocked, so it is allowed to call getTable().

Specified by:
getReloadDml in class DdlReloadTableStmt
Parameters:
writer - writer to uses for generating SQL
Returns:
DML statement which accomplishes reload