Dresden OCL Toolkit

tudresden.ocl.codegen.decl
Class Table

java.lang.Object
  extended bytudresden.ocl.codegen.decl.Table
Direct Known Subclasses:
View

public class Table
extends Object

This class represents metadata about tables of relational databases. A table consists of:
- an arbitrary number of columns;
- a primary key consisting of zero ore more columns;
- foreign key references consisting of zero or more columns;
The columns of the table can be associated to an attribute name that can be different from the real column name. The columns of the table can have a type. Since the metadata is not dependend of a specific database system, no special types are prescribed. It is suggested to follow the java basic data types like int, long, boolean, real and so on and map them to the specific database system types if necessary. The foreign keys are ordinary columns that are associated to additional information. These information are:
- the name of a foreign table;(deprecated)
modified for reference to foreign table object
- the name of a column in the foreign table.
- possibly other columns that are part of the same (multiple) foreign key

Version:
2.1 (Revised by Andrea Kling 2002, enhanced foreign key references)
Author:
Sten Loecher

Nested Class Summary
private  class Table.Column
           
 
Field Summary
private  List columns
           
private static String EX_COL_NE
           
private static String EX_COL_NULL
           
private static String EX_DUPL_COL
           
private static String EX_FCOL_NE
           
private static String EX_FK_SNOTS
           
private static String EX_TMAC
           
private  String name
           
 
Constructor Summary
Table(String name)
          Creates a new empty table.
 
Method Summary
 void addColumn(String colName)
          Adds a new column to the table.
 void addColumn(String attName, String colName, boolean pk)
          Adds a new column to the table.
 void addColumn(String attName, String type, String colName)
          Adds a new column to the table.
 void addColumn(String attName, String type, String colName, boolean pk)
          Adds a new column to the table.
protected  void addReferringTable(String referredColumn, Table referringTable, String referringColumn)
          used to set the reverse table reference for foreign key references
 Set attributes()
           
 String[] getAllForeignKeyColumns(String colName)
           
 String getAttributeColumn(String attName)
           
 String[] getAttributeColumns(String attName)
           
private  Table.Column getColumn(String colName)
           
 String getColumnAttribute(String colName)
           
 String[] getColumns()
           
 String getColumnType(String colName)
           
 String getForeignColumn(String colName)
           
 String[] getForeignKeyColumns()
           
 String getForeignKeyRepresentation(String colName)
           
 String getForeignTable(String colName)
           
 String[] getKeyColumns()
          Deprecated. Use methode getPrimaryKeyColumns instead !
 String[] getPrimaryKeyColumns()
           
 String getPrimaryKeyRepresentation()
           
 Table getReferredTable(String colName)
           
 String getTableName()
           
 boolean isColumn(String colName)
           
 boolean isForeignKeyColumn(String colName)
           
 boolean isKeyColumn(String colName)
          Deprecated. Use methode isPrimaryKeyColumn instead !
 boolean isOptional(String colName)
           
 boolean isPrimaryKeyColumn(String colName)
           
 void removeColumn(String colName)
           
 void removePrimaryKey()
           
 void setColumnType(String colName, String colType)
           
 void setForeignKey(String[] colNames, Table fkTable, String[] fkColumns)
          Marks the specified columns as multi column foreign key reference.
 void setForeignKey(String colName, String fkTable, String fkColumn)
          Deprecated. use setForeignKey(String colName, Table fkTable, String fkColumn) instead
 void setForeignKey(String colName, Table fkTable, String fkColumn)
          Sets the specified column to foreign key state.
 void setName(String name)
          sets the Table's name
 void setOptional(String colName)
          marks a column as optional column (may contain null values)
 void setPrimaryKey(String colName)
          Sets the specified column to primary key column state.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EX_DUPL_COL

private static String EX_DUPL_COL

EX_COL_NULL

private static String EX_COL_NULL

EX_COL_NE

private static String EX_COL_NE

EX_FCOL_NE

private static String EX_FCOL_NE

EX_FK_SNOTS

private static String EX_FK_SNOTS

EX_TMAC

private static String EX_TMAC

