Payara icon indicating copy to clipboard operation
Payara copied to clipboard

Bug Report: JDBC javax.sql.XADatasource type pool doesn't return XADatasource instance

Open sabrieker opened this issue 2 years ago • 1 comments

Brief Summary

We configure the jdbc connection pool to be an javax.sql.XADataSource but when we query the data source in code to determine if it is an javax.sql.XADataSource then we have the following code,

ds.unwrap(javax.sql.XADataSource)

and this throws an exception because the DataSource we receive does not implement javax.sql.XADataSource.

Configurations used to define the connection pool.

create-jdbc-connection-pool --datasourceclassname=com.ibm.db2.jcc.DB2XADataSource --restype=javax.sql.XADataSource --property user=\${ENV\=DB2USER}:password=\${ENV\=DB2PASS}:databaseName=\${ENV\=DB2NAME}:portNumber=\${ENV\=DB2PORT}:driverType=4:serverName=\${ENV\=DB2HOST}:sslConnection=true:dateFormat=3:timeFormat=3:minPoolSize=4:maxPoolSize=10:allowLocalTransactions=false:enableJdbc4ConnectionTest=true:isolationLevel=READ_COMMITTED xaDataSourcePool
create-jdbc-resource --connectionpoolid xaDataSourcePool jdbc/XA

We see javax.sql.XADatasource type at the admin console too.

When we check the datasource it is an instance of com.sun.gjc.spi.jdbc40.DataSource40 class.

Expected Outcome

We expect a datasource instance which implements javax.sql.XADataSource otherwise we can not decide if if is a XA or not.

Current Outcome

We got an instance of com.sun.gjc.spi.jdbc40.DataSource40 class and it is implementing javax.sql.Datasource not javax.sql.XADatasource.

Reproducer

Declare a datasource and retrieve it with following case, you can see the SQLException.

try {
InitialContext  namingContext=new InitialContext()
			        ds=(DataSource)(namingContext.lookup(datasource));
			    } catch (Exception e) {
                    
	            
				final java.sql.Connection con;
				boolean usingDataSource=false;
				boolean isXADataSource=false;
				
              	               con=ds.getConnection();
				try{
                                   ds.unwrap(javax.sql.XADataSource.class);
					        isXADataSource=true;
				}
				catch (SQLException sqle) {
						isXADataSource=false;
					}
				}

Operating System

macOS Monterey / Version 6.2023.6

JDK Version

openjdk/17.0.2

Payara Distribution

Payara Server Full Profile

sabrieker avatar Oct 13 '23 14:10 sabrieker

Greetings @sabrieker

I was able to reproduce the issue by casting directly to XADataSource:

XADataSource xaDS = (XADataSource) initialContext.lookup("JDBC_XA_Resource")

I have escalated this to the platform development team with internal JIRA FISH-7952. I will let you know once we are able to proceed with the development of the fix.

Regards, Artur

artur-mal avatar Oct 20 '23 13:10 artur-mal