org.apache.derby.impl.store.access.heap
Class Heap

java.lang.Object
  extended by org.apache.derby.iapi.types.DataType
      extended by org.apache.derby.impl.store.access.conglomerate.GenericConglomerate
          extended by org.apache.derby.impl.store.access.heap.Heap
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Comparable, Formatable, Storable, TypedFormat, Conglomerate, StaticCompiledOpenConglomInfo, DataValueDescriptor, Orderable
Direct Known Subclasses:
Heap_v10_2

public class Heap
extends GenericConglomerate
implements Conglomerate, StaticCompiledOpenConglomInfo

A heap object corresponds to an instance of a heap conglomerate. It caches information which makes it fast to open heap controllers from it.

See Also:
Serialized Form

Field Summary
private static int BASE_MEMORY_USAGE
           
protected  int[] collation_ids
          The array of collation id's for each column in the template.
protected  int conglom_format_id
          Format id of the conglomerate.
private static int CONTAINER_KEY_MEMORY_USAGE
           
(package private)  int[] format_ids
          The format id's of each of the columns in the heap table.
private  ContainerKey id
           
 
Fields inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
UNKNOWN_LOGICAL_LENGTH
 
Fields inherited from interface org.apache.derby.iapi.types.Orderable
ORDER_OP_EQUALS, ORDER_OP_GREATEROREQUALS, ORDER_OP_GREATERTHAN, ORDER_OP_LESSOREQUALS, ORDER_OP_LESSTHAN
 
Constructor Summary
Heap()
          Zero arg constructor for Monitor to create empty object.
 
Method Summary
 void addColumn(TransactionManager xact_manager, int column_id, Storable template_column, int collation_id)
          Add a column to the heap conglomerate.
 void boot_create(long containerid, DataValueDescriptor[] template)
          Create a heap conglomerate during the boot process.
 void compressConglomerate(TransactionManager xact_manager, Transaction rawtran)
           
protected  void create(Transaction rawtran, int segmentId, long input_containerid, DataValueDescriptor[] template, ColumnOrdering[] columnOrder, int[] collationIds, java.util.Properties properties, int conglom_format_id, int tmpFlag)
          Create a heap conglomerate.
 ScanManager defragmentConglomerate(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level)
          Open a heap compress scan.
 void drop(TransactionManager xact_manager)
          Drop this heap.
 int estimateMemoryUsage()
          Estimate the memory usage in bytes of the data value and the overhead of the class.
 boolean fetchMaxOnBTree(TransactionManager xact_manager, Transaction rawtran, long conglomId, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] fetchRow)
          Retrieve the maximum value row in an ordered conglomerate.
 DataValueDescriptor getConglom()
          return the "Conglomerate".
 long getContainerid()
          Get the containerid of conglomerate.
 DynamicCompiledOpenConglomInfo getDynamicCompiledConglomInfo()
          Return dynamic information about the conglomerate to be dynamically reused in repeated execution of a statement.
 ContainerKey getId()
          Get the id of the container of the conglomerate.
 StaticCompiledOpenConglomInfo getStaticCompiledConglomInfo(TransactionController tc, long conglomId)
          Return static information about the conglomerate to be included in a a compiled plan.
 int getTypeFormatId()
          Return my format identifier.
 boolean isNull()
          Return whether the value is null or not.
 boolean isTemporary()
          Is this conglomerate temporary?
 long load(TransactionManager xact_manager, boolean createConglom, RowLocationRetRowSource rowSource)
          Bulk load into the conglomerate.
private  void localReadExternal(java.io.ObjectInput in)
          Restore the in-memory representation from the stream.
 ConglomerateController open(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info)
          Open a heap controller.
 ScanManager openScan(TransactionManager xact_manager, Transaction rawtran, boolean hold, int open_mode, int lock_level, LockingPolicy locking_policy, int isolation_level, FormatableBitSet scanColumnList, DataValueDescriptor[] startKeyValue, int startSearchOperator, Qualifier[][] qualifier, DataValueDescriptor[] stopKeyValue, int stopSearchOperator, StaticCompiledOpenConglomInfo static_info, DynamicCompiledOpenConglomInfo dynamic_info)
          Open a heap scan controller.
 StoreCostController openStoreCost(TransactionManager xact_manager, Transaction rawtran)
          Return an open StoreCostController for the conglomerate.
 void purgeConglomerate(TransactionManager xact_manager, Transaction rawtran)
           
 void readExternal(java.io.ObjectInput in)
           
 void readExternalFromArray(ArrayInputStream in)
          Read the DataValueDescriptor from the stream.
 void restoreToNull()
          Restore the in-memory representation to the null value.
 java.lang.String toString()
          Print this heap.
