com.syncsoft.plainsql
Class RowSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<InternalRow>
              extended by com.syncsoft.plainsql.RowSet
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<InternalRow>, java.util.Collection<InternalRow>, java.util.List<InternalRow>, java.util.RandomAccess

public class RowSet
extends java.util.ArrayList<InternalRow>

A class that extends ArrayList with some methods to support result sets from SQL statements.

See Also:
Serialized Form

Constructor Summary
RowSet(java.sql.ResultSet resultSet)
          Create a RowSet, providing the JDBC ResultSet, potentially making the RowSet updateable.
RowSet(Row row)
          Create the rowSet, providing a row to use to create the strucutre.
 
Method Summary
 void addRow(java.lang.Object... args)
          Add a row as a comma seperated list of name,value pairs
 void addRow(Row row)
          Add an existing row to the rowset
 void deleteRow(Row deleteRow)
          Delete the row from the database (if possible)
 int getColumnCount()
           
 java.util.ArrayList<java.lang.String> getColumnNames()
          Get an ArrayList containing the columns in this RowSet()
 Row getRow(int rowno)
          Return the nominated row
 java.util.ArrayList<Row> getRows()
          Return the rowset as an ArrayList of Row objects (rather than the more compact but less readable InternalRow)
 PlainTable getTableName()
           
 java.lang.String getValue(int rowno, java.lang.String colname)
          Get the value corresponding to the nominated row and column name.
 boolean hasColumn(java.lang.String columnName)
           
 boolean hasColumnValue(java.lang.String columnName, java.lang.Object value)
           
 boolean hasNext()
          return true if there are more elements in the rowSet (Part of Iterator interface)
 Row next()
          Return the next row in the arrayset.
 void remove()
           
 void replaceRow(int RowNo, Row row)
          Replace the rowat RowNo, with the row given
 void setTableName(PlainTable tableName)
          Set the name of the PlainTable associated with the RowSet.
 void setValue(int rowNo, java.lang.String columnName, java.lang.Object newValue)
           
 void updateRow(Row updateRow)
          If this is a RowSet from a PlainTable that has primary keys, then this method receives a Row and applies that row to the table via an update.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

RowSet

public RowSet(java.sql.ResultSet resultSet)
       throws java.sql.SQLException
Create a RowSet, providing the JDBC ResultSet, potentially making the RowSet updateable. Only creates the structure; not the data

Parameters:
resultSet -
Throws:
java.sql.SQLException

RowSet

public RowSet(Row row)
Create the rowSet, providing a row to use to create the strucutre.

Method Detail

getColumnCount

public int getColumnCount()
Returns:
Number of columns in the rowset

hasColumn

public boolean hasColumn(java.lang.String columnName)
Parameters:
columnName -
Returns:
true if the column name is part of the rowset

hasColumnValue

public boolean hasColumnValue(java.lang.String columnName,
                              java.lang.Object value)
                       throws java.sql.SQLException
Parameters:
columnName -
value -
Returns:
true if there is a row in which the column has the value
Throws:
java.sql.SQLException

hasNext

public boolean hasNext()
return true if there are more elements in the rowSet (Part of Iterator interface)

Returns:
true if there are more elements

next

public Row next()
Return the next row in the arrayset. (part of Iterator interface)

Returns:

remove

public void remove()

addRow

public void addRow(java.lang.Object... args)
            throws java.sql.SQLException
Add a row as a comma seperated list of name,value pairs

Parameters:
args -
Throws:
java.sql.SQLException

addRow

public void addRow(Row row)
Add an existing row to the rowset

Parameters:
row -

deleteRow

public void deleteRow(Row deleteRow)
               throws java.sql.SQLException
Delete the row from the database (if possible)

Throws:
java.sql.SQLException

getColumnNames

public java.util.ArrayList<java.lang.String> getColumnNames()
Get an ArrayList containing the columns in this RowSet()

Returns:
Returns the columnNames.

getRow

public Row getRow(int rowno)
           throws java.sql.SQLException
Return the nominated row

Parameters:
rowno -
Returns:
Throws:
java.sql.SQLException

getRows

public java.util.ArrayList<Row> getRows()
                                 throws java.sql.SQLException
Return the rowset as an ArrayList of Row objects (rather than the more compact but less readable InternalRow)

Returns:
ArrayList of objects
Throws:
java.sql.SQLException

getTableName

public PlainTable getTableName()
Returns:
Returns the (PlainTable) tableName.

getValue

public java.lang.String getValue(int rowno,
                                 java.lang.String colname)
                          throws java.sql.SQLException
Get the value corresponding to the nominated row and column name.

Parameters:
row - - 0 is the first row
colname - - String
Returns:
- an Object containing the value
Throws:
java.sql.SQLException

setTableName

public void setTableName(PlainTable tableName)
Set the name of the PlainTable associated with the RowSet. If set, the rowSet can be updated, if the table concerned has primary keys.

Parameters:
tableName - The tableName to set.

setValue

public void setValue(int rowNo,
                     java.lang.String columnName,
                     java.lang.Object newValue)
              throws java.sql.SQLException
Throws:
java.sql.SQLException

updateRow

public void updateRow(Row updateRow)
               throws java.sql.SQLException
If this is a RowSet from a PlainTable that has primary keys, then this method receives a Row and applies that row to the table via an update.

Parameters:
row - containing new data
Throws:
java.sql.SQLException

replaceRow

public void replaceRow(int RowNo,
                       Row row)
                throws java.sql.SQLException
Replace the rowat RowNo, with the row given

Parameters:
RowNo - - row position in RowSet
row - - new row
Throws:
java.sql.SQLException