I have a io.agroal.springframework.boot.AgroalDataSource and I wrap it into another DataSource like DelegatingDataSource, for example. After that I need to unwrap it to retrieve the AgroalDataSource. For this purpose I tried DataSourceUnwrapper doing the following:
DelegatingDataSource delegatingDataSource = ... //wrap AgraolDataSource
...
AgroalDataSource agroalDataSource = DataSourceUnwrapper.unwrap(delegatingDataSource , io.agroal.api.AgroalDataSource.class);
But I get null.
This is due to implementation of methods isWrapperFor and unwrap in class io.agroal.springframework.boot.AgroalDataSource are delegating into the underlying datasource.
I have a workaround, extending io.agroal.springframework.boot.AgroalDataSource, and implemeting these methods:
public class MyAgroalDataSource extends io.agroal.springframework.boot.AgroalDataSource { @Override @SuppressWarnings("unchecked") public <T> T unwrap(Class<T> iface) throws SQLException { if (iface.isInstance(this)) { return (T) this; } return super.unwrap(iface); } @Override public boolean isWrapperFor(Class<?> iface) throws SQLException { return iface.isInstance(this) || super.isWrapperFor(iface); } }
But It will be nice if Agroal take into account this use case and apply this changes in its source code.