org.h2.table
Class TableData

java.lang.Object
  extended by org.h2.engine.DbObjectBase
      extended by org.h2.schema.SchemaObjectBase
          extended by org.h2.table.Table
              extended by org.h2.table.TableData
All Implemented Interfaces:
DbObject, SchemaObject, RecordReader

public class TableData
extends Table
implements RecordReader

Most tables are an instance of this class. For this table, the data is stored in the database. The actual data is not kept here, instead it is kept in the indexes. There is at least one index, the scan index.


Field Summary
 
Fields inherited from class org.h2.table.Table
columns, compareMode, memoryPerRow, SYSTEM_TABLE, TABLE, TABLE_LINK, TYPE_CACHED, TYPE_MEMORY, VIEW
 
Fields inherited from class org.h2.engine.DbObjectBase
comment, database, trace
 
Fields inherited from interface org.h2.engine.DbObject
AGGREGATE, COMMENT, CONSTANT, CONSTRAINT, FUNCTION_ALIAS, INDEX, RIGHT, ROLE, SCHEMA, SEQUENCE, SETTING, TABLE_OR_VIEW, TRIGGER, USER, USER_DATATYPE
 
Constructor Summary
TableData(CreateTableData data)
           
 
Method Summary
 Index addIndex(Session session, java.lang.String indexName, int indexId, IndexColumn[] cols, IndexType indexType, int headPos, java.lang.String indexComment)
          Create an index for this table
 void addRow(Session session, Row row)
          Add a row to the table and all indexes.
 boolean canDrop()
          Check if this table can be dropped.
 boolean canGetRowCount()
          Check if the row count can be retrieved quickly.
 boolean canTruncate()
          Check if this table can be truncated.
 ObjectArray<Session> checkDeadlock(Session session, Session clash, java.util.Set<Session> visited)
          Check if a deadlock occurred.
 void checkRename()
          Check if this object can be renamed.
 void checkSupportAlter()
          Check if this table supports ALTER TABLE.
 void close(Session session)
          Close the table object and flush changes.
 Row createRow(Value[] data)
          Create a row from the values.
 boolean getContainsLargeObject()
           
 java.lang.String getCreateSQL()
          Build a SQL statement to re-create this object.
 java.lang.String getDropSQL()
          Build a SQL statement to drop this object.
 int getHeadPos()
          Get the position of the head record.
 ObjectArray<Index> getIndexes()
          Get all indexes for this table.
 long getMaxDataModificationId()
          Get the last data modification id.
 Row getRow(Session session, long key)
          Read the given row.
 long getRowCount(Session session)
          Get the row count for this table.
 long getRowCountApproximation()
          Get the approximated row count for this table.
 Index getScanIndex(Session session)
          Get the scan index to iterate through all rows.
 java.lang.String getTableType()
          Get the table type name
 Index getUniqueIndex()
          Get any unique index for this table if one exists.
 boolean isDeterministic()
          Check if the table is deterministic.
 boolean isGlobalTemporary()
           
 boolean isLockedExclusively()
          Check if this table is locked exclusively.
 void lock(Session session, boolean exclusive, boolean force)
          Lock the table for the given session.
 Record read(Session session, DataPage s)
          Read a record from the data page.
 Row readRow(DataPage s)
          Read a row from the data page.
 void removeChildrenAndResources(Session session)
          Remove all dependent objects and free all resources (files, blocks in files) of this object.
 void removeRow(Session session, Row row)
          Remove a row from the table and all indexes.
 void setCompareMode(CompareMode compareMode)
           
 void setGlobalTemporary(boolean globalTemporary)
           
 void setRowCount(long count)
          Set the row count of this table.
 java.lang.String toString()
           
 void truncate(Session session)
          Remove all rows from the table and indexes.
 void unlock(Session s)
          Release the lock for this session.
 
Methods inherited from class org.h2.table.Table
addConstraint, addDependencies, addSequence, addTrigger, addView, checkColumnIsNotReferenced, compareTypeSave, findPrimaryKey, fireAfter, fireAfterRow, fireBefore, fireBeforeRow, fireRow, getBestPlanItem, getCheckForeignKeyConstraints, getChildren, getColumn, getColumn, getColumns, getCompareMode, getConstraints, getCreateSQLForCopy, getIndexForColumn, getOnCommitDrop, getOnCommitTruncate, getPrimaryKey, getTemplateRow, getTemplateSimpleRow, getType, isPersistData, isPersistIndexes, removeConstraint, removeIndex, removeIndexOrTransferOwnership, removeSequence, removeTrigger, rename, renameColumn, setCheckForeignKeyConstraints, setColumns, setOnCommitDrop, setOnCommitTruncate, updateRows, validateConvertUpdateSequence
 
