com.workingdogs.village
Class TableDataSet

java.lang.Object
  extended bycom.workingdogs.village.DataSet
      extended bycom.workingdogs.village.TableDataSet

public class TableDataSet
extends DataSet

This class is used for doing select/insert/delete/update on the database. A TableDataSet cannot be used to join multiple tables for an update, if you need join functionality on a select, you should use a QueryDataSet.

Here is an example usage for this code that gets the first 10 records where column "a" = 1:

KeyDef kd = new KeyDef().setAttrib("column");
TableDataSet tds = new TableDataSet(connection, "table_name", kd );
tds.where ("a=1" ); // WHERE a = 1
tds.fetchRecords(10); // fetch first 10 records where column a=1
for ( int i=0;i< tds.size(); i++ )
{
  Record rec = tds.getRecord(i); // zero based
  String columnA = rec.getValue("a");
  if ( columnA.equals ("1") )
    System.out.print ("We got a column!");
}
tds.close();
  

It is important to remember to always close() the TableDataSet when you are finished with it.

As you can see, using a TableDataSet makes doing selects from the database trivial. You do not need to write any SQL and it makes it easy to cache a TableDataSet for future use within your application.

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

Field Summary
private  java.lang.String optimisticLockingCol
          the optimistic locking column value
private  java.lang.String order
          the value for the sql order by clause
private  java.lang.String other
          the value for the sql other clause
private  boolean refreshOnSave
           
private  java.lang.String where
          the value for the sql where clause
 
Fields inherited from class com.workingdogs.village.DataSet
ALL_RECORDS, allRecordsRetrieved, conn, lastFetchSize, recordRetrievedCount, records, resultSet, schema, selectString, stmt, totalFetchCount
 
Constructor Summary
TableDataSet()
          Default constructor.
TableDataSet(java.sql.Connection conn, Schema schema, KeyDef keydef)
           
TableDataSet(java.sql.Connection conn, java.lang.String tableName)
           
TableDataSet(java.sql.Connection conn, java.lang.String tableName, KeyDef keydef)
           
TableDataSet(java.sql.Connection conn, java.lang.String tableName, java.lang.String columns)
           
TableDataSet(java.sql.Connection conn, java.lang.String tableName, java.lang.String columns, KeyDef keydef)
           
 
Method Summary
 java.lang.String attributes()
          this is a string that contains the columns for the table that this TableDataSet represents.
private  void buildSelectString()
          Used by getSelectString to build the select string that was used to populate this TableDataSet.
 java.lang.String debugInfo()
          Hell if I know what this does.
 DataSet fetchRecords()
          Use the TDS fetchRecords instead of the DataSet.fetchRecords
 DataSet fetchRecords(int max)
          Use the TDS fetchRecords instead of the DataSet.fetchRecords
 DataSet fetchRecords(int start, int max)
          Fetch start to max records.
(package private)  java.lang.String getOrder()
          Gets the value of the SQL portion of ORDER.
(package private)  java.lang.String getOther()
          Gets the value of the SQL portion of OTHER.
 java.lang.String getSelectString()
          Builds the select string that was used to populate this TableDataSet.
