jimm.datavision.source
Class Column

java.lang.Object
  extended by jimm.datavision.source.Column
All Implemented Interfaces:
Draggable, Identity, Nameable, Selectable, Writeable
Direct Known Subclasses:
NCColumn, SQLColumn, TestColumn

public class Column
extends java.lang.Object
implements Identity, Nameable, Selectable, Draggable, Writeable

Represents a data column. Not all data sources' columns will be contained within tables. For those that don't, their columns' getTable method will return null.

Author:
Jim Menard, jimm@io.com
See Also:
Table, DataSource

Field Summary
protected  java.lang.String dateParseFormat
           
static java.lang.String DEFAULT_DATE_PARSE_FORMAT
           
protected  java.lang.Object id
           
protected  java.lang.String name
           
protected  int type
           
 
Constructor Summary
Column(java.lang.Object id, java.lang.String name, int type)
           
 
Method Summary
 java.lang.String dragString()
          Returns the string used to identify the object when dragging it.
 boolean equals(java.lang.Object obj)
          Returns true if the other object is a column with the same id.
 java.lang.String fieldTypeString()
          Returns the string used to create a field of the appropriate type.
 java.lang.String fullName()
          Returns the full named of this column: the id as a string.
 java.lang.String getDateParseFormat()
          Returns the date parse format, useful for data sources that read text strings and convert them into date objects.
 java.lang.String getDisplayName()
           
 java.lang.Object getId()
          Returns the table id.
 java.lang.String getName()
          Returns the column's name.
 java.lang.String getSelectString(SQLQuery query)
          Returns the string used by a SQL query to select this object.
 java.lang.String getSortString(SQLQuery query)
          Returns the string used as the name/value of this selectable in a SQL ORDER BY clause.
 Table getTable()
          Returns the table to which this column belongs, if any.
 int getType()
          Returns the type constant (a java.sql.Types value).
 java.lang.Object getValue(Report report)
          Returns the current value.
 int hashCode()
           
 boolean isDate()
          Returns true if this column is some date type.
 boolean isNumeric()
          Returns true if this column is some numeric type (double, int, etc.)
 boolean isString()
          Returns true if this column is some character type.
 Selectable reloadInstance(DataSource dataSource)
          Returns a (possibly new) instance of this selectable object.
 void setDateParseFormat(java.lang.String format)
          Sets the date parse format, useful for data sources that read text strings and convert them into date objects.
 void setName(java.lang.String name)
          A column's name is immutable.
 java.lang.String toString()
          Returns a string representation of this column.
static int typeFromString(java.lang.String str)
           
static java.lang.String typeToString(int type)
           
 void writeXML(XMLWriter out)
          Writes this object as an XML tag.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DATE_PARSE_FORMAT

public static final java.lang.String DEFAULT_DATE_PARSE_FORMAT
See Also:
Constant Field Values

id

protected java.lang.Object id

name

protected java.lang.String name

type

protected int type

dateParseFormat

protected java.lang.String dateParseFormat
Constructor Detail

Column

public Column(java.lang.Object id,
              java.lang.String name,
              int type)
Method Detail

typeFromString

public static int typeFromString(java.lang.String str)

typeToString

public static java.lang.String typeToString(int type)

equals

public boolean equals(java.lang.Object obj)
Returns true if the other object is a column with the same id.

Overrides:
equals in class java.lang.Object
Parameters:
obj - any Object
Returns:
true if the other object is a column with the same id.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getId

public java.lang.Object getId()
Returns the table id. This is a string of the form "table_name.column_name".

Specified by:
getId in interface Identity
Specified by:
getId in interface Selectable
Returns:
the id string

getName

public java.lang.String getName()
Returns the column's name. The name may not be unique. To retrieve a unique name (for example, "table.column"), use fullName.

Specified by:
getName in interface Nameable
Returns:
the column's name
See Also:
fullName()

setName

public void setName(java.lang.String name)
A column's name is immutable.

Specified by:
setName in interface Nameable
Parameters:
name - the new name

getDateParseFormat

public java.lang.String getDateParseFormat()
Returns the date parse format, useful for data sources that read text strings and convert them into date objects. If no format has been defined, returns DEFAULT_DATE_PARSE_FORMAT

Returns:
the date parse format string (if not defined, returns DEFAULT_DATE_PARSE_FORMAT)

setDateParseFormat

public void setDateParseFormat(java.lang.String format)
Sets the date parse format, useful for data sources that read text strings and convert them into date objects. Called from ReportReader.column, for example.

Parameters:
format - the date parse format string

getTable

public Table getTable()
Returns the table to which this column belongs, if any.

Specified by:
getTable in interface Selectable
Returns:
the table, or null if there is none

fullName

public java.lang.String fullName()
Returns the full named of this column: the id as a string. The column's name may not be unique, but the full name should be unique.

For SQL columns, this is a string of the form "table_name.column_name". To retrieve just the column name, use getName.

Returns:
the full name; this is the same as the id as a string
See Also:
getName()

getType

public int getType()
Returns the type constant (a java.sql.Types value).

Returns:
a java.sql.Types value
See Also:
Types

getValue

public java.lang.Object getValue(Report report)
Description copied from interface: Selectable
Returns the current value. May only be valid during a report run.

Specified by:
getValue in interface Selectable
Parameters:
report - a report
Returns:
the current value

fieldTypeString

public java.lang.String fieldTypeString()
Description copied from interface: Selectable
Returns the string used to create a field of the appropriate type.

Specified by:
fieldTypeString in interface Selectable
Returns:
a string useable by Field.create
See Also:
Field.create(java.lang.Long, jimm.datavision.Report, jimm.datavision.Section, java.lang.String, java.lang.Object, boolean)

getSelectString

public java.lang.String getSelectString(SQLQuery query)
Description copied from interface: Selectable
Returns the string used by a SQL query to select this object.

Specified by:
getSelectString in interface Selectable

getSortString

public java.lang.String getSortString(SQLQuery query)
Description copied from interface: Selectable
Returns the string used as the name/value of this selectable in a SQL ORDER BY clause. This may be the same as the select string returned by getSelectString.

Specified by:
getSortString in interface Selectable
Returns:
a string used when creating the ORDER BY clause
See Also:
Selectable.getSelectString(jimm.datavision.source.sql.SQLQuery)

dragString

public java.lang.String dragString()
Description copied from interface: Draggable
Returns the string used to identify the object when dragging it.

Specified by:
dragString in interface Draggable
Returns:
a string used to identify the object when dragging it

getDisplayName

public java.lang.String getDisplayName()
Specified by:
getDisplayName in interface Selectable

reloadInstance

public Selectable reloadInstance(DataSource dataSource)
Description copied from interface: Selectable
Returns a (possibly new) instance of this selectable object. Used when we are reestablishing or resetting a connection to a database. The instance returned may or may not be the same object as this one.

Specified by:
reloadInstance in interface Selectable

isNumeric

public boolean isNumeric()
Returns true if this column is some numeric type (double, int, etc.)

Returns:
true if this column is some numeric type (double, int, etc.)

isDate

public boolean isDate()
Returns true if this column is some date type.

Returns:
true if this column is some date type

isString

public boolean isString()
Returns true if this column is some character type.

Returns:
true if this column is some character type

toString

public java.lang.String toString()
Returns a string representation of this column. Calls fullName.

Overrides:
toString in class java.lang.Object
See Also:
fullName()

writeXML

public void writeXML(XMLWriter out)
Description copied from interface: Writeable
Writes this object as an XML tag.

Specified by:
writeXML in interface Writeable
Parameters:
out - a writer that knows how to write XML