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

java.lang.Object
  extended by org.apache.torque.engine.database.model.Column

public class Column
extends Object

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

Version:
$Id: Column.java,v 1.1 2007-10-21 07:57:27 abyrne Exp $
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(String name)
          Creates a new column and set the name
 
Method Summary
 Inheritance addInheritance(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(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 column.
 String getAutoIncrementString()
           
 List getChildren()
          Get the inheritance definitions.
 String getDefaultSetting()
          Deprecated.  
 String getDefaultValue()
          Get a string that will give this column a default value.
 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
 String getFullyQualifiedName()
          Returns table.column
 String getGetterName()
          Returns the name for the getter method to retrieve the value of this column
 String getInheritanceType()
          Get the value of the inheritance attribute defined in the schema XML.
 String getInputValidator()
          Returns the class name to do input validation
 String getJavaName()
          Get name to use in Java sources to build method names.
 String getJavaNative()
          Return a string representation of the native java type which corresponds to the JDBC type of this column.
 String getJavaObject()
          Return a string representation of the Java object which corresponds to the JDBC type of this column.
 String getJavaPrimitive()
          Return a string representation of the primitive java type which corresponds to the JDBC type of this column.
 String getJavaType()
          Returns whether the type in the java object should be an object or primitive.
 int getJdbcType()
           
 String getName()
          Get the name of the column
 String getNotNullString()
          Return NOT NULL String for this column
 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 getParameterParserMethod()
          Return ParameterParser getX() method which corresponds to the JDBC type which represents this column.
 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).
 String getPrecision()
          Try to determine the precision of the field from the size attribute.
 List getReferrers()
          Get list of references to this column.
 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.
 String getRelatedTableName()
          Utility method to get the related table of this column if it is a foreign key or part of a foreign key
 String getScale()
          Try to determine the scale of the field from the scale and size attribute.
 String getSetterName()
          Returns the name for the setter method to set the value of this column
 String getSize()
          Returns the size of the column
 String getSqlString()
           
 Table getTable()
          Get the parent Table of the column
 String getTableName()
          Returns the Name of the table the column is in
 Object getTorqueType()
          Returns the column type as given in the schema as an object
 Object getType()
          Deprecated. the type conversion is handled by the platform package (since torque 3.2)
 String getUncapitalisedJavaName()
          Get variable name to use in Java sources (= uncapitalised java name)
 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(Attributes attrib)
          Imports a column from an XML specification
static String makeList(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.
 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(String def)
          Set a string that will give this column a default value.
 void setDescription(String newDescription)
          Set the description for the Table
 void setDomain(Domain domain)
           
 void setJavaName(String javaName)
          Set the name to use in Java sources.
 void setJdbcType(int jdbcType)
           
 void setName(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(String newScale)
          Set the scale of the column
 void setSize(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(String torqueType)
          Sets the colunm type
 void setTypeFromString(String typeName, 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
 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(String name)
Creates a new column and set the name

Parameters:
name - column name
Method Detail

makeList

public static String makeList(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(Attributes attrib)
Imports a column from an XML specification


getFullyQualifiedName

public String getFullyQualifiedName()
Returns table.column


getName

public String getName()
Get the name of the column


setName

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


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

Returns:
the capitalised javaName

getGetterName

public 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 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 String getUncapitalisedJavaName()
Get variable name to use in Java sources (= uncapitalised java name)


getPeerJavaName

public 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(String javaName)
Set the name to use in Java sources.


getJavaType

public 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 String getTableName()
Returns the Name of the table the column is in


addInheritance

public Inheritance addInheritance(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 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 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 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 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 List getReferrers()
Get list of references to this column.


setType

public void setType(String torqueType)
Sets the colunm type


setType

public void setType(SchemaType torqueType)
Sets the colunm type


getType

public 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 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 String toString()
String representation of the column. This is an xml representation.

Overrides:
toString in class Object
Returns:
string representation in xml

getSize

public String getSize()
Returns the size of the column


setSize

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


getPrecision

public 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 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(String newScale)
Set the scale of the column


printSize

public 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 String getDefaultSetting()
Deprecated. 

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


setDefaultValue

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


getDefaultValue

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


getInputValidator

public 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 String getAutoIncrementString()

setTypeFromString

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


getJavaObject

public 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 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 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 String getVillageMethod()
Return Village asX() method which corresponds to the JDBC type which represents this column.


getParameterParserMethod

public 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 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 String getInheritanceType()
Get the value of the inheritance attribute defined in the schema XML.

Returns:
Returns the inheritanceType.

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.

getJdbcType

public int getJdbcType()

setJdbcType

public void setJdbcType(int jdbcType)


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