Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing only the updates to objects

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am currently working on an application where in I have to communicate to web services. We have used xmlbeans to create the java wrapper classes for these webservices exposed functionality.
All scenarios pertain to create and updates. Creates are fine where in I set all the values from our business objects to the xmlbeans representative objects of webservices and pass it on.
For updates I wanted to know if there are any good practices available which I can use. What I want to do is compare the fetched object with changes made by user at the front end. This determination can be carried by using equals method. We plan to override the equals method in our business objects.
Now the second part of passing only the changes. Now while calling the webservice I want to assemble the input objects only with changed attributes.
I am wondering how best can I handle this rather than using if-else constructs.

Do post your thoughts on the same


~Manish
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I reading you right ... you want an object with only the fields that changed populated? That would generate XML with only the tags that changed?

I can imagine using reflection or something in bean utils to call each public getter on two instances of the same class and call set on a third instance only if the results are not the same.

As a non-standard alternative, you might make all the setters track "dirty bits" to indicate which fields have changed. I'm working with a framework now that does that. I think they load an object, clear all the dirty bits, then apply changes from the user which sets new dirty bits.

Every once in a great while I miss PowerBuilder. This stuff was all built in. Sigh.
 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan James,

Thanks for your response.

----------------------
Am I reading you right ... you want an object with only the fields that changed populated? That would generate XML with only the tags that changed?
----------------------
Yes this is exactly what I want to achieve.

----------------
As a non-standard alternative, you might make all the setters track "dirty bits" to indicate which fields have changed. I'm working with a framework now that does that. I think they load an object, clear all the dirty bits, then apply changes from the user which sets new dirty bits.
----------------
Can you elaborate a bit more on "all setters track dirty bits". I did not get this from an implementation perspective. This alternative sounds apt for the scenario I am working on.


Thanks & Regards,
Manish
 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stan,

Could you provide a few hints on the same.

Thanks in advance.

Manish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic