What`s the best way to simulate Oracle Autonomous Transactions on SQLA?
I`m think publishing an webservice on database and create a stored funcion/procedure to consume it.
That`s the better option?
| SQLA is STILL in BETA |
|
1
|
What`s the best way to simulate Oracle Autonomous Transactions on SQLA? I`m think publishing an webservice on database and create a stored funcion/procedure to consume it. That`s the better option? |
|||
|
|
|
|
There is no direct way of doing an autonomous transaction in SQLAnywhere. You can get close to the same thing by triggering an event that will then perform the transaction. Example:
Then you can add an error message to the log at any time by using:
Some things to note - the size of the parameters passed to the trigger is limited by the database page size. If you need to pass larger pieces of information, then it would be best to create a global temporary table non transactional shared by all and insert the data into this table and pass an "id" of the newly inserted row to the event - the event can then pull the data out of the temp table and do what it needs with it. Your second requirement - waiting for the transaction to complete before proceeding is a bit more difficult. One method, but not really a decent one (for several reasons), would be to poll the above mentioned global temp table to wait for the row to be deleted and have the event delete the row once it has processed it. A perhaps better method would be to use |
||||
|
|
|
In this case I think that my solution (publish and consume webservices in database) is the best option. |
||
|
|
|
|
If your autonomous transaction is independent from the calling transaction, a manually triggered event would suffice. |
||
|
|
|
To expand on what Mark said... when an event is executed (triggered), it gets a separate connection, which is why it can commit separately. It also means the event runs asynchronously, unlike a procedure call which runs synchronously. In other words, events run in "fire and forget" mode. Like Stan Lee said, with great power there must also come — great responsibility! Events are wonderful things. Manually-executed events (as opposed to regularly scheduled ones) are even more wonderful. The great power is "commits separately". The great responsibility is solving the "bit more difficult" problem of which Mark speaks. I can personally testify that the effort is worth it... I have developed a commercial multi-threaded application which runs entirely inside SQL Anywhere, based on both scheduled and manually-executed events: the Foxhound database monitor. (that's not intended as a pitch for Foxhound, but for SQL Anywhere, without which I would have been floundering in C ten years from now) |
||
|
|
|
|
You simply nest BEGIN TRANSACTION calls to get the same effect as Oracle's autonomous transactions. The transactions can even be named and independently savepointed, rollbacked or committed. As for web services, creating stored procedures to respond to the web requests is the typical configuration. |
||||||
|