Insert Unique and Tamino Resource Adapter

:confused:

Hello

I’m newbie in Tamino and newbie in english, sorry about mistakes :slight_smile:

I’v developed persistence layer using Tamino API 4 Java.
It’s something like “automatic persistence”. It works very well.
So well, that I want to move this to EJB enviroment. I want to use Tamino Resource Adapter, JCA implementation. But I have some problems with this.

As everyone can read in Tamino documentation or in this forum Tamino doesn’t support contraint checking between documents. In current version of my persistence layer I’m using method showed in documentation (Taminio API 4 Java | All that Jazz | Testing for Unique Keys) for checking uniqueness of attributes of xml documents. It works, but I found some problems when I’v tried to do the same using Resource Adapter in EJB enviroment.

Documentation says “transaction first, connection second” in EJB env.
In other place documentation says, that changing isolation level inside pending transaction is impossible. How then implement “Insert Unique” example in EJB? To do this I need two connections with different isolation levels! Even if I change isolation level for some connection this connection will be returned to pool later. There can be many connections with different isolation levels in pool! How to obtain two connections with two diferent isolation levels using Resource Adapter?

Second problem is: how to rollback transaction ( ie. when constraint is violated ), or mark transaction to be “rollback only” without having access to the SessionContext of EJB? Is it possible to rollback EJB transaction from Resource Adapter (TaminoDataSource?) level? Passing SessionContext from EJB to the persistence layer is possible of course, but it vilolates OOP rules I think. I dont’t want my persistent layer to “see” EJB API. I want to use the same API in non-manged eviroments (for example).

It wouldn’t be a problem If I don’t need to implement checkig unique keys in my persistence layer…

By the way… do you plan to implement sth. like “JDO for Tamino”? I think it’s good idea. I think that XMLDB is better for storing objects then any RDBMS.

Thanks,
Stahoo

? inside pending transaction is impossible.
This is when you have already send a command to Tamino. In other words you can change the isolation level but you have to do this before any other call to Tamino.
This is because a Transaction in Tamino starts with the first operation and ends with commit or rollback.

> ? two connections with different isolation levels
I assume you are in a LocalTransaction scenario. In this scenario only one physical connection can be used to the same Resource Manager. It means you?ll always get a handler to the same physical connection. In the LocalTransaction scenario the container should not support two different connections. This is an XA scenarion. To work with a connection in different isolation levels inside one business method you have deal like this:

A business method:
- // first operation
- Start a user transaction
- lookup
- getConnection
- change isolation level
- do the operation
- close the connection
- commit transaction
- // second operation
- Start a user transaction
- GetConnection
- Change isolation level
- do the operation
- close connection
- commit transaction


> ? different isolation levels in pool.
The isolation level and the lockwait mode is set to default when a connection is taken from the pool.

> rollback transaction
An instance which starts a transaction should also ends it. For example a in a session bean:
- start user transaction
- let the persistence layer do the work
- commit or rollback transaction

> Is it possible to rollback EJB transaction from Resource Adapter
No. The transaction context of a Resource Adapter is hidden to the user. It?s visible only to the container. The user can start and end user transaction which then starts and ends the transaction in the Resource Manager. Use rollback() method of the javax.transaction.UserTransaction interface.

> Passing SessionContext ? and non-manged eviroment
Check your architecture. Separate the transactional context.
In the EJB environment you have to remember passivation and activation.


> rollback only
An enterprise bean with bean-managed transaction demarcation must not use the getRollback-Only()
and setRollbackOnly() methods of the EJBContext interface.

> JDO for Tamino
No. I have no better information.

Cheers
Josef Haiduk

Hello

Thanks for Your reply. I’m student and I’v learned a lot about transactions and Tamino Resource Adapter from this reply.

But some of my problems haven’t been solved yet.

The “Insert Unique” example shows something like “nested transaction” rather then “XA transaction” I think?

The scenario is somthenig like this:

| #1 begin transaction
|
| #2 insert document, isolation level “shared”
|
| | #3 query for unique keys, isolation level “unprotected”
| | (auto-commit mode)
| | return count of matching documents
|
| #4 if count == 1 commit else rollback transaction

Is it possible to implement this in EJB env. using Resource Adapter?

In step #3 using the same isolation level as in #1 (“shared”) wolud couse that documents inserted by another uncommited process wouldn’t be “seen” in “count” query. Am I right?

I think about something like this:

Deploy transactional resource adapter and no tx adapter under different JNDI names. Use connection from Tx adapter to insert and connection from noTx adapter to count documents.

Would it be transactional safe way to check uniqunes??
Or can anybody suggest simpler method?

Thanks,
Stahoo

Yes. It’s possible inside of a local transaction scope (Local Tx Connector) to use NoTx connector. Now you have to study the Tamino isolation level and lock modes to prevent deadlocks.
Take a look in “Isolation Levels, Locking and Concurrent Database Access” in Tamino XML Server Documentation.

Josef Haiduk

Thanks for your help.

Stahoo.