File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes passing only the updates to objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "passing only the updates to objects" Watch "passing only the updates to objects" New topic
Author

passing only the updates to objects

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
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

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
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

Joined: Oct 23, 2003
Posts: 312
Hi Stan,

Could you provide a few hints on the same.

Thanks in advance.

Manish
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing only the updates to objects
 
Similar Threads
consuming messages from JMS Queue without other group having to do anything
Use of value objects in your EJB apps
Converting a DTD to XSD
approach to detect change in objects
creating huge xml file using xmlbeans