net.sf.farrago.ddl
Class DdlReloadTableStmt.ReloadTableIndexMap

java.lang.Object
  extended by net.sf.farrago.ddl.DdlReloadTableStmt.ReloadTableIndexMap
All Implemented Interfaces:
FarragoSessionIndexMap
Enclosing class:
DdlReloadTableStmt

private class DdlReloadTableStmt.ReloadTableIndexMap
extends Object
implements FarragoSessionIndexMap

A special index map used when rebuildIndexes=true. This index map overrides index roots for writes, allowing reload queries such as:

"insert into t select * from t"
to copy data from old roots to new roots.


Field Summary
private  FarragoSessionIndexMap internalMap
           
private  Map<String,Long> writeIndexMap
           
 
Constructor Summary
DdlReloadTableStmt.ReloadTableIndexMap(FarragoSessionIndexMap internalMap, Map<String,Long> writeIndexMap)
          Constructs a ReloadTableIndexMap as a wrapper around a standard index map.
 
Method Summary
 FarragoMedLocalIndexStats computeIndexStats(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, boolean estimate)
          Verifies an index and records returns page count for the index.
 void createIndexStorage(FarragoDataWrapperCache wrapperCache, FemLocalIndex index)
          Creates an index and records its root in this map.
 long createIndexStorage(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, boolean updateMap)
          Creates an index and optionally records its root in this map.
 void dropIndexStorage(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, boolean truncate)
          Drops an index and removes its root from this map.
 void dropIndexStorage(FarragoDataWrapperCache wrapperCache, String indexMofId, boolean truncate)
          Drops an index by MOFID and removes its root from this map.
 FemLocalIndex getIndexById(long id)
          Gets an index by its repository ID.
 long getIndexRoot(FemLocalIndex index)
          Gets the root PageId of an index to be used for reading.
 long getIndexRoot(FemLocalIndex index, boolean write)
          Gets the root PageId of an index to be used for reading or for writing.
 CwmTable getOldTableStructure()
          For ALTER TABLE ADD COLUMN, retrieves the old table structure corresponding to the table being modified.
 CwmTable getReloadTable()
          For ALTER TABLE ADD COLUMN or REBUILD, retrieves the target table.
 void instantiateTemporaryTable(FarragoDataWrapperCache wrapperCache, CwmTable table)
          Called on every reference to a temporary table.
 void onCommit()
          Commit hook.
 void setIndexRoot(FemLocalIndex index, long pageId)
          Sets the root PageId of an index.
 void versionIndexRoot(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, Long newRoot)
          Versions an index root page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

internalMap

private FarragoSessionIndexMap internalMap

writeIndexMap

private Map<String,Long> writeIndexMap
Constructor Detail

DdlReloadTableStmt.ReloadTableIndexMap

public DdlReloadTableStmt.ReloadTableIndexMap(FarragoSessionIndexMap internalMap,
                                              Map<String,Long> writeIndexMap)
Constructs a ReloadTableIndexMap as a wrapper around a standard index map.

Parameters:
internalMap - the original index map
writeIndexMap - a mapping of roots to be returned for writes
Method Detail

getIndexById

public FemLocalIndex getIndexById(long id)
Description copied from interface: FarragoSessionIndexMap
Gets an index by its repository ID.

Specified by:
getIndexById in interface FarragoSessionIndexMap
Parameters:
id - index ID in repository
Returns:
corresponding index

getIndexRoot

public long getIndexRoot(FemLocalIndex index)
Description copied from interface: FarragoSessionIndexMap
Gets the root PageId of an index to be used for reading.

Specified by:
getIndexRoot in interface FarragoSessionIndexMap
Parameters:
index - the index of interest
Returns:
root PageId as a long

getIndexRoot

public long getIndexRoot(FemLocalIndex index,
                         boolean write)
Description copied from interface: FarragoSessionIndexMap
Gets the root PageId of an index to be used for reading or for writing.

Specified by:
getIndexRoot in interface FarragoSessionIndexMap
Parameters:
index - the index of interest
write - whether to access a root for reading or writing. A root for reading reflects the index before modifications. A root for writing may be the same root, or may reflect an updated index, depending on the implementation of the session index map.
Returns:
root PageId as a long

setIndexRoot

