org.apache.torque.map
Class TableMap

java.lang.Object
  extended byorg.apache.torque.map.TableMap
All Implemented Interfaces:
IDMethod, java.io.Serializable

public class TableMap
extends java.lang.Object
implements IDMethod, java.io.Serializable

TableMap is used to model a table in a database.

Version:
$Id: TableMap.java,v 1.13 2003/08/23 13:18:54 mpoeschl Exp $
Author:
John D. McNally, Daniel Rall
See Also:
Serialized Form

Field Summary
private  java.util.Hashtable columns
          The columns in the table.
private  DatabaseMap dbMap
          The database this table belongs to.
private  java.lang.Object pkInfo
          Object to store information that is needed if the for generating primary keys.
private  java.lang.String prefix
          The prefix on the table name.
private  java.lang.String primaryKeyMethod
          The primary key generation method.
private  java.lang.String tableName
          The name of the table.
protected static java.lang.String[] VALID_ID_METHODS
          The list of valid ID generation methods.
 
Fields inherited from interface org.apache.torque.adapter.IDMethod
AUTO_INCREMENT, ID_BROKER, NATIVE, NO_ID_METHOD, SEQUENCE
 
Constructor Summary
TableMap()
          Required by proxy.
TableMap(java.lang.String tableName, DatabaseMap containingDB)
          Constructor.
TableMap(java.lang.String tableName, int numberOfColumns, DatabaseMap containingDB)
          Constructor.
TableMap(java.lang.String tableName, java.lang.String prefix, DatabaseMap containingDB)
          Constructor.
 
Method Summary
 void addColumn(ColumnMap cmap)
          Add a pre-created column to this table.
 void addColumn(java.lang.String columnName, java.lang.Object type)
          Add a column to this table of a certain type.
private  void addColumn(java.lang.String name, java.lang.Object type, boolean pk, java.lang.String fkTable, java.lang.String fkColumn, int size)
          Add a column to the table.
 void addColumn(java.lang.String columnName, java.lang.Object type, int size)
          Add a column to this table of a certain type and size.
 void addForeignKey(java.lang.String columnName, java.lang.Object type, java.lang.String fkTable, java.lang.String fkColumn)
          Add a foreign key column to the table.
 void addForeignKey(java.lang.String columnName, java.lang.Object type, java.lang.String fkTable, java.lang.String fkColumn, int size)
          Add a foreign key column to the table.
 void addForeignPrimaryKey(java.lang.String columnName, java.lang.Object type, java.lang.String fkTable, java.lang.String fkColumn)
          Add a foreign primary key column to the table.
 void addForeignPrimaryKey(java.lang.String columnName, java.lang.Object type, java.lang.String fkTable, java.lang.String fkColumn, int size)
          Add a foreign primary key column to the table.
 void addPrimaryKey(java.lang.String columnName, java.lang.Object type)
          Add a primary key column to this Table.
 void addPrimaryKey(java.lang.String columnName, java.lang.Object type, int size)
          Add a primary key column to this Table.
 boolean containsColumn(ColumnMap column)
          Does this table contain the specified column?
 boolean containsColumn(java.lang.String name)
          Does this table contain the specified column?
 boolean containsObjectColumn()
          Returns true if this tableMap contains a column with object data.
 ColumnMap getColumn(java.lang.String name)
          Get a ColumnMap for the named table.
 ColumnMap[] getColumns()
          Get a ColumnMap[] of the columns in this table.
 DatabaseMap getDatabaseMap()
          Get the DatabaseMap containing this TableMap.
 IdGenerator getIdGenerator()
          Get the value of idGenerator.
 java.lang.String getName()
          Get the name of the Table.
 java.lang.String getPrefix()
          Get table prefix name.
 java.lang.String getPrimaryKeyMethod()
          Get the method used to generate primary keys for this table.
 java.lang.Object getPrimaryKeyMethodInfo()
          Get the information used to generate a primary key
private  boolean hasPrefix(java.lang.String data)
          Tell me if i have PREFIX in my string.
private  java.lang.String removePrefix(java.lang.String data)
          Removes the PREFIX.
 java.lang.String removeUnderScores(java.lang.String data)
          Removes the PREFIX, removes the underscores and makes first letter caps.
 void setPrefix(java.lang.String prefix)
          Set table prefix name.
 void setPrimaryKeyMethod(java.lang.String method)
          Sets the method used to generate a key for this table.
 void setPrimaryKeyMethodInfo(java.lang.Object pkInfo)
          Sets the pk information needed to generate a key
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALID_ID_METHODS

protected static final java.lang.String[] VALID_ID_METHODS
The list of valid ID generation methods.


columns

private java.util.Hashtable columns
The columns in the table.


dbMap

private DatabaseMap dbMap
The database this table belongs to.


tableName

private java.lang.String tableName
The name of the table.


prefix

private java.lang.String prefix
The prefix on the table name.


primaryKeyMethod

private java.lang.String primaryKeyMethod
The primary key generation method.


pkInfo

private java.lang.Object pkInfo
Object to store information that is needed if the for generating primary keys.

Constructor Detail

TableMap

public TableMap()
Required by proxy. Not used.


TableMap

public TableMap(java.lang.String tableName,
                int numberOfColumns,
                DatabaseMap containingDB)
Constructor.

Parameters:
tableName - The name of the table.
numberOfColumns - The number of columns in the table.
containingDB - A DatabaseMap that this table belongs to.

TableMap

public TableMap(java.lang.String tableName,
                DatabaseMap containingDB)
Constructor.

Parameters:
tableName - The name of the table.
containingDB - A DatabaseMap that this table belongs to.

TableMap

public TableMap(java.lang.String tableName,
                java.lang.String prefix,
                DatabaseMap containingDB)
Constructor.

