Expand my Community achievements bar.

DataService gives events for each item in collection when only committing one

Avatar

Former Community Member
I have a DataService that uses the Assembler interface approach (I subclassed AbstractAssembler). When I update one item in the managed Collection and commit it (autoCommit is false) I'm getting a PropertyChangeEvent of kind UPDATE for each item in the Collection from the DataService. In addition I get a CollectionEvent of kind REMOVE for each item in the Collection, then a CollectionEvent of kind ADD for each item in the Collection from the Collection itself.



I'm assuming this is because the fill() is being called after the update is completed. How do I commit/update the individual item so that I only get an event (or set of events) for the item that was modified? Is that possible when using a managed Collection or do I need to operate at the individual item level. Am I doing something wrong (or not doing something at all) in the Assembler?



I'm very experienced with Remoting and Messaging but this is my first time dealing with DataServices. Any help, samples,etc. are greatly appreciated. Thanks.



Here's the Assembler code...



public class MyAssembler extends AbstractAssembler {



private MyService svc = MyService.getInstance();



public Collection fill(List fillParameters) {



if (fillParameters.size() >= 2) {



int fillType = FlexDataHelper.getIntPrimitive( fillParameters.get(0) );



Long companyId = FlexDataHelper.getLong( fillParameters.get(1) );



switch(fillType) {



case QueryType.ALL_WIDGETS_FOR_COMPANY:



return svc.getAllWidgets(companyId);



case QueryType.ACTIVE_WIDGETS_FOR_COMPANY_:



return svc.getActiveWidgets(companyId);



case QueryType.WIDGETS_BY_COMPANY_AND_CATEGORY:



if (fillParameters.size() == 3) {



Integer categoryId = FlexDataHelper.getInteger( fillParameters.get(2) );



return svc.getWidgets(companyId, categoryId);



}



}



}



// Throws a nice error



return super.fill(fillParameters);



}



public Object getItem(Map uid) {



return svc.getWidget( FlexDataHelper.getLong(uid.get("companyId")), FlexDataHelper.getInteger(uid.get("widgetId")) );



}



public void createItem(Object newVersion) {



svc.saveWidget((WidgetValue)newVersion);



}



public void updateItem(Object newVersion, Object prevVersion, List changes) {



try {



svc.saveWidget((WidgetValue)newVersion);



} catch (Exception e) {



Long companyId = ((WidgetValue)prevVersion).getCompanyId();



Integer widgetId = ((WidgetValue)prevVersion).getWidgetId();



System.



err.println("*** Throwing DataSyncException when trying to save widget = " + widgetId);



throw new DataSyncException(svc.getWidget(companyId, widgetId), null);



}



}



public void deleteItem(Object prevVersion) {



try {



svc.deleteWidget( (WidgetValue)prevVersion );



} catch (Exception e) {



Long companyId = ((WidgetValue)prevVersion).getCompanyId();



Integer widgetId = ((WidgetValue)prevVersion).getWidgetId();



System.



err.println("*** Throwing DataSyncException when trying to delete widget = " + widgetId);



throw new DataSyncException(svc.getWidget(companyId, widgetId), null);



}



}







Here's the Flex UI code...



public function getWidgetsForCompany( company:CompanyValue ):void {



var widgets:ArrayCollection = new ArrayCollection();



var call:AsyncToken = widgetService.fill(widgets, QueryType.ALL_WIDGETS_FOR_COMPANY, company.companyId);



// Add a reference to the collection that will be filled for access by the responder



call.useLocalData = true;



call.localData = widgets;



call.addResponder( responder );



}



public function saveWidget( widget:WidgetValue ):void {



var call:AsyncToken;



if (isNaN(widget.widgetId)) {



call = widgetService.createItem(widget);



} else {



//Update



call = widgetService.commit(



new Array(widget), false);



}



call.addResponder( responder );



}
1 Reply

Avatar

Former Community Member
Hellow,

I found the same problem. Im using some dataservices, but when we update an item, it throws an event CHANGE_COLLECTION at each item on Collection. Is there any chance to disable the event from all items, and only throws the event on the modified item? Is there any other way to solve this problem? Thanks for all.