You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by gf...@fys.com.ar on 2004/06/04 14:23:26 UTC

Handling dirty objects in a CRUD web MVC app, OJB handles object store.

Hi folks,

When handling objects in a typical CRUD MVC type web app (let’s say Apache 
Struts based app), most of us have went through the update problem.
The fact that web apps are "disconnected" and following the MVC paradigm 
,means the data, while in the browser is just that presentation data, adds 
a dimension batch processing or monolithically built apps do not  present.

Let’s say object A has a collection of object B (compound assoc., for 
example an Order -A- and it’s detail Line -B-).

In moment m1, The user Creates the Order and stores it temporary in order 
to review it later.
In moment m2, the user retrieve the Order (object class A) using some 
criteria, then he does some modifications in a few detail lines (object 
class B), then  delete some detail lines, and add a bunch of new ones.

Then he submit the changed Object A.
The "action" in the server, will then materialize the object once again, 
and some coding will update the object with the data received from the 
browser.

Question is: which is the best way to handle the dirty Object (A) and its 
collections of somehow dirty objects B.
Is there any well know pattern to to this? What if someone has changed the 
object while the user was doing his changes in the web?
Here we’ve implemented different strategies, from deleting all existing 
childs and storing the new ones to sending hidden attributes with OIDs and 
dirty flags and writing some logic to handle the changes. But, I  fee we 
are not using some OJB capabilities that might do this for us.

Regards,
Gustavo.



RE: Handling dirty objects in a CRUD web MVC app, OJB handles object store.

Posted by Daniel Perry <d....@netcase.co.uk>.
There are endless ways of handling this "web transaction" problem. I dont know of any patterns that fit all problems.

OJB could handle the transation for you:
You start a tranaction.
Load some data. (and lock it)
Store transaction in session.
User edit's the data and submits it.
....
You commit the tranaction.

I'm not sure how well this can be done with OJB (never tried) but i have done similar things in a web app where i've used a field to lock data to one specific session.  This an ideal solution for stopping double logins, etc.

But it has drawbacks, as say the user leaves their browser open, without submitting the transaction.  The data remains locked until their session times out!

Another approach i've used (v. easy with OJB if you use a DAO pattern as you can implement it in the base DAO) is to use object timestamps.

When you insert or update an object, the timestamp gets updated.  You can check an object you have in memory to see if it's been changed in the database by it's timestamp (ie a method in BaseDAO that loads the object again (by pk id), and checks if the timestamps are different).

So,
You load objects, put them into ActionForm's (struts!), and go through the user edits.
The user submits the data to the action that saves them.
You start a transaction. You go through the updates, and as you do you check each ActionForm and compare the timestamp you saved with the one in the database.  If any fail you abort the tranaction and alert the user.

The drawback of this approach is that if anyone else does an update, the user has to start all over again.

Hope this has given you some insight into my experience.

Daniel.

> -----Original Message-----
> From: gfaerman@fys.com.ar [mailto:gfaerman@fys.com.ar]
> Sent: 04 June 2004 13:23
> To: OJB Users List
> Subject: Handling dirty objects in a CRUD web MVC app, OJB handles
> object store.
> 
> 
> Hi folks,
> 
> When handling objects in a typical CRUD MVC type web app (let’s 
> say Apache 
> Struts based app), most of us have went through the update problem.
> The fact that web apps are "disconnected" and following the MVC paradigm 
> ,means the data, while in the browser is just that presentation 
> data, adds 
> a dimension batch processing or monolithically built apps do not  present.
> 
> Let’s say object A has a collection of object B (compound assoc., for 
> example an Order -A- and it’s detail Line -B-).
> 
> In moment m1, The user Creates the Order and stores it temporary in order 
> to review it later.
> In moment m2, the user retrieve the Order (object class A) using some 
> criteria, then he does some modifications in a few detail lines (object 
> class B), then  delete some detail lines, and add a bunch of new ones.
> 
> Then he submit the changed Object A.
> The "action" in the server, will then materialize the object once again, 
> and some coding will update the object with the data received from the 
> browser.
> 
> Question is: which is the best way to handle the dirty Object (A) and its 
> collections of somehow dirty objects B.
> Is there any well know pattern to to this? What if someone has 
> changed the 
> object while the user was doing his changes in the web?
> Here we’ve implemented different strategies, from deleting all existing 
> childs and storing the new ones to sending hidden attributes with 
> OIDs and 
> dirty flags and writing some logic to handle the changes. But, I  fee we 
> are not using some OJB capabilities that might do this for us.
> 
> Regards,
> Gustavo.
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org