Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    javadoc bug? DSResponse.addRelatedUpdates()

    Is there a new way to do addRelatedUpdates() or is it just not exposed yet? I can't find this method on the server version of DSResponse ( http://www.smartclient.com/smartgwte...SResponse.html )


    This is what the client doc says:
    http://www.smartclient.com/smartgwte...ata.DSResponse

    public void updateCaches(DSResponse dsResponse)

    <snip>

    This API should be used when you have found out about changes made by other users or by automatic processes. For example, using the Smart GWT Messaging system to receive real-time updates via HTTP streaming, you may get updates that should affect a ListGrid which is using a ResultSet to view a portion of a large dataset.

    Alternatively, an operation that removes a record from one DataSource may cause a new record to be added to another DataSource (such as Lead -> Account conversion in CRM applications). This could be accomplished by using the callback from the "remove" operation to call updateCaches with a DSResponse representing an "add" operation on the related DataSource.

    Cache updates of this kind can also be driven from server-side code - see the related server-side API DSResponse.addRelatedUpdate().

    <snip>

    #2
    Oops - that API is planned, but not implemented yet, and the mention of it leaked through in the documentation.

    Instead, for now, if you need to deliver data for related updates to updateCaches(), you can place it in the first record of the normal response as an extra attribute.

    Comment


      #3
      Ah, a sneak peak. :)

      In your suggestion, do you mean that I add extra attributes and then write a DSCallback to call the relevant updateCaches after the client add/update call? Doesn't seem to be a big deal to do that.

      Comment


        #4
        Yes exactly. addRelatedUpdates will be a convenience method to do just that.

        Comment


          #5
          Here's my version of it. I didn't use the record, but stuffed it in the DSResponse instead. In this way, it can also be used on a remove() - though I guess I would need to add a different handler for that.

          Pretty tempting to add a row hint for which rows changed, but then where do you stop...

          Server side:
          Code:
          	public static void addRelatedUpdates(DSResponse dsResponse,
          			String... dataSourceNames) {
          		dsResponse.setProperty(Constants.RELATED_UPDATES, dataSourceNames);
          	}

          Client side:
          Code:
          		grid.addEditCompleteHandler(new EditCompleteHandler() {
          			@Override
          			public void onEditComplete(EditCompleteEvent event) {
          				DSResponse response = event.getDsResponse();
          				String relatedUpdates = response
          						.getAttribute(Constants.RELATED_UPDATES);
          				if (relatedUpdates != null) {
          					String[] dataSourceNames = relatedUpdates.split(",");
          					for (String dataSourceName : dataSourceNames) {
          						DataSource dataSource = DataSource.get(dataSourceName);
          						if (dataSource != null)
          							dataSource.invalidateCache();
          					}
          				}
          			}
          		});

          Comment


            #6
            Is there a way this could be done through the DataSource.xml definitions, something like the Velocity definitions but on the response?

            Comment


              #7
              For what specific scenario?

              You can always add your own custom properties that drive behaviors such as cascading deletes with updates of related DataSources delivered automatically to the client..

              Comment


                #8
                The scenario I was thinking was when using one of the isomorphic datasource classes. Instead of having to subclass them and add extra code, you could specify that an update/add requires other datasources to be checked.

                Comment


                  #9
                  of course, that could be done client side too.

                  Comment


                    #10
                    The client code I posted earlier does not work. This does.
                    Code:
                    		grid.addEditCompleteHandler(new EditCompleteHandler() {
                    			@Override
                    			public void onEditComplete(EditCompleteEvent event) {
                    				DSResponse response = event.getDsResponse();
                    				String relatedUpdates = response
                    						.getAttribute(Constants.RELATED_UPDATES);
                    				if (relatedUpdates != null) {
                    					String[] dataSourceNames = relatedUpdates.split(",");
                    					for (String dataSourceName : dataSourceNames) {
                    						DataSource dataSource = DataSource.get(dataSourceName);
                    						if (dataSource != null) {
                    [b]							DSResponse dsResponse = new DSResponse();
                    							dsResponse.setInvalidateCache(true);
                    							dataSource.updateCaches(dsResponse);[/b]
                    						}
                    					}
                    				}
                    			}
                    		});

                    Comment


                      #11
                      I'm pretty excited to see this is there now. But I tried it out and the client side did not update the related data source. Do I need to check the response or are there still parts missing from the client code to support addRelatedUpdates?

                      The SmartGWTEE server returned what looked like a well formed response

                      Code:
                      [
                          {
                              relatedUpdates:[
                                  {
                                      dataSource:"another_DataSource", 
                                      isDSResponse:true,
                                      invalidateCache:false, 
                                      status:0, 
                                      data:{
                                       ....

                      Comment


                        #12
                        Check the ResultSet log to see what went wrong.

                        Comment


                          #13
                          Strange. It looks like the ResultSet was updated but the ListGrid containing the related update is not changed.

                          Code:
                          16:12:56.001:XRP1:INFO:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):updating cache in place after operationType: update, allMatchingRowsCached true
                          16:12:56.002:XRP1:INFO:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):Updating cache: operationType 'update' submitted by 'isc_PrimaryGrid_10_0',1 rows update data:
                          [
                          {id: 4592,
                          employeeId: 4592,
                          skills: Array[1],
                          lastName: "Mo",
                          order: 2,
                          firstName: "Joe"}
                          ]
                          16:12:56.002:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):updated cache: 0 row(s) added, 1 row(s) updated, 0 row(s) removed.
                          16:12:56.003:XRP1:INFO:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):$391: sorting on properties [order] : directions [true] : full cache allows local sort
                          16:12:56.022:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.024:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.026:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.028:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.029:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.031:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.033:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.035:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.038:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.040:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.043:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.046:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.049:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.052:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.055:XRP1:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:12:56.103:RDQ9:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 2) satisfied from cache
                          16:12:59.316:MUP3:INFO:ResultSet:isc_ListGrid_0:Creating new isc.ResultSet for operation 'skill_DataSource_fetch' with filterValues: {
                          }
                          16:12:59.317:MUP3:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):setCriteria: filter criteria changed, invalidating cache
                          16:12:59.318:MUP3:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):Invalidating cache
                          16:12:59.322:MUP3:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):getRange(0,7), cache check: 0,40 firstMissingRow: 0 lastMissingRow: 40
                          16:12:59.322:MUP3:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):getRange: guessing forward scrolling
                          16:12:59.323:MUP3:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):getRange(0, 7) will fetch from 0 to 75
                          16:12:59.323:MUP3:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):fetching rows 0,75 from server
                          16:12:59.418:MUP3:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):getRange(0, 26) satisfied from cache
                          16:12:59.848:XRP2:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):Received 3 records from server
                          16:12:59.849:XRP2:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):full length set to: 3
                          16:12:59.849:XRP2:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):integrating 3 rows into cache at position 0
                          16:12:59.849:XRP2:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):cached 3 rows, from 0 to 3 (3 total rows, 3 cached)
                          16:12:59.849:XRP2:INFO:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):Cache for entire DataSource complete
                          16:12:59.977:RDQ5:DEBUG:ResultSet:isc_ResultSet_8 (created by: isc_ListGrid_0):getRange(0, 2) satisfied from cache
                          16:13:02.857:MDN8[E]:INFO:ResultSet:isc_RelatedList_2_0:Creating new isc.ResultSet for operation 'employee_DataSource_fetch' with filterValues: {
                          }
                          16:13:02.858:MDN8[E]:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):setCriteria: filter criteria changed, invalidating cache
                          16:13:02.859:MDN8[E]:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):Invalidating cache
                          16:13:02.865:MDN8[E]:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):getRange(0,7), cache check: 0,40 firstMissingRow: 0 lastMissingRow: 40
                          16:13:02.865:MDN8[E]:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):getRange: guessing forward scrolling
                          16:13:02.865:MDN8[E]:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):getRange(0, 7) will fetch from 0 to 75
                          16:13:02.865:MDN8[E]:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):fetching rows 0,75 from server
                          16:13:03.021:MDN8[E]:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):getRange(0, 26) satisfied from cache
                          16:13:03.551:XRP2:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):Received 3 records from server
                          16:13:03.551:XRP2:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):full length set to: 3
                          16:13:03.551:XRP2:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):integrating 3 rows into cache at position 0
                          16:13:03.551:XRP2:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):cached 3 rows, from 0 to 3 (3 total rows, 3 cached)
                          16:13:03.552:XRP2:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):Cache for entire DataSource complete
                          16:13:03.552:XRP2:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):$391: sorting on properties [order] : directions [true] : full cache allows local sort
                          16:13:03.555:XRP2:INFO:ResultSet:isc_ResultSet_10 (created by: undefined):creating auto-operation for operationType: fetch
                          16:13:03.556:XRP2:INFO:ResultSet:isc_ResultSet_10 (created by: undefined):setCriteria: filter criteria changed, invalidating cache
                          16:13:03.556:XRP2:INFO:ResultSet:isc_ResultSet_10 (created by: undefined):Invalidating cache
                          16:13:03.557:XRP2:DEBUG:ResultSet:isc_ResultSet_10 (created by: undefined):integrating 3 rows into cache at position 0
                          16:13:03.557:XRP2:DEBUG:ResultSet:isc_ResultSet_10 (created by: undefined):full length set to: 3
                          16:13:03.617:RDQ6:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):getRange(0, 2) satisfied from cache
                          16:13:06.900:MUP7:WARN:deprecated:isc_globalWarn:Window.setButtons() method called. This has been deprecated in favor of Window.setToolbarButtons()
                          16:13:11.203:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.205:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.207:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.209:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.210:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.212:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.213:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.215:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.220:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.224:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.227:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.229:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.232:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.235:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:11.238:DEBUG:ResultSet:isc_ResultSet_6 (created by: isc_PrimaryGrid_10_0):getRange(0, 3) satisfied from cache
                          16:13:12.310:XRP3:DEBUG:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):dataSource data changed firing
                          16:13:12.310:XRP3:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):updating cache in place after operationType: undefined, allMatchingRowsCached true
                          16:13:12.311:XRP3:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):Updating cache: operationType 'undefined' (no componentID) ,1 rows update data:
                          [
                          {
                          emailAddress: null,
                          employeeId: 4592,
                          firstName: "Joe",
                          id: 4592,
                          lastName: "Mo5",
                          name: "Joe Mo5",
                          order: 2,
                          skills: Array[1]}
                          ]
                          16:13:12.311:XRP3:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):$391: sorting on properties [order] : directions [true] : full cache allows local sort

                          Comment


                            #14
                            These are the settings on the related listgrid

                            Code:
                            		listGrid.setShowRollOverCanvas(true);
                            		listGrid.setDataSource(DataSources.employees);
                            		listGrid.setCanEdit(true);
                            		listGrid.setAutoFetchData(true);
                            		listGrid.setHeight100();
                            		listGrid.setFields(getFields());
                            		SortSpecifier[] sortSpecifiers = { new SortSpecifier(Employee.ORDER,
                            				SortDirection.ASCENDING) };
                            		listGrid.setSort(sortSpecifiers);

                            Comment


                              #15
                              If the "RelatedList" component is the one you're hoping to update, note the undefined operationType in the logs

                              16:13:12.310:XRP3:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):updating cache in place after operationType: undefined, allMatchingRowsCached true
                              16:13:12.311:XRP3:INFO:ResultSet:isc_ResultSet_9 (created by: isc_RelatedList_2_0):Updating cache: operationType 'undefined' (no componentID) ,1 rows update data:
                              [
                              Did you possibly omit this in your server-side code?

                              Comment

                              Working...
                              X