public void setIndexRoot(FemLocalIndex index,
                         long pageId)
Description copied from interface: FarragoSessionIndexMap
Sets the root PageId of an index.

Specified by:
setIndexRoot in interface FarragoSessionIndexMap
Parameters:
index - the index to be updated
pageId - the root PageId

instantiateTemporaryTable

public void instantiateTemporaryTable(FarragoDataWrapperCache wrapperCache,
                                      CwmTable table)
Description copied from interface: FarragoSessionIndexMap
Called on every reference to a temporary table. Some implementations may use this to create empty temporary indexes on first reference.

Specified by:
instantiateTemporaryTable in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
table - the temporary table

getReloadTable

public CwmTable getReloadTable()
Description copied from interface: FarragoSessionIndexMap
For ALTER TABLE ADD COLUMN or REBUILD, retrieves the target table.

Specified by:
getReloadTable in interface FarragoSessionIndexMap
Returns:
target table, or null if not executing ALTER TABLE ADD COLUMN or REBUILD

getOldTableStructure

public CwmTable getOldTableStructure()
Description copied from interface: FarragoSessionIndexMap
For ALTER TABLE ADD COLUMN, retrieves the old table structure corresponding to the table being modified. Be warned that the old table structure is not a complete copy; it consists of only the column definitions and their datatypes (without default values). Additional logical constructs such as constraints are not present on the returned object, nor are physical constructs such as indexes.

Specified by:
getOldTableStructure in interface FarragoSessionIndexMap
Returns:
copy of old table, or null if not executing ALTER TABLE ADD COLUMN

createIndexStorage

public void createIndexStorage(FarragoDataWrapperCache wrapperCache,
                               FemLocalIndex index)
Description copied from interface: FarragoSessionIndexMap
Creates an index and records its root in this map.

Specified by:
createIndexStorage in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
index - the index to create

createIndexStorage

public long createIndexStorage(FarragoDataWrapperCache wrapperCache,
                               FemLocalIndex index,
                               boolean updateMap)
Description copied from interface: FarragoSessionIndexMap
Creates an index and optionally records its root in this map.

Specified by:
createIndexStorage in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
index - the index to create
updateMap - whether to record the new root in the map
Returns:
the root of the newly created index storage

dropIndexStorage

public void dropIndexStorage(FarragoDataWrapperCache wrapperCache,
                             FemLocalIndex index,
                             boolean truncate)
Description copied from interface: FarragoSessionIndexMap
Drops an index and removes its root from this map.

Specified by:
dropIndexStorage in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
index - the index to drop
truncate - if true, only truncate storage; if false, drop storage entirely

dropIndexStorage

public void dropIndexStorage(FarragoDataWrapperCache wrapperCache,
                             String indexMofId,
                             boolean truncate)
Description copied from interface: FarragoSessionIndexMap
Drops an index by MOFID and removes its root from this map. This method is used in contexts (e.g. TRUNCATE) where it is undesirable to hold a catalog lock across the entire operation. (Really, this should be the case for all callers, so eventually we should deprecate the version which takes a direct index reference.)

Specified by:
dropIndexStorage in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
indexMofId - MOFID of the index to drop
truncate - if true, only truncate storage; if false, drop storage entirely

computeIndexStats

public FarragoMedLocalIndexStats computeIndexStats(FarragoDataWrapperCache wrapperCache,
                                                   FemLocalIndex index,
                                                   boolean estimate)
Description copied from interface: FarragoSessionIndexMap
Verifies an index and records returns page count for the index.

Specified by:
computeIndexStats in interface FarragoSessionIndexMap
Parameters:
wrapperCache - cache for looking up data wrappers
index - the index to verify
Returns:
page count for the index

onCommit

public void onCommit()
Description copied from interface: FarragoSessionIndexMap
Commit hook.

Specified by:
onCommit in interface FarragoSessionIndexMap

versionIndexRoot

public void versionIndexRoot(FarragoDataWrapperCache wrapperCache,
                             FemLocalIndex index,
                             Long newRoot)
Description copied from interface: FarragoSessionIndexMap
Versions an index root page.

Specified by:
versionIndexRoot in interface FarragoSessionIndexMap
Parameters:
wrapperCache - Wrapper cache
index - Index definition
newRoot - new index root ids