Class DataRecordSet

java.lang.Object
mgui.datasources.DataRecordSet
All Implemented Interfaces:
DataSet

public class DataRecordSet
extends java.lang.Object
implements DataSet
Stores an open connection with a data source based upon an SQL specification. TODO: Include methods for searching, editing, deleting, and appending data.
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Details

    • recordSet

      protected java.sql.ResultSet recordSet
    • dataSource

      protected DataSource dataSource
    • fields

      protected java.util.ArrayList<DataField> fields
    • isUpdatable

      protected boolean isUpdatable
    • isAddNew

      protected boolean isAddNew
    • isEdit

      protected boolean isEdit
    • isLocked

      protected boolean isLocked
    • field_map

      protected NameMap field_map
    • field_indices

      protected NameMap field_indices
  • Constructor Details

    • DataRecordSet

      public DataRecordSet()
    • DataRecordSet

      public DataRecordSet​(DataSource ds)
  • Method Details

    • setDataSource

      public void setDataSource​(DataSource ds)
    • set

      public boolean set​(DataSourceItem item) throws DataSourceException
      Throws:
      DataSourceException
    • getFields

      public java.util.ArrayList<DataField> getFields()
    • isUpdatable

      public boolean isUpdatable()
      Specifies whether this record set can be updated.
      Returns:
    • setRecordSet

      protected boolean setRecordSet​(java.lang.String SQLStr) throws DataSourceException
      Throws:
      DataSourceException
    • setRecordSet

      protected boolean setRecordSet() throws DataSourceException
      Throws:
      DataSourceException
    • deleteRecords

      public boolean deleteRecords​(int[] rows) throws DataSourceException
      Attempts to delete the specified records from the underlying table.
      Parameters:
      rows -
      Returns:
      Throws:
      DataSourceException
    • getRecordCount

      public int getRecordCount()
      Specified by:
      getRecordCount in interface DataSet
    • getFieldCount

      public int getFieldCount()
      Specified by:
      getFieldCount in interface DataSet
    • getField

      public DataField getField​(int f)
      Specified by:
      getField in interface DataSet
    • setFields

      protected boolean setFields()
    • getCurrentRecord

      public int getCurrentRecord()
    • getValueAt

      public java.lang.Object getValueAt​(int record, int field) throws java.sql.SQLException
      Returns the value at the given record and field indices. The field index is interpreted as the sorted index; therefore it is first mapped to the sorted name and back to the actual stored index.
      Specified by:
      getValueAt in interface DataSet
      Throws:
      java.sql.SQLException
    • setValueAt

      public boolean setValueAt​(int record, int field, java.lang.Object value)
      Sets the value of a specified field for a specified record. The field index is interpreted as the sorted index; therefore it is first mapped to the sorted name and back to the actual stored index.
      Specified by:
      setValueAt in interface DataSet
      Parameters:
      record - record to update
      field - field to update
      value - Object with which to set the field
      Returns:
      true is update is successful, false otherwise
    • getObject

      public java.lang.Object getObject​(int fieldIndex) throws java.sql.SQLException
      Throws:
      java.sql.SQLException
    • getFieldVal

      public java.lang.Object getFieldVal​(java.lang.String fieldName) throws java.sql.SQLException
      Returns the current value of this field
      Parameters:
      fieldName -
      Returns:
      Throws:
      java.sql.SQLException
    • getFieldVal

      public java.lang.Object getFieldVal​(int field_index) throws java.sql.SQLException
      Throws:
      java.sql.SQLException
    • getBinaryStream

      public java.io.ObjectInputStream getBinaryStream​(java.lang.String fieldName)
    • getBinaryStream

      public java.io.ObjectInputStream getBinaryStream​(int fieldNo)
      Fetches the serialized binary data stream from a specified field in the data set.
      Parameters:
      fieldNo - index of field from which to read binary stream
      Returns:
      ObjectInputStream containing serializated object
    • getFieldIndex

      public int getFieldIndex​(java.lang.String name)
    • getField

      public DataField getField​(java.lang.String name)
      Searches for and returns the field named name; case insensitive.
      Parameters:
      s -
      Returns:
    • updateField

      public boolean updateField​(java.lang.String field, java.lang.Object newVal)
      Updates the current value associated with field.
      Parameters:
      field -
      newVal -
      Returns:
    • resetCursor

      public boolean resetCursor()
    • moveFirst

      public boolean moveFirst()
    • moveNext

      public boolean moveNext()
    • moveLast

      public boolean moveLast()
    • isClosed

      public boolean isClosed()
    • moveTo

      public boolean moveTo​(int row)
    • moveRelative

      public boolean moveRelative​(int offset)
    • EOF

      public boolean EOF()
    • BOF

      public boolean BOF()
    • getFieldClass

      public java.lang.Class getFieldClass​(java.lang.String field)
    • getFieldClass

      public java.lang.Class getFieldClass​(int field)
    • getFieldName

      public java.lang.String getFieldName​(int field)
    • close

      public void close()
    • addNew

      public boolean addNew()
      Initiate the addition of a new record to this record set.
      Returns:
    • edit

      public boolean edit()
      Initiate editing of current record.
      Returns:
      true if successful, false otherwise
    • cancelUpdate

      public boolean cancelUpdate()
      Cancels an update initiated by an AddNew or Edit process.
    • update

      public boolean update()
      Apply the changes from an AddNew or Edit process. Ensure that the record is valid; i.e., required values are set, unique fields are not violated, etc. Update the record set with these changes and return true if successful, false otherwise.
      Returns: