Possibility of intercepting method getConnection() if exception is thrown by original DataSource
setofaces opened this issue · comments
Hi there. I am looking forward to intercepting each getConnection
invocation, however, as I see there is no way to deal with exceptions thrown after invocation of getConnection
method,afterGetConnection
is not visited in that case, is there any workaround which I could have missed or maybe some plans to add feature like that?
ah ok, yes it has a problem in the current ProxyDataSource
implementation.
Instead, what you can do as a workaround is to create a pure proxy for DataSource
.
DataSource original = ...
ProxyConfig proxyConfig = ProxyConfig.Builder.create().methodListener(methodListener).queryListener(listener).build();
DataSource proxy = proxyConfig.getJdbcProxyFactory().createDataSource(original, proxyConfig);
Note: since you mentioned afterGetConnection
method, I assume you are using JdbcLifecycleEventListener
.
This one is a bit tricky to register to ProxyConfig
. Please check how ProxyDataSourceBuilder#listener(JdbcLifecycleEventListener)
method registers the listener to ProxyConfig
if that is the case.
Yes, this approach works exactly as I want. Thank you!