So is there somewhere an updated version of the SpringExceptionTranslationExecuteListener and any supporting classes that was shown in the "A nice way of using jOOQ with Spring" blog entry that can be downloaded? I am just starting out experimenting with jOOQ and proper integration with Spring's transaction management is mandatory.I found a few Gist pages by azell but could not find the complete classes.The way things stand right now, I think I could only use jOOQ for help in construction SQL String generation that I can then use with Spring's JdbcTemplate. This is not quite optimal; but at least would be a start.Thanks for what looks like a GREAT libary.Martin Bosak--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hello Martin,
You can use jOOQ without JdbcTemplate and SpringExceptionTranslationExecuteListener.
Just create DSLContextImpl in spring context and use it into your service class.Below you and find example how to initialize DSLContext instance in spring context.
Unfortunately we found DefaultConfiguration deprecated in jOOQ 3.0.
Sergey,THANK YOU!That is exactly what I was looking for (and for me, it wasn't clear in the docs).And PLEASE allow Lucas to include it in the docs. I am sure others would appreciate it too.
private class TransactionAwareInvocationHandler implements InvocationHandler { private final DataSource targetDataSource; private Connection target; private boolean closed = false; public TransactionAwareInvocationHandler(DataSource targetDataSource) { this.targetDataSource = targetDataSource; } public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... if (method.getName().equals("equals")) { // Only considered as equal when proxies are identical. return (proxy == args[0]); } else if (method.getName().equals("hashCode")) { // Use hashCode of Connection proxy. return System.identityHashCode(proxy); } else if (method.getName().equals("toString")) { // Allow for differentiating between the proxy and the raw Connection. StringBuilder sb = new StringBuilder("Transaction-aware proxy for target Connection "); if (this.target != null) { sb.append("[").append(this.target.toString()).append("]"); } else { sb.append(" from DataSource [").append(this.targetDataSource).append("]"); } return sb.toString(); } else if (method.getName().equals("unwrap")) { if (((Class) args[0]).isInstance(proxy)) { return proxy; } } else if (method.getName().equals("isWrapperFor")) { if (((Class) args[0]).isInstance(proxy)) { return true; } } else if (method.getName().equals("close")) { // Handle close method: only close if not within a transaction. DataSourceUtils.doReleaseConnection(this.target, this.targetDataSource); this.closed = true; return null; } else if (method.getName().equals("isClosed")) { return this.closed; } if (this.target == null) { if (this.closed) { throw new SQLException("Connection handle already closed"); } if (shouldObtainFixedConnection(this.targetDataSource)) { this.target = DataSourceUtils.doGetConnection(this.targetDataSource); } } Connection actualTarget = this.target; if (actualTarget == null) { actualTarget = DataSourceUtils.doGetConnection(this.targetDataSource); } if (method.getName().equals("getTargetConnection")) { // Handle getTargetConnection method: return underlying Connection. return actualTarget; } // Invoke method on target Connection. try { Object retVal = method.invoke(actualTarget, args); // If return value is a Statement, apply transaction timeout. // Applies to createStatement, prepareStatement, prepareCall. if (retVal instanceof Statement) { DataSourceUtils.applyTransactionTimeout((Statement) retVal, this.targetDataSource); } return retVal; } catch (InvocationTargetException ex) { throw ex.getTargetException(); } finally { if (actualTarget != this.target) { DataSourceUtils.doReleaseConnection(actualTarget, this.targetDataSource); } } } }
--