ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.beans
Class AbleDBTable

java.lang.Object
  |
  +--com.ibm.able.beans.AbleDBTable
All Implemented Interfaces:
AbleImportData, java.io.Serializable

public class AbleDBTable
extends java.lang.Object
implements AbleImportData, java.io.Serializable

This class describes and reads an SQL database table. It uses metadata from the result set to obtain the field name and type in order to create a Vector of AbleFields. It reads a block of records specified by bufferSize into a textData Vector where each element consists of an array of String objects.

See Also:
Serialized Form

Field Summary
protected  boolean allNumericData
          A boolean indicating whether all fields in the data source are continuous.
protected  int bufferSize
          An integer specifying the number of records to read from the database table and insert into the textData Vector.
protected  java.util.Vector fieldList
          A Vector of AbleField elements in order of definition; ie, Vector index equals SQL column number.
protected  long numRecords
          A long calculated to be the number of records in the database table.
protected  java.lang.String query
          The Query to execute to obtain the resultSet.
protected  boolean ready
          A boolean indicating whether the database table is ready for processing.
protected  java.sql.ResultSet resultSet
          The result of the query.
protected  java.util.Vector textData
          A Vector of String arrays containing records from the database table.
 
Constructor Summary
AbleDBTable(java.sql.Connection connection, java.lang.String query)
          Construct an AbleDBTable object for a given connection and query.
 
Method Summary
 void close()
          Close the Statement and ResultSet.
static java.lang.String Copyright()
          Determine the copyright of this class.
