• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with commit while deleting rows from table
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with commit while deleting rows from table


  • Subject: Re: Problem with commit while deleting rows from table
  • From: Art Isbell <email@hidden>
  • Date: Wed, 14 Jul 2004 10:45:01 -1000

On Jul 14, 2004, at 4:50 AM, LD wrote:

On 14/07/2004, at 8:19 PM, Tanmoy Roy wrote:

I have a requirement where for any user updation I need to first delete some specific rows and then insert the fresh rows in the database. EOModeler does a AutoCommit whenever we are deleting or updating something in the database.
But the scenario is if we have deleted some rows and during insertion some exception occurs then all our data will be lost. Is there a work around here ?

EOEditingContext will do the work for you in normal circumstances... saveChanges() or revert() as needed.

myJDBCContext.connection().getAutoCommit() should be false prior to transaction, at least.
myJDBCContext.connection().setAutoCommit(false) if not...

EOF is a layered architecture with JDBC at the bottom. If you do something in the JDBC layer while you are operating at a higher layer (e.g., EOEditingContext in EOControl), you need to understand how that might affect the higher layers. If you don't understand the ramifications, the higher layers may become out of sync with the changes made in the lower layer, so be careful.


As LD stated, transaction management should be handled correctly by EOEditingContext's saveChanges(). So if you deleteObject(), insertObject(), then saveChanges(), the delete and insert should occur within the same transaction such that an insertion failure will result in a rollback of the delete. You can verify this by turning on adaptor debugging to watch the generated SQL.

But if you want to change the transaction handling, EOF offers several approaches. If your database supports nested transactions, you can begin a transaction when you desire (EOAdaptorContext.beginTransaction()) and commit or rollback when you desire (EOAdaptorContext.commitTransaction(), EOAdaptorContext.rollbackTransaction()), meanwhile letting EOF manage its own transaction which would be nested inside yours.

EOAdaptorContext adaptorContext = EOUtilities.databaseContextForModelNamed(editingContext, eomodelName).adaptorContext();

Or you can take control of transaction management by setting an object to be your adaptor context's delegate. Then implement adaptorContextShouldBegin(), adaptorContextShouldCommit(), and adaptorContextShouldRollback() to return false. You will then have to begin, commit, and rollback explicitly in your code.

Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Problem with commit while deleting rows from table (From: "Tanmoy Roy" <email@hidden>)
 >Re: Problem with commit while deleting rows from table (From: LD <email@hidden>)

  • Prev by Date: Including the .js files
  • Next by Date: 'escapeHTML off' weirdness
  • Previous by thread: Re: Problem with commit while deleting rows from table
  • Next by thread: Re: mod_rewrite
  • Index(es):
    • Date
    • Thread