Methods inherited from class org.h2.schema.SchemaObjectBase
getSchema, getSQL, initSchemaObjectBase
 
Methods inherited from class org.h2.engine.DbObjectBase
getComment, getDatabase, getId, getModificationId, getName, initDbObjectBase, invalidate, isTemporary, setComment, setModified, setObjectName, setTemporary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.h2.engine.DbObject
getComment, getDatabase, getId, getModificationId, getName, isTemporary, setComment, setModified, setTemporary
 

Constructor Detail

TableData

public TableData(CreateTableData data)
          throws java.sql.SQLException
Throws:
java.sql.SQLException
Method Detail

getHeadPos

public int getHeadPos()
Description copied from interface: DbObject
Get the position of the head record.

Specified by:
getHeadPos in interface DbObject
Overrides:
getHeadPos in class DbObjectBase
Returns:
the head position

close

public void close(Session session)
           throws java.sql.SQLException
Description copied from class: Table
Close the table object and flush changes.

Specified by:
close in class Table
Parameters:
session - the session
Throws:
java.sql.SQLException

getRow

public Row getRow(Session session,
                  long key)
           throws java.sql.SQLException
Read the given row.

Parameters:
session - the session
key - unique key
Returns:
the row
Throws:
java.sql.SQLException

addRow

public void addRow(Session session,
                   Row row)
            throws java.sql.SQLException
Description copied from class: Table
Add a row to the table and all indexes.

Specified by:
addRow in class Table
Parameters:
session - the session
row - the row
Throws:
java.sql.SQLException - if a constraint was violated

getScanIndex

public Index getScanIndex(Session session)
Description copied from class: Table
Get the scan index to iterate through all rows.

Specified by:
getScanIndex in class Table
Parameters:
session - the session
Returns:
the index

getUniqueIndex

public Index getUniqueIndex()
Description copied from class: Table
Get any unique index for this table if one exists.

Specified by:
getUniqueIndex in class Table
Returns:
a unique index

getIndexes

public ObjectArray<Index> getIndexes()
Description copied from class: Table
Get all indexes for this table.

Specified by:
getIndexes in class Table
Returns:
the list of indexes

addIndex

public Index addIndex(Session session,
                      java.lang.String indexName,
                      int indexId,
                      IndexColumn[] cols,
                      IndexType indexType,
                      int headPos,
                      java.lang.String indexComment)
               throws java.sql.SQLException
Description copied from class: Table
Create an index for this table

Specified by:
addIndex in class Table
Parameters:
session - the session
indexName - the name of the index
indexId - the id
cols - the index columns
indexType - the index type
headPos - the position of the head (if the index already exists)
indexComment - the comment
Returns:
the index
Throws:
java.sql.SQLException

canGetRowCount

public boolean canGetRowCount()
Description copied from class: Table
Check if the row count can be retrieved quickly.

Specified by:
canGetRowCount in class Table
Returns:
true if it can

canDrop

public boolean canDrop()
Description copied from class: Table
Check if this table can be dropped.

Specified by:
canDrop in class Table
Returns:
true if it can

getRowCount

public long getRowCount(Session session)
Description copied from class: Table
Get the row count for this table.

Specified by:
getRowCount in class Table
Parameters:
session - the session
Returns:
the row count

removeRow

public void removeRow(Session session,
                      Row row)
               throws java.sql.SQLException
Description copied from class: Table
Remove a row from the table and all indexes.

Specified by:
removeRow in class Table
Parameters:
session - the session
row - the row
Throws:
java.sql.SQLException

truncate

public void truncate(Session session)
              throws java.sql.SQLException
Description copied from class: Table
Remove all rows from the table and indexes.

Specified by:
truncate in class Table
Parameters:
session - the session
Throws:
java.sql.SQLException

lock

public void lock(Session session,
                 boolean exclusive,
                 boolean force)
          throws java.sql.SQLException
Description copied from class: Table
Lock the table for the given session. This method waits until the lock is granted.

Specified by:
lock in class Table
Parameters:
session - the session
exclusive - true for write locks, false for read locks
force - lock even in the MVCC mode
Throws:
java.sql.SQLException - if a lock timeout occurred

