org.apache.torque.engine.database.model
Class Table

java.lang.Object
  extended by org.apache.torque.engine.database.model.Table
All Implemented Interfaces:
IDMethod

public class Table
extends Object
implements IDMethod

Data about a table used in an application.

Version:
$Id: Table.java,v 1.1 2007-10-21 07:57:27 abyrne Exp $
Author:
Leon Messerschmidt, Jason van Zyl, John McNally, Byron Foster,
Field Summary
 
Fields inherited from interface org.apache.torque.engine.database.model.IDMethod
ID_BROKER, NATIVE, NO_ID_METHOD
 
Constructor Summary
Table()
          Default Constructor
Table(String name)
          Constructs a table object with a name
 
Method Summary
 Column addColumn(Attributes attrib)
          A utility function to create a new column from attrib and add it to this table.
 void addColumn(Column col)
          Adds a new column to the column list and set the parent table of the column to the current table
 ForeignKey addForeignKey(Attributes attrib)
          A utility function to create a new foreign key from attrib and add it to this table.
 void addForeignKey(ForeignKey fk)
          Adds a new FK to the FK list and set the parent table of the column to the current table
 IdMethodParameter addIdMethodParameter(Attributes attrib)
          A utility function to create a new id method parameter from attrib and add it to this table.
 void addIdMethodParameter(IdMethodParameter imp)
          Adds a new ID method parameter to the list and sets the parent table of the column associated with the supplied parameter to this table.
 Index addIndex(Attributes attrib)
          A utility function to create a new index from attrib and add it to this table.
 void addIndex(Index index)
          Adds a new index to the index list and set the parent table of the column to the current table
 void addOption(String key, String value)
          Add an XML Specified option key/value pair to this element's option set.
 void addReferrer(ForeignKey fk)
          Adds the foreign key from another table that refers to this table.
 Unique addUnique(Attributes attrib)
          A utility function to create a new Unique from attrib and add it to this table.
 void addUnique(Unique unique)
          Adds a new Unique to the Unique list and set the parent table of the column to the current table
 boolean containsColumn(Column col)
          Returns true if the table contains a specified column
 boolean containsColumn(String name)
          Returns true if the table contains a specified column
 void doFinalInitialization()
           A hook for the SAX XML parser to call when this table has been fully loaded from the XML, and all nested elements have been processed.
 String getAlias()
          JavaName of om object this entry references.
 String getBaseClass()
          Gets the value of base class for classes produced from this table.
 String getBasePeer()
          Get the value of basePeer.
 Column getChildrenColumn()
          Gets the column that subclasses of the class representing this table can be produced from.
 List getChildrenNames()
          Get the objects that can be created from this table.
 Column getColumn(String name)
          Returns a specified column.
 Column getColumnByJavaName(String javaName)
          Returns a specified column.
 List getColumns()
          Returns a List containing all the columns in the table
 boolean getContainsForeignPK()
          Determine if this table contains a foreign PK
 Database getDatabase()
          Get the parent of the table
 String getDescription()
          Get the description for the Table
 ForeignKey getForeignKey(String col)
          Return the first foreign key that includes col in it's list of local columns.
 List getForeignKeys()
          Returns a List containing all the FKs in the table
 List getForeignTableNames()
          A list of tables referenced by foreign keys in this table
 String getIdMethod()
          Get the method for generating pk's
 List getIdMethodParameters()
          Returns a Collection of parameters relevant for the chosen id generation method.
 List getIndices()
          Returns a List containing all the indices in the table
 String getInterface()
          Interface which objects for this table will implement
 String getJavaName()
          Get name to use in Java sources
 String getName()
          Get the name of the Table
 int getNumColumns()
          Utility method to get the number of columns in this table
 String getOption(String key)
          Get the value that was associated with this key in an XML option element.
 Map getOptions()
          Gets the full ordered hashtable array of items specified by XML option statements under this element.
 String getPackage()
          Get the value of package.
 List getPrimaryKey()
          Returns the collection of Columns which make up the single primary key for this table.
 List getReferrers()
          Get list of references to this table.
 String getSequenceName()
          A name to use for creating a sequence if one is not specified.
 List getUnices()
          Returns a List containing all the UKs in the table
 boolean hasPrimaryKey()
          Determine whether this table has a primary key.
 boolean isAbstract()
          When a table is abstract, it marks the business object class that is generated as being abstract.
 boolean isAlias()
          Is this table specified in the schema or is there just a foreign key reference to it.
 boolean isForReferenceOnly()
          Flag to determine if code/sql gets created for this table.
 boolean isSkipSql()
          Skip generating sql for this table (in the event it should not be created from scratch).
 void loadFromXML(Attributes attrib, String defaultIdMethod)
          Load the table object from an xml tag.
 String printPrimaryKey()
          Returns all parts of the primary key, separated by commas.
 boolean requiresTransactionInPostgres()
          Return true if the column requires a transaction in Postgres
 void setAbstract(boolean v)
          When a table is abstract, it marks the business object class that is generated as being abstract.
 void setAlias(String v)
          Set whether this table specified in the schema or is there just a foreign key reference to it.
 void setBaseClass(String v)
          Set the value of baseClass.
 void setBasePeer(String v)
          Set the value of basePeer.
 void setContainsForeignPK(boolean b)
          Set whether this table contains a foreign PK
 void setCorrectGetters(Boolean value)
          Force all columns to set the correctGetters property.
 void setDatabase(Database parent)
          Set the parent of the table
 void setDescription(String newDescription)
          Set the description for the Table
 void setForReferenceOnly(boolean v)
          Flag to determine if code/sql gets created for this table.
 void setIdMethod(String idMethod)
          Set the method for generating pk's
 void setInterface(String v)
          Interface which objects for this table will implement
 void setJavaName(String javaName)
          Set name to use in Java sources
 void setName(String newName)
          Set the name of the Table
 void setPackage(String v)
          Set the value of package.
 void setSkipSql(boolean v)
          Set whether this table should have its creation sql generated.
 String toString()
          Returns a XML representation of this table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table()
Default Constructor


Table

public Table(String name)
Constructs a table object with a name

Parameters:
name - table name
Method Detail

loadFromXML

public void loadFromXML(Attributes attrib,
                        String defaultIdMethod)
Load the table object from an xml tag.

Parameters:
attrib - xml attributes
defaultIdMethod - defined at db level

doFinalInitialization

public void doFinalInitialization()

A hook for the SAX XML parser to call when this table has been fully loaded from the XML, and all nested elements have been processed.

Performs heavy indexing and naming of elements which weren't provided with a name.


getBaseClass

public String getBaseClass()
Gets the value of base class for classes produced from this table.

Returns:
The base class for classes produced from this table.

setBaseClass

public void setBaseClass(String v)
Set the value of baseClass.

Parameters:
v - Value to assign to baseClass.

getBasePeer

public String getBasePeer()
Get the value of basePeer.

Returns:
value of basePeer.

setBasePeer

public void setBasePeer(String v)
Set the value of basePeer.

Parameters:
v - Value to assign to basePeer.

addColumn

public Column addColumn(Attributes attrib)
A utility function to create a new column from attrib and add it to this table.

Parameters:
attrib - xml attributes for the column to add
Returns:
the added column

addColumn

public void addColumn(Column col)
Adds a new column to the column list and set the parent table of the column to the current table

Parameters:
col - the column to add

addForeignKey

public ForeignKey addForeignKey(Attributes attrib)
A utility function to create a new foreign key from attrib and add it to this table.

Parameters:
attrib - the xml attributes
Returns:
the created ForeignKey

getChildrenColumn

public Column getChildrenColumn()
Gets the column that subclasses of the class representing this table can be produced from.


getChildrenNames

public List getChildrenNames()
Get the objects that can be created from this table.


addReferrer

public void addReferrer(ForeignKey fk)
Adds the foreign key from another table that refers to this table.

Parameters:
fk - A foreign key refering to this table

getReferrers

public List getReferrers()
Get list of references to this table.

Returns:
A list of references to this table

setContainsForeignPK

public void setContainsForeignPK(boolean b)
Set whether this table contains a foreign PK

Parameters:
b -

getContainsForeignPK

public boolean getContainsForeignPK()
Determine if this table contains a foreign PK


getForeignTableNames

public List getForeignTableNames()
A list of tables referenced by foreign keys in this table

Returns:
A list of tables

addForeignKey

public void addForeignKey(ForeignKey fk)
Adds a new FK to the FK list and set the parent table of the column to the current table

Parameters:
fk - A foreign key

requiresTransactionInPostgres

public boolean requiresTransactionInPostgres()
Return true if the column requires a transaction in Postgres


addIdMethodParameter

public IdMethodParameter addIdMethodParameter(Attributes attrib)
A utility function to create a new id method parameter from attrib and add it to this table.


addIdMethodParameter

public void addIdMethodParameter(IdMethodParameter imp)
Adds a new ID method parameter to the list and sets the parent table of the column associated with the supplied parameter to this table.

Parameters:
imp - The column to add as an ID method parameter.

addIndex

public void addIndex(Index index)
Adds a new index to the index list and set the parent table of the column to the current table


addIndex

public Index addIndex(Attributes attrib)
A utility function to create a new index from attrib and add it to this table.


addUnique

public void addUnique(Unique unique)
Adds a new Unique to the Unique list and set the parent table of the column to the current table


addUnique

public Unique addUnique(Attributes attrib)
A utility function to create a new Unique from attrib and add it to this table.

Parameters:
attrib - the xml attributes

getName

public String getName()
Get the name of the Table


setName

public void setName(String newName)
Set the name of the Table


getDescription

public String getDescription()
Get the description for the Table


setDescription

public void setDescription(String newDescription)
Set the description for the Table

Parameters:
newDescription - description for the Table

getJavaName

public String getJavaName()
Get name to use in Java sources


setJavaName

public void setJavaName(String javaName)
Set name to use in Java sources


getIdMethod

public String getIdMethod()
Get the method for generating pk's


setIdMethod

public void setIdMethod(String idMethod)
Set the method for generating pk's


isSkipSql

public boolean isSkipSql()
Skip generating sql for this table (in the event it should not be created from scratch).

Returns:
value of skipSql.

setSkipSql

public void setSkipSql(boolean v)
Set whether this table should have its creation sql generated.

Parameters:
v - Value to assign to skipSql.

getAlias

public String getAlias()
JavaName of om object this entry references.

Returns:
value of external.

isAlias

public boolean isAlias()
Is this table specified in the schema or is there just a foreign key reference to it.

Returns:
value of external.

setAlias

public void setAlias(String v)
Set whether this table specified in the schema or is there just a foreign key reference to it.

Parameters:
v - Value to assign to alias.

getInterface

public String getInterface()
Interface which objects for this table will implement

Returns:
value of interface.

setInterface

public void setInterface(String v)
Interface which objects for this table will implement

Parameters:
v - Value to assign to interface.

isAbstract

public boolean isAbstract()
When a table is abstract, it marks the business object class that is generated as being abstract. If you have a table called "FOO", then the Foo BO will be public abstract class Foo This helps support class hierarchies

Returns:
value of abstractValue.

setAbstract

public void setAbstract(boolean v)
When a table is abstract, it marks the business object class that is generated as being abstract. If you have a table called "FOO", then the Foo BO will be public abstract class Foo This helps support class hierarchies

Parameters:
v - Value to assign to abstractValue.

getPackage

public String getPackage()
Get the value of package.

Returns:
value of package.

setPackage

public void setPackage(String v)
Set the value of package.

Parameters:
v - Value to assign to package.

getColumns

public List getColumns()
Returns a List containing all the columns in the table

Returns:
a List containing all the columns

getNumColumns

public int getNumColumns()
Utility method to get the number of columns in this table


getForeignKeys

public List getForeignKeys()
Returns a List containing all the FKs in the table

Returns:
a List containing all the FKs

getIdMethodParameters

public List getIdMethodParameters()
Returns a Collection of parameters relevant for the chosen id generation method.


getSequenceName

public String getSequenceName()
A name to use for creating a sequence if one is not specified.

Returns:
name of the sequence

getIndices

public List getIndices()
Returns a List containing all the indices in the table

Returns:
A List containing all the indices

getUnices

public List getUnices()
Returns a List containing all the UKs in the table

Returns:
A List containing all the UKs

getColumn

public Column getColumn(String name)
Returns a specified column.

Parameters:
name - name of the column
Returns:
Return a Column object or null if it does not exist.

getColumnByJavaName

public Column getColumnByJavaName(String javaName)
Returns a specified column.

Parameters:
javaName - java name of the column
Returns:
Return a Column object or null if it does not exist.

getForeignKey

public ForeignKey getForeignKey(String col)
Return the first foreign key that includes col in it's list of local columns. Eg. Foreign key (a,b,c) refrences tbl(x,y,z) will be returned of col is either a,b or c.

Parameters:
col - column name included in the key
Returns:
Return a Column object or null if it does not exist.

containsColumn

public boolean containsColumn(Column col)
Returns true if the table contains a specified column

Parameters:
col - the column
Returns:
true if the table contains the column

containsColumn

public boolean containsColumn(String name)
Returns true if the table contains a specified column

Parameters:
name - name of the column
Returns:
true if the table contains the column

setDatabase

public void setDatabase(Database parent)
Set the parent of the table

Parameters:
parent - the parant database

getDatabase

public Database getDatabase()
Get the parent of the table

Returns:
the parant database

isForReferenceOnly

public boolean isForReferenceOnly()
Flag to determine if code/sql gets created for this table. Table will be skipped, if return true.

Returns:
value of forReferenceOnly.

setForReferenceOnly

public void setForReferenceOnly(boolean v)
Flag to determine if code/sql gets created for this table. Table will be skipped, if set to true.

Parameters:
v - Value to assign to forReferenceOnly.

toString

public String toString()
Returns a XML representation of this table.

Overrides:
toString in class Object
Returns:
XML representation of this table

getPrimaryKey

public List getPrimaryKey()
Returns the collection of Columns which make up the single primary key for this table.

Returns:
A list of the primary key parts.

hasPrimaryKey

public boolean hasPrimaryKey()
Determine whether this table has a primary key.

Returns:
Whether this table has any primary key parts.

printPrimaryKey

public String printPrimaryKey()
Returns all parts of the primary key, separated by commas.

Returns:
A CSV list of primary key parts.

setCorrectGetters

public void setCorrectGetters(Boolean value)
Force all columns to set the correctGetters property.

Parameters:
value - The new value of the correctGetters property.
Since:
3.2

addOption

public void addOption(String key,
                      String value)
Add an XML Specified option key/value pair to this element's option set.

Parameters:
key - the key of the option.
value - the value of the option.

getOption

public String getOption(String key)
Get the value that was associated with this key in an XML option element.

Parameters:
key - the key of the option.
Returns:
The value for the key or a null.

getOptions

public Map getOptions()
Gets the full ordered hashtable array of items specified by XML option statements under this element.

Note, this is not thread save but since it's only used for generation which is single threaded, there should be minimum danger using this in Velocity.

Returns:
An Map of all options. Will not be null but may be empty.


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.