protected  void writeExternal_v10_2(java.io.ObjectOutput out)
          Store the 10.2 format stored representation of column value in stream.
 void writeExternal(java.io.ObjectOutput out)
          Store the stored representation of column value in stream.
 
Methods inherited from class org.apache.derby.impl.store.access.conglomerate.GenericConglomerate
cloneValue, compare, getLength, getNewNull, getObject, getString, getTypeName, setFrom, setValueFromResultSet
 
Methods inherited from class org.apache.derby.iapi.types.DataType
checkHostVariable, cloneHolder, coalesce, compare, compare, compare, compareTo, dataTypeConversion, equals, equals, flip, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLong, getNationalString, getShort, getStream, getTime, getTimestamp, getTraceString, greaterOrEquals, greaterThan, hasStream, in, invalidFormat, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, outOfRange, recycle, setBigDecimal, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, throwLangSetMismatch, typePrecedence, typeToBigDecimal
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.derby.iapi.types.DataValueDescriptor
checkHostVariable, cloneHolder, cloneValue, coalesce, compare, compare, compare, compare, equals, getBoolean, getByte, getBytes, getDate, getDouble, getFloat, getInt, getLength, getLong, getNewNull, getObject, getShort, getStream, getString, getTime, getTimestamp, getTraceString, getTypeName, greaterOrEquals, greaterThan, hasStream, in, isNotNull, isNullOp, lessOrEquals, lessThan, normalize, notEquals, recycle, setBigDecimal, setInto, setInto, setObjectForCast, setToNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromResultSet, typePrecedence, typeToBigDecimal
 

Field Detail

conglom_format_id

protected int conglom_format_id
Format id of the conglomerate.


id

private ContainerKey id

format_ids

int[] format_ids
The format id's of each of the columns in the heap table.


collation_ids

protected int[] collation_ids
The array of collation id's for each column in the template.


BASE_MEMORY_USAGE

private static final int BASE_MEMORY_USAGE

CONTAINER_KEY_MEMORY_USAGE

private static final int CONTAINER_KEY_MEMORY_USAGE
Constructor Detail

Heap

public Heap()
Zero arg constructor for Monitor to create empty object.

Method Detail

estimateMemoryUsage

public int estimateMemoryUsage()
Description copied from interface: DataValueDescriptor
Estimate the memory usage in bytes of the data value and the overhead of the class.

Specified by:
estimateMemoryUsage in interface DataValueDescriptor
Returns:
the estimated memory usage

create

protected void create(Transaction rawtran,
                      int segmentId,
                      long input_containerid,
                      DataValueDescriptor[] template,
                      ColumnOrdering[] columnOrder,
                      int[] collationIds,
                      java.util.Properties properties,
                      int conglom_format_id,
                      int tmpFlag)
               throws StandardException
Create a heap conglomerate.

Create a heap conglomerate. This method is called from the heap factory to create a new instance of a heap.

Throws:
StandardException - Standard exception policy.

boot_create

public void boot_create(long containerid,
                        DataValueDescriptor[] template)
Create a heap conglomerate during the boot process.

Manufacture a Heap Conglomerate out of "thin" air, to boot strap the system. Create an in-memory Heap Conglomerate with the input parameters, The caller will use this to open the conglomerate conglomerate and read the "real" values from disk. Conglom-conglom is always on segment 0.

Parameters:
containerid - The container id of the conglomerate.
template - Object array describing the columns of the heap.

addColumn

public void addColumn(TransactionManager xact_manager,
                      int column_id,
                      Storable template_column,
                      int collation_id)
               throws StandardException
