use of org.spf4j.recyclable.ObjectCreationException in project spf4j by zolyfarkas.
the class JdbcConnectionFactory method create.
@Override
public Connection create() throws ObjectCreationException {
final Connection conn;
try {
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException ex) {
throw new ObjectCreationException(ex);
}
return (Connection) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { Connection.class }, new InvocationHandler() {
private Exception ex;
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Exception {
if ("close".equals(method.getName())) {
pool.recycle((Connection) proxy, ex);
ex = null;
return null;
} else {
try {
return method.invoke(conn, args);
} catch (IllegalAccessException | InvocationTargetException | RuntimeException e) {
ex = e;
throw e;
}
}
}
});
}
Aggregations