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 DataSource
dataSource
protected NameMap
field_indices
protected NameMap
field_map
protected java.util.ArrayList<DataField>
fields
protected boolean
isAddNew
protected boolean
isEdit
protected boolean
isLocked
protected boolean
isUpdatable
protected java.sql.ResultSet
recordSet
-
Constructor Summary
Constructors Constructor Description DataRecordSet()
DataRecordSet(DataSource ds)
-
Method Summary
Modifier and Type Method Description boolean
addNew()
Initiate the addition of a new record to this record set.boolean
BOF()
boolean
cancelUpdate()
Cancels an update initiated by an AddNew or Edit process.void
close()
boolean
deleteRecords(int[] rows)
Attempts to delete the specified records from the underlying table.boolean
edit()
Initiate editing of current record.boolean
EOF()
java.io.ObjectInputStream
getBinaryStream(int fieldNo)
Fetches the serialized binary data stream from a specified field in the data set.java.io.ObjectInputStream
getBinaryStream(java.lang.String fieldName)
int
getCurrentRecord()
DataField
getField(int f)
DataField
getField(java.lang.String name)
Searches for and returns the field namedname
; case insensitive.java.lang.Class
getFieldClass(int field)
java.lang.Class
getFieldClass(java.lang.String field)
int
getFieldCount()
int
getFieldIndex(java.lang.String name)
java.lang.String
getFieldName(int field)
java.util.ArrayList<DataField>
getFields()
java.lang.Object
getFieldVal(int field_index)
java.lang.Object
getFieldVal(java.lang.String fieldName)
Returns the current value of this fieldjava.lang.Object
getObject(int fieldIndex)
int
getRecordCount()
java.lang.Object
getValueAt(int record, int field)
Returns the value at the given record and field indices.boolean
isClosed()
boolean
isUpdatable()
Specifies whether this record set can be updated.boolean
moveFirst()
boolean
moveLast()
boolean
moveNext()
boolean
moveRelative(int offset)
boolean
moveTo(int row)
boolean
resetCursor()
boolean
set(DataSourceItem item)
void
setDataSource(DataSource ds)
protected boolean
setFields()
protected boolean
setRecordSet()
protected boolean
setRecordSet(java.lang.String SQLStr)
boolean
setValueAt(int record, int field, java.lang.Object value)
Sets the value of a specified field for a specified record.boolean
update()
Apply the changes from an AddNew or Edit process.boolean
updateField(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:
getRecordCount
in interfaceDataSet
-
getFieldCount
public int getFieldCount()- Specified by:
getFieldCount
in 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:
getValueAt
in 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:
setValueAt
in 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:
-