Add a column to the heap conglomerate.

This routine update's the in-memory object version of the Heap Conglomerate to have one more column of the type described by the input template column.

Specified by:
addColumn in interface Conglomerate
Parameters:
column_id - The column number to add this column at.
template_column - An instance of the column to be added to table.
collation_id - Collation id of the column added.
xact_manager - The TransactionController under which this operation takes place.
Throws:
StandardException - Standard exception policy.

drop

public void drop(TransactionManager xact_manager)
          throws StandardException
Drop this heap.

Specified by:
drop in interface Conglomerate
Throws:
StandardException - Standard exception policy.
See Also:
Conglomerate.drop(org.apache.derby.iapi.store.access.conglomerate.TransactionManager)

fetchMaxOnBTree

public boolean fetchMaxOnBTree(TransactionManager xact_manager,
                               Transaction rawtran,
                               long conglomId,
                               int open_mode,
                               int lock_level,
                               LockingPolicy locking_policy,
                               int isolation_level,
                               FormatableBitSet scanColumnList,
                               DataValueDescriptor[] fetchRow)
                        throws StandardException
Retrieve the maximum value row in an ordered conglomerate.

Returns true and fetches the rightmost row of an ordered conglomerate into "fetchRow" if there is at least one row in the conglomerate. If there are no rows in the conglomerate it returns false.

Non-ordered conglomerates will not implement this interface, calls will generate a StandardException.

RESOLVE - this interface is temporary, long term equivalent (and more) functionality will be provided by the openBackwardScan() interface.

Specified by:
fetchMaxOnBTree in interface Conglomerate
Parameters:
conglomId - The identifier of the conglomerate to open the scan for.
open_mode - Specifiy flags to control opening of table. OPENMODE_FORUPDATE - if set open the table for update otherwise open table shared.
lock_level - One of (MODE_TABLE, MODE_RECORD, or MODE_NONE).
isolation_level - The isolation level to lock the conglomerate at. One of (ISOLATION_READ_COMMITTED or ISOLATION_SERIALIZABLE).
scanColumnList - A description of which columns to return from every fetch in the scan. template, and scanColumnList work together to describe the row to be returned by the scan - see RowUtil for description of how these three parameters work together to describe a "row".
fetchRow - The row to retrieve the maximum value into.
xact_manager - The TransactionController under which this operation takes place.
rawtran - The raw store xact to associate all ops with.
locking_policy - The LockingPolicy to use to open the conglomerate.
Returns:
boolean indicating if a row was found and retrieved or not.
Throws:
StandardException - Standard exception policy.

getId

public final ContainerKey getId()
Get the id of the container of the conglomerate.

Will have to change when a conglomerate could have more than one container. The ContainerKey is a combination of the container id and segment id.

Specified by:
getId in interface Conglomerate
Returns:
The ContainerKey.

getContainerid

public final long getContainerid()
Description copied from interface: Conglomerate
Get the containerid of conglomerate.

Will have to change when a conglomerate could have more than one containerid.

Specified by:
getContainerid in interface Conglomerate
Returns:
The containerid.

getDynamicCompiledConglomInfo

public DynamicCompiledOpenConglomInfo getDynamicCompiledConglomInfo()
                                                             throws StandardException
Return dynamic information about the conglomerate to be dynamically reused in repeated execution of a statement.

The dynamic info is a set of variables to be used in a given ScanController or ConglomerateController. It can only be used in one controller at a time. It is up to the caller to insure the correct thread access to this info. The type of info in this is a scratch template for btree traversal, other scratch variables for qualifier evaluation, ...

Specified by:
getDynamicCompiledConglomInfo in interface Conglomerate
Returns:
The dynamic information.
Throws:
StandardException - Standard exception policy.

getStaticCompiledConglomInfo

public StaticCompiledOpenConglomInfo getStaticCompiledConglomInfo(TransactionController tc,
                                                                  long conglomId)
                                                           throws StandardException
Return static information about the conglomerate to be included in a a compiled plan.

