Is it possible to use UCP to create an OracleConnection to use enqueue method?
Nowadays, which is the best way to enqueue a message into Oracle AQ queue from a java client using a Connection Pool?
Javadoc from OracleDatasource advice about cache deprecation and recommend UCP instead. But I’ve tried to instantiate a connection with it, but is not possible to cast it to OracleConnection, I got a proxy exception instead.
It seems clear that UCP is designed to return common java interfaces like Connection from sql package and is not familiar with Oracle specific use cases?
Somebody can help me to understand how to use an Oracle AQ through a connection pool?
Thank you.
Java dependencies:
Spring ucp properties:
spring.datasource.type=oracle.ucp.jdbc.PoolDataSource
spring.datasource.oracleucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
Exception message:
java.lang.ClassCastException: oracle.ucp.jdbc.proxy.oracle$1ucp$1jdbc$1proxy$1oracle$1ConnectionProxy$2oracle$1jdbc$1internal$1OracleConnection$$$Proxy cannot be cast to oracle.jdbc.driver.OracleConnection
Source code:
@Autowired
public InsertController(DataSource ds) {
this.ds = ds;
}
private OracleConnection getConnection() throws Exception {
Connection con = this.ds.getConnection();
return (OracleConnection) con; //Proxy error propagation
}
You can type cast the UCP connection to oracle.jdbc.OracleConnection and then call below API to enqueue the message.
public void enqueue(String queueName, oracle.jdbc.aq.AQEnqueueOptions opt, oracle.jdbc.aq.AQMessage mesg) throws SQLException;