protected  AbleField createAbleField(AbleFieldDefinition definition)
          Construct a corresponding AbleField from an AbleFieldDefinition.
 void displayVariables()
          Display the fieldList and its values.
 int getBufferSize()
          Return the number of records to place in the textData Vector each time a record block is read with readNextRecordBlock.
 java.util.Vector getFieldList()
          Return a Vector of AbleField objects where each object describes a data column.
 int getNumFieldsPerRec()
          Return the number of fields in each record.
 long getNumRecords()
          Return the number of records in this database table.
 java.sql.ResultSet getResultSet()
          Return the ResultSet object, which may be null.
 java.sql.Statement getStatement()
          Return the Statement object, which may be null.
 java.util.Vector getTextData()
          Returns a Vector of String[] objects representing all loaded text data.
 boolean isAllNumericData()
          Returns true if all fields are "continuous", false if any are "discrete" or "categorical" (i.e.
 boolean isReady()
          Return whether or not the database table is ready for processing.
 void loadDataFile()
          Load the entire data file from a database table into the textData Vector.
 void loadMetaDataDefinition()
          Read the meta data from the resultSet, and then construct corresponding AbleField objects.
 void open()
          Execute the query, obtaining a ResultSet.
 void readNextRecordBlock()
          Read the next n records from a database table into a vector of String arrays.
 void reopen()
          Execute the query.
 void setBufferSize(int size)
          Set the number of records to place in the textData Vector each time a record block is read with readNextRecordBlock.
 void setFieldList(java.util.Vector fieldList)
          Set a Vector of AbleField objects where each object describes a data column.
 java.lang.String toString()
          Return a formatted string describing the state of this DataSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

query

protected java.lang.String query
The Query to execute to obtain the resultSet.

resultSet

protected transient java.sql.ResultSet resultSet
The result of the query.

textData

protected java.util.Vector textData
A Vector of String arrays containing records from the database table. The Vector contains all records if bufferSize is 0.

fieldList

protected java.util.Vector fieldList
A Vector of AbleField elements in order of definition; ie, Vector index equals SQL column number.

bufferSize

protected int bufferSize
An integer specifying the number of records to read from the database table and insert into the textData Vector. A value of 0 means all records are to be read.

numRecords

protected long numRecords
A long calculated to be the number of records in the database table.

ready

protected boolean ready
A boolean indicating whether the database table is ready for processing.

allNumericData

protected boolean allNumericData
A boolean indicating whether all fields in the data source are continuous.
Constructor Detail

AbleDBTable

public AbleDBTable(java.sql.Connection connection,
                   java.lang.String query)
            throws AbleException
Construct an AbleDBTable object for a given connection and query.
Parameters:
connection - A Connection object from which an SQL Statement will be created.
query - A String containing the SQL statement text to be executed.
Method Detail

isReady

public boolean isReady()
Return whether or not the database table is ready for processing.
Specified by:
isReady in interface AbleImportData

displayVariables

public void displayVariables()
Display the fieldList and its values.

createAbleField

protected AbleField createAbleField(AbleFieldDefinition definition)
                             throws AbleException
Construct a corresponding AbleField from an AbleFieldDefinition. Categorical, continuous, and discrete are supported.
Parameters:
definition - An AbleFieldDefinition.
Returns:
A corresponding AbleField object.
Throws:
An - exception if the AbleFieldDefinition provided is unsupported.

loadMetaDataDefinition

public void loadMetaDataDefinition()
                            throws AbleException
Read the meta data from the resultSet, and then construct corresponding AbleField objects. Note SQL metadata does not include column usage.

getNumFieldsPerRec

public int getNumFieldsPerRec()
Return the number of fields in each record.
Specified by:
getNumFieldsPerRec in interface AbleImportData

open

public void open()
          throws AbleException
Execute the query, obtaining a ResultSet. From the resultSet, create the fieldList from the resultSet's meta data. Then read each record in the table, and populate the textData Vector with as many records as specified by the bufferSize.
Specified by:
open in interface AbleImportData

reopen

public void reopen()
            throws AbleException
Execute the query. Close the resultSet if it exists.

close

public void close()
Close the Statement and ResultSet.
Specified by:
close in interface AbleImportData

loadDataFile

public void loadDataFile()
                  throws AbleException
Load the entire data file from a database table into the textData Vector. Once the number of records specified by bufferSize is reached, cease populating the textData Vector, but continue reading so that the AbleField values for each field type and the number of records is calculated. Access the data via the getTextData method.

readNextRecordBlock

public void readNextRecordBlock()
                         throws AbleException
Read the next n records from a database table into a vector of String arrays. Assumes that the fieldList and textData Vectors have already been created, and the query has been executed. When the last record in the database is found, wrap back to the first record and continue populating elements of the textData Vector until its size reaches the bufferSize.
Specified by:
readNextRecordBlock in interface AbleImportData

getTextData

public java.util.Vector getTextData()
Returns a Vector of String[] objects representing all loaded text data. Note: This represents the original data as read from the file.
Specified by:
getTextData in interface AbleImportData

isAllNumericData

public boolean isAllNumericData()
Returns true if all fields are "continuous", false if any are "discrete" or "categorical" (i.e. symbols).
Specified by:
isAllNumericData in interface AbleImportData

setBufferSize

public void setBufferSize(int size)
Set the number of records to place in the textData Vector each time a record block is read with readNextRecordBlock.
Specified by:
setBufferSize in interface AbleImportData

getBufferSize

public int getBufferSize()
Return the number of records to place in the textData Vector each time a record block is read with readNextRecordBlock.
Specified by:
getBufferSize in interface AbleImportData

getFieldList

public java.util.Vector getFieldList()
Return a Vector of AbleField objects where each object describes a data column.
Specified by:
getFieldList in interface AbleImportData

getResultSet

public java.sql.ResultSet getResultSet()
                                throws AbleException
Return the ResultSet object, which may be null.

getStatement

public java.sql.Statement getStatement()
                                throws AbleException
Return the Statement object, which may be null.

setFieldList

public void setFieldList(java.util.Vector fieldList)
Set a Vector of AbleField objects where each object describes a data column.
Specified by:
setFieldList in interface AbleImportData

getNumRecords

public long getNumRecords()
Return the number of records in this database table.
Specified by:
getNumRecords in interface AbleImportData

toString

public java.lang.String toString()
Return a formatted string describing the state of this DataSet.
Overrides:
toString in class java.lang.Object

Copyright

public static java.lang.String Copyright()
Determine the copyright of this class.
Returns:
A String containing this class's copyright statement.


ABLE 2.0.0 07/02/2003 10:25:01

(C) Copyright IBM Corporation 1999, 2003