(package private)  java.lang.String getWhere()
          Gets the value of the SQL portion of WHERE.
 KeyDef keydef()
          Returns the KeyDef for the DataSet
 java.lang.String optimisticLockingCol()
          Gets the table column used for optomistic locking.
 TableDataSet order(java.lang.String order)
          Sets the value for the SQL portion of the ORDER statement
 TableDataSet other(java.lang.String other)
          Sets the value for the SQL portion of the OTHER statement
 void refresh(java.sql.Connection conn)
          This method refreshes all of the Records stored in this TableDataSet.
 boolean refreshOnSave()
          Setting this causes each Record to refresh itself when a save() is performed on it.
 void removeDeletedRecords()
          Removes any records that are marked as a zombie.
 java.sql.ResultSet resultSet()
          Returns the ResultSet for the DataSet
 int save()
          Saves all the records in the DataSet.
 int save(boolean intransaction)
          Saves all the records in the DataSet with the intransaction boolean value.
 int save(java.sql.Connection conn, boolean intransaction)
          Saves all the records in the DataSet with the given connection and intransaction boolean value.
 int saveWithoutStatusUpdate(java.sql.Connection conn)
          Not yet implemented
 Schema schema()
          Returns the Schema for the DataSet
 void setOptimisticLockingColumn(java.lang.String olc)
          Sets the table column used for optomistic locking.
 void setRefreshOnSave(boolean val)
          Setting this causes each Record to refresh itself when a save() is performed on it.
 java.lang.String tableName()
          The name of the table for which this TableDataSet was created.
 TableDataSet tableQualifier(java.lang.String tq)
          This sets additional SQL for the table name.
 void updateStatus()
          Not yet implemented
 TableDataSet where(java.lang.String where)
          Sets the value for the SQL portion of the WHERE statement
 
Methods inherited from class com.workingdogs.village.DataSet
addRecord, addRecord, allRecordsRetrieved, clearRecords, close, connection, containsRecord, findRecord, getColumns, getRecord, lastFetchSize, maxColumnWidths, releaseRecords, removeRecord, reset, setAllRecordsRetrieved, size, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

optimisticLockingCol

private java.lang.String optimisticLockingCol
the optimistic locking column value


where

private java.lang.String where
the value for the sql where clause


order

private java.lang.String order
the value for the sql order by clause


other

private java.lang.String other
the value for the sql other clause


refreshOnSave

private boolean refreshOnSave
Constructor Detail

TableDataSet

public TableDataSet()
             throws java.sql.SQLException,
                    DataSetException
Default constructor.

Throws:
java.sql.SQLException
DataSetException

TableDataSet

public TableDataSet(java.sql.Connection conn,
                    java.lang.String tableName)
             throws java.sql.SQLException,
                    DataSetException

TableDataSet

public TableDataSet(java.sql.Connection conn,
                    Schema schema,
                    KeyDef keydef)
             throws java.sql.SQLException,
                    DataSetException

TableDataSet

public TableDataSet(java.sql.Connection conn,
                    java.lang.String tableName,
                    KeyDef keydef)
             throws java.sql.SQLException,
                    DataSetException

TableDataSet

public TableDataSet(java.sql.Connection conn,
                    java.lang.String tableName,
                    java.lang.String columns)
             throws java.sql.SQLException,
                    DataSetException

TableDataSet

public TableDataSet(java.sql.Connection conn,
                    java.lang.String tableName,
                    java.lang.String columns,
                    KeyDef keydef)
             throws java.sql.SQLException,
                    DataSetException
Method Detail

fetchRecords

public DataSet fetchRecords()
                     throws java.sql.SQLException,
                            DataSetException
Use the TDS fetchRecords instead of the DataSet.fetchRecords

Overrides:
fetchRecords in class DataSet
Returns:
an instance of myself
Throws:
java.sql.SQLException
DataSetException

fetchRecords

public DataSet fetchRecords(int max)
                     throws java.sql.SQLException,
                            DataSetException
Use the TDS fetchRecords instead of the DataSet.fetchRecords

Overrides:
fetchRecords in class DataSet
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
Fetch start to max records. start is at Record 0

Overrides:
fetchRecords in class DataSet
Parameters:
start -
max -
Returns:
an instance of myself
Throws:
java.sql.SQLException
DataSetException

attributes

public java.lang.String attributes()
this is a string that contains the columns for the table that this TableDataSet represents.

Returns:
columns separated by ","

keydef

public KeyDef keydef()
Returns the KeyDef for the DataSet

Overrides:
keydef in class DataSet
Returns:
a keydef

resultSet

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

Overrides:
resultSet in class DataSet
Returns:
a ResultSet
Throws:
java.sql.SQLException
DataSetException

