Class RowSetTableContentProvider
- All Implemented Interfaces:
IPageFlowScopeAdapter
,IAddressableTableContentProvider
,IContentProvider
,IRefreshable
,IRefreshableContentProvider
,ISelectableTableContentProvider
,ISortableTableContentProvider
,ITableContentProvider
,ITransactionalContentProvider
,IUpdateableContentProvider
,IUpdateableTableContentProvider
,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 only
CachedRowSetImpl 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? }
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Object
protected boolean
Indicates if provider is in "autoRefresh" modeprotected boolean
protected static final String
protected IErrorHandler
protected int
protected int
protected RowSetMetaData
protected boolean
Indicates if provider needs to be refreshedprotected MethodExpression
protected MethodExpression
protected CachedRowSet
Wrapped instance of CachedRowSetprotected String
protected SelectableTableContentProviderHelper
protected ISortInfo
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected String
protected Object
protected boolean
Fields inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
fExpireWithPageFlow
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Initializes with the given rowSet object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Commits changes back to the data source.void
Reverts all changes made since the lastITransactionalContentProvider.applyChanges()
call.protected boolean
canOpen()
Returns true if the row set can be opened, i.e.void
Creates new row in the row set.void
Deletes current row in the row setprotected boolean
Opens row set if it is not currently open and can be opened, i.e.boolean
True if provider can be put into template row state.getCon()
Returns wrapped current row object.Returns current error handler.int
Returns the maximum results amount.boolean
Returns true whenever a query parameter has changed since lastrefresh()
call.Deprecated.Returns the custom handler forcreateRow()
methodDeprecated.Returns custom handler fordeleteRow()
methodReturns parameters list.Object[]
ReturnsString
array of all column names in the row set.int
Returns number of records in the row set.getRowId()
Calculates row id based onCachedRowSet.getKeyColumns()
.Returns row id properties list.int
Return current row indexint
Returns number of selected rows.Returns collection ofString
ids of the selected rows.Returns currently set row set instanceReturns collection ofString
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.Returns row variable name.getSort()
Returns current sort info.Class<?>
Returns java type of the given propertyboolean
Returns true if it's more effecient to use unselected model (ieISelectableTableContentProvider.getRowUnselectedIds()
rather thanISelectableTableContentProvider.getRowSelectedIds()
).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 providerprotected void
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
Checks if this content provider truly is addressable.boolean
Returnstrue
if the provider is currenlty in auto-refresh modeprotected boolean
isOpen()
Returns true if the row set is currently openboolean
isReadOnly
(Object propertyKey) Returns true if the given column is readonlyboolean
true if row is availableboolean
Returnstrue
if current row is selected.boolean
Is provider in state where it returns properties for template pseudo-row.protected boolean
Executes the SQL query and populates the row setvoid
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
setCon
(Connection con) void
setCurrentRow
(Object row) Sets new current row objectvoid
setErrorHandler
(IErrorHandler errorHandler) Set the errorhandler for this providervoid
setMaxResult
(int maxResult) Sets the maximum resultsvoid
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 viaIContentProvider.getValue(Object)
.void
setOnCreateRow
(MethodBinding onNewRow) Deprecated.usesetOnCreateRowExpression(MethodExpression)
insteadvoid
setOnCreateRowExpression
(MethodExpression onNewRow) Sets custom handler forcreateRow()
methodvoid
setOnDeleteRow
(MethodBinding deleteRow) Deprecated.usesetOnDeleteRowExpression(MethodExpression)
insteadvoid
setOnDeleteRowExpression
(MethodExpression deleteRow) Sets custom handler fordeleteRow()
methodvoid
setRowById
(String id) Iterates through the row set to find a record with the given id.void
JavaBean property setter forsetRowById(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
Sets new selection using a collection ofString
ids of the rows to select.void
setRowSet
(CachedRowSet rowSet) Sets new row set instancevoid
Unselects rows using a collection ofString
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
Augments the SQL query with ORDER BY clause based on the sort info and re-execute it.void
setSyncProviderId
(String syncProviderId) void
Sets provider to state where it returns properties for template pseudo-row.void
Sets new value for the given column on the current row.boolean
Returns trueMethods inherited from class com.webmethods.caf.faces.bean.PageFlowScopeAdapter
getExpireWithPageFlow, setExpireWithPageFlow
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.webmethods.caf.faces.data.IContentProvider
toString
-
Field Details
-
rowSet
Wrapped instance of CachedRowSet -
metaData
-
autoRefreshMode
protected boolean autoRefreshModeIndicates if provider is in "autoRefresh" mode -
needRefresh
protected boolean needRefreshIndicates if provider needs to be refreshed -
sortInfo
-
propertyNames
-
index
protected int index -
updated
protected boolean updated -
templateRow
-
canTemplateRow
protected boolean canTemplateRow -
autoIncementKeyValue
-
errorHandler
-
onCreateRow
-
onDeleteRow
-
maxResult
protected int maxResult -
syncProviderId
-
rowIdProperties
-
SQL_ORDERBY
- See Also:
-
SQL_PARAMETER
- See Also:
-
SPACE
- See Also:
-
COMMA
- See Also:
-
SQL_ASCENDING
- See Also:
-
SQL_DESCENDING
- See Also:
-
parameters
-
rowVariable
-
selectableHelper
-
-
Constructor Details
-
RowSetTableContentProvider
public RowSetTableContentProvider()Default constructor.setRowSet(CachedRowSet)
must be called before use -
RowSetTableContentProvider
Initializes with the given rowSet object.- Parameters:
rowSet
- a cached row set instance
-
-
Method Details
-
getRowSet
Returns currently set row set instance- Returns:
- null if not set
-
getErrorHandler
Returns current error handler.- Returns:
- null if doesn't exist
-
setErrorHandler
Set the errorhandler for this provider- Parameters:
errorHandler
- the errorhandler to be set
-
setRowSet
Sets new row set instance- Parameters:
rowSet
- row set instance
-
getParameters
Returns parameters list. Each ? in the command can be set using this list. The index of the ? in the SQL query corresponds to the index in this list, starting from 0.- Returns:
- parameters list, can be empty, never
null
.
-
ensureRowSetOpen
protected boolean ensureRowSetOpen()Opens row set if it is not currently open and can be opened, i.e. all required parameters are supplied.- Returns:
- false if the row set cannot be opened.
- Throws:
ContentProviderException
- if error happens during this operation
-
canOpen
protected boolean canOpen()Returns true if the row set can be opened, i.e. all required parameters are set.- Returns:
- false if any parameter is not set (
null
)
-
isOpen
protected boolean isOpen()Returns true if the row set is currently open- Returns:
- false if it is closed.
-
openRowSet
protected boolean openRowSet()Executes the SQL query and populates the row set- Returns:
- true if successful
-
getCanTemplateRow
public boolean getCanTemplateRow()Description copied from interface:IUpdateableTableContentProvider
True if provider can be put into template row state.- Specified by:
getCanTemplateRow
in interfaceIUpdateableTableContentProvider
-
setCanTemplateRow
public void setCanTemplateRow(boolean value) Description copied from interface:IUpdateableTableContentProvider
True if provider can be put into template row state. Default: true- Specified by:
setCanTemplateRow
in interfaceIUpdateableTableContentProvider
-
isTemplateRow
public boolean isTemplateRow()Description copied from interface:IUpdateableTableContentProvider
Is provider in state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null;ITableContentProvider.isRowAvailable()
returns false. Setting the row index or id to any value removes provider from this state.- Specified by:
isTemplateRow
in interfaceIUpdateableTableContentProvider
-
setTemplateRow
public void setTemplateRow()Description copied from interface:IUpdateableTableContentProvider
Sets provider to state where it returns properties for template pseudo-row. In this state, row index is -1 and row id is null;ITableContentProvider.isRowAvailable()
returns false. Setting the row index or id to any value removes provider from this state.- Specified by:
setTemplateRow
in interfaceIUpdateableTableContentProvider
-
setCurrentRow
Description copied from interface:IUpdateableTableContentProvider
Sets new current row object- Specified by:
setCurrentRow
in interfaceIUpdateableTableContentProvider
- Parameters:
row
- new row object to replace object returned byITableContentProvider.getCurrentRow()
-
initializeTemplateRecord
Creates an object with the default values for a template record (not inserted yet into the rowset). By default, creates a map with the default value for each named column specified by rowset's metadata.- Parameters:
withCurrentRowValues
-- Returns:
-
createRow
public void createRow()Creates new row in the row set. CallsinitializeNewRecord()
before inserting the record.- Specified by:
createRow
in interfaceIUpdateableTableContentProvider
-
initializeNewRecord
Initializes new record at "insert" row, using current state of templateRow. By default, copies name columns from templateRow map object into "insert" row.- Throws:
SQLException
-
deleteRow
public void deleteRow()Deletes current row in the row set- Specified by:
deleteRow
in interfaceIUpdateableTableContentProvider
- See Also:
-
refresh
Re-executes the SQL query and populates the row set with new data.- Specified by:
refresh
in interfaceIRefreshable
- Throws:
ContentProviderException
- if error loading data from the data source
-
supportsAutoRefresh
public boolean supportsAutoRefresh()Returns true- Specified by:
supportsAutoRefresh
in interfaceIRefreshable
- Returns:
- true
- See Also:
-
setAutoRefresh
Description copied from interface: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 returnstrue
, the provider callsIRefreshable.refresh()
method to updated the result properties.- Specified by:
setAutoRefresh
in interfaceIRefreshable
- Parameters:
autorefresh
- true to turn it on- Throws:
ContentProviderException
- if auto refresh mode is not supported- See Also:
-
isAutoRefresh
public boolean isAutoRefresh()Description copied from interface:IRefreshable
Returnstrue
if the provider is currenlty in auto-refresh mode- Specified by:
isAutoRefresh
in interfaceIRefreshable
- Returns:
- false if auto-refresh mode is off or not supported
-
getNeedRefresh
public boolean getNeedRefresh()Returns true whenever a query parameter has changed since lastrefresh()
call.- Specified by:
getNeedRefresh
in interfaceIRefreshable
- Returns:
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.
-
setNeedRefresh
public void setNeedRefresh(boolean needRefresh) Description copied from interface:IRefreshable
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 viaIContentProvider.getValue(Object)
.- Specified by:
setNeedRefresh
in interfaceIRefreshable
- Parameters:
needRefresh
-true
if the input parameters have changed
-
applyChanges
Commits changes back to the data source. In case of an error clients may need to examine the wrappedSyncProviderException
for details.- Specified by:
applyChanges
in interfaceITransactionalContentProvider
- Throws:
ContentProviderException
- if commit fails
-
cancelChanges
Description copied from interface:ITransactionalContentProvider
Reverts all changes made since the last
ITransactionalContentProvider.applyChanges()
call.- Specified by:
cancelChanges
in interfaceITransactionalContentProvider
- Throws:
ContentProviderException
-
getPropertyKeys
ReturnsString
array of all column names in the row set. Executes the SQL query to find out.- Specified by:
getPropertyKeys
in interfaceIContentProvider
- Returns:
- array of column names in the row set
-
hasProperty
Description copied from interface:IContentProvider
Checks if the given property is supported by this content provider- Specified by:
hasProperty
in interfaceIContentProvider
- Parameters:
propertyKey
- property key of typeString
orInteger
- Returns:
true
if property is supported
-
getType
Description copied from interface:IContentProvider
Returns java type of the given property- Specified by:
getType
in interfaceIContentProvider
- Parameters:
propertyKey
- the property key of typeString
orInteger
- Returns:
- property java
Class
-
getValue
Returns column value of the current row for the given column name or index starting from 0. The row set will be opened if it is closed.- Specified by:
getValue
in interfaceIContentProvider
- Parameters:
propertyKey
- column name of index- Returns:
- value of the property, can be
null
- Throws:
PropertyNotFoundException
- if property is not supportedELException
-
setValue
public void setValue(Object propertyKey, Object value) throws ELException, PropertyNotFoundException Sets new value for the given column on the current row. The row set will be opened if it is closed.- Specified by:
setValue
in interfaceIUpdateableContentProvider
- Parameters:
propertyKey
- column name of indexvalue
- new value- Throws:
ELException
- if error updating the columnPropertyNotFoundException
- if column does not exist
-
isReadOnly
Returns true if the given column is readonly- Specified by:
isReadOnly
in interfaceIUpdateableContentProvider
- Parameters:
propertyKey
- column name or index- Returns:
- true if the column is readonly
- Throws:
PropertyNotFoundException
ELException
-
isRowAvailable
public boolean isRowAvailable()true if row is available- Specified by:
isRowAvailable
in interfaceITableContentProvider
- See Also:
-
getRowCount
public int getRowCount()Returns number of records in the row set. Executes the query if necessary.- Specified by:
getRowCount
in interfaceITableContentProvider
- Returns:
- number of records
- See Also:
-
getRowIndex
public int getRowIndex()Return current row index- Specified by:
getRowIndex
in interfaceITableContentProvider
- See Also:
-
setRowIndex
public void setRowIndex(int rowIndex) Set index row to input value.- Specified by:
setRowIndex
in interfaceITableContentProvider
- See Also:
-
getRowVariable
Description copied from interface: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.
- Specified by:
getRowVariable
in interfaceITableContentProvider
- Returns:
- row variable name or null if not specified
- See Also:
-
setRowVariable
Description copied from interface: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 isitem
, then the provider implementation can accessid
property of each record asitem.id
.This property should set only once at the provider initialization time
- Specified by:
setRowVariable
in interfaceITableContentProvider
-
getCurrentRow
Description copied from interface:ITableContentProvider
Returns wrapped current row object. Can be
null
if not data is available- Specified by:
getCurrentRow
in interfaceITableContentProvider
- Returns:
- current row object
- See Also:
-
isAddressable
public boolean isAddressable()Description copied from interface:IAddressableTableContentProvider
Checks if this content provider truly is addressable.- Specified by:
isAddressable
in interfaceIAddressableTableContentProvider
- Returns:
true
if addressable.
-
getRowIdProperties
Returns row id properties list.- Returns:
- empty list of no row id properties are set
-
setRowIdProperties
Sets new row id properties. Can use property names or indexes compatibly withgetPropertyKeys()
andgetValue(Object)
- Parameters:
binding
- value binding expression to evaluate row id
-
getRowId
Calculates row id based onCachedRowSet.getKeyColumns()
.- Specified by:
getRowId
in interfaceIAddressableTableContentProvider
- Returns:
- current row id or null
-
setRowById
Iterates through the row set to find a record with the given id. If not found sets current row index to -1.- Specified by:
setRowById
in interfaceIAddressableTableContentProvider
- Parameters:
id
- row id
-
setRowId
JavaBean property setter forsetRowById(String)
- Parameters:
id
-
-
isRowSelected
public boolean isRowSelected()Description copied from interface:ISelectableTableContentProvider
Returnstrue
if current row is selected.- Specified by:
isRowSelected
in interfaceISelectableTableContentProvider
- Returns:
- true if current row is selection
-
setRowSelected
public void setRowSelected(boolean selected) Description copied from interface:ISelectableTableContentProvider
Sets the selection status for the current row.- Specified by:
setRowSelected
in interfaceISelectableTableContentProvider
- Parameters:
selected
-true
to select current row;false
to unselect.
-
getRowSelectedCount
public int getRowSelectedCount()Description copied from interface:ISelectableTableContentProvider
Returns number of selected rows.- Specified by:
getRowSelectedCount
in interfaceISelectableTableContentProvider
- Returns:
- number of currently selection rows
-
getRowSelectedIds
Description copied from interface:ISelectableTableContentProvider
Returns collection ofString
ids of the selected rows. May be empty or contain non-existent ids; never null, never contains null.- Specified by:
getRowSelectedIds
in interfaceISelectableTableContentProvider
- Returns:
- collection of ids of selected rows
-
setRowSelectedIds
Description copied from interface:ISelectableTableContentProvider
Sets new selection using a collection ofString
ids of the rows to select. May be empty or contain non-existent ids; never null, never contains null.- Specified by:
setRowSelectedIds
in interfaceISelectableTableContentProvider
- Parameters:
ids
- the collection ofString
row ids
-
getUseUnselectedModel
public boolean getUseUnselectedModel()Description copied from interface:ISelectableTableContentProvider
Returns true if it's more effecient to use unselected model (ieISelectableTableContentProvider.getRowUnselectedIds()
rather thanISelectableTableContentProvider.getRowSelectedIds()
).- Specified by:
getUseUnselectedModel
in interfaceISelectableTableContentProvider
- Returns:
- true if it's more effecient to use unselected model
-
getRowUnselectedIds
Description copied from interface:ISelectableTableContentProvider
Returns collection ofString
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.- Specified by:
getRowUnselectedIds
in interfaceISelectableTableContentProvider
- Returns:
- collection of ids of the un-selection rows
-
setRowUnselectedIds
Description copied from interface:ISelectableTableContentProvider
Unselects rows using a collection ofString
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.- Specified by:
setRowUnselectedIds
in interfaceISelectableTableContentProvider
- Parameters:
ids
- collection ofString
row ids
-
getSort
Description copied from interface:ISortableTableContentProvider
Returns current sort info. Never null.- Specified by:
getSort
in interfaceISortableTableContentProvider
- Returns:
- currenly set sort info
-
setSort
Augments the SQL query with ORDER BY clause based on the sort info and re-execute it. Soft info property keys may be either binding expressions of row set field names.- Specified by:
setSort
in interfaceISortableTableContentProvider
- Parameters:
sort
- new sort info
-
getOnCreateRow
Deprecated.Returns the custom handler forcreateRow()
method -
getOnCreateRowExpression
Returns the custom handler forcreateRow()
method -
setOnCreateRow
Deprecated.usesetOnCreateRowExpression(MethodExpression)
insteadSets custom handler forcreateRow()
method- Parameters:
onNewRow
- method binding expression for a method that is called fromcreateRow()
-
setOnCreateRowExpression
Sets custom handler forcreateRow()
method- Parameters:
onNewRow
- method binding expression for a method that is called fromcreateRow()
-
getOnDeleteRow
Deprecated.usegetOnDeleteRowExpression()
insteadReturns custom handler fordeleteRow()
method -
getOnDeleteRowExpression
Returns custom handler fordeleteRow()
method -
setOnDeleteRow
Deprecated.usesetOnDeleteRowExpression(MethodExpression)
insteadSets custom handler fordeleteRow()
method- Parameters:
onNewRow
- method binding expression for a method that is called fromdeleteRow()
-
setOnDeleteRowExpression
Sets custom handler fordeleteRow()
method- Parameters:
onNewRow
- method binding expression for a method that is called fromdeleteRow()
-
getSyncProviderId
-
setSyncProviderId
-
getMaxResult
public int getMaxResult()Returns the maximum results amount.- Returns:
- value for maximum amount of results that can be made
-
setMaxResult
public void setMaxResult(int maxResult) Sets the maximum results- Parameters:
maxResult
- max number of results
-
getCon
-
setCon
-
getOnDeleteRowExpression()
instead