Bug 168944 - [DataBinding] Need API to get the object wrapped by an IObservable
Summary: [DataBinding] Need API to get the object wrapped by an IObservable
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.3 M6   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on: 171616
Blocks: 171906
  Show dependency tree
 
Reported: 2006-12-22 12:15 EST by Dave Orme CLA
Modified: 2007-03-23 08:41 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Orme CLA 2006-12-22 12:15:59 EST
When editing objects that are managed by a persistence tier like Hibernate, one needs to tell Hibernate when to save changes to objects.

The usual way to do this is to add a binding event listener that tells the persistence layer to write changes immediately after successful completion of a BindingEvent.EVENT_COPY_TO_MODEL.

This works well for small object graphs because you can just tell Hibernate to save the whole object graph, and let Hibernate work out what actually needs to be saved.

This doesn't work well for large object graphs because the amount of time Hibernate needs to compute what needs saved and to perform the actual save can rise into a very noticable amount of time--seconds--if you ask Hibernate to save the whole object graph at once.

What is needed is a way for the BindingEventListener to determine the actual object that just changed, and to ask Hibernate to save just the relevant portion of the object graph.  We currently cannot do this, because BindingEvent.target and BindingEvent.model are just IObservables and IObservableValue.getValue() returns the value of the property that changed, not the object itself.

Therefore, what is needed is API on IObservable to return the object that it is wrapping--say, IObservable.getWrappedObject() or IObservable.getBackingObject().

We have implemented this in the older version of data binding that we are still using until after our big release.  The only tricky thing we ran into was how to implement this for nested observables.  In that case, the solution was to return currentOuterValue (which could be null) as the wrapped object.


Marking major since this is pretty fundamental and probably needs to make it in before M5.
Comment 1 Boris Bokowski CLA 2006-12-22 13:15:10 EST
+1 for this but as an optional mix-in interface which is implemented by at least the Java bean observables (returning the bean), the SWT observables (returning the control), but not by e.g. WritableList and the like.
Comment 2 Dave Orme CLA 2006-12-22 15:22:21 EST
(In reply to comment #1)
> +1 for this but as an optional mix-in interface which is implemented by at
> least the Java bean observables (returning the bean), the SWT observables
> (returning the control), but not by e.g. WritableList and the like.

Why not Writable*?

WritableList: return this;
WritableSet: return this;
WritableValue: return getValue();

Am I missing something?
Comment 3 Boris Bokowski CLA 2006-12-22 15:32:33 EST
Not all observables wrap something else.
Comment 4 Dave Orme CLA 2006-12-22 15:45:37 EST
(In reply to comment #3)
> Not all observables wrap something else.
> 

Maybe the API should be called 

public Object getObservedObject();

?

That way, Writable* objects could feel free to `return this` and Observables that are abstractions for something else could return the thing they are abstracting.
Comment 5 Brad Reynolds CLA 2006-12-23 11:23:35 EST
Another observable that would have an issue with the generic approach is ComputedValue. 
 
I agree with Boris that it might be best to keep this specific to beans.  You could then return the observed object and also the property being observed for optimzation/debugging purposes.
Comment 6 Dave Orme CLA 2006-12-23 11:27:49 EST
(In reply to comment #5)
> Another observable that would have an issue with the generic approach is
> ComputedValue. 
Wait!  (Please re-read comment #4) If the API is:

getObservedValue()

then ComputedValue can

return this;


Then there are no issues.

:)
Comment 7 Brad Reynolds CLA 2006-12-23 11:31:23 EST
What I meant was that it wouldn't make sense for that type of observable.  It could be done, yes, but I'm not seeing the point for it in all observables.  It seems like returning 'this' would be just to pacify the API rather than returning an appropriate value, at least for ComputedValue.
Comment 8 Dave Orme CLA 2006-12-23 11:42:03 EST
Hmmm; not sure why this is "pacifying the API"

Logically, an Observable will have something that is being observed; after all, that's the whole point of being Observable.

Within this context, there are two choices: either the Observable is wrapping something, or the Observable itself supplies the abstraction that is being observed.  So, it makes perfect sense to me to have API on all Observables to:

public Object getObservedValue();

In the former case, the wrapped value will be returned; in the latter, 'this' will be returned.

Am I missing something?
Comment 9 Brad Reynolds CLA 2006-12-23 11:57:55 EST
But what is the point of returning 'this'?  That's what I'm not getting and my comment that it was just pacifying the API.  My viewpoint is that it doesn't make sense for the abstractions to have the API.  Plus what if we wanted ComputedValue to one day return the observables that it is wrapping?  I would think that would be more correct than returning 'this'.

I'm just having an issue seeing why the API needs to be on all observables.  Plus I would think that it would be simpler for there to be API on each type of observables (beans, widgets, etc.) that can be tailored to that type of object.  Then for beans you could return the property as well.  And for the abstractions that don't necessarily observe a specific object we wouldn't provide the API.  

So actually I'm missing something. :)
Comment 10 Brad Reynolds CLA 2007-02-25 00:09:18 EST
Dave, is it OK to close this?  We introduced IBeanObservable in 3.3M5 in bug 171616.
Comment 11 Boris Bokowski CLA 2007-03-01 21:58:37 EST
public interface IObserving {

	/**
	 * Returns the observed object, or <code>null</code> if this observing
	 * object does not currently observe an object.
	 * 
	 * @return the observed object, or <code>null</code>
	 */
	public Object getObserved();

}
Comment 12 Boris Bokowski CLA 2007-03-13 00:23:52 EDT
Released (as part of the fix for bug 175840) >20070312.
Comment 13 Paul Webster CLA 2007-03-23 08:41:14 EDT
in I20070322-1800
PW