The static info would be valid until any ddl was executed on the conglomid, and would be up to the caller to throw away when that happened. This ties in with what language already does for other invalidation of static info. The type of info in this would be containerid and array of format id's from which templates can be created. The info in this object is read only and can be shared among as many threads as necessary.

Specified by:
getStaticCompiledConglomInfo in interface Conglomerate
Parameters:
conglomId - The identifier of the conglomerate to open.
tc - The TransactionController under which this operation takes place.
Returns:
The static compiled information.
Throws:
StandardException - Standard exception policy.

isTemporary

public boolean isTemporary()
Is this conglomerate temporary?

Specified by:
isTemporary in interface Conglomerate
Returns:
whether conglomerate is temporary or not.

load

public long load(TransactionManager xact_manager,
                 boolean createConglom,
                 RowLocationRetRowSource rowSource)
          throws StandardException
Bulk load into the conglomerate.

Specified by:
load in interface Conglomerate
Parameters:
xact_manager - The TransactionController under which this operation takes place.
createConglom - If true, the conglomerate is being created in the same operation as the openAndLoadConglomerate. The enables further optimization as recovery does not require page allocation to be logged.
rowSource - Where the rows come from.
Returns:
The number of rows loaded.
Throws:
StandardException - Standard exception policy.
See Also:
Conglomerate.load(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, boolean, org.apache.derby.iapi.store.access.RowLocationRetRowSource)

open

public ConglomerateController open(TransactionManager xact_manager,
                                   Transaction rawtran,
                                   boolean hold,
                                   int open_mode,
                                   int lock_level,
                                   LockingPolicy locking_policy,
                                   StaticCompiledOpenConglomInfo static_info,
                                   DynamicCompiledOpenConglomInfo dynamic_info)
                            throws StandardException
Open a heap controller.

Specified by:
open in interface Conglomerate
Parameters:
xact_manager - The access xact to associate all ops on cc with.
rawtran - The raw store xact to associate all ops on cc with.
open_mode - A bit mask of TransactionController.MODE_* bits, indicating info about the open.
lock_level - Either TransactionController.MODE_TABLE or TransactionController.MODE_RECORD, as passed into the openConglomerate() call.
locking_policy - The LockingPolicy to use to open the conglomerate.
Returns:
The open ConglomerateController.
Throws:
StandardException - Standard exception policy.
See Also:
Conglomerate.open(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, org.apache.derby.iapi.store.raw.Transaction, boolean, int, int, org.apache.derby.iapi.store.raw.LockingPolicy, org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo, org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)

openScan

public ScanManager openScan(TransactionManager xact_manager,
                            Transaction rawtran,
                            boolean hold,
                            int open_mode,
                            int lock_level,
                            LockingPolicy locking_policy,
                            int isolation_level,
                            FormatableBitSet scanColumnList,
                            DataValueDescriptor[] startKeyValue,
                            int startSearchOperator,
                            Qualifier[][] qualifier,
                            DataValueDescriptor[] stopKeyValue,
                            int stopSearchOperator,
                            StaticCompiledOpenConglomInfo static_info,
                            DynamicCompiledOpenConglomInfo dynamic_info)
                     throws StandardException
Open a heap scan controller.

Specified by:
openScan in interface Conglomerate
Throws:
StandardException - Standard exception policy.
See Also:
Conglomerate.openScan(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, org.apache.derby.iapi.store.raw.Transaction, boolean, int, int, org.apache.derby.iapi.store.raw.LockingPolicy, int, org.apache.derby.iapi.services.io.FormatableBitSet, org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.Qualifier[][], org.apache.derby.iapi.types.DataValueDescriptor[], int, org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo, org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo)

purgeConglomerate

public void purgeConglomerate(TransactionManager xact_manager,
                              Transaction rawtran)
                       throws StandardException
Specified by:
purgeConglomerate in interface Conglomerate
Throws:
StandardException

compressConglomerate

public void compressConglomerate(TransactionManager xact_manager,
                                 Transaction rawtran)
                          throws StandardException
Specified by:
compressConglomerate in interface Conglomerate
Throws:
StandardException

defragmentConglomerate

