Menu

Transactions

2004-01-13
2004-06-09
  • Elliot Gage

    Elliot Gage - 2004-01-13

    Are there any plans to support manual transactions?
    I know that we can take advantage of the automatic transactions by defining classes and related classes within the config xml.

    There are times when it would be nice to be able to easily:

    PersistenceBroker.BeginTransaction
    object.Save
    object2.Save
    object3.Delete...
    PersistenceBroker.Commit

    Respecting that all the objects persist to the same database, if the above was called by yet another BeginTransaction block , and the outer block failed, then roll back all inner transactions.

    Could anyone else use this?

     
    • Richard Banks

      Richard Banks - 2004-01-13

      Hi Elliot,

      Manual transactions are already supported.  The following provides an example:

      Dim conn as _CConnection
      conn = classmap.RelationalDatabase.getConnection(nothing)
      conn.startTransaction()
      try
        .....  'save objects, etc
        conn.commit()
        conn.CloseConnection()
      catch
        conn.rollback()
        conn.CloseConnection()
      end try

      Hope this helps,
      Richard.

       
    • Richard Banks

      Richard Banks - 2004-01-20

      I've added code to the persistence broker to manually control transactions.  It's as we discussed in that all connections have transactions actioned at the same time, regardless of wether the transaction is required or not.

       
    • Elliot Gage

      Elliot Gage - 2004-01-20

      Great! I'll check it out.

       
    • Nobody/Anonymous

      Are you confirm the following statement is still valid since AtomsFramework version 0.1.5

      PersistenceBroker.BeginTransaction
      object.Save
      object2.Save
      object3.Delete...
      PersistenceBroker.Commit

      i try to use transaction with onetomany associated.
      Example Invoice has invoiceitem.
      when i save invoice. It automatic save Invoiceitem and Invoiceitem automatic adjust stockbalance.
      Or Whern I edit invoiceitem and save its. it will automatic adjust stockbalance.

      what should i do?
      I need really Help.

       
      • Nobody/Anonymous

        The manual starting and committing of transactions is still valid and works as you have written.

        For the invoice, as long as the associations are marked as SaveAutomatic="True" the invoice and it's lines will be saved in a single automatic transaction.

        Adjusting the stock balance would be something you would have to do manually.  I would suggest that your code look like the following

        Broker.BeginTransaction
        Invoice.Save
        AdjustStock()
        Broker.Commit

         
    • Nobody/Anonymous

      for me it would be very cool if the transactions could be passed into the persistent methods (save, delete, etc) so you could localise which db operations you wanted in the transaction.

      or some way to have multiple persist brokers and assign them to cpersist objects

       
      • Nobody/Anonymous

        This is unlikely to happen as it goes against the philosophy of the Framework (to minimise thinking about the database)

        Can you give me some examples of where you might want to do this?  Maybe there is a different way to accomplish what you need to do.

         
    • Nobody/Anonymous

      Thank you For Reply.

      Refer to your statements
      ........
      Broker.BeginTransaction
      Invoice.Save
      AdjustStock()
      Broker.Commit
      ........
      I marked SaveAutomatic="True" for associate OneToMany

      After Save Invoice and Automatic Save all InvoiceItems

      I think that Problem is "AdjustStock" Procedure For All InvoiceItems.

      For InvoiceItems(0) Refer To Product "A"
      For InvoiceItems(1) Refer To Product "B"
      For InvoiceItems(2) Refer To Product "A"

      When It Retrieves StockBalance Record For InvoiceItems(2) It can not get StockBalance Record For Product "A"

      I think Product "A" Is Locked For InvoiceItems(0) At Connect(1) When I Retrieve Product "A" Again For InvoiceItems(2) It May be Connect With Other Connect Not Connect(1)

      It Just I think.
      It May be wrong.

       
      • Richard Banks

        Richard Banks - 2004-06-09

        I doubt there is a locking issue as there is only one connection ever in use (the connection is reused if it is already open) and there is only ever one transaction open.  If a second transaction is started the first transaction is reused - no nested transactions.

        Without seeing your code and debug output I can't be sure exactly what is happening but my guess is that you have a bug in the code.  If you create a support item and post your code and debug output I'd be happy to look at it for you.

        - Richard

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.