net.sf.farrago.db
Class FarragoDbSessionIndexMap

java.lang.Object
  extended by org.eigenbase.util.CompoundClosableAllocation
      extended by net.sf.farrago.util.FarragoCompoundAllocation
          extended by net.sf.farrago.db.FarragoDbSessionIndexMap
All Implemented Interfaces:
FarragoSessionIndexMap, FarragoAllocation, FarragoAllocationOwner, ClosableAllocation, ClosableAllocationOwner

 class FarragoDbSessionIndexMap
extends FarragoCompoundAllocation
implements FarragoSessionIndexMap

FarragoDbSessionIndexMap implements FarragoSessionIndexMap, resolving indexes for both permanent and temporary tables.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/db/FarragoDbSessionIndexMap.java#29 $
Author:
John V. Sichi

Field Summary
private  FarragoDbSession dbSession
           
private  FarragoDataWrapperCache privateDataWrapperCache
          Cache for local data wrappers used to manage indexes.
private  FarragoRepos repos
          Repos for this session.
private  Map<String,Long> tempIndexRootMap
          Map from index MOF ID to root PageId for temporary tables.
 
Fields inherited from class org.eigenbase.util.CompoundClosableAllocation
allocations
 
Constructor Summary
FarragoDbSessionIndexMap(FarragoAllocationOwner owner, FarragoDbSession dbSession, FarragoRepos repos)
          Creates a new FarragoDbSessionIndexMap.
 
Method Summary
 void closeAllocation()
          Closes this object.
 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.
private  void dropIndexStorageImpl(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, String indexMofId, boolean truncate)
           
 FemLocalIndex getIndexById(long id)
          Gets an index by its repository ID.
private  FarragoMedLocalDataServer getIndexDataServer(FarragoDataWrapperCache wrapperCache, FemLocalIndex index)
           
 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: truncates any indexes for tables defined with ON COMMIT DELETE ROWS.
 void setIndexRoot(FemLocalIndex index, long root)
          Sets the root PageId of an index.
 void versionIndexRoot(FarragoDataWrapperCache wrapperCache, FemLocalIndex index, Long newRoot)
          Versions an index root page.
 
Methods inherited from class org.eigenbase.util.CompoundClosableAllocation
addAllocation, forgetAllocation, hasAllocations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eigenbase.util.ClosableAllocationOwner
addAllocation
 

Field Detail

dbSession

private FarragoDbSession dbSession

tempIndexRootMap

private Map<String,Long> tempIndexRootMap
Map from index MOF ID to root PageId for temporary tables.


repos

private FarragoRepos repos
Repos for this session.


privateDataWrapperCache

private FarragoDataWrapperCache privateDataWrapperCache
Cache for local data wrappers used to manage indexes.

Constructor Detail

FarragoDbSessionIndexMap

public FarragoDbSessionIndexMap(FarragoAllocationOwner owner,
                                FarragoDbSession dbSession,
                                FarragoRepos repos)
Creates a new FarragoDbSessionIndexMap.

Parameters:
owner - FarragoAllocationOwner which will own this map; on closeAllocation, any temporary indexes will be deleted automatically
dbSession - FarragoDbSession context
repos - the repos for this session
Method Detail

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

closeAllocation

public void closeAllocation()
Description copied from interface: ClosableAllocation
Closes this object.

Specified by:
closeAllocation in interface ClosableAllocation
Overrides:
closeAllocation in class CompoundClosableAllocation

onCommit

public void onCommit()
Commit hook: truncates any indexes for tables defined with ON COMMIT DELETE ROWS.

Specified by:
onCommit in interface FarragoSessionIndexMap

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

dropIndexStorageImpl

private void dropIndexStorageImpl(FarragoDataWrapperCache wrapperCache,
                                  FemLocalIndex index,
                                  String indexMofId,
                                  boolean truncate)

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

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

getIndexDataServer

private FarragoMedLocalDataServer getIndexDataServer(FarragoDataWrapperCache wrapperCache,
                                                     FemLocalIndex index)

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