public ScanManager defragmentConglomerate(TransactionManager xact_manager,
                                          Transaction rawtran,
                                          boolean hold,
                                          int open_mode,
                                          int lock_level,
                                          LockingPolicy locking_policy,
                                          int isolation_level)
                                   throws StandardException
Open a heap compress scan.

Specified by:
defragmentConglomerate in interface Conglomerate
hold - see openScan()
open_mode - see openScan()
lock_level - see openScan()
isolation_level - see openScan()
Returns:
The GroupFetchScanController to be used to fetch the rows.
Throws:
StandardException - Standard exception policy.
See Also:
Conglomerate.defragmentConglomerate(org.apache.derby.iapi.store.access.conglomerate.TransactionManager, org.apache.derby.iapi.store.raw.Transaction, boolean, int, int, org.apache.derby.iapi.store.raw.LockingPolicy, int)

openStoreCost

public StoreCostController openStoreCost(TransactionManager xact_manager,
                                         Transaction rawtran)
                                  throws StandardException
Return an open StoreCostController for the conglomerate.

Return an open StoreCostController which can be used to ask about the estimated row counts and costs of ScanController and ConglomerateController operations, on the given conglomerate.

Specified by:
openStoreCost in interface Conglomerate
Parameters:
xact_manager - The TransactionController under which this operation takes place.
rawtran - raw transaction context in which scan is managed.
Returns:
The open StoreCostController.
Throws:
StandardException - Standard exception policy.
See Also:
StoreCostController

toString

public java.lang.String toString()
Print this heap.

Overrides:
toString in class java.lang.Object

getConglom

public DataValueDescriptor getConglom()
return the "Conglomerate".

For heap just return "this", which both implements Conglomerate and StaticCompiledOpenConglomInfo.

Specified by:
getConglom in interface StaticCompiledOpenConglomInfo
Returns:
this

getTypeFormatId

public int getTypeFormatId()
Return my format identifier.

Specified by:
getTypeFormatId in interface TypedFormat
Returns:
The identifier. (A UUID stuffed in an array of 16 bytes).
See Also:
TypedFormat.getTypeFormatId()

isNull

public boolean isNull()
Return whether the value is null or not.

Specified by:
isNull in interface Storable
Returns:
true if the value is null and false otherwise.
See Also:
Storable.isNull()

restoreToNull

public void restoreToNull()
Restore the in-memory representation to the null value.

Specified by:
restoreToNull in interface Storable
See Also:
Storable.restoreToNull()

writeExternal_v10_2

protected void writeExternal_v10_2(java.io.ObjectOutput out)
                            throws java.io.IOException
Store the 10.2 format stored representation of column value in stream.

This routine stores the 10.2 version the Heap, ie. the ACCESS_HEAP_V2_ID format. It is used by any database which has been created in 10.2 or a previous release and has not been hard upgraded to a version subsequent to 10.2.

Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Store the stored representation of column value in stream.

This routine uses the current database version to either store the the 10.2 format (ACCESS_HEAP_V2_ID) or the current format (ACCESS_HEAP_V3_ID).

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

localReadExternal

private final void localReadExternal(java.io.ObjectInput in)
                              throws java.io.IOException,
                                     java.lang.ClassNotFoundException
Restore the in-memory representation from the stream.

Throws:
java.lang.ClassNotFoundException - Thrown if the stored representation is serialized and a class named in the stream could not be found.
java.io.IOException
See Also:
Externalizable.readExternal(java.io.ObjectInput)

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

readExternalFromArray

public void readExternalFromArray(ArrayInputStream in)
                           throws java.io.IOException,
                                  java.lang.ClassNotFoundException
Description copied from interface: DataValueDescriptor
Read the DataValueDescriptor from the stream.

Initialize the data value by reading it's values from the ArrayInputStream. This interface is provided as a way to achieve possible performance enhancement when reading an array can be optimized over reading from a generic stream from readExternal().

Specified by:
readExternalFromArray in interface DataValueDescriptor
Parameters:
in - The array stream positioned at the beginning of the byte stream to read from.
Throws:
java.io.IOException - Usual error is if you try to read past limit on the stream.
java.lang.ClassNotFoundException - If a necessary class can not be found while reading the object from the stream.

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.