public class RowSetTableContentProvider extends PageFlowScopeAdapter implements IUpdateableTableContentProvider, ISortableTableContentProvider, ISelectableTableContentProvider, IRefreshableContentProvider, ITransactionalContentProvider, Serializable
JDBC CachedRowSet
table content provider implementation. Allows to
access a JDBC datasource and execute SQL queries againt it. Supports
auto-refresh, transactional writebacks, row selection and row sorting. Needs
an configured CachedRowSet instance to wrap. The CachedRowSet object must
have the following properties set:
RowSet.setDataSourceName(java.lang.String)
RowSet.setCommand(java.lang.String)
CachedRowSet.setTableName(java.lang.String)
for
writebacks onlyCachedRowSetImpl rowSet = new CachedRowSetImpl(); rowSet.setDataSourceName("northwind"); rowSet.setCommand("SELECT * FROM CUSTOMERS WHERE Country = ?"); rowSet.setTableName("CUSTOMERS"); ITableContentProvider provider = new RowSetTableContentProvider(rowSet); provider.getParameters().set(0, "USA"); // country value // execute the query and read the data for (int i = 0; i < provider.getRowCount(); i++) { provider.setRowIndex(i); if (provider.isRowAvailable()) { String customerID = (String) provider.getValue("CustomerID"); String companyName = (String) provider.getValue("CompanyName"); } } ; // find a customer by id provider.setRowById("ANTON"); // Customer ID if (provider.isRowAvailable()) { provider.setValue("ContactName", "Jonh Doe"); } provider.setRowById("ALFKI"); // another customer if (provider.isRowAvailable()) { provider.setValue("Country", "USA"); } provider.setRowById("TODELETE"); if (provider.isRowAvailable()) { provider.deleteRow(); // delete row } provider.applyChanges(); // commit changes // change query parameters provider.getParameters().set(0, "Ukraine"); // new country value if (provider.getRowCount() > 0) { // auto-refresh the provider by re-executing // the query and returing new record count // no customers from Ukraine, ha? }
Modifier and Type | Field and Description |
---|---|
protected Object |
autoIncementKeyValue |
protected boolean |
autoRefreshMode
Indicates if provider is in "autoRefresh" mode
|
protected boolean |
canTemplateRow |
protected static String |
COMMA |
protected IErrorHandler |
errorHandler |
protected int |
index |
protected int |
maxResult |
protected RowSetMetaData |
metaData |
protected boolean |
needRefresh
Indicates if provider needs to be refreshed
|
protected MethodBinding |
onCreateRow |
protected MethodBinding |
onDeleteRow |
protected List<Object> |
parameters |
protected List<String> |
propertyNames |
protected List<Object> |
rowIdProperties |
protected CachedRowSet |
rowSet
Wrapped instance of CachedRowSet
|
protected String |
rowVariable |
protected SelectableTableContentProviderHelper |
selectableHelper |
protected ISortInfo |
sortInfo |
protected static String |
SPACE |
protected static String |
SQL_ASCENDING |
protected static String |
SQL_DESCENDING |
protected static String |
SQL_ORDERBY |
protected static String |
SQL_PARAMETER |
protected String |
syncProviderId |
protected Object |
templateRow |
protected boolean |
updated |
fExpireWithPageFlow
Constructor and Description |
---|
RowSetTableContentProvider()
Default constructor.
|
RowSetTableContentProvider(CachedRowSet rowSet)
Initializes with the given rowSet object.
|
Modifier and Type | Method and Description |
---|---|
void |
applyChanges()
Commits changes back to the data source.
|
void |
cancelChanges()
Reverts all changes made since the last
ITransactionalContentProvider.applyChanges() call. |
protected boolean |
canOpen()
Returns true if the row set can be opened, i.e.
|
void |
createRow()
Creates new row in the row set.
|
void |
deleteRow()
Deletes current row in the row set
|
protected boolean |
ensureRowSetOpen()
Opens row set if it is not currently open and can be opened, i.e.
|
boolean |
getCanTemplateRow()
True if provider can be put into template row state.
|
Object |
getCurrentRow()
Returns wrapped current row object.
|
IErrorHandler |
getErrorHandler()
Returns current error handler.
|
int |
getMaxResult()
Returns the maximum results amount.
|
boolean |
getNeedRefresh()
Returns true whenever a query parameter has changed since last
refresh() call. |
MethodBinding |
getOnCreateRow()
Returns the custom handler for
createRow() method |
MethodBinding |
getOnDeleteRow()
Returns custom handler for
deleteRow() method |
List |
getParameters()
Returns parameters list.
|
Object[] |
getPropertyKeys()
Returns
String array of all column names in the row set. |
int |
getRowCount()
Returns number of records in the row set.
|
String |
getRowId()
Calculates row id based on
CachedRowSet.getKeyColumns() . |
List |
getRowIdProperties()
Returns row id properties list.
|
int |
getRowIndex()
Return current row index
|
int |
getRowSelectedCount()
Returns number of selected rows.
|
Collection |
getRowSelectedIds()
Returns collection of
String ids of the selected rows. |
CachedRowSet |
getRowSet()
Returns currently set row set instance
|
Collection |
getRowUnselectedIds()
Returns collection of
String ids of the un-selected rows
(all other rows are selected implicitly)
May be empty or contain non-existent ids; never null, never contains null. |
String |
getRowVariable()
Returns row variable name.
|
ISortInfo |
getSort()
Returns current sort info.
|
String |
getSyncProviderId() |
Class |
getType(Object propertyKey)
Returns java type of the given property
|
boolean |
getUseUnselectedModel()
Returns true if it's more effecient to use unselected model
(ie
ISelectableTableContentProvider.getRowUnselectedIds() rather than ISelectableTableContentProvider.getRowSelectedIds() ). |
Object |
getValue(Object propertyKey)
Returns column value of the current row for the given column name or
index starting from 0.
|
boolean |
hasProperty(Object propertyKey)
Checks if the given property is supported by this content provider
|
protected void |
initializeNewRecord()
Initializes new record at "insert" row, using current state of
templateRow.
|
protected Object |
initializeTemplateRecord(boolean withCurrentRowValues)
Creates an object with the default values for a template record (not
inserted yet into the rowset).
|
boolean |
isAddressable()
Checks if this content provider truly is addressable.
|
boolean |
isAutoRefresh()
Returns
true if the provider is currenlty in auto-refresh mode |
protected boolean |
isOpen()
Returns true if the row set is currently open
|
boolean |
isReadOnly(Object propertyKey)
Returns true if the given column is readonly
|
boolean |
isRowAvailable()
true if row is available
|
boolean |
isRowSelected()
Returns
true if current row is selected. |
boolean |
isTemplateRow()
Is provider in state where it returns properties for template pseudo-row.
|
protected boolean |
openRowSet()
Executes the SQL query and populates the row set
|
void |
refresh()
Re-executes the SQL query and populates the row set with new data.
|
void |
setAutoRefresh(boolean autorefresh)
Sets auto refresh mode on.
|
void |
setCanTemplateRow(boolean value)
True if provider can be put into template row state.
|
void |
setCurrentRow(Object row)
Sets new current row object
|
void |
setErrorHandler(IErrorHandler errorHandler)
Set the errorhandler for this provider
|
void |
setMaxResult(int maxResult)
Sets the maximum results
|
void |
setNeedRefresh(boolean needRefresh)
Tells the provider that the input parameters have changed and the output results need to be refreshed the next time any
output property is requested via
IContentProvider.getValue(Object) . |
void |
setOnCreateRow(MethodBinding onNewRow)
Sets custom handler for
createRow() method |
void |
setOnDeleteRow(MethodBinding deleteRow)
Sets custom handler for
deleteRow() method |
void |
setRowById(String id)
Iterates through the row set to find a record with the given id.
|
void |
setRowId(String id)
JavaBean property setter for
setRowById(String) |
void |
setRowIdProperties(List rowIdProperties)
Sets new row id properties.
|
void |
setRowIndex(int rowIndex)
Set index row to input value.
|
void |
setRowSelected(boolean selected)
Sets the selection status for the current row.
|
void |
setRowSelectedIds(Collection ids)
Sets new selection using a collection of
String ids of the rows to select. |
void |
setRowSet(CachedRowSet rowSet)
Sets new row set instance
|
void |
setRowUnselectedIds(Collection ids)
Unselects rows using a collection of
String ids of the un-selected rows
(all other rows are selected implicitly). |
void |
setRowVariable(String var)
Sets row variable name to use for accessing row specific data.
|
void |
setSort(ISortInfo sort)
Augments the SQL query with ORDER BY clause based on the sort info and
re-execute it.
|
void |
setSyncProviderId(String syncProviderId) |
void |
setTemplateRow()
Sets provider to state where it returns properties for template pseudo-row.
|
void |
setValue(Object propertyKey,
Object value)
Sets new value for the given column on the current row.
|
boolean |
supportsAutoRefresh()
Returns true
|
getExpireWithPageFlow, setExpireWithPageFlow
protected CachedRowSet rowSet
protected RowSetMetaData metaData
protected boolean autoRefreshMode
protected boolean needRefresh
protected ISortInfo sortInfo
protected int index
protected boolean updated
protected Object templateRow
protected boolean canTemplateRow
protected Object autoIncementKeyValue
protected IErrorHandler errorHandler
protected MethodBinding onCreateRow
protected MethodBinding onDeleteRow
protected int maxResult
protected String syncProviderId
protected static final String SQL_ORDERBY
protected static final String SQL_PARAMETER
protected static final String SPACE
protected static final String COMMA
protected static final String SQL_ASCENDING
protected static final String SQL_DESCENDING
protected String rowVariable
protected SelectableTableContentProviderHelper selectableHelper
public RowSetTableContentProvider()
setRowSet(CachedRowSet)
must be called
before usepublic RowSetTableContentProvider(CachedRowSet rowSet)
rowSet
- a cached row set instancepublic CachedRowSet getRowSet()
public IErrorHandler getErrorHandler()
public void setErrorHandler(IErrorHandler errorHandler)
errorHandler
- the errorhandler to be setpublic void setRowSet(CachedRowSet rowSet)
rowSet
- row set instancepublic List getParameters()
null
.protected boolean ensureRowSetOpen()
ContentProviderException
- if error happens during this operationprotected boolean canOpen()
null
)protected boolean isOpen()
protected boolean openRowSet()
public boolean getCanTemplateRow()
IUpdateableTableContentProvider
getCanTemplateRow
in interface IUpdateableTableContentProvider
#setTemplateRow()}
public void setCanTemplateRow(boolean value)
IUpdateableTableContentProvider
setCanTemplateRow
in interface IUpdateableTableContentProvider
public boolean isTemplateRow()
IUpdateableTableContentProvider
ITableContentProvider.isRowAvailable()
returns false.
Setting the row index or id to any value removes provider from this state.isTemplateRow
in interface IUpdateableTableContentProvider
public void setTemplateRow()
IUpdateableTableContentProvider
ITableContentProvider.isRowAvailable()
returns false.
Setting the row index or id to any value removes provider from this state.setTemplateRow
in interface IUpdateableTableContentProvider
public void setCurrentRow(Object row)
IUpdateableTableContentProvider
setCurrentRow
in interface IUpdateableTableContentProvider
row
- new row object to replace object returned by ITableContentProvider.getCurrentRow()
protected Object initializeTemplateRecord(boolean withCurrentRowValues)
withCurrentRowValues
- public void createRow()
initializeNewRecord()
before inserting the record.createRow
in interface IUpdateableTableContentProvider
protected void initializeNewRecord() throws SQLException
SQLException
public void deleteRow()
deleteRow
in interface IUpdateableTableContentProvider
ITableContentProvider.getRowIndex()
public void refresh() throws ContentProviderException
refresh
in interface IRefreshable
ContentProviderException
- if error loading data from the data sourcepublic boolean supportsAutoRefresh()
supportsAutoRefresh
in interface IRefreshable
IRefreshable.setAutoRefresh(boolean)
public void setAutoRefresh(boolean autorefresh) throws ContentProviderException
IRefreshable
Sets auto refresh mode on. When auto refresh mode is on, the provider calls IRefreshable.getNeedRefresh()
to determine whether the refresh needs to be done before returning any result properties. If it returns
true
, the provider calls IRefreshable.refresh()
method to updated the result properties.
setAutoRefresh
in interface IRefreshable
autorefresh
- true to turn it onContentProviderException
- if auto refresh mode is not supportedIRefreshable.supportsAutoRefresh()
,
IRefreshable.getNeedRefresh()
,
IRefreshable.setNeedRefresh(boolean)
public boolean isAutoRefresh()
IRefreshable
true
if the provider is currenlty in auto-refresh modeisAutoRefresh
in interface IRefreshable
public boolean getNeedRefresh()
refresh()
call.getNeedRefresh
in interface IRefreshable
true
when the output properties are not up-to-date with the current input parameters, i.e. IRefreshable.refresh()
needs to be executed manually or automatically.public void setNeedRefresh(boolean needRefresh)
IRefreshable
IContentProvider.getValue(Object)
.setNeedRefresh
in interface IRefreshable
needRefresh
- true
if the input parameters have changedpublic void applyChanges() throws ContentProviderException
SyncProviderException
for details.applyChanges
in interface ITransactionalContentProvider
ContentProviderException
- if commit failspublic void cancelChanges() throws ContentProviderException
ITransactionalContentProvider
Reverts all changes made since the last ITransactionalContentProvider.applyChanges()
call.
cancelChanges
in interface ITransactionalContentProvider
ContentProviderException
public Object[] getPropertyKeys()
String
array of all column names in the row set. Executes
the SQL query to find out.getPropertyKeys
in interface IContentProvider
public boolean hasProperty(Object propertyKey)
IContentProvider
hasProperty
in interface IContentProvider
propertyKey
- property key of type String
or Integer
true
if property is supportedpublic Class getType(Object propertyKey)
IContentProvider
getType
in interface IContentProvider
propertyKey
- the property key of type String
or Integer
Class
public Object getValue(Object propertyKey) throws EvaluationException, PropertyNotFoundException
getValue
in interface IContentProvider
propertyKey
- column name of indexnull
EvaluationException
- if error during property evaluationPropertyNotFoundException
- if property is not supportedpublic void setValue(Object propertyKey, Object value) throws EvaluationException, PropertyNotFoundException
setValue
in interface IUpdateableContentProvider
propertyKey
- column name of indexvalue
- new valueEvaluationException
- if error updating the columnPropertyNotFoundException
- if column does not existpublic boolean isReadOnly(Object propertyKey) throws EvaluationException, PropertyNotFoundException
isReadOnly
in interface IUpdateableContentProvider
propertyKey
- column name or indexEvaluationException
PropertyNotFoundException
public boolean isRowAvailable()
isRowAvailable
in interface ITableContentProvider
DataModel.isRowAvailable()
public int getRowCount()
getRowCount
in interface ITableContentProvider
DataModel.getRowCount()
public int getRowIndex()
getRowIndex
in interface ITableContentProvider
DataModel.getRowIndex()
public void setRowIndex(int rowIndex)
setRowIndex
in interface ITableContentProvider
DataModel.getRowIndex()
public String getRowVariable()
ITableContentProvider
Returns row variable name.
If specified row variable can be used to access current row data for the provider internal needs, like sorting or addressing.
getRowVariable
in interface ITableContentProvider
ITableContentProvider.setRowVariable(String)
public void setRowVariable(String var)
ITableContentProvider
Sets row variable name to use for accessing row specific data. For
example, if the provider wrapps an array of a data objects with
id
property and the variable name is item
, then
the provider implementation can access id
property of each
record as item.id
.
This property should set only once at the provider initialization time
setRowVariable
in interface ITableContentProvider
public Object getCurrentRow()
ITableContentProvider
Returns wrapped current row object. Can be null
if not data
is available
getCurrentRow
in interface ITableContentProvider
ITableContentProvider.isRowAvailable()
public boolean isAddressable()
IAddressableTableContentProvider
isAddressable
in interface IAddressableTableContentProvider
true
if addressable.public List getRowIdProperties()
public void setRowIdProperties(List rowIdProperties)
getPropertyKeys()
and getValue(Object)
binding
- value binding expression to evaluate row idpublic String getRowId()
CachedRowSet.getKeyColumns()
.getRowId
in interface IAddressableTableContentProvider
public void setRowById(String id)
setRowById
in interface IAddressableTableContentProvider
id
- row idpublic void setRowId(String id)
setRowById(String)
id
- public boolean isRowSelected()
ISelectableTableContentProvider
true
if current row is selected.isRowSelected
in interface ISelectableTableContentProvider
public void setRowSelected(boolean selected)
ISelectableTableContentProvider
setRowSelected
in interface ISelectableTableContentProvider
selected
- true
to select current row; false
to unselect.public int getRowSelectedCount()
ISelectableTableContentProvider
getRowSelectedCount
in interface ISelectableTableContentProvider
public Collection getRowSelectedIds()
ISelectableTableContentProvider
String
ids of the selected rows.
May be empty or contain non-existent ids; never null, never contains null.getRowSelectedIds
in interface ISelectableTableContentProvider
public void setRowSelectedIds(Collection ids)
ISelectableTableContentProvider
String
ids of the rows to select.
May be empty or contain non-existent ids; never null, never contains null.setRowSelectedIds
in interface ISelectableTableContentProvider
ids
- the collection of String
row idspublic boolean getUseUnselectedModel()
ISelectableTableContentProvider
ISelectableTableContentProvider.getRowUnselectedIds()
rather than ISelectableTableContentProvider.getRowSelectedIds()
).getUseUnselectedModel
in interface ISelectableTableContentProvider
public Collection getRowUnselectedIds()
ISelectableTableContentProvider
String
ids of the un-selected rows
(all other rows are selected implicitly)
May be empty or contain non-existent ids; never null, never contains null.getRowUnselectedIds
in interface ISelectableTableContentProvider
public void setRowUnselectedIds(Collection ids)
ISelectableTableContentProvider
String
ids of the un-selected rows
(all other rows are selected implicitly).
May be empty or contain non-existent ids; never null, never contains null.setRowUnselectedIds
in interface ISelectableTableContentProvider
ids
- collection of String
row idspublic ISortInfo getSort()
ISortableTableContentProvider
getSort
in interface ISortableTableContentProvider
public void setSort(ISortInfo sort)
setSort
in interface ISortableTableContentProvider
sort
- new sort infopublic MethodBinding getOnCreateRow()
createRow()
methodsetOnCreateRow(MethodBinding)
public void setOnCreateRow(MethodBinding onNewRow)
createRow()
methodonNewRow
- method binding expression for a method that is called from
createRow()
public MethodBinding getOnDeleteRow()
deleteRow()
methodsetOnDeleteRow(MethodBinding)
public void setOnDeleteRow(MethodBinding deleteRow)
deleteRow()
methodonNewRow
- method binding expression for a method that is called from
deleteRow()
public String getSyncProviderId()
public void setSyncProviderId(String syncProviderId)
public int getMaxResult()
public void setMaxResult(int maxResult)
maxResult
- max number of results