Top Description Fields Constructors Methods
org.hsqldb

public Class TableWorks

extends Object
Class Inheritance
Imports
org.hsqldb.HsqlNameManager.HsqlName, org.hsqldb.error.Error, .ErrorCode, org.hsqldb.index.Index, org.hsqldb.lib.ArrayUtil, .HsqlArrayList, .OrderedHashSet, org.hsqldb.navigator.RowIterator, org.hsqldb.persist.DataSpaceManager, .PersistentStore, org.hsqldb.rights.Grantee, org.hsqldb.types.Type, .Types

The methods in this class perform alterations to the structure of an existing table which may result in a new Table object
Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.0
Version
2.7.3

Field Summary

Modifier and TypeField and Description
private Database
pack-priv OrderedHashSet<HsqlNameManager.HsqlName>
private Session
private Table

Constructor Summary

AccessConstructor and Description
public
TableWorks(Session session, Table table)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
addColumn(ColumnSchema column, int colIndex, HsqlArrayList<Constraint> constraints)

pack-priv void
addForeignKey(Constraint
the constraint object
c
)

Creates a foreign key on an existing table.

pack-priv Index

Returns:

new index
addIndex
(int[]
int[]
col
,
HsqlNameManager.HsqlName
HsqlName
name
,
boolean
boolean
unique
)

Because of the way indexes and column data are held in memory and on disk, it is necessary to recreate the table when an index is added to a non-empty cached table.

pack-priv void
pack-priv void
pack-priv void
addUniqueConstraint(int[]
int[]
cols
,
HsqlNameManager.HsqlName
HsqlName
name
)

A unique constraint relies on a unique index on the table.

pack-priv void
pack-priv void
alterIndex(Index index, int[] columns)

pack-priv void
checkAddColumn(ColumnSchema
the Column to add to the Table, t
col
)

Checks if the attributes of the Column argument, c, are compatible with the operation of adding such a Column to the Table argument, table.

pack-priv void
checkAddDomainConstraint(Type
domain
domain
,
Constraint
added constraint
check
)

pack-priv void
pack-priv void
private void
checkModifyTable(boolean withContents)

pack-priv void
dropColumn(int colIndex, boolean cascade)

pack-priv void
dropConstraint(String name, boolean cascade)

pack-priv OrderedHashSet<Table>
pack-priv void
dropConstraintsAndIndexes(OrderedHashSet<HsqlNameManager.HsqlName> dropConstraintSet, OrderedHashSet<HsqlNameManager.HsqlName> dropIndexSet)

Drops a set of fk constraints, their indexes and other indexes in table.

pack-priv void
dropIndex(String
String
indexName
)

Because of the way indexes and column data are held in memory and on disk, it is necessary to recreate the table when an index is added to or removed from a non-empty table.

pack-priv void
dropSystemPeriod(boolean cascade)

pack-priv void
dropSystemVersioning(boolean cascade)

public Table
pack-priv void
moveData(Table oldTable, Table newTable, int[] colIndex, int adjust)

pack-priv void
pack-priv void
pack-priv void
retypeColumn(ColumnSchema
Column
oldCol
,
ColumnSchema
Column
newCol
)

Allows changing the type only.

private void
retypeColumn(ColumnSchema
Column
column
,
int
int
colIndex
)

pack-priv void
setColDefaultExpression(int
int
colIndex
,
Expression
Expression
def
)

performs the work for changing the default value of a column

pack-priv void
setColNullability(ColumnSchema
Column
column
,
boolean
boolean
nullable
)

performs the work for changing the nullability of a column

pack-priv void
pack-priv void
public boolean

Returns:

boolean
setTableType
(int
int
newType
)

Changes the type of the table

pack-priv void
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databaseback to summary
private Database database
emptySetback to summary
pack-priv OrderedHashSet<HsqlNameManager.HsqlName> emptySet
sessionback to summary
private Session session
tableback to summary
private Table table

Constructor Detail

TableWorksback to summary
public TableWorks(Session session, Table table)

Method Detail

addCheckConstraintback to summary
pack-priv void addCheckConstraint(Constraint c)
addColumnback to summary
pack-priv void addColumn(ColumnSchema column, int colIndex, HsqlArrayList<Constraint> constraints)
addForeignKeyback to summary
pack-priv void addForeignKey(Constraint c)

Creates a foreign key on an existing table. Foreign keys are enforced by indexes on both the referencing (child) and referenced (main) tables.

Since version 1.7.2, a unique constraint on the referenced columns must exist. The non-unique index on the referencing table is now always created whether or not a PK or unique constraint index on the columns exist. Foreign keys on temp tables can reference other temp tables with the same rules above. Foreign keys on permanent tables cannot reference temp tables. Duplicate foreign keys are now disallowed.

Parameters
c:Constraint

the constraint object

addIndexback to summary
pack-priv Index addIndex(int[] col, HsqlNameManager.HsqlName name, boolean unique)

Because of the way indexes and column data are held in memory and on disk, it is necessary to recreate the table when an index is added to a non-empty cached table.

With empty tables, Index objects are simply added

With MEOMRY and TEXT tables, a new index is built up and nodes for earch row are interlinked (fredt@users)

