Propagation of Oracle Transactions Between C++ and Java
Asked Answered
O

3

14

We have an existing C++ application that we are going to gradually replace with a new Java-based system. Until we have completely reimplemented everything in Java we expect the C++ and Java to have to communicate with each other (RMI, SOAP, messaging, etc - we haven't decided).

Now my manager thinks we'll need the Java and C++ sides to participate in the same Oracle DB transaction. This is related to, but different from the usual distrbuted transaction problem of having a single process co-ordinate 2 transactional resources, such as a DB and a message queue.

I think propagating a transaction across processes is a terrible idea from a performance and stability point-of-view, but I am still going to be asked for a solution.

I am familiar with XA transactions and I've done some work with the JBoss Transaction Manager, but my googling hasn't turned up anything good on propagating an XA transaction between 2 processes.

We are using Spring on the Java side and their documentation explicitly states they do not provide any help with transaction propagation.

We are not planning on using a traditional Java EE server (for example: IBM Websphere), which may have support for propagation (not that I can find any definitive documentation).

Any help or pointers on solutions is greatly appreciated.

Ovate answered 4/9, 2008 at 15:21 Comment(4)
can you "embed" you application as JVM stored procedure? Then you can "simply" call fragment of your application from C++ through database connection.Pad
Theoretically you can also do the oposit. Mame a c-stored procedure, which will "connect" back to the database. Then this procedure will participate in the same transaction.Pad
you can also "name" distributed transaction. i.e. you assign it a cooked name. then another process, can "join" the same transaction. AFAIK DBMS_XA or DBMS_TRANSACTION can be used for this purpose.Pad
Can you provide a complete usecaseKnox
S
10

There is an example on Laurent Schneider's blog of using the DBMS_XA package inside Oracle to permit multiple sessions to work in the same transaction. So it would be possible to have Java and C++ sessions participating in the same transaction without needing any sort of additional coordinator.

Alternately, you might consider using Workspace Manager. That was originally designed to support extremely long-running transactions (i.e. manipulating lots of spatial data for a proposed development). Essentially, you can create a workspace, which in your case would be roughly equivalent to a named transaction. Both the Java and C++ code could enter that workspace (from separate sessions) and both could manipulate and commit data in that workspace. When the transaction was complete, you could then merge the workspace to the LIVE workspace, which is equivalent to doing a commit in a normal transaction.

On the other hand, I would strongly agree with your initial assessment that coordinating transactions between processes is very likely to be a bad idea from a performance, stability, simplicity, and maintenance standpoint. On the other hand, it may well be a legitimate business requirement depending on how the C++ code is going to be retired (i.e. whether it is possible to replace code in such a way that transactions can be either exclusively Java or exclusively C++)

Suntan answered 17/9, 2008 at 20:46 Comment(0)
K
4

I have been using Hazlecast Messaging and Distributed memory locks to solve some of these concerns, however using such a tool would require that you redisign your software in those parts where you touch the same data. C++ client docs here Java client here

Oracle also has a similar product called Oracle Coherence that may help you, see locking in the dev guide.

Also the database contains a MQ system called Oracle Streams Advanced queueing ( transactional persistent queues) that might help you in some situations. Oracle AQ integrates well with Oracle triggers.

Additionally there is the Database Change Notification that may help you update caches or notify processes of updates, this can be used together with the Optimistic Offline Lock pattern.

See also Software transactional memory

Apache Zookeeper can also help you with distributed locking.

Knox answered 7/4, 2015 at 8:46 Comment(2)
Thanks for the detailed answer describing several approaches which I'll have to check. I am going to award the bounty to you because it's the only new answer to this question. However, I'm still looking for further alternatives, especially lightweight solutions which do not need possibly expensive 3rd-party products (nor oracle enterprise edition).Canter
I dont think there is an easy way of doing this. Depending on what the system does and looks like there are options have a look at "Working with legacy code" programmers.stackexchange.com/a/122100Knox
H
0

I believe JBoss Transaction Manager supports 2pc tx propagation across web service calls. You could, I suppose integrate your systems that way, but the performance would stink.

Headon answered 23/9, 2008 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.