ca.sqlpower.architect
Class SQLColumn

java.lang.Object
  extended by ca.sqlpower.architect.SQLObject
      extended by ca.sqlpower.architect.SQLColumn
All Implemented Interfaces:
java.io.Serializable

public class SQLColumn
extends SQLObject
implements java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
static class SQLColumn.ColumnNameComparator
          A comparator for SQLColumns that only pays attention to the column names.
static class SQLColumn.CompareByPKSeq
          This comparator helps you sort a list of columns so that the primary key columns come first in their correct order, and all the other columns come after.
 
Field Summary
protected  boolean autoIncrement
          This property indicates that values stored in this column should default to some automatcially-incrementing sequence of values.
protected  java.lang.String defaultValue
           
protected  int nullable
          This column's nullability type.
protected  SQLObject parent
           
protected  int precision
          The maximum length of the field in digits or characters.
protected  java.lang.Integer primaryKeySeq
          This property is the sort key for this column in primary key index.
protected  int referenceCount
          referenceCount is meant to keep track of how many containers (i.e.
protected  java.lang.String remarks
           
protected  int scale
          The maximum number of digits after the decimal point.
protected  SQLColumn sourceColumn
          Refers back to the real database-connected SQLColumn that this column was originally derived from.
protected  int type
          Must be a type defined in java.sql.Types.
 
Fields inherited from class ca.sqlpower.architect.SQLObject
children, magicDisableCount, populated, undoEventListeners
 
Constructor Summary
SQLColumn()
           
SQLColumn(SQLColumn col)
          Creates a reasonable facsimile of the given column.
SQLColumn(SQLTable parent, java.lang.String colName, int type, int precision, int scale)
           
SQLColumn(SQLTable parentTable, java.lang.String colName, int dataType, java.lang.String nativeType, int precision, int scale, int nullable, java.lang.String remarks, java.lang.String defaultValue, java.lang.Integer primaryKeySeq, boolean isAutoIncrement)
          Constructs a SQLColumn that will be a part of the given SQLTable.
 
Method Summary
 void addReference()
           
 boolean allowsChildren()
          Returns true if and only if this object can have child SQLObjects.
 java.lang.String getAutoIncrementSequenceName()
          Returns the auto-increment sequence name, or a made-up default (parentTableName_columnName_seq) if the sequence name has not been set explicitly.
 java.lang.Class<? extends SQLObject> getChildType()
           
 java.lang.String getDefaultValue()
          Gets the value of defaultValue
static SQLColumn getDerivedInstance(SQLColumn source, SQLTable addTo)
          Makes a near clone of the given source column.
 int getNullable()
           
 SQLObject getParent()
          Returns the parent of this SQLObject or null if it is a root object such as SQLDatabase.
 SQLTable getParentTable()
          Returns the parent SQLTable object, which is actually a grandparent.
 int getPrecision()
          Gets the value of precision
 java.lang.Integer getPrimaryKeySeq()
          Gets the value of primaryKeySeq
 int getReferenceCount()
           
 java.lang.String getRemarks()
          Gets the value of remarks
 int getScale()
          Gets the value of scale
 java.lang.String getShortDisplayName()
          Returns a short string that should be displayed to the user for representing this SQLObject as a label.
 SQLColumn getSourceColumn()
           
 java.lang.String getSourceDataTypeName()
           
 int getType()
          Gets the value of type
 boolean isAutoIncrement()
          Gets the value of autoIncrement
 boolean isAutoIncrementSequenceNameSet()
          Returns true if the auto-increment sequence name of this column has been changed from its default value.
 boolean isDefinitelyNullable()
          Figures out this column's nullability
 boolean isExported()
          Indicates whether or not this column is exported into a foreign key in a child table.
 boolean isForeignKey()
          Indicates whether this column is a foreign key
 boolean isIndexed()
          Returns whether this column is in an index
 boolean isPopulated()
          Tells if this object has already been filled with children, or if that operation is still pending.
 boolean isPrimaryKey()
          Is primaryKeySeq defined
 boolean isUniqueIndexed()
          Returns whether this column is in an unique index.
 void populate()
          Causes this SQLObject to load its children (if any exist).
 void removeReference()
           
 void setAutoIncrement(boolean argAutoIncrement)
          Sets the value of autoIncrement
 void setAutoIncrementSequenceName(java.lang.String autoIncrementSequenceName)
          Only sets the name if it is different from the default name.
 void setDefaultValue(java.lang.String argDefaultValue)
          Sets the value of defaultValue
 void setNullable(int argNullable)
          Sets the value of nullable
protected  void setParent(SQLObject argParent)
          Sets the value of parent
 void setPrecision(int argPrecision)
          Sets the value of precision
 void setPrimaryKeySeq(java.lang.Integer argPrimaryKeySeq)
          Sets the value of primaryKeySeq, and moves the column to the appropriate location in the parent table's column folder.
 void setReferenceCount(int referenceCount)
          Deprecated. This method exists only to be called reflectively by the undo manager. You should use addReference() and removeReference().
 void setRemarks(java.lang.String argRemarks)
          Sets the value of remarks
 void setScale(int argScale)
          Sets the value of scale
 void setSourceColumn(SQLColumn col)
           
 void setSourceDataTypeName(java.lang.String n)
           
 void setType(int argType)
          Sets the value of type
 java.lang.String toString()
           
 
Methods inherited from class ca.sqlpower.architect.SQLObject
addChild, addChild, addChildImpl, addSQLObjectListener, addSQLObjectPreEventListener, addUndoEventListener, endCompoundEdit, fireDbChildInserted, fireDbChildPreRemove, fireDbChildRemoved, fireDbChildrenInserted, fireDbChildrenPreRemove, fireDbChildrenRemoved, fireDbObjectChanged, fireDbStructureChanged, getChild, getChildByName, getChildByNameIgnoreCase, getChildCount, getChildren, getIndexOfChildByName, getName, getPhysicalName, getSQLObjectListeners, getSQLObjectPreEventListeners, getUndoEventListeners, isMagicEnabled, removeChild, removeChild, removeImpl, removeSQLObjectListener, removeSQLObjectPreEventListener, removeUndoEventListener, setMagicEnabled, setName, setPhysicalName, setPopulated, startCompoundEdit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sourceColumn

protected SQLColumn sourceColumn
Refers back to the real database-connected SQLColumn that this column was originally derived from.


parent

protected SQLObject parent

type

protected int type
Must be a type defined in java.sql.Types. Move to enum in 1.5 (we hope!).


precision

protected int precision
The maximum length of the field in digits or characters. For numeric types, this value includes all significant digits on both sides of the decimal point.


scale

protected int scale
The maximum number of digits after the decimal point. For non-numeric data types, this value should be set to 0.


nullable

protected int nullable
This column's nullability type. One of:


remarks

protected java.lang.String remarks

defaultValue

protected java.lang.String defaultValue

primaryKeySeq

protected java.lang.Integer primaryKeySeq
This property is the sort key for this column in primary key index. If the value is null, then it is not a primary key column.


autoIncrement

protected boolean autoIncrement
This property indicates that values stored in this column should default to some automatcially-incrementing sequence of values. Every database platform handles the specifics of this a little differently, but the DDL generators are responsible for taking care of that.


referenceCount

protected int referenceCount
referenceCount is meant to keep track of how many containers (i.e. folders and relationships) have a reference to a column. A new SQLColumn always starts off life with a reference count of 1. (it is set in the constructors). When creating a new relationship which reuses a column, the call addReference() on the column to increment the referenceCount. When removing a relationship, call removeReference() on the column to decrement the referenceCount. If the referenceCount falls to zero, it removes itself from the containing table (because it imported by the creation of a relationship.

Constructor Detail

SQLColumn

public SQLColumn()

SQLColumn

public SQLColumn(SQLTable parentTable,
                 java.lang.String colName,
                 int dataType,
                 java.lang.String nativeType,
                 int precision,
                 int scale,
                 int nullable,
                 java.lang.String remarks,
                 java.lang.String defaultValue,
                 java.lang.Integer primaryKeySeq,
                 boolean isAutoIncrement)
Constructs a SQLColumn that will be a part of the given SQLTable.

Parameters:
parentTable - The table that this column will think it belongs to.
colName - This column's name.
dataType - The number that represents this column's type. See java.sql.Types.
nativeType - The type as it is called in the source database.
scale - The length of this column. Size is type-dependant.
precision - The number of places of precision after the decimal place for numeric types.
nullable - This column's nullability. One of:
  • DatabaseMetaData.columnNoNulls - might not allow NULL values
  • DatabaseMetaData.columnNullable - definitely allows NULL values
  • DatabaseMetaData.columnNullableUnknown - nullability unknown
remarks - User-defined remarks about this column
defaultValue - The value this column will have if another value is not specified.
primaryKeySeq - This column's position in the table's primary key. Null if it is not in the PK.
isAutoIncrement - Does this column auto-increment?

SQLColumn

public SQLColumn(SQLTable parent,
                 java.lang.String colName,
                 int type,
                 int precision,
                 int scale)

SQLColumn

public SQLColumn(SQLColumn col)
Creates a reasonable facsimile of the given column.

Method Detail

getDerivedInstance

public static SQLColumn getDerivedInstance(SQLColumn source,
                                           SQLTable addTo)
Makes a near clone of the given source column. The new column you get back will have a parent pointer of addTo.columnsFolder, but will not be attached as a child (you will normally do that right after calling this). It will refer to source as its sourceColumn property, and otherwise be identical to source. getDerivedInstance is used for reverse engineering. Will not preserve listeners.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

populate

public void populate()
              throws ArchitectException
Description copied from class: SQLObject
Causes this SQLObject to load its children (if any exist). This method will be called lots of times, so track whether or not you need to do anything and return right away whenever possible.

Specified by:
populate in class SQLObject
Throws:
ArchitectException

isPopulated

public boolean isPopulated()
Description copied from class: SQLObject
Tells if this object has already been filled with children, or if that operation is still pending.

Overrides:
isPopulated in class SQLObject

getShortDisplayName

public java.lang.String getShortDisplayName()
Description copied from class: SQLObject
Returns a short string that should be displayed to the user for representing this SQLObject as a label.

Specified by:
getShortDisplayName in class SQLObject

allowsChildren

public boolean allowsChildren()
Description copied from class: SQLObject
Returns true if and only if this object can have child SQLObjects. Your implementation of this method must not cause JDBC activity, or the lazy loading properties of your SQLObjects will be wasted! Typically, you will implement this with a hardcoded "return true" or "return false" depending on object type.

Specified by:
allowsChildren in class SQLObject

getParent

public SQLObject getParent()
Description copied from class: SQLObject
Returns the parent of this SQLObject or null if it is a root object such as SQLDatabase.

Specified by:
getParent in class SQLObject

getSourceColumn

public SQLColumn getSourceColumn()

setSourceColumn

public void setSourceColumn(SQLColumn col)

getType

public int getType()
Gets the value of type

Returns:
the value of type

setType

public void setType(int argType)
Sets the value of type

Parameters:
argType - Value to assign to this.type

getSourceDataTypeName

public java.lang.String getSourceDataTypeName()

setSourceDataTypeName

public void setSourceDataTypeName(java.lang.String n)

getScale

public int getScale()
Gets the value of scale

Returns:
the value of scale

setScale

public void setScale(int argScale)
Sets the value of scale

Parameters:
argScale - Value to assign to this.scale

getPrecision

public int getPrecision()
Gets the value of precision

Returns:
the value of precision

setPrecision

public void setPrecision(int argPrecision)
Sets the value of precision

Parameters:
argPrecision - Value to assign to this.precision

isDefinitelyNullable

public boolean isDefinitelyNullable()
Figures out this column's nullability

Returns:
true iff this.nullable == DatabaseMetaData.columnNullable.

isPrimaryKey

public boolean isPrimaryKey()
Is primaryKeySeq defined

Returns:
whether or not primaryKeySeq is defined

isForeignKey

public boolean isForeignKey()
Indicates whether this column is a foreign key

Returns:
whether this column exists as a foreign key column in any of its parent table's imported keys

isExported

public boolean isExported()
Indicates whether or not this column is exported into a foreign key in a child table.

Returns:
Returns true if this column is in an exported key. Otherwise, returns false.

isIndexed

public boolean isIndexed()
Returns whether this column is in an index


isUniqueIndexed

public boolean isUniqueIndexed()
Returns whether this column is in an unique index.


getParentTable

public SQLTable getParentTable()
Returns the parent SQLTable object, which is actually a grandparent.


setParent

protected void setParent(SQLObject argParent)
Sets the value of parent

Specified by:
setParent in class SQLObject
Parameters:
argParent - Value to assign to this.parent

getNullable

public int getNullable()

setNullable

public void setNullable(int argNullable)
Sets the value of nullable

Parameters:
argNullable - Value to assign to this.nullable

getRemarks

public java.lang.String getRemarks()
Gets the value of remarks

Returns:
the value of remarks

setRemarks

public void setRemarks(java.lang.String argRemarks)
Sets the value of remarks

Parameters:
argRemarks - Value to assign to this.remarks

getDefaultValue

public java.lang.String getDefaultValue()
Gets the value of defaultValue

Returns:
the value of defaultValue

setDefaultValue

public void setDefaultValue(java.lang.String argDefaultValue)
Sets the value of defaultValue

Parameters:
argDefaultValue - Value to assign to this.defaultValue

getPrimaryKeySeq

public java.lang.Integer getPrimaryKeySeq()
Gets the value of primaryKeySeq

Returns:
the value of primaryKeySeq

setPrimaryKeySeq

public void setPrimaryKeySeq(java.lang.Integer argPrimaryKeySeq)
Sets the value of primaryKeySeq, and moves the column to the appropriate location in the parent table's column folder. However, if magic is disabled on this column, this method simply sets the PrimaryKeySeq property to the given value, fires the change event, and returns without trying to re-order the columns. If there is no primary key on this column's table it will create a new key with default values.


isAutoIncrement

public boolean isAutoIncrement()
Gets the value of autoIncrement

Returns:
the value of autoIncrement

setAutoIncrement

public void setAutoIncrement(boolean argAutoIncrement)
Sets the value of autoIncrement

Parameters:
argAutoIncrement - Value to assign to this.autoIncrement

getAutoIncrementSequenceName

public java.lang.String getAutoIncrementSequenceName()
Returns the auto-increment sequence name, or a made-up default (parentTableName_columnName_seq) if the sequence name has not been set explicitly. The auto-increment sequence name is a hint to DDL generators for platforms that need sequence objects to support auto-incrementing column values.


setAutoIncrementSequenceName

public void setAutoIncrementSequenceName(java.lang.String autoIncrementSequenceName)
Only sets the name if it is different from the default name. This is important in case the table name changes; the name should be expected to update.


isAutoIncrementSequenceNameSet

public boolean isAutoIncrementSequenceNameSet()
Returns true if the auto-increment sequence name of this column has been changed from its default value. Code that loads and saves this SQLColumn will want to know if the value is a default or not.


addReference

public void addReference()

removeReference

public void removeReference()

getReferenceCount

public int getReferenceCount()
Returns:
Returns the referenceCount.

setReferenceCount

@Deprecated
public void setReferenceCount(int referenceCount)
Deprecated. This method exists only to be called reflectively by the undo manager. You should use addReference() and removeReference().

WARNING this should not be used by hand coded objects

Parameters:
referenceCount -

getChildType

public java.lang.Class<? extends SQLObject> getChildType()
Specified by:
getChildType in class SQLObject


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca