com.workingdogs.village
Class DataSet

java.lang.Object
  extended bycom.workingdogs.village.DataSet
Direct Known Subclasses:
QueryDataSet, TableDataSet

public abstract class DataSet
extends java.lang.Object

The DataSet represents a table in the database. It is extended by QueryDataSet and TableDataSet and should not be used directly. A DataSet contains a Schema and potentially a collection of Records.

Version:
$Revision: 1.17 $
Author:
Jon S. Stevens jon@latchkey.com

Field Summary
protected static int ALL_RECORDS
          indicates that all records should be retrieved during a fetch
(package private)  boolean allRecordsRetrieved
          have all records been retrieved with the fetchRecords?
private  java.lang.String columns
          the columns in the SELECT statement for this DataSet
(package private)  java.sql.Connection conn
          this DataSet's connection object
private  KeyDef keyDefValue
          the KeyDef for this DataSet
(package private)  int lastFetchSize
          number of records that were last fetched
(package private)  int recordRetrievedCount
          number of records retrieved
(package private)  java.util.Vector records
          this DataSet's collection of Record objects
(package private)  java.sql.ResultSet resultSet
          the result set for this DataSet
(package private)  Schema schema
          this DataSet's schema object
(package private)  java.lang.StringBuffer selectString
          the select string that was used to build this DataSet
(package private)  java.sql.Statement stmt
          the Statement for this DataSet
(package private)  int totalFetchCount
          number of records total that have been fetched
 
Constructor Summary
  DataSet()
          Private, not used
(package private) DataSet(java.sql.Connection conn, Schema schema, KeyDef keydef)
          Create a new DataSet with a connection, schema and KeyDef
(package private) DataSet(java.sql.Connection conn, java.lang.String tableName)
          Create a new DataSet with a connection and a Table name
(package private) DataSet(java.sql.Connection conn, java.lang.String tableName, KeyDef keydef)
          Create a new DataSet with a connection, tablename and KeyDef
(package private) DataSet(java.sql.Connection conn, java.lang.String tableName, java.lang.String columns)
          Create a new DataSet with a connection, tablename and list of columns
(package private) DataSet(java.sql.Connection conn, java.lang.String tableName, java.lang.String columns, KeyDef keyDef)
          Create a new DataSet with a connection, tableName, columns and a KeyDef
 
Method Summary
 Record addRecord()
          Calls addRecord(DataSet)
 Record addRecord(DataSet ds)
          Creates a new Record within this DataSet
 boolean allRecordsRetrieved()
          Check if all the records have been retrieve
 DataSet clearRecords()
          Remove all records from the DataSet and nulls those records out and close() the DataSet.
 void close()
          Releases the records, closes the ResultSet and the Statement, and nulls the Schema and Connection references.
 java.sql.Connection connection()
          Gets the current database connection
 boolean containsRecord(int pos)
          Check to see if the DataSet contains a Record at 0 based position
 DataSet fetchRecords()
          Causes the DataSet to hit the database and fetch all the records.
 DataSet fetchRecords(int max)
          Causes the DataSet to hit the database and fetch max records.
 DataSet fetchRecords(int start, int max)
          Causes the DataSet to hit the database and fetch max records, starting at start.
(package private)  Record findRecord(int pos)
          Find Record at 0 based index position.
(package private)  java.lang.String getColumns()
          Returns the columns attribute for the DataSet
 Record getRecord(int pos)
          Get Record at 0 based index position
abstract  java.lang.String getSelectString()
          Classes extending this class must implement this method.
 KeyDef keydef()
          gets the KeyDef object for this DataSet
 int lastFetchSize()
          The number of records that were fetched with the last fetchRecords.
 int[] maxColumnWidths(boolean with_heading)
          Calculates the maxColumnWidths for the column in a DataSet I really don't know what this is used for so it isn't implemented.
 DataSet releaseRecords()
          Removes the records from the DataSet, but does not null the records out
 Record removeRecord(Record rec)
          Remove a record from the DataSet's internal storage
 DataSet reset()
          Essentially the same as releaseRecords, but it won't work on a QueryDataSet that has been created with a ResultSet
 java.sql.ResultSet resultSet()
          Gets the ResultSet for this DataSet
 Schema schema()
          Gets the Schema for this DataSet
