The way I have done this is by writing an object that sets up itself as the 
delegate of the adaptor context and the editing context. 

The object implements adaptorContextShouldCommit(adaptorContext) and returns a 
flag shouldCommit which is initially false. 

This keeps the transaction open while you call your stored procedures or 
execute bulk updates or whatever. Then the object implements 
editingContextWillSaveChanges(editingContext) and simply sets the shouldCommit 
flag to true.  In other her words, calling saveChanges on the editing context 
will call that delegate which will set the flag and then when the 
adaptorContextShouldCommit(adaptorContext) delegate method gets called again, 
this time it will return true because the flag has been set and the transaction 
will commit. 

The flow is like the this:

1. Create delegate object and set it up as the delegate of your editing context 
and adaptor context.  EOUtilities has databaseContextForModelNamed() that may 
come in handy. 

2. Create and update your EOs. Don't save changes yet. 

3. Call your stored procedures or execute special sql or bulk update, etc. the 
transaction will not commit and will remain open. 

4. Update and create more EOs if you want. 

5. Call saveChanges() in your editing context. This time the transaction will 
commit. 

That is what I have done and it works. 



> On Oct 28, 2015, at 9:12 AM, Birthe Berland <[email protected]> wrote:
> 
> I need to be able to do several things in the same transaction. 
> 
> Specifically I have inserted some new objects in the editing context and I 
> need to save them and make at number og stored procedure calls in the same 
> transaction. I have tried to insert  beginTransaction and commitTransaction 
> around it all, but Webobjects sends a commit between each.
> 
> Is there any way I can do this?
> 
> ed venlig hilsen
> 
> Birthe Berland
> Complimenta
> Tel.: 8830 7600
> 
> 
> 
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      ([email protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/rparada%40mac.com
> 
> This email sent to [email protected]
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to