Parameters
col:int[]

int[]

name:HsqlNameManager.HsqlName

HsqlName

unique:boolean

boolean

Returns:Index

new index

addPrimaryKeyback to summary
pack-priv void addPrimaryKey(Constraint constraint)
addSystemPeriodback to summary
pack-priv void addSystemPeriod(PeriodDefinition period)
addUniqueConstraintback to summary
pack-priv void addUniqueConstraint(int[] cols, HsqlNameManager.HsqlName name)

A unique constraint relies on a unique index on the table. It can cover a single column or multiple columns.

All constraint names are unique within the database. Duplicate constraints (more than one unique constraint on the same set of columns) are not allowed. (fredt@users)

Parameters
cols:int[]

int[]

name:HsqlNameManager.HsqlName

HsqlName

addUniqueConstraintback to summary
pack-priv void addUniqueConstraint(Constraint constraint)
alterIndexback to summary
pack-priv void alterIndex(Index index, int[] columns)
checkAddColumnback to summary
pack-priv void checkAddColumn(ColumnSchema col)

Checks if the attributes of the Column argument, c, are compatible with the operation of adding such a Column to the Table argument, table.

Parameters
col:ColumnSchema

the Column to add to the Table, t

checkAddDomainConstraintback to summary
pack-priv void checkAddDomainConstraint(Type domain, Constraint check)
Parameters
domain:Type

domain

check:Constraint

added constraint

checkConvertColDataTypeback to summary
pack-priv void checkConvertColDataType(ColumnSchema oldCol, ColumnSchema newCol)
Parameters
oldCol:ColumnSchema

Column

newCol:ColumnSchema

Column

checkCreateForeignKeyback to summary
pack-priv void checkCreateForeignKey(Table fkTable, Constraint c)
checkModifyTableback to summary
private void checkModifyTable(boolean withContents)
dropColumnback to summary
pack-priv void dropColumn(int colIndex, boolean cascade)
dropConstraintback to summary
pack-priv void dropConstraint(String name, boolean cascade)
dropConstraintsAndIndexesback to summary
pack-priv OrderedHashSet<Table> dropConstraintsAndIndexes(OrderedHashSet<Table> tableSet, OrderedHashSet<HsqlNameManager.HsqlName> dropConstraintSet, OrderedHashSet<HsqlNameManager.HsqlName> dropIndexSet)
dropConstraintsAndIndexesback to summary
pack-priv void dropConstraintsAndIndexes(OrderedHashSet<HsqlNameManager.HsqlName> dropConstraintSet, OrderedHashSet<HsqlNameManager.HsqlName> dropIndexSet)

Drops a set of fk constraints, their indexes and other indexes in table. Uses sets of names which may contain names that are unrelated to this table.

dropIndexback to summary
pack-priv void dropIndex(String indexName)

Because of the way indexes and column data are held in memory and on disk, it is necessary to recreate the table when an index is added to or removed from a non-empty table.

Originally, this method would break existing foreign keys as the table order in the DB was changed. The new table is now linked in place of the old table (fredt@users)

Parameters
indexName:String

String

dropSystemPeriodback to summary
pack-priv void dropSystemPeriod(boolean cascade)
dropSystemVersioningback to summary
pack-priv void dropSystemVersioning(boolean cascade)
getTableback to summary
public Table getTable()
moveDataback to summary
pack-priv void moveData(Table oldTable, Table newTable, int[] colIndex, int adjust)
registerConstraintNamesback to summary
pack-priv void registerConstraintNames(HsqlArrayList<Constraint> constraints)
removeColumnNotNullConstraintsback to summary
pack-priv void removeColumnNotNullConstraints(int colIndex)
retypeColumnback to summary
pack-priv void retypeColumn(ColumnSchema oldCol, ColumnSchema newCol)

Allows changing the type only.

Parameters
oldCol:ColumnSchema

Column

newCol:ColumnSchema

Column

retypeColumnback to summary
private void retypeColumn(ColumnSchema column, int colIndex)
Parameters
column:ColumnSchema

Column

colIndex:int

int

setColDefaultExpressionback to summary
pack-priv void setColDefaultExpression(int colIndex, Expression def)

performs the work for changing the default value of a column

Parameters
colIndex:int

int

def:Expression

Expression

setColNullabilityback to summary
pack-priv void setColNullability(ColumnSchema column, boolean nullable)

performs the work for changing the nullability of a column

Parameters
column:ColumnSchema

Column

nullable:boolean

boolean

setNewTableInSchemaback to summary
pack-priv void setNewTableInSchema(Table newTable)
setNewTablesInSchemaback to summary
pack-priv void setNewTablesInSchema(OrderedHashSet<Table> tableSet)
setTableTypeback to summary
public boolean setTableType(int newType)

Changes the type of the table

Parameters
newType:int

int

Returns:boolean

boolean

updateConstraintsback to summary
pack-priv void updateConstraints(OrderedHashSet<Table> tableSet, OrderedHashSet<HsqlNameManager.HsqlName> dropConstraints)
updateConstraintsback to summary
pack-priv void updateConstraints(Table t, OrderedHashSet<HsqlNameManager.HsqlName> dropConstraints)