columns

private List columns

name

private String name
Constructor Detail

Table

public Table(String name)
Creates a new empty table.

Parameters:
name - the name of the table
Method Detail

addColumn

public void addColumn(String colName)
               throws NullPointerException,
                      IllegalArgumentException
Adds a new column to the table.

Parameters:
colName - the name of the column
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName still exists

addColumn

public void addColumn(String attName,
                      String type,
                      String colName)
               throws NullPointerException,
                      IllegalArgumentException
Adds a new column to the table.

Parameters:
attName - the name of the attribute associated to the column
type - the type name of the column
colName - the name of the column
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName still exists

addColumn

public void addColumn(String attName,
                      String colName,
                      boolean pk)
               throws NullPointerException,
                      IllegalArgumentException
Adds a new column to the table.

Parameters:
attName - the name of the attribute associated to the column
colName - the name of the column
pk - a flag that should be true if the column is a primary key column, false otherwise
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName still exists

addColumn

public void addColumn(String attName,
                      String type,
                      String colName,
                      boolean pk)
               throws NullPointerException,
                      IllegalArgumentException
Adds a new column to the table.

Parameters:
attName - the name of the attribute associated to the column
type - the type name of the column
colName - the name of the column
pk - a flag that should be true if the column is a primary key column, false otherwise
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName still exists

setPrimaryKey

public void setPrimaryKey(String colName)
                   throws NullPointerException,
                          IllegalArgumentException
Sets the specified column to primary key column state.

Parameters:
colName - the column name
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

setForeignKey

public void setForeignKey(String colName,
                          String fkTable,
                          String fkColumn)
                   throws NullPointerException,
                          IllegalArgumentException
Deprecated. use setForeignKey(String colName, Table fkTable, String fkColumn) instead

Sets the specified column to foreign key state.

Parameters:
colName - the column name
fkTable - the name of the foreign table
fkColumn - the name of the foreign column
Throws:
NullPointerException - if one of colName, fkTable or fkColumn is null
IllegalArgumentException - if colName does not exists

setForeignKey

public void setForeignKey(String colName,
                          Table fkTable,
                          String fkColumn)
                   throws NullPointerException,
                          IllegalArgumentException
Sets the specified column to foreign key state.

Parameters:
colName - the column name
fkTable - the foreign table
fkColumn - the name of the foreign column
Throws:
NullPointerException - if one of colName, fkTable or fkColumn is null
IllegalArgumentException - if colName does not exists

setForeignKey

public void setForeignKey(String[] colNames,
                          Table fkTable,
                          String[] fkColumns)
                   throws NullPointerException,
                          IllegalArgumentException
Marks the specified columns as multi column foreign key reference.

Parameters:
colNames - the column names that are part of the foreign key
fkTable - the foreign table
fkColumns - the names of the corresponding foreign columns
Throws:
NullPointerException - if one of colName, fkTable or fkColumn is null
IllegalArgumentException - if colName does not exists or columns do not match foreign columns

addReferringTable

protected void addReferringTable(String referredColumn,
                                 Table referringTable,
                                 String referringColumn)
used to set the reverse table reference for foreign key references


getColumns

public String[] getColumns()
Returns:
a String array that contains all column names of this table

getAttributeColumn

public String getAttributeColumn(String attName)
                          throws NullPointerException,
                                 IllegalStateException
Parameters:
attName - the name of an attribute
Returns:
a String that contains the name of the associated column
Throws:
NullPointerException - if attName is null
IllegalStateException - if the specified attribute is mapped to more than one column

getAttributeColumns

public String[] getAttributeColumns(String attName)
                             throws NullPointerException
Parameters:
attName - the name of an attribute
Returns:
a String array that contains the names of the associated columns
Throws:
NullPointerException - if attName is null

getColumnAttribute

public String getColumnAttribute(String colName)
                          throws NullPointerException,
                                 IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
a String that contains the name of the associated attribute
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

getKeyColumns

public String[] getKeyColumns()
Deprecated. Use methode getPrimaryKeyColumns instead !

Returns:
a String array that contains all primary key column names