Parameters:
tableName - The name of the table.
prefix - The prefix for the table name (ie: SCARAB for SCARAB_PROJECT).
containingDB - A DatabaseMap that this table belongs to.
Method Detail

containsColumn

public boolean containsColumn(ColumnMap column)
Does this table contain the specified column?

Parameters:
column - A ColumnMap.
Returns:
True if the table contains the column.

containsColumn

public boolean containsColumn(java.lang.String name)
Does this table contain the specified column?

Parameters:
name - A String with the name of the column.
Returns:
True if the table contains the column.

getDatabaseMap

public DatabaseMap getDatabaseMap()
Get the DatabaseMap containing this TableMap.

Returns:
A DatabaseMap.

containsObjectColumn

public boolean containsObjectColumn()
Returns true if this tableMap contains a column with object data. If the type of the column is not a string, a number or a date, it is assumed that it is object data.

Returns:
True if map contains a column with object data.

getName

public java.lang.String getName()
Get the name of the Table.

Returns:
A String with the name of the table.

getPrefix

public java.lang.String getPrefix()
Get table prefix name.

Returns:
A String with the prefix.

setPrefix

public void setPrefix(java.lang.String prefix)
Set table prefix name.

Parameters:
prefix - The prefix for the table name (ie: SCARAB for SCARAB_PROJECT).

getPrimaryKeyMethod

public java.lang.String getPrimaryKeyMethod()
Get the method used to generate primary keys for this table.

Returns:
A String with the method.

getIdGenerator

public IdGenerator getIdGenerator()
Get the value of idGenerator.

Returns:
value of idGenerator.

getPrimaryKeyMethodInfo

public java.lang.Object getPrimaryKeyMethodInfo()
Get the information used to generate a primary key

Returns:
An Object.

getColumns

public ColumnMap[] getColumns()
Get a ColumnMap[] of the columns in this table.

Returns:
A ColumnMap[].

getColumn

public ColumnMap getColumn(java.lang.String name)
Get a ColumnMap for the named table.

Parameters:
name - A String with the name of the table.
Returns:
A ColumnMap.

addColumn

public void addColumn(ColumnMap cmap)
Add a pre-created column to this table. It will replace any existing column.

Parameters:
cmap - A ColumnMap.

addColumn

public void addColumn(java.lang.String columnName,
                      java.lang.Object type)
Add a column to this table of a certain type.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.

addColumn

public void addColumn(java.lang.String columnName,
                      java.lang.Object type,
                      int size)
Add a column to this table of a certain type and size.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
size - An int specifying the size.

addPrimaryKey

public void addPrimaryKey(java.lang.String columnName,
                          java.lang.Object type)
Add a primary key column to this Table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.

addPrimaryKey

public void addPrimaryKey(java.lang.String columnName,
                          java.lang.Object type,
                          int size)
Add a primary key column to this Table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
size - An int specifying the size.

addForeignKey

public void addForeignKey(java.lang.String columnName,
                          java.lang.Object type,
                          java.lang.String fkTable,
                          java.lang.String fkColumn)
Add a foreign key column to the table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
fkTable - A String with the foreign key table name.
fkColumn - A String with the foreign key column name.

addForeignKey

public void addForeignKey(java.lang.String columnName,
                          java.lang.Object type,
                          java.lang.String fkTable,
                          java.lang.String fkColumn,
                          int size)
Add a foreign key column to the table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
fkTable - A String with the foreign key table name.
fkColumn - A String with the foreign key column name.
size - An int specifying the size.

addForeignPrimaryKey

public void addForeignPrimaryKey(java.lang.String columnName,
                                 java.lang.Object type,
                                 java.lang.String fkTable,
                                 java.lang.String fkColumn)
Add a foreign primary key column to the table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
fkTable - A String with the foreign key table name.
fkColumn - A String with the foreign key column name.

addForeignPrimaryKey

public void addForeignPrimaryKey(java.lang.String columnName,
                                 java.lang.Object type,
                                 java.lang.String fkTable,
                                 java.lang.String fkColumn,
                                 int size)
Add a foreign primary key column to the table.

Parameters:
columnName - A String with the column name.
type - An Object specifying the type.
fkTable - A String with the foreign key table name.
fkColumn - A String with the foreign key column name.
size - An int specifying the size.

addColumn

private void addColumn(java.lang.String name,
                       java.lang.Object type,
                       boolean pk,
                       java.lang.String fkTable,
                       java.lang.String fkColumn,
                       int size)
Add a column to the table.

Parameters:
name - A String with the column name.
type - An Object specifying the type.
pk - True if column is a primary key.
fkTable - A String with the foreign key table name.
fkColumn - A String with the foreign key column name.
size - An int specifying the size.

setPrimaryKeyMethod

public void setPrimaryKeyMethod(java.lang.String method)
Sets the method used to generate a key for this table. Valid values are as specified in the IDMethod interface.

Parameters:
method - The ID generation method type name.

setPrimaryKeyMethodInfo

public void setPrimaryKeyMethodInfo(java.lang.Object pkInfo)
Sets the pk information needed to generate a key

Parameters:
pkInfo - information needed to generate a key

hasPrefix

private final boolean hasPrefix(java.lang.String data)
Tell me if i have PREFIX in my string.

Parameters:
data - A String.
Returns:
True if prefix is contained in data.

removePrefix

private final java.lang.String removePrefix(java.lang.String data)
Removes the PREFIX.

Parameters:
data - A String.
Returns:
A String with data, but with prefix removed.

removeUnderScores

public final java.lang.String removeUnderScores(java.lang.String data)
Removes the PREFIX, removes the underscores and makes first letter caps. SCARAB_FOO_BAR becomes FooBar.

Parameters:
data - A String.
Returns:
A String with data processed.


Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.