Sunny Gupta
Sunny Gupta

Reputation: 7067

How to Implement Transactions in a Non-Transactional Database

How to Implement Transactions in a Non-Transactional Database.

1) Please explain in How you can do this on java side.

Note: I will share the efforts I put in finding the answer.

Suppose you have two inserts and two updates in a single transaction. So you will have four threads executing each instruction, One thread will monitor them all. If there is any failure in one of the thread so the monitoring thread will cancel out everything.

Upvotes: 1

Views: 1547

Answers (1)

Mike
Mike

Reputation: 3311

Each thread that participates in the transaction is given a transaction id. You need to create a structure that they can write to that keeps track of the data (or keys) in order to back out changes.

Like a real database, when you do an update, the before changed data needs to be stored and the after changed data needs to be recorded as well. You need this, because you may need it to find the record.

Inserts are a little easier, just delete the record.

Deletes need to store the before deleted data as well.

So any structure you create, needs a transaction ID, a table name and say a list of column data (which can be a map of String, object to store the column name, column data).

That should be a pretty good start...

Upvotes: 3

Related Questions