| java.lang.Object workbench.storage.DataStore
DataStore | public class DataStore (Code) | | A class to cache the result of a database query.
If the underlying SELECT used only one table, then the
DataStore can be updated and the changes can be saved back
to the database.
For updating or deleting rows, key columns are required
For inserting new rows, no keys are required.
See Also: workbench.storage.ResultInfo author: support@sql-workbench.net |
Constructor Summary | |
public | DataStore(String[] aColNames, int[] colTypes) | public | DataStore(String[] colNames, int[] colTypes, int[] colSizes) | public | DataStore(ResultSet aResultSet, WbConnection aConn) Create a DataStore based on the contents of the given ResultSet. | | DataStore(ResultInfo metaData) | public | DataStore(ResultSet aResult) Initialize this DataStore based on the given ResultSet but without reading the data. | public | DataStore(ResultSet aResult, boolean readData) Initialize this DataStore based on the given ResultSet
The ResultSet has to be closed by the caller. | public | DataStore(ResultSet aResult, WbConnection conn, boolean readData) | public | DataStore(ResultSet aResult, boolean readData, int maxRows) Create a DataStore based on the given ResultSet. | public | DataStore(ResultSet aResult, boolean readData, RowActionMonitor aMonitor) Create a DataStore based on the given ResultSet. | public | DataStore(ResultSet aResult, boolean readData, RowActionMonitor aMonitor, int maxRows, WbConnection conn) Create a DataStore based on the given ResultSet. | public | DataStore(ResultSetMetaData metaData, WbConnection aConn) Create an empty DataStore based on the information given in the MetaData
object. |
Method Summary | |
public int | addRow(ResultSet rs) Adds the next row from the result set
to the DataStore. | public int | addRow() Adds a new empty row to the DataStore. | public int | addRow(RowData row) | public void | applyFilter(FilterExpression filterExpression) Applies a filter based on the given
workbench.storage.filter.FilterExpression to this datastore. | public boolean | canSaveAsSqlInsert() Returns true if the current data can be converted to SQL INSERT statements. | public void | cancelRetrieve() If the DataStore is beeing initialized with a ResultSet, this
cancels the processing of the ResultSet. | public void | cancelUpdate() Cancels a currently running update. | public boolean | checkUpdateTable() | public boolean | checkUpdateTable(WbConnection aConn) | public void | clearFilter() Restores all rows that were filtered. | public Object | convertCellValue(Object aValue, int aColumn) | public void | deleteRow(int aRow) | public void | deleteRowWithDependencies(int aRow) | public int | duplicateRow(int aRow) | public Class | getColumnClass(int aColumn) | public String | getColumnClassName(int aColumn) | public int | getColumnCount() | public int | getColumnDisplaySize(int aColumn) Return the suggested display size of the column. | public int | getColumnIndex(String aName) Returns the index of the column with the given name. | public String | getColumnName(int aColumn) Return the name of the given column
Parameters: aColumn - The index of the column in this DataStore. | public int | getColumnType(int aColumn) | public ColumnIdentifier[] | getColumns() | public String | getGeneratingSql() | public String | getInsertTable() Return the table that should be used when generating INSERTs
("copy as INSERT")
Normally this is the update table. | public List<ColumnIdentifier> | getMissingPkColumns() | public int | getModifiedCount() | protected RowData | getNextDeletedRow() | public WbConnection | getOriginalConnection() Return the connection that was used to retrieve the result. | protected Object | getOriginalValue(int aRow, int aColumn) | public List<ColumnData> | getPkValues(int aRow) Returns a list with the value of all PK columns for the given
row. | public List<ColumnData> | getPkValues(int aRow, boolean originalValues) Returns a list with the value of all PK columns for the given
row. | public RowActionMonitor | getProgressMonitor() Getter for property progressMonitor. | public ResultInfo | getResultInfo() | public RowData | getRow(int aRow) | public int | getRowCount() | public Integer | getRowStatus(int aRow) Return the status object for the given row. | public List<DmlStatement> | getUpdateStatements(WbConnection aConnection) Returns a List of
workbench.storage.DmlStatement s which
would be executed in order to store the current content
of the DataStore. | public TableIdentifier | getUpdateTable() | public Object | getValue(int aRow, int aColumn) Returns the current value of the specified column in the specified row. | public Object | getValue(int aRow, String columnName) Returns the current value of the named column in the specified row. | public int | getValueAsInt(int aRow, int aColumn, int aDefault) Return the value of a column as an int value. | public long | getValueAsLong(int aRow, int aColumn, long aDefault) Return the value of a column as an long value. | public String | getValueAsString(int aRow, String colName) Returns the value of the given row/column as a String. | public String | getValueAsString(int aRow, int aColumn) Returns the value of the given row/column as a String. | public boolean | hasDeletedRows() | public boolean | hasPkColumns() | public boolean | hasUpdateableColumns() | public boolean | hasUpdatedRows() Returns true if at least one row has been updated. | public void | initData(ResultSet aResultSet) Read the column definitions from the result set's meta data
and store the data from the ResultSet in this DataStore with no maximum
The ResultSet must be closed by the caller. | public void | initData(ResultSet aResultSet, int maxRows) Read the column definitions from the result set's meta data
and store the data from the ResultSet in this DataStore (up to maxRows)
The ResultSet must be closed by the caller.
Parameters: aResultSet - the ResultSet to read Parameters: maxRows - max. | public int | insertRowAfter(int anIndex) Inserts a row after the given row number. | public boolean | isCancelled() Checks if the last ResultSet processing was cancelled. | public boolean | isFiltered() | public boolean | isModified() | public boolean | isRowModified(int aRow) Returns true if the given row has been modified. | public boolean | isUpdateable() | public boolean | lastUpdateHadErrors() | public boolean | needPkForUpdate() Returns true if key columns are needed to save the changes
to the database. | public boolean | pkColumnsComplete() | public void | reset() | public void | resetCancelStatus() | public void | resetDmlSentStatus() Clears the flag for all modified rows that indicates any pending update
has already been sent to the database. | public void | resetStatus() Reset all rows to not modified. | public void | resetStatusForSentRows() | protected void | resetUpdateRowCounters() | public void | restoreOriginalValues() Restore the original values as retrieved from the database. | public void | setAllowUpdates(boolean aFlag) | public void | setColumnSizes(int[] sizes) | public void | setGeneratingSql(String aSql) Define the (SELECT) statement that was used to produce this
DataStore's result set. | public void | setInputValue(int row, int col, Object value) Set a value received from a user input. | public void | setOriginalConnection(WbConnection aConn) | public void | setPKColumns(ColumnIdentifier[] pkColumns) | public void | setProgressMonitor(RowActionMonitor aMonitor) Setter for property progressMonitor. | public void | setRowNull(int aRow) | public void | setUpdateTable(String aTablename, WbConnection aConn) | public void | setUpdateTable(TableIdentifier tbl) | public void | setUpdateTable(TableIdentifier tbl, WbConnection conn) Sets the table to be updated for this DataStore. | public void | setUpdateTableToBeUsed(TableIdentifier tbl) Prepare the information which table should be updated. | public void | setValue(int aRow, int aColumn, Object aValue) Set the value for the given column. | public void | sort(SortDefinition sortDef) | public void | sortByColumn(int col, boolean ascending) | public boolean | sqlHasUpdateTable() Checks if the underlying SQL statement references only one table. | public synchronized int | updateDb(WbConnection aConnection, JobErrorHandler errorHandler) Save the changes to this DataStore to the database. | public void | updatePkInformation() Check if the currently defined updateTable
has any Primary keys defined in the database. |
DataStore | public DataStore(String[] aColNames, int[] colTypes)(Code) | | Create a DataStore which is not based on a result set
and contains the columns defined in the given array
The column types need to match the values from from java.sql.Types
Parameters: aColNames - the column names Parameters: colTypes - data types for each column (matching java.sql.Types.XXXX) |
DataStore | public DataStore(ResultSet aResult, boolean readData) throws SQLException(Code) | | Initialize this DataStore based on the given ResultSet
The ResultSet has to be closed by the caller.
Parameters: aResult - the ResultSet to process Parameters: readData - if true, the ResultSet will be processed, otherwise only the MetaData will be read throws: java.sql.SQLException - See Also: DataStore.initData(ResultSet,int) |
DataStore | public DataStore(ResultSet aResult, boolean readData, int maxRows) throws SQLException(Code) | | Create a DataStore based on the given ResultSet.
Parameters: aResult - the result set to use Parameters: readData - if true the data from the ResultSet should be read into memory, otherwise only MetaData information is read Parameters: maxRows - limit number of rows to maxRows if the JDBC driver does not already limit them |
DataStore | public DataStore(ResultSet aResult, boolean readData, RowActionMonitor aMonitor) throws SQLException(Code) | | Create a DataStore based on the given ResultSet.
Parameters: aResult - the result set to use Parameters: readData - if true the data from the ResultSet should be read into memory, otherwise only MetaData information is read Parameters: aMonitor - if not null, the loading process is displayed through this monitor |
DataStore | public DataStore(ResultSet aResult, boolean readData, RowActionMonitor aMonitor, int maxRows, WbConnection conn) throws SQLException(Code) | | Create a DataStore based on the given ResultSet.
Parameters: aResult - the result set to use Parameters: readData - if true the data from the ResultSet should be read into memory, otherwise only MetaData information is read Parameters: aMonitor - if not null, the loading process is displayed through this monitor Parameters: maxRows - limit number of rows to maxRows if the JDBC driver does not already limit them Parameters: conn - the connection that was used to retrieve the result set |
addRow | public int addRow(ResultSet rs) throws SQLException(Code) | | Adds the next row from the result set
to the DataStore. No check will be done
if the ResultSet matches the current
column structure!!
int - the new row numberThe new row will be marked as "Not modified". |
addRow | public int addRow()(Code) | | Adds a new empty row to the DataStore.
The new row will be marked as Modified
int - the new row number |
canSaveAsSqlInsert | public boolean canSaveAsSqlInsert()(Code) | | Returns true if the current data can be converted to SQL INSERT statements.
The data can be saved as SQL INSERTs if an update table is defined.
If no update table is defined, then this method will call
DataStore.checkUpdateTable() and try to determine the table from the used SQL statement.
true if an update table is defined |
checkUpdateTable | public boolean checkUpdateTable()(Code) | | |
clearFilter | public void clearFilter()(Code) | | Restores all rows that were filtered.
|
convertCellValue | public Object convertCellValue(Object aValue, int aColumn) throws ConverterException(Code) | | Convert the value to the approriate class instance
for the given column
Parameters: aValue - the value as entered by the user Parameters: aColumn - the column for which this value should be converted an Object of the needed class for the column See Also: ValueConverter.convertValue(Objectint) |
deleteRow | public void deleteRow(int aRow) throws IndexOutOfBoundsException(Code) | | Deletes the given row and saves it in the delete buffer
in order to be able to generate a DELETE statement if
this DataStore needs updating
|
duplicateRow | public int duplicateRow(int aRow)(Code) | | |
getColumnClass | public Class getColumnClass(int aColumn)(Code) | | |
getColumnClassName | public String getColumnClassName(int aColumn)(Code) | | |
getColumnCount | public int getColumnCount()(Code) | | |
getColumnIndex | public int getColumnIndex(String aName)(Code) | | Returns the index of the column with the given name.
Parameters: aName - The column's name to search for The column's index (first column starts at 0) |
getColumnName | public String getColumnName(int aColumn) throws IndexOutOfBoundsException(Code) | | Return the name of the given column
Parameters: aColumn - The index of the column in this DataStore. The first column index is 0 The name of the column |
getInsertTable | public String getInsertTable()(Code) | | Return the table that should be used when generating INSERTs
("copy as INSERT")
Normally this is the update table. If no update table
is defined, the table from the SQL statement will be used
but no checking for key columns takes place (which might take long)
|
getModifiedCount | public int getModifiedCount()(Code) | | Returns the total number of modified, new or deleted rows
|
getOriginalConnection | public WbConnection getOriginalConnection()(Code) | | Return the connection that was used to retrieve the result.
Can be null if the DataStore was not populated using a ResultSet
|
getOriginalValue | protected Object getOriginalValue(int aRow, int aColumn)(Code) | | |
getProgressMonitor | public RowActionMonitor getProgressMonitor()(Code) | | Getter for property progressMonitor.
Value of property progressMonitor. |
getRowCount | public int getRowCount()(Code) | | |
getValueAsInt | public int getValueAsInt(int aRow, int aColumn, int aDefault)(Code) | | Return the value of a column as an int value.
If the object stored in the DataStore is an instance of Number
the intValue() of that object will be returned, otherwise the String value
of the column will be converted to an integer.
If it cannot be converted to an int, the default value will be returned
Parameters: aRow - The row Parameters: aColumn - The column to be returned Parameters: aDefault - The default value that will be returned if the the column's value cannot be converted to an int |
getValueAsLong | public long getValueAsLong(int aRow, int aColumn, long aDefault)(Code) | | Return the value of a column as an long value.
If the object stored in the DataStore is an instance of Number
the longValue() of that object will be returned, otherwise the String value
of the column will be converted to a long.
If it cannot be converted to an long, the default value will be returned
Parameters: aRow - The row Parameters: aColumn - The column to be returned Parameters: aDefault - The default value that will be returned if the the column's value cannot be converted to a long |
getValueAsString | public String getValueAsString(int aRow, String colName) throws IndexOutOfBoundsException(Code) | | Returns the value of the given row/column as a String.
The value's toString() method is used to convert the value to a String value.
Null if the column is null, or the column's value as a String |
getValueAsString | public String getValueAsString(int aRow, int aColumn) throws IndexOutOfBoundsException(Code) | | Returns the value of the given row/column as a String.
The value's toString() method is used to convert the value to a String value.
Null if the column is null, or the column's value as a String |
hasDeletedRows | public boolean hasDeletedRows()(Code) | | Returns true if at least one row has been deleted
|
hasPkColumns | public boolean hasPkColumns()(Code) | | |
hasUpdateableColumns | public boolean hasUpdateableColumns()(Code) | | |
hasUpdatedRows | public boolean hasUpdatedRows()(Code) | | Returns true if at least one row has been updated.
|
initData | public void initData(ResultSet aResultSet) throws SQLException(Code) | | Read the column definitions from the result set's meta data
and store the data from the ResultSet in this DataStore with no maximum
The ResultSet must be closed by the caller.
Parameters: aResultSet - the ResultSet to read See Also: DataStore.initData(ResultSet,int) |
initData | public void initData(ResultSet aResultSet, int maxRows) throws SQLException(Code) | | Read the column definitions from the result set's meta data
and store the data from the ResultSet in this DataStore (up to maxRows)
The ResultSet must be closed by the caller.
Parameters: aResultSet - the ResultSet to read Parameters: maxRows - max. number of rows to read. Zero or lower to read all rows See Also: DataStore.initData(ResultSet) |
insertRowAfter | public int insertRowAfter(int anIndex)(Code) | | Inserts a row after the given row number.
If the new Index is greater then the current
row count or the new index is < 0 the new
row will be added at the end.
int - the new row number |
isFiltered | public boolean isFiltered()(Code) | | |
isModified | public boolean isModified()(Code) | | |
isRowModified | public boolean isRowModified(int aRow)(Code) | | Returns true if the given row has been modified.
A new row is considered modified only if setValue() has been called at least once.
Parameters: aRow - The row to check |
isUpdateable | public boolean isUpdateable()(Code) | | |
lastUpdateHadErrors | public boolean lastUpdateHadErrors()(Code) | | |
needPkForUpdate | public boolean needPkForUpdate()(Code) | | Returns true if key columns are needed to save the changes
to the database. If only inserted rows are present, then no
key is needed. For updated or deleted rows a key is needed
|
pkColumnsComplete | public boolean pkColumnsComplete()(Code) | | |
reset | public void reset()(Code) | | Remove all data from the DataStore
|
resetCancelStatus | public void resetCancelStatus()(Code) | | |
resetDmlSentStatus | public void resetDmlSentStatus()(Code) | | Clears the flag for all modified rows that indicates any pending update
has already been sent to the database.
This is necessary if an error occurs during update, to ensure the
rows are re-send the next time.
|
resetStatus | public void resetStatus()(Code) | | Reset all rows to not modified. After this a call
to #isModified() will return false.
|
resetStatusForSentRows | public void resetStatusForSentRows()(Code) | | Clears the modified status for those rows where
the update has been sent to the database
|
resetUpdateRowCounters | protected void resetUpdateRowCounters()(Code) | | |
setAllowUpdates | public void setAllowUpdates(boolean aFlag)(Code) | | |
setColumnSizes | public void setColumnSizes(int[] sizes)(Code) | | |
setGeneratingSql | public void setGeneratingSql(String aSql)(Code) | | Define the (SELECT) statement that was used to produce this
DataStore's result set. This is used to find the update table later
|
setInputValue | public void setInputValue(int row, int col, Object value) throws ConverterException(Code) | | Set a value received from a user input. This
will convert the given value to an object of the
correct class
|
setProgressMonitor | public void setProgressMonitor(RowActionMonitor aMonitor)(Code) | | Setter for property progressMonitor.
Parameters: aMonitor - New value of property progressMonitor. |
setRowNull | public void setRowNull(int aRow)(Code) | | Set all values in the given row to NULL
|
setUpdateTableToBeUsed | public void setUpdateTableToBeUsed(TableIdentifier tbl)(Code) | | Prepare the information which table should be updated. This
will not trigger the retrieval of the columns.
This table will be used the next time checkUpdateTable() will
be called. checkUpdateTable() will not retrieve the
table name from the original SQL then.
See Also: DataStore.setUpdateTable(TableIdentifier) |
setValue | public void setValue(int aRow, int aColumn, Object aValue) throws IndexOutOfBoundsException(Code) | | Set the value for the given column. This will change the internal state of the DataStore to modified.
Parameters: aRow - Parameters: aColumn - Parameters: aValue - The value to be set |
sortByColumn | public void sortByColumn(int col, boolean ascending)(Code) | | |
updatePkInformation | public void updatePkInformation() throws SQLException(Code) | | Check if the currently defined updateTable
has any Primary keys defined in the database.
If it has, a subsequent call to hasPkColumns() returns true
|
|
|