schema

public Schema schema()
Returns the Schema for the DataSet

Overrides:
schema in class DataSet
Returns:
a Schema

save

public int save()
         throws java.sql.SQLException,
                DataSetException
Saves all the records in the DataSet.

Returns:
total number of records updated/inserted/deleted
Throws:
java.sql.SQLException
DataSetException

save

public int save(boolean intransaction)
         throws java.sql.SQLException,
                DataSetException
Saves all the records in the DataSet with the intransaction boolean value.

Returns:
total number of records updated/inserted/deleted
Throws:
java.sql.SQLException
DataSetException

save

public int save(java.sql.Connection conn,
                boolean intransaction)
         throws java.sql.SQLException,
                DataSetException
Saves all the records in the DataSet with the given connection and intransaction boolean value.

Returns:
total number of records updated/inserted/deleted
Throws:
java.sql.SQLException
DataSetException

saveWithoutStatusUpdate

public int saveWithoutStatusUpdate(java.sql.Connection conn)
                            throws java.sql.SQLException,
                                   DataSetException
Not yet implemented

Throws:
java.sql.SQLException
DataSetException

debugInfo

public java.lang.String debugInfo()
Hell if I know what this does.


removeDeletedRecords

public void removeDeletedRecords()
                          throws DataSetException
Removes any records that are marked as a zombie.

Throws:
DataSetException

setOptimisticLockingColumn

public void setOptimisticLockingColumn(java.lang.String olc)
Sets the table column used for optomistic locking.


optimisticLockingCol

public java.lang.String optimisticLockingCol()
Gets the table column used for optomistic locking.


where

public TableDataSet where(java.lang.String where)
                   throws DataSetException
Sets the value for the SQL portion of the WHERE statement

Throws:
DataSetException

getWhere

java.lang.String getWhere()
Gets the value of the SQL portion of WHERE.


order

public TableDataSet order(java.lang.String order)
                   throws DataSetException
Sets the value for the SQL portion of the ORDER statement

Throws:
DataSetException

getOrder

java.lang.String getOrder()
Gets the value of the SQL portion of ORDER.


other

public TableDataSet other(java.lang.String other)
                   throws DataSetException
Sets the value for the SQL portion of the OTHER statement

Throws:
DataSetException

getOther

java.lang.String getOther()
Gets the value of the SQL portion of OTHER.


refresh

public void refresh(java.sql.Connection conn)
             throws java.sql.SQLException,
                    DataSetException
This method refreshes all of the Records stored in this TableDataSet.

Throws:
java.sql.SQLException
DataSetException

setRefreshOnSave

public void setRefreshOnSave(boolean val)
Setting this causes each Record to refresh itself when a save() is performed on it.

Default value is false.


refreshOnSave

public boolean refreshOnSave()
Setting this causes each Record to refresh itself when a save() is performed on it.

Default value is false.


tableQualifier

public TableDataSet tableQualifier(java.lang.String tq)
This sets additional SQL for the table name. The string appears after the table name. Sybase users would set this to "HOLDLOCK" to get repeatable reads.

FIXME: Is this right? I don't use Sybase.


tableName

public java.lang.String tableName()
                           throws DataSetException
The name of the table for which this TableDataSet was created.

Overrides:
tableName in class DataSet
Returns:
string
Throws:
DataSetException

updateStatus

public void updateStatus()
                  throws java.sql.SQLException,
                         DataSetException
Not yet implemented

Throws:
java.sql.SQLException
DataSetException

getSelectString

public java.lang.String getSelectString()
                                 throws DataSetException
Builds the select string that was used to populate this TableDataSet.

Specified by:
getSelectString in class DataSet
Returns:
the select string
Throws:
DataSetException

buildSelectString

private void buildSelectString()
                        throws DataSetException
Used by getSelectString to build the select string that was used to populate this TableDataSet.

Throws:
DataSetException


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