DataPortal.ReFetch?

DataPortal.ReFetch?

Old forum URL: forums.lhotka.net/forums/t/608.aspx


Kirk posted on Wednesday, July 12, 2006

I have certain objects in my system that are time-sensitive - in other words, they are retrieved by a combination of primary key + date (for example, a stock "price" object).

One thing I am struggling with is the desired behavior to allow a user to change the effective date in a user interface, and have all the time-sensitive objects in the form re-fetch themselves accordingly.

I would prefer to not get a new object reference, since the databinding implications would require the UI to be a lot smarter than it should be.

The proper solution – I think – is to implement a data portal “re-fetch” method.  This would allow me to re-populate the internal members without returning a new instance of the object.

 

An alternative would be to implement a static (not factory) method that takes the object reference and the criteria, invokes the fetch, and in some fashion copies the values from the new object to the “old” object… not sure which is preferable to everyone else but this seems like more of a hack to me.

 

Has anyone else run into this type of issue?

 

SonOfPirate replied on Friday, July 14, 2006

We have the same mechanism built-into our framework to support "real-time" information that needs periodic refreshing.  Without getting too much into the inner workings, the basic problem you have with the CSLA implementation when doing this is, as you eluded, the fact that the data portal returns a new instance of the object each time and the goal is to maintain the current object with the updated information.  Check out this post:

http://forums.lhotka.net/forums/thread/2690.aspx

There's been quite a discussion on this concept.  Once you sort out how to perform the update on the client with the information returned from the data portal, implementing the refresh process is much easier.

In our case, we have a Refresh() method on our objects (instance scope, not static), that will call our data portal Fetch method just as we do when first instantiating the object.  The difference is that we don't pass the returned object back to the caller, instead we pass this object to our MergeWith() method which performs the update to the existing instance.

With this in place, we can tailor our application to make use of this Refresh method either through manual means, such as a toolbar button, or automatically via the event handler for a timer.

Hope that helps.

 

Copyright (c) Marimer LLC