public interface DsFacade
DSRequests
by passing them on to another DataSource.
This can be useful for:
DataSource.cacheAllData
or
automatic caching done by ResultSet
DataSourceField.includeFrom
if you have Smart GWT Pro or better)
OperationBinding.operationId
for this)
This facade pattern can be implemented either server-side or client-side:
dataProtocol:"clientCustom"
. The
FacadeDataSource
provides a specific implementation that is
useful for testing
purposes. Alternative, the code below shows the simplest possible code for the facade
pattern when implemented client-side via dataProtocol:"clientCustom"
- requests
are forwarded to another DataSource, and the responses are returned completely unchanged.
final DataSource facadeDataSource = new DataSource() { { setDataProtocol(DSProtocol.CLIENTCUSTOM); setInheritsFrom(ItemSupplyXmlDS.getInstance()); } @Override public Object transformRequest(final DSRequest dsRequest) { final DataSource superDS = DataSource.get(getInheritsFrom()), selfDS = this; final DSRequest derivedDSRequest = cloneDSRequest(dsRequest); derivedDSRequest.setShowPrompt(false); derivedDSRequest.setCallback(new DSCallback() { @Override public void execute(DSResponse dsResponse, Object data, DSRequest derivedDSRequest) { selfDS.processResponse(dsRequest.getRequestId(), superDS.cloneDSResponse(dsResponse)); } }); superDS.execute(derivedDSRequest); return dsRequest.getData(); } };
Check out this example of the DataSource facade pattern being used to create a DataSource that may work with already loaded data, or may use another DataSource to fulfill its requests.