This is a migrated thread and some comments may be shown as answers.

Implementing a RollBack in the Disconnected API

2 Answers 84 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
James Denning
Top achievements
Rank 1
James Denning asked on 02 Sep 2009, 10:04 AM
Hi
I see that the ObjectContainer Transaction Rollback method throws a not implemented exception. So what I want to do is reset the ObjectContainer content back to before the ObejctContainer Transaction was opened by getting the CHangeSet discarded and repopulaitng the ObjectContainer with the original data entity that was updated - however preferably I do NOT want to discard the entire ObjectContainer as I would need to repopulate it with a lot of reference data (I suppose I could maintain a reference data Container and transfer its content to a new ObjectContainer to be used for updates BUT keeping it synchronised would be complex).

So my question is can I commit the transaction, then extract and discard the ChangeSet and then refresh the objects I changed with the original versions by applying a new ChangeSet from the server? Would there be any issues regarding the object state - will there be a problem replacing a dirty object?

Also I am unclear what ObjectContainer.Transaction.Flush() does - can it be clarified what it does when called if you have a Container with an open transaction and changes made.

Are there plans to implement RollBack() for the disconnected API?

Thanks
James

2 Answers, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 04 Sep 2009, 07:46 AM
Hi James Denning,

The optimal workaround at the moment is the following:
  • Before starting a transaction that may end up with a rollback, extract a ChangeSet from the container; We will use this change set as a "restore point";
  • Start a transaction;
  • Modify some objects in the container; 
  • To rollback the changes, create new container;
  • Apply the previously extracted change set to the new container;
The code would look like this:
ObjectContainer.ChangeSet set = container.GetContent(); 
 
container.Transaction.Begin(); 
// do some changes 
 
if(commit) 
    container.Transaction.Commit(); 
else 
    container = new ObjectContainer(); 
    container.Apply(set); 

Providing Rollback functionality for ObjectContainer is on our list but at this point we cannot give an exact time-frame for implementing it.

The Flush() method is used to commit the dirty and new objects to the database and evict the cache content during transaction. However, it does not make much sense to use this method with object containers as nothing is physically committed to the database.
Hope that helps.

Best wishes,
Alexander
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
James Denning
Top achievements
Rank 1
answered on 07 Sep 2009, 01:11 PM
Thanks for the reply - I hadn't thought of extracting a changeset at the point of commit.

James
Tags
Development (API, general questions)
Asked by
James Denning
Top achievements
Rank 1
Answers by
Alexander
Telerik team
James Denning
Top achievements
Rank 1
Share this question
or