net.sf.farrago.ddl
Class DdlReloadTableStmt

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

public abstract class DdlReloadTableStmt
extends DdlStmt
implements DdlMultipleTransactionStmt

DdlReloadTableStmt is an abstract base for statements which need to self-insert data from an existing table. Currently this includes ALTER TABLE REBUILD and ALTER TABLE ADD COLUMN.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/ddl/DdlReloadTableStmt.java#8 $
Author:
John Pham, John Sichi

Nested Class Summary
private  class DdlReloadTableStmt.ReloadTableIndexMap
          A special index map used when rebuildIndexes=true.
 
Field Summary
private  FarragoSessionIndexMap baseIndexMap
           
private  boolean rebuildingIndexes
           
private  FarragoSessionIndexMap rebuildMap
           
private  String recoveryRefMofId
           
private  String reloadSql
           
private  FarragoRepos repos
           
private  CwmTable table
           
private  RefClass tableClass
           
private  String tableMofId
           
private  FarragoDataWrapperCache wrapperCache
           
private  Map<String,Long> writeIndexMap
           
 
Constructor Summary
DdlReloadTableStmt(CwmTable table)
          Constructs a DdlReloadTableStmt.
 
Method Summary
 void completeAfterExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session, boolean success)
          Provides access to the repository after execution of the DDL.
 boolean completeRequiresWriteTxn()
          Checks whether the DdlMultipleTransactionStmt.completeAfterExecuteUnlocked( FarragoSessionDdlValidator, FarragoSession, boolean) method requires a repository write transaction.
private  void crashIfTrapSet()
           
 void executeUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
          Executes long-running DDL actions.
protected  CwmTable getOldTableStructureForIndexMap()
           
protected abstract  String getReloadDml(SqlPrettyWriter writer)
          Generates the SQL to be used to reload the table.
protected  CwmTable getTable()
           
 void prepForExecuteUnlocked(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
          Provides access to the repository in preparation for the execution of DdlStmt.
protected  void recoverFromFailure(FarragoSessionDdlValidator ddlValidator, FarragoSession session)
          Called after an exception is thrown during the execution phase.
protected  void setRecoveryRef(FemRecoveryReference recoveryRef)
          Sets up a recovery reference to be used in the event of a crash.
protected  boolean shouldRebuildIndexes(FarragoSessionDdlValidator ddlValidator)
          Determines whether statement execution should rebuild all indexes on the table.
private  void sleepIfTrapSet()
           
 void visit(DdlVisitor visitor)
          Invokes a visitor on this statement.
 
Methods inherited from class net.sf.farrago.ddl.DdlStmt
getModelElement, isDropRestricted, postCommit, postExecute, preExecute, preValidate, 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, preValidate, requiresCommit, runsAsDml
 

Field Detail

table

private CwmTable table

tableMofId

private String tableMofId

tableClass

private RefClass tableClass

repos

private FarragoRepos repos

baseIndexMap

private FarragoSessionIndexMap baseIndexMap

wrapperCache

private FarragoDataWrapperCache wrapperCache

writeIndexMap

private Map<String,Long> writeIndexMap

rebuildMap

private FarragoSessionIndexMap rebuildMap

reloadSql

private String reloadSql

rebuildingIndexes

private boolean rebuildingIndexes

recoveryRefMofId

private String recoveryRefMofId
Constructor Detail

DdlReloadTableStmt

public DdlReloadTableStmt(CwmTable table)
Constructs a DdlReloadTableStmt.

Parameters:
table - target table
Method Detail

visit

public void visit(DdlVisitor visitor)
Description copied from class: DdlStmt
Invokes a visitor on this statement.

Specified by:
visit in class DdlStmt
Parameters:
visitor - DdlVisitor to invoke

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
Parameters:
ddlValidator - DDL validator for this statement
See Also:
FarragoReposTxnContext

executeUnlocked

public void executeUnlocked(FarragoSessionDdlValidator ddlValidator,
                            FarragoSession session)
Description copied from interface: DdlMultipleTransactionStmt
Executes long-running DDL actions. This method is invoked outside the context of any repository transaction.

Specified by:
executeUnlocked in interface DdlMultipleTransactionStmt
Parameters:
ddlValidator - DDL validator for this statement
session - reentrant Farrago session which may be used to execute DML statements

sleepIfTrapSet

private void sleepIfTrapSet()

completeRequiresWriteTxn

public boolean completeRequiresWriteTxn()
Description copied from interface: DdlMultipleTransactionStmt
Checks whether the DdlMultipleTransactionStmt.completeAfterExecuteUnlocked( FarragoSessionDdlValidator, FarragoSession, boolean) method requires a repository write transaction.

Specified by:
completeRequiresWriteTxn in interface DdlMultipleTransactionStmt
Returns:
true if a write txn must be started before executing the completion step, false if a read txn is sufficient

recoverFromFailure

protected void recoverFromFailure(FarragoSessionDdlValidator ddlValidator,
                                  FarragoSession session)
Called after an exception is thrown during the execution phase.

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

crashIfTrapSet

private void crashIfTrapSet()

shouldRebuildIndexes

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

Parameters:
ddlValidator - validator for this DDL statement
Returns:
whether to rebuild

getReloadDml

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

Parameters:
writer - writer to uses for generating SQL
Returns:
DML statement which accomplishes reload

setRecoveryRef

protected void setRecoveryRef(FemRecoveryReference recoveryRef)
Sets up a recovery reference to be used in the event of a crash.

Parameters:
recoveryRef - recovery reference for this operation

getTable

protected CwmTable getTable()
Returns:
the table affected by this statement

getOldTableStructureForIndexMap

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