checkDeadlock

public ObjectArray<Session> checkDeadlock(Session session,
                                          Session clash,
                                          java.util.Set<Session> visited)
Description copied from class: Table
Check if a deadlock occurred. This method is called recursively. There is a circle if the session to be tested has already being visited. If this session is part of the circle (if it is the clash session), the method must return an empty object array. Once a deadlock has been detected, the methods must add the session to the list. If this session is not part of the circle, or if no deadlock is detected, this method returns null.

Overrides:
checkDeadlock in class Table
Parameters:
session - the session to be tested for
clash - set with sessions already visited, and null when starting verification
visited - set with sessions already visited, and null when starting verification
Returns:
an object array with the sessions involved in the deadlock, or null

getDropSQL

public java.lang.String getDropSQL()
Description copied from class: DbObjectBase
Build a SQL statement to drop this object.

Specified by:
getDropSQL in interface DbObject
Specified by:
getDropSQL in class DbObjectBase
Returns:
the SQL statement

getCreateSQL

public java.lang.String getCreateSQL()
Description copied from class: DbObjectBase
Build a SQL statement to re-create this object.

Specified by:
getCreateSQL in interface DbObject
Specified by:
getCreateSQL in class DbObjectBase
Returns:
the SQL statement

isLockedExclusively

public boolean isLockedExclusively()
Description copied from class: Table
Check if this table is locked exclusively.

Specified by:
isLockedExclusively in class Table
Returns:
true if it is.

unlock

public void unlock(Session s)
Description copied from class: Table
Release the lock for this session.

Specified by:
unlock in class Table
Parameters:
s - the session

read

public Record read(Session session,
                   DataPage s)
            throws java.sql.SQLException
Description copied from interface: RecordReader
Read a record from the data page.

Specified by:
read in interface RecordReader
Parameters:
session - the session
s - the data page
Returns:
the record
Throws:
java.sql.SQLException

readRow

public Row readRow(DataPage s)
            throws java.sql.SQLException
Read a row from the data page.

Parameters:
s - the data page
Returns:
the row
Throws:
java.sql.SQLException

createRow

public Row createRow(Value[] data)
Create a row from the values.

Parameters:
data - the value list
Returns:
the row

setRowCount

public void setRowCount(long count)
Set the row count of this table.

Parameters:
count - the row count

removeChildrenAndResources

public void removeChildrenAndResources(Session session)
                                throws java.sql.SQLException
Description copied from class: DbObjectBase
Remove all dependent objects and free all resources (files, blocks in files) of this object.

Specified by:
removeChildrenAndResources in interface DbObject
Overrides:
removeChildrenAndResources in class Table
Parameters:
session - the session
Throws:
java.sql.SQLException

toString

public java.lang.String toString()
Overrides:
toString in class DbObjectBase

checkRename

public void checkRename()
Description copied from class: DbObjectBase
Check if this object can be renamed. System objects may not be renamed.

Specified by:
checkRename in interface DbObject
Specified by:
checkRename in class DbObjectBase

checkSupportAlter

public void checkSupportAlter()
Description copied from class: Table
Check if this table supports ALTER TABLE.

Specified by:
checkSupportAlter in class Table

canTruncate

public boolean canTruncate()
Description copied from class: Table
Check if this table can be truncated.

Overrides:
canTruncate in class Table
Returns:
true if it can

getTableType

public java.lang.String getTableType()
Description copied from class: Table
Get the table type name

Specified by:
getTableType in class Table
Returns:
the table type name

setGlobalTemporary

public void setGlobalTemporary(boolean globalTemporary)

isGlobalTemporary

public boolean isGlobalTemporary()
Overrides:
isGlobalTemporary in class Table

getMaxDataModificationId

public long getMaxDataModificationId()
Description copied from class: Table
Get the last data modification id.

Specified by:
getMaxDataModificationId in class Table
Returns:
the modification id

getContainsLargeObject

public boolean getContainsLargeObject()

getRowCountApproximation

public long getRowCountApproximation()
Description copied from class: Table
Get the approximated row count for this table.

Specified by:
getRowCountApproximation in class Table
Returns:
the approximated row count

setCompareMode

public void setCompareMode(CompareMode compareMode)

isDeterministic

public boolean isDeterministic()
Description copied from class: Table
Check if the table is deterministic.

Specified by:
isDeterministic in class Table
Returns:
true if it is