(package private)  void setAllRecordsRetrieved(boolean set)
          Set all records retrieved
 int size()
          Gets the number of Records in this DataSet.
 java.lang.String tableName()
          Gets the tableName defined in the schema
 java.lang.String toString()
          This returns a represention of this DataSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL_RECORDS

protected static final int ALL_RECORDS
indicates that all records should be retrieved during a fetch

See Also:
Constant Field Values

schema

Schema schema
this DataSet's schema object


records

java.util.Vector records
this DataSet's collection of Record objects


conn

java.sql.Connection conn
this DataSet's connection object


allRecordsRetrieved

boolean allRecordsRetrieved
have all records been retrieved with the fetchRecords?


recordRetrievedCount

int recordRetrievedCount
number of records retrieved


lastFetchSize

int lastFetchSize
number of records that were last fetched


totalFetchCount

int totalFetchCount
number of records total that have been fetched


columns

private java.lang.String columns
the columns in the SELECT statement for this DataSet


selectString

java.lang.StringBuffer selectString
the select string that was used to build this DataSet


keyDefValue

private KeyDef keyDefValue
the KeyDef for this DataSet


resultSet

java.sql.ResultSet resultSet
the result set for this DataSet


stmt

java.sql.Statement stmt
the Statement for this DataSet

Constructor Detail

DataSet

public DataSet()
        throws DataSetException,
               java.sql.SQLException
Private, not used

Throws:
DataSetException
java.sql.SQLException

DataSet

DataSet(java.sql.Connection conn,
        java.lang.String tableName)
  throws DataSetException,
         java.sql.SQLException
Create a new DataSet with a connection and a Table name

Parameters:
conn -
tableName -
Throws:
DataSetException
java.sql.SQLException

DataSet

DataSet(java.sql.Connection conn,
        Schema schema,
        KeyDef keydef)
  throws DataSetException,
         java.sql.SQLException
Create a new DataSet with a connection, schema and KeyDef

Parameters:
conn -
schema -
keydef -
Throws:
DataSetException
java.sql.SQLException

DataSet

DataSet(java.sql.Connection conn,
        java.lang.String tableName,
        KeyDef keydef)
  throws java.sql.SQLException,
         DataSetException
Create a new DataSet with a connection, tablename and KeyDef

Parameters:
conn -
tableName -
keydef -
Throws:
java.sql.SQLException
DataSetException

DataSet

DataSet(java.sql.Connection conn,
        java.lang.String tableName,
        java.lang.String columns)
  throws java.sql.SQLException,
         DataSetException
Create a new DataSet with a connection, tablename and list of columns

Parameters:
conn -
tableName -
columns -
Throws:
java.sql.SQLException
DataSetException

DataSet

DataSet(java.sql.Connection conn,
        java.lang.String tableName,
        java.lang.String columns,
        KeyDef keyDef)
  throws java.sql.SQLException,
         DataSetException
Create a new DataSet with a connection, tableName, columns and a KeyDef

Parameters:
conn -
tableName -
columns -
keyDef -
Throws:
java.sql.SQLException
DataSetException
Method Detail

resultSet

public java.sql.ResultSet resultSet()
                             throws java.sql.SQLException,
                                    DataSetException
Gets the ResultSet for this DataSet

Returns:
the result set for this DataSet
Throws:
java.sql.SQLException
DataSetException

addRecord

public Record addRecord()
                 throws DataSetException,
                        java.sql.SQLException
Calls addRecord(DataSet)

Returns:
the added record
Throws:
DataSetException
java.sql.SQLException

addRecord

public Record addRecord(DataSet ds)
                 throws DataSetException,
                        java.sql.SQLException
Creates a new Record within this DataSet

Parameters:
ds -
Returns:
the added record
Throws:
DataSetException
java.sql.SQLException

allRecordsRetrieved

public boolean allRecordsRetrieved()
Check if all the records have been retrieve

Returns:
true if all records have been retrieved

setAllRecordsRetrieved

void setAllRecordsRetrieved(boolean set)
Set all records retrieved


removeRecord

public Record removeRecord(Record rec)
                    throws DataSetException
Remove a record from the DataSet's internal storage

Parameters:
rec -
Returns:
the record removed
Throws:
DataSetException

clearRecords

public DataSet clearRecords()
Remove all records from the DataSet and nulls those records out and close() the DataSet.

Returns:
an instance of myself

releaseRecords

public DataSet releaseRecords()
Removes the records from the DataSet, but does not null the records out

Returns:
an instance of myself

close

public void close()
           throws java.sql.SQLException,
                  DataSetException
Releases the records, closes the ResultSet and the Statement, and nulls the Schema and Connection references.

Throws:
java.sql.SQLException
DataSetException

reset

public DataSet reset()
              throws DataSetException,
                     java.sql.SQLException
Essentially the same as releaseRecords, but it won't work on a QueryDataSet that has been created with a ResultSet

Returns:
an instance of myself
Throws:
DataSetException
java.sql.SQLException

connection

public java.sql.Connection connection()
                               throws java.sql.SQLException
Gets the current database connection

Returns:
a database connection
Throws:
java.sql.SQLException

schema

public Schema schema()
Gets the Schema for this DataSet

Returns:
the Schema for this DataSet

getRecord

public Record getRecord(int pos)
                 throws DataSetException
Get Record at 0 based index position

Parameters:
pos -
Returns:
an instance of the found Record
Throws:
DataSetException

findRecord

Record findRecord(int pos)
            throws DataSetException
Find Record at 0 based index position. This is an internal alternative to getRecord which tries to be smart about the type of record it is.

Parameters:
pos -
Returns:
an instance of the found Record
Throws:
DataSetException

containsRecord

public boolean containsRecord(int pos)
Check to see if the DataSet contains a Record at 0 based position

Parameters:
pos -
Returns:
true if record exists

fetchRecords

public DataSet fetchRecords()
                     throws java.sql.SQLException,
                            DataSetException
Causes the DataSet to hit the database and fetch all the records.

Returns:
an instance of myself
Throws:
java.sql.SQLException
DataSetException

fetchRecords

public DataSet fetchRecords(int max)
                     throws java.sql.SQLException,
                            DataSetException
Causes the DataSet to hit the database and fetch max records.

Parameters:
max -
Returns:
an instance of myself
Throws:
java.sql.SQLException
DataSetException

fetchRecords

public DataSet fetchRecords(int start,
                            int max)
                     throws java.sql.SQLException,
                            DataSetException
Causes the DataSet to hit the database and fetch max records, starting at start. Record count begins at 0.

Parameters:
start -
max -
Returns:
an instance of myself
Throws:
java.sql.SQLException
DataSetException

lastFetchSize

public int lastFetchSize()
The number of records that were fetched with the last fetchRecords.

Returns:
int

keydef

public KeyDef keydef()
gets the KeyDef object for this DataSet

Returns:
the keydef for this DataSet, this value can be null

toString

public java.lang.String toString()
This returns a represention of this DataSet


tableName

public java.lang.String tableName()
                           throws DataSetException
Gets the tableName defined in the schema

Returns:
string
Throws:
DataSetException

maxColumnWidths

public int[] maxColumnWidths(boolean with_heading)
                      throws DataSetException,
                             java.sql.SQLException
Calculates the maxColumnWidths for the column in a DataSet I really don't know what this is used for so it isn't implemented.

Parameters:
with_heading -
Returns:
int
Throws:
DataSetException
java.sql.SQLException

getSelectString

public abstract java.lang.String getSelectString()
                                          throws DataSetException
Classes extending this class must implement this method.

Returns:
the select string
Throws:
DataSetException

getColumns

java.lang.String getColumns()
Returns the columns attribute for the DataSet

Returns:
the columns attribute for the DataSet

size

public int size()
Gets the number of Records in this DataSet. It is 0 based.

Returns:
number of Records in this DataSet


Copyright © 1999-2002 Share.Whichever.com All Rights Reserved.