Package mgui.datasources
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 Summary
Fields Modifier and Type Field Description protected DataSourcedataSourceprotected NameMapfield_indicesprotected NameMapfield_mapprotected java.util.ArrayList<DataField>fieldsprotected booleanisAddNewprotected booleanisEditprotected booleanisLockedprotected booleanisUpdatableprotected java.sql.ResultSetrecordSet -
Constructor Summary
Constructors Constructor Description DataRecordSet()DataRecordSet(DataSource ds) -
Method Summary
Modifier and Type Method Description booleanaddNew()Initiate the addition of a new record to this record set.booleanBOF()booleancancelUpdate()Cancels an update initiated by an AddNew or Edit process.voidclose()booleandeleteRecords(int[] rows)Attempts to delete the specified records from the underlying table.booleanedit()Initiate editing of current record.booleanEOF()java.io.ObjectInputStreamgetBinaryStream(int fieldNo)Fetches the serialized binary data stream from a specified field in the data set.java.io.ObjectInputStreamgetBinaryStream(java.lang.String fieldName)intgetCurrentRecord()DataFieldgetField(int f)DataFieldgetField(java.lang.String name)Searches for and returns the field namedname; case insensitive.java.lang.ClassgetFieldClass(int field)java.lang.ClassgetFieldClass(java.lang.String field)intgetFieldCount()intgetFieldIndex(java.lang.String name)java.lang.StringgetFieldName(int field)java.util.ArrayList<DataField>getFields()java.lang.ObjectgetFieldVal(int field_index)java.lang.ObjectgetFieldVal(java.lang.String fieldName)Returns the current value of this fieldjava.lang.ObjectgetObject(int fieldIndex)intgetRecordCount()java.lang.ObjectgetValueAt(int record, int field)Returns the value at the given record and field indices.booleanisClosed()booleanisUpdatable()Specifies whether this record set can be updated.booleanmoveFirst()booleanmoveLast()booleanmoveNext()booleanmoveRelative(int offset)booleanmoveTo(int row)booleanresetCursor()booleanset(DataSourceItem item)voidsetDataSource(DataSource ds)protected booleansetFields()protected booleansetRecordSet()protected booleansetRecordSet(java.lang.String SQLStr)booleansetValueAt(int record, int field, java.lang.Object value)Sets the value of a specified field for a specified record.booleanupdate()Apply the changes from an AddNew or Edit process.booleanupdateField(java.lang.String field, java.lang.Object newVal)Updates the current value associated withfield.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
recordSet
protected java.sql.ResultSet recordSet -
dataSource
-
fields
-
isUpdatable
protected boolean isUpdatable -
isAddNew
protected boolean isAddNew -
isEdit
protected boolean isEdit -
isLocked
protected boolean isLocked -
field_map
-
field_indices
-
-
Constructor Details
-
DataRecordSet
public DataRecordSet() -
DataRecordSet
-
-
Method Details
-
setDataSource
-
set
- Throws:
DataSourceException
-
getFields
-
isUpdatable
public boolean isUpdatable()Specifies whether this record set can be updated.- Returns:
-
setRecordSet
- Throws:
DataSourceException
-
setRecordSet
- Throws:
DataSourceException
-
deleteRecords
Attempts to delete the specified records from the underlying table.- Parameters:
rows-- Returns:
- Throws:
DataSourceException
-
getRecordCount
public int getRecordCount()- Specified by:
getRecordCountin interfaceDataSet
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCountin interfaceDataSet
-
getField
-
setFields
protected boolean setFields() -
getCurrentRecord
public int getCurrentRecord() -
getValueAt
public java.lang.Object getValueAt(int record, int field) throws java.sql.SQLExceptionReturns 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:
getValueAtin interfaceDataSet- 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:
setValueAtin interfaceDataSet- Parameters:
record- record to updatefield- field to updatevalue- 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.SQLExceptionReturns 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
Searches for and returns the field namedname; case insensitive.- Parameters:
s-- Returns:
-
updateField
public boolean updateField(java.lang.String field, java.lang.Object newVal)Updates the current value associated withfield.- 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:
-