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

java.lang.Object
  extended by org.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 476581 2006-11-18 18:14:14Z tv $
Author:
Leon Messerschmidt, Jason van Zyl, Jon S. Stevens, Daniel Rall, Martin Poeschl,
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 addOption(java.lang.String key, java.lang.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 column.
 java.lang.String getAutoIncrementString()
           
 java.util.List getChildren()
          Get the inheritance definitions.
 java.lang.String getDefaultSetting()
          Deprecated.  
 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
 Domain getDomain()
           
 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 getGetterName()
          Returns the name for the getter method to retrieve the value of this column
 java.lang.String getInheritanceType()
          Get the value of the inheritance attribute defined in the schema XML.
 java.lang.String getInputValidator()
          Returns the class name to do input validation
 java.lang.String getJavaName()
          Get name to use in Java sources to build method names.
 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()
          Returns whether the type in the java object should be an object or primitive.
 java.lang.String getName()
          Get the name of the column
 java.lang.String getNotNullString()
          Return NOT NULL String for this column
 java.lang.String getOption(java.lang.String key)
          Get the value that was associated with this key in an XML option element.
 java.util.Map getOptions()
          Gets the full ordered hashtable array of items specified by XML option statements under this element.
 java.lang.String getParameterParserMethod()
          Return ParameterParser getX() method which corresponds to the JDBC type which represents this column.
 java.lang.String getPeerJavaName()
          Returns the name of the constant that is used for the column in the Peer class, e.g., RecordPeer.COLVARNAME.
 int getPosition()
          Get the location of this column within the table (one-based).
 java.lang.String getPrecision()
          Try to determine the precision of the field from the size attribute.
 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 getScale()
          Try to determine the scale of the field from the scale and size attribute.
 java.lang.String getSetterName()
          Returns the name for the setter method to set the value of this column
 java.lang.String getSize()
          Returns the size of the column
 java.lang.String getSqlString()
           
 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()
          Deprecated. the type conversion is handled by the platform package (since torque 3.2)
 java.lang.String getUncapitalisedJavaName()
          Get variable name to use in Java sources (= uncapitalised java name)
 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 isBit()
          Returns true if the column type is boolean in the java object and a Bit ("1" or "0") in the db.
 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 isCorrectGetters()
          Return the correctGetters property of the column
 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 isProtected()
          Return the isProtected property of the column
 boolean isString()
          Deprecated. will be removed after the 3.3 release
 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.
 boolean needEscapedValue()
          Utility method to return the value as an element to be usable in an SQL insert statement.
 java.lang.String printSize()
          Return the size and scale in brackets for use in an sql schema.
 boolean requiresTransactionInPostgres()
          Return true if the column requires a transaction in Postgres
 void setAutoIncrement(boolean value)
          Set the auto increment value.
 void setCorrectGetters(boolean correctGetters)
          Set the correctGetters property of the column.
 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 setDomain(Domain domain)
           
 void setJavaName(java.lang.String javaName)
          Set the 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 setProtected(boolean prot)
          Set the isProtected property of the Column
 void setScale(java.lang.String newScale)
          Set the scale of the column
 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(SchemaType torqueType)
          Sets the colunm type
 void setType(java.lang.String torqueType)
          Sets 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
 

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 to build method names.

Returns:
the capitalised javaName

getGetterName

public java.lang.String getGetterName()
Returns the name for the getter method to retrieve the value of this column

Returns:
A getter method name for this column.
Since:
3.2

getSetterName

public java.lang.String getSetterName()
Returns the name for the setter method to set the value of this column

Returns:
A setter method name for this column.
Since:
3.2

getUncapitalisedJavaName

public java.lang.String getUncapitalisedJavaName()
Get variable name to use in Java sources (= uncapitalised java name)


getPeerJavaName

public java.lang.String getPeerJavaName()
Returns the name of the constant that is used for the column in the Peer class, e.g., RecordPeer.COLVARNAME. Generally this will be a straight conversion to upper case. But if the column name is equals to TABLE_NAME or DATABASE_NAME (Torque predefined vars), the column name will have an _ prefixed, e.g. _TABLE_NAME.

TODO: Handle delimited column names that have non-Java identifier characters in them.

Returns:
The name to use in defining the Peer class column variable.

setJavaName

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


getJavaType

public java.lang.String getJavaType()
Returns whether the type in the java object should be an object or primitive.


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


getNotNullString

public java.lang.String getNotNullString()
Return NOT NULL String for this column

Returns:
"NOT NULL" if null values are not allowed or an empty String.

isProtected

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


setProtected

public void setProtected(boolean prot)
Set the isProtected 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)
Sets the colunm type


setType

public void setType(SchemaType torqueType)
Sets the colunm type


getType

public java.lang.Object getType()
Deprecated. the type conversion is handled by the platform package (since torque 3.2)

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()
Deprecated. will be removed after the 3.3 release

Utility method to see if the column is a string


needEscapedValue

public boolean needEscapedValue()
Utility method to return the value as an element to be usable in an SQL insert statement. This is used from the SQL loader task


toString

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

Overrides:
toString in class java.lang.Object
Returns:
string representation in xml

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


getPrecision

public java.lang.String getPrecision()
Try to determine the precision of the field from the size attribute. If size attribute is an integer number, it will be returned. If size attribute is of the format "Precision,Scale", then Precision will be returned. If size is null or the size value is not an valid integer, null is returned.

Note: Unparseable values will be logged as a warning.

Returns:
The precision portion of the size attribute.

getScale

public java.lang.String getScale()
Try to determine the scale of the field from the scale and size attribute. If scale attribute is an integer number, it will be returned. If size attribute is of the format "Precision,Scale", then Scale will be returned. If scale and size attributes are null or the scale value found is not an valid integer, a null value is returned.

Note: Unparseable values will be logged as a warning.

Returns:
The precision portion of the size attribute.

setScale

public void setScale(java.lang.String newScale)
Set the scale of the column


printSize

public java.lang.String printSize()
Return the size and scale in brackets for use in an sql schema.

Returns:
size and scale or an empty String if there are no values available.

getDefaultSetting

public java.lang.String getDefaultSetting()
Deprecated. 

Return a string that will give this column a default value.


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.


getAutoIncrementString

public java.lang.String getAutoIncrementString()

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.


isBit

public boolean isBit()
Returns true if the column type is boolean in the java object and a Bit ("1" or "0") 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()

getDomain

public Domain getDomain()
Returns:
Returns the domain.

setDomain

public void setDomain(Domain domain)
Parameters:
domain - The domain to set.

getSqlString

public java.lang.String getSqlString()

isCorrectGetters

public boolean isCorrectGetters()
Return the correctGetters property of the column

Returns:
The currentValue of the correctGetters property.
Since:
3.2

setCorrectGetters

public void setCorrectGetters(boolean correctGetters)
Set the correctGetters property of the column. If set to true, the column returns is<xxx> as the getter name which is correct for the Bean Specs but incompatible to pre-3.2 releases.

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

getInheritanceType

public java.lang.String getInheritanceType()
Get the value of the inheritance attribute defined in the schema XML.

Returns:
Returns the inheritanceType.

addOption

public void addOption(java.lang.String key,
                      java.lang.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 java.lang.String getOption(java.lang.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 java.util.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 © 2000-2012 Apache Software Foundation. All Rights Reserved.