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

java.lang.Object
  extended byorg.apache.torque.engine.database.model.Column

public class Column
extends java.lang.Object

A Class for holding data about a column used in an Application.

Version:
$Id: Column.java,v 1.24 2002/11/29 13:50:29 mpoeschl Exp $
Author:
Leon Messerschmidt, Jason van Zyl, Jon S. Stevens, Daniel Rall,
Field Summary
private  java.lang.Object columnType
           
private  java.lang.String defaultValue
           
private  java.lang.String description
           
private  java.util.List inheritanceList
           
private  java.lang.String inheritanceType
           
private  java.lang.String inputValidator
          class name to do input validation on this column
private  boolean isAutoIncrement
           
private  boolean isEnumeratedClasses
           
private  boolean isInheritance
           
private  boolean isNotNull
           
private  boolean isPrimaryKey
           
private  boolean isUnique
           
private  java.lang.String javaName
           
private  java.lang.String javaNamingMethod
           
private  java.lang.String javaType
           
private  java.lang.String name
           
private  boolean needsTransactionInPostgres
           
private  Table parentTable
           
private  int position
           
private  java.util.List referrers
           
private  java.lang.String size
           
private  java.lang.String torqueType
          type as defined in schema.xml
 
Constructor Summary
Column()
          Creates a new instance with a null name.
Column(java.lang.String name)
          Creates a new column and set the name
 
Method Summary
 Inheritance addInheritance(org.xml.sax.Attributes attrib)
          A utility function to create a new column from attrib and add it to this table.
 void addInheritance(Inheritance inh)
          Adds a new inheritance definition to the inheritance list and set the parent column of the inheritance to the current column
 void addReferrer(ForeignKey fk)
          Adds the foreign key from another table that refers to this column.
 java.util.List getChildren()
          Get the inheritance definitions.
 java.lang.String getDefaultSetting()
          Return a string that will give this column a default value.
 java.lang.String getDefaultValue()
          Get a string that will give this column a default value.
 java.lang.String getDescription()
          Get the description for the Table
 ForeignKey getForeignKey()
          get the foreign key object for this column if it is a foreign key or part of a foreign key
 java.lang.String getFullyQualifiedName()
          Returns table.column
 java.lang.String getInputValidator()
          Returns the class name to do input validation
 java.lang.String getJavaName()
          Get name to use in Java sources
 java.lang.String getJavaNative()
          Return a string representation of the native java type which corresponds to the JDBC type of this column.
 java.lang.String getJavaObject()
          Return a string representation of the Java object which corresponds to the JDBC type of this column.
 java.lang.String getJavaPrimitive()
          Return a string representation of the primitive java type which corresponds to the JDBC type of this column.
 java.lang.String getJavaType()
          Get type to use in Java sources
 java.lang.String getName()
          Get the name of the column
 java.lang.String getParameterParserMethod()
          Return ParameterParser getX() method which corresponds to the JDBC type which represents this column.
 int getPosition()
          Get the location of this column within the table (one-based).
 java.util.List getReferrers()
          Get list of references to this column.
 java.lang.String getRelatedColumnName()
          Utility method to get the related column of this local column if this column is a foreign key or part of a foreign key.
 java.lang.String getRelatedTableName()
          Utility method to get the related table of this column if it is a foreign key or part of a foreign key
 java.lang.String getSize()
          Returns the size of the column
 Table getTable()
          Get the parent Table of the column
 java.lang.String getTableName()
          Returns the Name of the table the column is in
 java.lang.Object getTorqueType()
          Returns the column type as given in the schema as an object
 java.lang.Object getType()
          Returns the column jdbc type as an object
 java.lang.String getVillageMethod()
          Return Village asX() method which corresponds to the JDBC type which represents this column.
 boolean isAutoIncrement()
          Return auto increment/sequence string for the target database.
 boolean isBooleanChar()
          Returns true if the column type is boolean in the java object and a String ("Y" or "N") in the db.
 boolean isBooleanInt()
          Returns true if the column type is boolean in the java object and a numeric (1 or 0) in the db.
 boolean isEnumeratedClasses()
          Determine if possible classes have been enumerated in the xml file.
 boolean isForeignKey()
          Utility method to determine if this column is a foreign key.
 boolean isInheritance()
          Determine if this column is a normal property or specifies a the classes that are represented in the table containing this column.
 boolean isMultipleFK()
          Determine if this column is a foreign key that refers to the same table as another foreign key column in this table.
 boolean isNotNull()
          Return the isNotNull property of the column
 boolean isPrimaryKey()
          Return true if the column is a primary key
 boolean isPrimitive()
          returns true, if the columns java native type is an boolean, byte, short, int, long, float, double, char
 boolean isString()
          Utility method to see if the column is a string
 boolean isUnique()
          Get the UNIQUE property
 boolean isUsePrimitive()
           
 void loadFromXML(org.xml.sax.Attributes attrib)
          Imports a column from an XML specification
static java.lang.String makeList(java.util.List columns)
          Return a comma delimited string listing the specified columns.
 java.lang.String printSize()
          Return the size in brackets for use in an sql schema if the type is String.
 boolean requiresTransactionInPostgres()
          Return true if the column requires a transaction in Postgres
 void setAutoIncrement(boolean value)
          Set the auto increment value.
 void setDefaultValue(java.lang.String def)
          Set a string that will give this column a default value.
 void setDescription(java.lang.String newDescription)
          Set the description for the Table
 void setJavaName(java.lang.String javaName)
          Set name to use in Java sources
 void setName(java.lang.String newName)
          Set the name of the column
 void setNotNull(boolean status)
          Set the isNotNull property of the column
 void setPosition(int v)
          Get the location of this column within the table (one-based).
 void setPrimaryKey(boolean pk)
          Set if the column is a primary key or not
 void setSize(java.lang.String newSize)
          Set the size of the column
 void setTable(Table parent)
          Set the parent Table of the column
 void setType(java.lang.String torqueType)
          Returns the colunm type
 void setTypeFromString(java.lang.String typeName, java.lang.String size)
          Set the column type from a string property (normally a string from an sql input file)
 void setUnique(boolean u)
          Set true if the column is UNIQUE
 java.lang.String toString()
          String representation of the column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private java.lang.String name

description

private java.lang.String description

javaName

private java.lang.String javaName

javaNamingMethod

private java.lang.String javaNamingMethod

isNotNull

private boolean isNotNull

size

private java.lang.String size

torqueType

private java.lang.String torqueType
type as defined in schema.xml


javaType

private java.lang.String javaType

columnType

private java.lang.Object columnType

parentTable

private Table parentTable

position

private int position

isPrimaryKey

private boolean isPrimaryKey

isUnique

private boolean isUnique

isAutoIncrement

private boolean isAutoIncrement

defaultValue

private java.lang.String defaultValue

referrers

private java.util.List referrers

inheritanceType

private java.lang.String inheritanceType

isInheritance

private boolean isInheritance

isEnumeratedClasses

private boolean isEnumeratedClasses

inheritanceList

private java.util.List inheritanceList

needsTransactionInPostgres

private boolean needsTransactionInPostgres

inputValidator

private java.lang.String inputValidator
class name to do input validation on this column

Constructor Detail

Column

public Column()
Creates a new instance with a null name.


Column

public Column(java.lang.String name)
Creates a new column and set the name

Parameters:
name - column name
Method Detail

makeList

public static java.lang.String makeList(java.util.List columns)
Return a comma delimited string listing the specified columns.

Parameters:
columns - Either a list of Column objects, or a list of String objects with column names.

loadFromXML

public void loadFromXML(org.xml.sax.Attributes attrib)
Imports a column from an XML specification


getFullyQualifiedName

public java.lang.String getFullyQualifiedName()
Returns table.column


getName

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


setName

public void setName(java.lang.String newName)
Set the name of the column


getDescription

public java.lang.String getDescription()
Get the description for the Table


setDescription

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

Parameters:
newDescription - description for the Table

getJavaName

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


setJavaName

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


getJavaType

public java.lang.String getJavaType()
Get type to use in Java sources


getPosition

public int getPosition()
Get the location of this column within the table (one-based).

Returns:
value of position.

setPosition

public void setPosition(int v)
Get the location of this column within the table (one-based).

Parameters:
v - Value to assign to position.

setTable

public void setTable(Table parent)
Set the parent Table of the column


getTable

public Table getTable()
Get the parent Table of the column


getTableName

public java.lang.String getTableName()
Returns the Name of the table the column is in


addInheritance

public Inheritance addInheritance(org.xml.sax.Attributes attrib)
A utility function to create a new column from attrib and add it to this table.


addInheritance

public void addInheritance(Inheritance inh)
Adds a new inheritance definition to the inheritance list and set the parent column of the inheritance to the current column


getChildren

public java.util.List getChildren()
Get the inheritance definitions.


isInheritance

public boolean isInheritance()
Determine if this column is a normal property or specifies a the classes that are represented in the table containing this column.


isEnumeratedClasses

public boolean isEnumeratedClasses()
Determine if possible classes have been enumerated in the xml file.


isNotNull

public boolean isNotNull()
Return the isNotNull property of the column


setNotNull

public void setNotNull(boolean status)
Set the isNotNull property of the column


setPrimaryKey

public void setPrimaryKey(boolean pk)
Set if the column is a primary key or not


isPrimaryKey

public boolean isPrimaryKey()
Return true if the column is a primary key


setUnique

public void setUnique(boolean u)
Set true if the column is UNIQUE


isUnique

public boolean isUnique()
Get the UNIQUE property


requiresTransactionInPostgres

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


isForeignKey

public boolean isForeignKey()
Utility method to determine if this column is a foreign key.


isMultipleFK

public boolean isMultipleFK()
Determine if this column is a foreign key that refers to the same table as another foreign key column in this table.


getForeignKey

public ForeignKey getForeignKey()
get the foreign key object for this column if it is a foreign key or part of a foreign key


getRelatedTableName

public java.lang.String getRelatedTableName()
Utility method to get the related table of this column if it is a foreign key or part of a foreign key


getRelatedColumnName

public java.lang.String getRelatedColumnName()
Utility method to get the related column of this local column if this column is a foreign key or part of a foreign key.


addReferrer

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


getReferrers

public java.util.List getReferrers()
Get list of references to this column.


setType

public void setType(java.lang.String torqueType)
Returns the colunm type


getType

public java.lang.Object getType()
Returns the column jdbc type as an object


getTorqueType

public java.lang.Object getTorqueType()
Returns the column type as given in the schema as an object


isString

public boolean isString()
Utility method to see if the column is a string


toString

public java.lang.String toString()
String representation of the column. This is an xml representation.


getSize

public java.lang.String getSize()
Returns the size of the column


setSize

public void setSize(java.lang.String newSize)
Set the size of the column


printSize

public java.lang.String printSize()
Return the size in brackets for use in an sql schema if the type is String. Otherwise return an empty string


getDefaultSetting

public java.lang.String getDefaultSetting()
Return a string that will give this column a default value.

TODO: Properly SQL-escape text values.


setDefaultValue

public void setDefaultValue(java.lang.String def)
Set a string that will give this column a default value.


getDefaultValue

public java.lang.String getDefaultValue()
Get a string that will give this column a default value.


getInputValidator

public java.lang.String getInputValidator()
Returns the class name to do input validation


isAutoIncrement

public boolean isAutoIncrement()
Return auto increment/sequence string for the target database. We need to pass in the props for the target database!


setAutoIncrement

public void setAutoIncrement(boolean value)
Set the auto increment value. Use isAutoIncrement() to find out if it is set or not.


setTypeFromString

public void setTypeFromString(java.lang.String typeName,
                              java.lang.String size)
Set the column type from a string property (normally a string from an sql input file)


getJavaObject

public java.lang.String getJavaObject()
Return a string representation of the Java object which corresponds to the JDBC type of this column. Use in the generation of MapBuilders.


getJavaPrimitive

public java.lang.String getJavaPrimitive()
Return a string representation of the primitive java type which corresponds to the JDBC type of this column.

Returns:
string representation of the primitive java type

getJavaNative

public java.lang.String getJavaNative()
Return a string representation of the native java type which corresponds to the JDBC type of this column. Use in the generation of Base objects. This method is used by torque, so it returns Key types for primaryKey and foreignKey columns

Returns:
java datatype used by torque

getVillageMethod

public java.lang.String getVillageMethod()
Return Village asX() method which corresponds to the JDBC type which represents this column.


getParameterParserMethod

public java.lang.String getParameterParserMethod()
Return ParameterParser getX() method which corresponds to the JDBC type which represents this column.


isBooleanInt

public boolean isBooleanInt()
Returns true if the column type is boolean in the java object and a numeric (1 or 0) in the db.


isBooleanChar

public boolean isBooleanChar()
Returns true if the column type is boolean in the java object and a String ("Y" or "N") in the db.


isPrimitive

public boolean isPrimitive()
returns true, if the columns java native type is an boolean, byte, short, int, long, float, double, char


isUsePrimitive

public boolean isUsePrimitive()


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