com.workingdogs.village
Class TableDataSet

java.lang.Object
  extended by com.workingdogs.village.DataSet
      extended by com.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: 568 $
Author:
Jon S. Stevens

Field Summary
 
Fields inherited from class com.workingdogs.village.DataSet
ALL_RECORDS, conn, records, resultSet, schema, selectString, stmt
 
Constructor Summary
TableDataSet()
          Default constructor.
TableDataSet(Connection conn, Schema schema, KeyDef keydef)
          Creates a new TableDataSet object.
TableDataSet(Connection conn, String tableName)
          Creates a new TableDataSet object.
TableDataSet(Connection conn, String tableName, KeyDef keydef)
          Creates a new TableDataSet object.
TableDataSet(Connection conn, String tableName, String columns)
          Creates a new TableDataSet object.
TableDataSet(Connection conn, String tableName, String columns, KeyDef keydef)
          Creates a new TableDataSet object.
 
Method Summary
 String attributes()
          this is a string that contains the columns for the table that this TableDataSet represents.
 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.
 String getSelectString()
          Builds the select string that was used to populate this TableDataSet.
 KeyDef keydef()
          Returns the KeyDef for the DataSet
 String optimisticLockingCol()
          Gets the table column used for optomistic locking.
 TableDataSet order(String order)
          Sets the value for the SQL portion of the ORDER statement
 TableDataSet other(String other)
          Sets the value for the SQL portion of the OTHER statement
 void refresh(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.
 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(Connection conn, boolean intransaction)
          Saves all the records in the DataSet with the given connection and intransaction boolean value.
 int saveWithoutStatusUpdate(Connection conn)
          Not yet implemented
 Schema schema()
          Returns the Schema for the DataSet
 void setOptimisticLockingColumn(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.
 String tableName()
          The name of the table for which this TableDataSet was created.
 TableDataSet tableQualifier(String tq)
          This sets additional SQL for the table name.
 void updateStatus()
          Not yet implemented
 TableDataSet where(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, getRecord, lastFetchSize, maxColumnWidths, releaseRecords, removeRecord, reset, size, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableDataSet

public TableDataSet()
             throws SQLException,
                    DataSetException
Default constructor.

Throws:
SQLException
DataSetException

TableDataSet

public TableDataSet(Connection conn,
                    String tableName)
             throws SQLException,
                    DataSetException
Creates a new TableDataSet object.

Parameters:
conn - TODO: DOCUMENT ME!
tableName - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

TableDataSet

public TableDataSet(Connection conn,
                    Schema schema,
                    KeyDef keydef)
             throws SQLException,
                    DataSetException
Creates a new TableDataSet object.

Parameters:
conn - TODO: DOCUMENT ME!
schema - TODO: DOCUMENT ME!
keydef - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

TableDataSet

public TableDataSet(Connection conn,
                    String tableName,
                    KeyDef keydef)
             throws SQLException,
                    DataSetException
Creates a new TableDataSet object.

Parameters:
conn - TODO: DOCUMENT ME!
tableName - TODO: DOCUMENT ME!
keydef - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

TableDataSet

public TableDataSet(Connection conn,
                    String tableName,
                    String columns)
             throws SQLException,
                    DataSetException
Creates a new TableDataSet object.

Parameters:
conn - TODO: DOCUMENT ME!
tableName - TODO: DOCUMENT ME!
columns - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

TableDataSet

public TableDataSet(Connection conn,
                    String tableName,
                    String columns,
                    KeyDef keydef)
             throws SQLException,
                    DataSetException
Creates a new TableDataSet object.

Parameters:
conn - TODO: DOCUMENT ME!
tableName - TODO: DOCUMENT ME!
columns - TODO: DOCUMENT ME!
keydef - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!
Method Detail

fetchRecords

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

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

fetchRecords

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

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

fetchRecords

public DataSet fetchRecords(int start,
                            int max)
                     throws 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:
SQLException
DataSetException

attributes

public 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 ResultSet resultSet()
                    throws SQLException,
                           DataSetException
Returns the ResultSet for the DataSet

Overrides:
resultSet in class DataSet
Returns:
a ResultSet
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

schema

public Schema schema()
Returns the Schema for the DataSet

Overrides:
schema in class DataSet
Returns:
a Schema

save

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

Returns:
total number of records updated/inserted/deleted
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

save

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

Parameters:
intransaction - TODO: DOCUMENT ME!
Returns:
total number of records updated/inserted/deleted
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

save

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

Parameters:
conn - TODO: DOCUMENT ME!
intransaction - TODO: DOCUMENT ME!
Returns:
total number of records updated/inserted/deleted
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

saveWithoutStatusUpdate

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

Parameters:
conn - TODO: DOCUMENT ME!
Returns:
TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

debugInfo

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

Returns:
TODO: DOCUMENT ME!

removeDeletedRecords

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

Throws:
DataSetException - TODO: DOCUMENT ME!

setOptimisticLockingColumn

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

Parameters:
olc - TODO: DOCUMENT ME!

optimisticLockingCol

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

Returns:
string

where

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

Parameters:
where - TODO: DOCUMENT ME!
Returns:
instance of self
Throws:
DataSetException - TODO: DOCUMENT ME!

order

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

Parameters:
order - TODO: DOCUMENT ME!
Returns:
instance of self
Throws:
DataSetException - TODO: DOCUMENT ME!

other

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

Parameters:
other - TODO: DOCUMENT ME!
Returns:
instance of self
Throws:
DataSetException - TODO: DOCUMENT ME!

refresh

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

Parameters:
conn - TODO: DOCUMENT ME!
Throws:
SQLException - TODO: DOCUMENT ME!
DataSetException - TODO: DOCUMENT ME!

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.

Parameters:
val - TODO: DOCUMENT ME!

refreshOnSave

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

Default value is false.

Returns:
true if it is on; false otherwise

tableQualifier

public TableDataSet tableQualifier(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.

Parameters:
tq - TODO: DOCUMENT ME!
Returns:
an instance of self

tableName

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

Overrides:
tableName in class DataSet
Returns:
string
Throws:
DataSetException - TODO: DOCUMENT ME!

updateStatus

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

Throws:
SQLException
DataSetException

getSelectString

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

Specified by:
getSelectString in class DataSet
Returns:
SQL select string
Throws:
DataSetException - TODO: DOCUMENT ME!


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.