开发者

committing multiple connections during a transaction

开发者 https://www.devze.com 2023-01-09 08:54 出处:网络
can i create multiple connections during one transaction and perform commit on them provided the connection are taken from data source in webl开发者_C百科ogic. ??? please helpYou mean from different d

can i create multiple connections during one transaction and perform commit on them provided the connection are taken from data source in webl开发者_C百科ogic. ??? please help


You mean from different datasource?

Of course you can. That's what JTA are for.

Just make sure that involved datasources' driver are XA-awared.


Edited I got what you mean.

The application I developed has such feature. Assume you have some basic flow control or handler structure for your request processing routine, you can always start a new transaction just for the error handling part, commit that new tranasction, and rollback the original one.

With Spring + Declarative transaction control you need to have a transaction declared around the error handling routine, with a REQUIRES_NEW propagation policy


Based on the comment that you want, effectively, an autonomous transaction to log a failure, you can either use a second connection from your datasource and commit that while rolling back the original failed one (which doesn't require XA; the wording in your question suggests you want to commit both connections simultaneously); or if you can use an actual autonomous transaction to handle the logging inside your original connection before rolling back. This is probably simpler and cleaner, particularly if your failure is really coming from a package call anyway as it can be dealt with as the failure occurs rather than having the client worry about it. In outline:

PROCEDURE log_failure(...)
IS
    PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
    insert ...
    commit;
END log_failure;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号