Unit of work. What is the best approach to temporarily storing objects in a web farm?

I need to design and implement something similar to what Martin Fowler calls the Unit of Work pattern. I've heard others refer to it as a Trash template, but I'm not sure if everything is the same.

The particular issue is that users (and our UI team) want to be able to create and assign child objects (with referential integrity constraints in the database) before the parent object is created. Today I met with another designer of ours and we came up with two alternative approaches.

a) First create mock parent in the database and then create mock children and mock assignments. We could use negative keys (our usual keys are all positive) to distinguish between sheep and goats in the database. Then, when the user submits the entire transaction, we have to update the data and add and align the real keys.

I see several disadvantages to this.

  • This causes indignation of the indices.
  • We still need to come up with something to satisfy the unique constraints on the columns they have.
  • We have to modify a lot of existing SQL and code that generates SQL to add another predicate to many WHERE clauses.
  • Changing primary keys in Oracle can be done, but that's a call.

b) Create Transient tables for the objects and assignments that should be able to participate in these reverse transactions. When the user clicks Submit, we generate real records and clear the old ones.

I think this is cleaner than the first alternative, but still includes increased levels of database activity.

Both methods require me to have a way to expire temporary data if the session is lost before the user is able to submit or cancel requests.

Has anyone solved this problem differently?

Thanks in advance for your help.

+2


source to share


1 answer


I don't understand why these objects have to be created in the database before the transaction is committed, so you might want to refine your UI command before proceeding with the solution. You may find that all they want to do is read information previously stored by the user on another page.

So, assuming that objects shouldn't be stored in the database before commit, I give you plan C:



Save initialized business objects in session. Then you can create all the children you want and only touch the database (and set up the links) when the transaction needs to be done. If the session data is going to be large (individually or collectively), store the session information in the database (you may already have done this).

+1


source







All Articles