Transactions again

More trouble with transactions. Can someone explain how I can deal with this situation? This is all server-side by the way.

Say I have two totally separate TDAMemDataTable components. I make changes in each of these and then call ApplyUpdates on each one in turn.

This works fine of course but, say the second ApplyUpdates call throws an exception for some reason. In this case the updates aren’t applied because the transaction was rolled back, which is great.

The problem I’m having is that, in this case where the second ApplyUpdates call fails, I want the first one rolled back too. Basically it’s “all or nothing” - I want both sets of updates applied or none of them.

Now I just can’t make this work.

I understand fully what’s happening. Each ApplyUpdates call creates an instance of the relevant service which processes the update delta within the context of a transaction. What I need to do is get both of the calls to use the same transaction.

I’ve touched on this issue before and I understand that I need to use the OnUpdateDataXXXTransaction event handlers to disable the default transaction logic, but how do I then wrap the ApplyUpdates calls in a manually-created transaction of my own?

try to pass your tables to server in one call , like

RDA.ApplyUpdates([table1, table2]);

Unfortunately that won’t work if the tables aren’t using the same data adapter.

The server is broken down into separate services and data modules for each functional area, such as contacts or activities for example. Each has a service and an associated data module containing a data adapter and the tables. I then create instances of these data modules as required, either server or client-side.

This all works fine except that, quite often, I’ll want to make some changes in two different services/datamodules and then want to wrap both sets of updates in a single transaction as I don’t want one succeeding and the other failing.

I’ll only ever want to do this server-side, not from the client, so I have a bit more control over updates and transactions but I don’t know how I can achieve what I need. With two different data modules and data adapters and service instances, presumably I’d need to manually begin/commit the transaction at the connection level or something?

this isn’t easy task.
I’d say, it would be more simple to review your architecture and put these two tables into one service …

you need do these steps

  • create connection
  • start transaction
  • share it for service1 and service2
  • client should call table1.ApplyUpdates
  • handle state of update in service1
  • client should call table2.ApplyUpdates
  • handle state of update in service2
  • commit or rollback transaction.

I think, you can do this like:

  • create a new service, aka wrapper
  • client should pass all deltas to this wrapper
  • wrapper should create connection and transaction
  • wrapper creates 1st service, sets connection and calls UpdateData with 1st delta
  • wrapper creates 2nd service, sets connection and calls UpdateData with 2nd delta
  • commit or rollback transaction.
  • pass result to client

another way: create custom service methods like StartTransaction, Commit, Rollback and call them from client side. connection should be stored in user session.

Yeah I didn’t think it’d be easy. Sometimes the tables are in the same service in which case I’m ok but sometimes not.

I’ll have a play around with it.

Hi,

in fact, I faced the (almost the) same issue (see Transactions and ApplyUpdates with at least two tables): so even, if you have both TDAMemTables in one services, you still have to make some tweaks, in order to get this to work.