Hello,
2013/12/25 Stargate <[email protected]> > Hi, > > i have migrated the most parts of my code to Jooq 3.2.2 it seems that the > AutoCommit Feature now works. But did i still need the > "SpringExceptionTranslationExecuteListener" that i have posted in my first > post with 3.2.2 ? I did not exactly understand why i need this Listener!? > >From a quick glance at your code, I suspect you also introduced this listener to translate Exceptions, right? So if you want to keep this feature, you will need to keep the listener. I don't think you will need to explicitly close the connection, though. > For Transaction Handling i use google Guice, i have bind the @Transaction > annotation to a seperate class that does via MethodInvocation the commit > and rollback. > The Class looks like this: > > > class TransactionalMethodInterceptor implements MethodInterceptor { >> >> @Inject >> private DataSourceTransactionManager transactionManager; >> >> >> @Override >> public Object invoke(final MethodInvocation invocation) throws >> Throwable { >> DefaultTransactionDefinition transactionDefinition = new >> DefaultTransactionDefinition(); >> TransactionStatus transaction = transactionManager >> .getTransaction(transactionDefinition); >> try { >> Object result = invocation.proceed(); >> try { >> transactionManager.commit(transaction); >> } catch (UnexpectedRollbackException e) { >> LoggerFactory.getLogger(getClass()).error( >> "commit failed : " + e.getMessage()); >> } >> return result; >> } catch (Exception e) { >> transactionManager.rollback(transaction); >> throw e; >> } >> } >> >> } >> > > That looks reasonable to me. > And Second Question! > At the Moment i use this code to implement the SpringListener: > > > DataSourceConnectionProvider dataSourceProvider=new >> DataSourceConnectionProvider(dataSource); >> >> // Create a configuration with an appropriate listener provider: >> Configuration configuration = new >> DefaultConfiguration().set(dataSourceProvider).set(SQLDialect.POSTGRES); >> >> configuration.set(new DefaultExecuteListenerProvider(new >> SpringExceptionTranslationExecuteListener())); >> >> //----------------------------------------- >> DSLContext create = DSL.using(configuration); >> > > > I did initialize different DataSourceConnectionProvider in several classes > with the same dataSource Object(Via Singleton), can this be a problem ? > That will entirely depend on your data source implementation. DataSourceConnectionProvider only calls dataSource.getConnection() prior to a query execution, and connection.close() after a query execution. Some DataSources (e.g. many of those provided by Spring) will internally use a ThreadLocal to ensure thread-safety. JTA DataSources, on the other hand, are usually tied to the session / transaction and must not be shared. Cheers Lukas -- 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