getPrimaryKeyColumns

public String[] getPrimaryKeyColumns()
Returns:
a String array that contains all primary key column names

getForeignKeyColumns

public String[] getForeignKeyColumns()
Returns:
a String array that contains all columns referring to another Table

getColumnType

public String getColumnType(String colName)
                     throws NullPointerException,
                            IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
the name of the column type
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

setColumnType

public void setColumnType(String colName,
                          String colType)
                   throws NullPointerException,
                          IllegalArgumentException
Throws:
NullPointerException
IllegalArgumentException

getForeignTable

public String getForeignTable(String colName)
                       throws NullPointerException,
                              IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
the foreign table name of the specified column
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

getReferredTable

public Table getReferredTable(String colName)
                       throws NullPointerException,
                              IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
the foreign table of the specified column
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

getForeignColumn

public String getForeignColumn(String colName)
                        throws NullPointerException,
                               IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
the foreign column name of the specified column
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

getAllForeignKeyColumns

public String[] getAllForeignKeyColumns(String colName)
                                 throws NullPointerException,
                                        IllegalArgumentException
Parameters:
colName - the name of a column
Returns:
all column names that are part of the same foreign key as the specified column (including specified column)
Throws:
NullPointerException - if colName is null
IllegalArgumentException - if colName does not exists

getForeignKeyRepresentation

public String getForeignKeyRepresentation(String colName)
                                   throws NullPointerException,
                                          IllegalArgumentException
Returns:
a String representation of the Foreign key the given column is part of, (fk1, fk2, ...)
Throws:
NullPointerException
IllegalArgumentException

getPrimaryKeyRepresentation

public String getPrimaryKeyRepresentation()
Returns:
a String representation of all primary key columns, which is the column name in case of single column primary key or "(pk1, pk2, ..., pkn)" in case of a multi column key

getTableName

public String getTableName()
Returns:
the name of the table

isKeyColumn

public boolean isKeyColumn(String colName)
                    throws NullPointerException
Deprecated. Use methode isPrimaryKeyColumn instead !

Parameters:
colName - the name of a column
Returns:
true if the specified column is a primary key column, false otherwise
Throws:
NullPointerException - if colName is null

isPrimaryKeyColumn

public boolean isPrimaryKeyColumn(String colName)
                           throws NullPointerException
Parameters:
colName - the name of a column
Returns:
true if the specified column is a primary key column, false otherwise
Throws:
NullPointerException - if colName is null

isForeignKeyColumn

public boolean isForeignKeyColumn(String colName)
                           throws NullPointerException
Parameters:
colName - the name of a column
Returns:
true if the specified column is a foreign key column, false otherwise
Throws:
NullPointerException - if colName is null

isColumn

public boolean isColumn(String colName)
                 throws NullPointerException
Parameters:
colName - the name of a column
Returns:
true if the specified column is a column of this table, false otherwise
Throws:
NullPointerException - if colName is null

attributes

public Set attributes()
Returns:
a set of attribute names that are associated to the table columns

setName

public void setName(String name)
sets the Table's name


setOptional

public void setOptional(String colName)
                 throws IllegalArgumentException
marks a column as optional column (may contain null values)

Throws:
IlleglArgumentException - if column does not exist
IllegalArgumentException

isOptional

public boolean isOptional(String colName)
                   throws IllegalArgumentException
Returns:
true, if the column may contain null-values
Throws:
IlleglArgumentException - if column does not exist
IllegalArgumentException

removeColumn

public void removeColumn(String colName)
                  throws IllegalArgumentException
Parameters:
colName - the column to remove
Throws:
IlleglArgumentException - if column is Part of the primary key or of a foreign key
IllegalArgumentException

removePrimaryKey

public void removePrimaryKey()
                      throws IllegalArgumentException
Throws:
IlleglArgumentException - if primary key is referred to
IllegalArgumentException

toString

public String toString()
Returns:
a string representation of a table object

getColumn

private Table.Column getColumn(String colName)
Parameters:
colName - the name of a column
Returns:
a column object to the colName or null if such an object does not exist

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.