Hi Hans / Eric (what is your real name, actually?)

I've now had some time to look into your Spring / Guice support request and
as mentioned in a previous E-Mail, I can confirm that the implementation of
the ExecuteListener is not correct. As I already suggested, you should use
a ConnectionProvider to provide jOOQ with Connections. And in fact, you're
already doing that. But then you're fetching *another* connection from your
DataSource in your SpringExceptionTranslationExecuteListener. For some
reason, you're also closing all sorts of resources (Statement, Connection),
even if that is already done - again - by the ConnectionProvider.

All of this leads to your implementation fetching *two* connections from
the data source, but closing only *one*. So, your ExecuteListener would
look as simple as this:


--------------------------------------------------------------------
@SuppressWarnings("UnusedDeclaration")
public class SpringExceptionTranslationExecuteListener extends
DefaultExecuteListener {
 @Override
public void exception(ExecuteContext ctx) {
        DataSourceSingleton dataSourceSingleton =
DataSourceSingleton.getReference();
        DataSource dataSource3=null;
         try {
            dataSource3= dataSourceSingleton.getDataSource();
         } catch (Exception e) {
            // TODO Auto-generated catch block
             e.printStackTrace();
        }
         SQLException ex = ctx.sqlException();
 ctx.exception(getExceptionTranslator(dataSource3).translate("jOOQ",ctx.sql(),
ex));
}

public synchronized SQLExceptionTranslator getExceptionTranslator(
DataSource dataSource) {
final SQLExceptionTranslator exceptionTranslator;
if (dataSource != null) {
exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(
dataSource);
} else {
exceptionTranslator = new SQLStateSQLExceptionTranslator();
}
return exceptionTranslator;
}
}
--------------------------------------------------------------------



As far as the third test case you provided me with is concerned, I think it
is simply wrong

--------------------------------------------------------------------

public void shouldPerformAllSQLsInOneTransaction() throws Exception {
persistenceFacade.removeAccount("[email protected]"); //L�scht den Benutzer
try {
persistenceFacade.addAccount(1, "[email protected]", "Name",1,null); //schreibt
Daten in Tabelle Account und Auth
} catch (DataIntegrityViolationException e) {
}
AccountRecord user = persistenceFacade.getAccountByEmail("[email protected]");
 assertNull(user); // Falls die Transaction wie gew�nscht funktioniert
sollte es den user nicht mehr geben.
}

--------------------------------------------------------------------


I don't see why these statements should be performed in a single
transaction. Both calls (removeAccount(), addAccount()) start new
transactions, the way you have configured your GuiceModule.

Cheers
Lukas

2014/1/13 Stargate <[email protected]>

> Hi,
>
> ok the Transactions are working now.. but if i did not add the
> @Transcational Annotation to a Class or method the AutoCommit did not work..
>
> the Problem is in the "SpringExceptionTranslationExecuteListener"  that i
> use:
>
>
> public class SpringExceptionTranslationExecuteListener extends
>>         DefaultExecuteListener {
>>
>>
>>     @Override
>>     public void start(ExecuteContext ctx) {
>>         DataSource dataSource=null;
>>         try {
>>             dataSource= dataSourceSingleton.getDataSource();
>>         } catch (Exception e) {
>>             e.printStackTrace();
>>         }
>>
>>         Connection con=DataSourceUtils.getConnection(dataSource);
>>
>>         DefaultConnectionProvider dCP=new DefaultConnectionProvider(con);
>>
>>         ctx.connectionProvider(dCP);
>>
>>
>>     }
>>
>>     @Override
>>     public void exception(ExecuteContext ctx) {
>>
>>         DataSourceSingleton dataSourceSingleton =
>> DataSourceSingleton.getReference();
>>         DataSource dataSource=null;
>>         try {
>>             dataSource= dataSourceSingleton.getDataSource();
>>         } catch (Exception e) {
>>             e.printStackTrace();
>>         }
>>
>>
>>         SQLException ex = ctx.sqlException();
>>         Statement stmt = ctx.statement();
>>         Connection con = ctx.connection();
>>
>>         DataSourceUtils.releaseConnection(con, dataSource3);
>>
>>         JdbcUtils.closeStatement(stmt);
>>
>>
>> ctx.exception(getExceptionTranslator(dataSource3).translate("jOOQ",ctx.sql(),
>> ex));
>>
>>
>>     }
>>
>>     /**
>>      * Return the exception translator for this instance.
>>      * <p>
>>      * Creates a default {@link SQLErrorCodeSQLExceptionTranslator} for
>> the
>>      * specified DataSource if none set, or a
>>      * {@link SQLStateSQLExceptionTranslator} in case of no DataSource.
>>      */
>>     public synchronized SQLExceptionTranslator getExceptionTranslator(
>>             DataSource dataSource) {
>>         final SQLExceptionTranslator exceptionTranslator;
>>         if (dataSource != null) {
>>             exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(
>>                     dataSource);
>>         } else {
>>             exceptionTranslator = new SQLStateSQLExceptionTranslator();
>>         }
>>         return exceptionTranslator;
>>     }
>>
>>
>>
>> }
>>
>
>
>  and the Problem is this part:
>
>
> @Override
>>     public void start(ExecuteContext ctx) {
>>         DataSource dataSource=null;
>>         try {
>>             dataSource= dataSourceSingleton.getDataSource();
>>         } catch (Exception e) {
>>             e.printStackTrace();
>>         }
>>
>>         Connection con=DataSourceUtils.getConnection(dataSource);
>>
>>         DefaultConnectionProvider dCP=new DefaultConnectionProvider(con);
>>
>>         ctx.connectionProvider(dCP);
>>
>>     }
>>
>
>
> if i uncomment the following line "ctx.connectionProvider(dCP);" the
> AutoCommit will work, but then the Transactions are not working. I have a
> pooled connection and so i must set the connection directly if i want use
> the @Transactional Annotation..
>
> But if there is no @Transactional Annotation and i set the connection
> directly "ctx.connectionProvider(dCP);" the AutoCommit is not working..
> How can i fix this problem ? Im new in AOP,Interceptors and so on
>
> The binding for Guice looks like this
>
> bindInterceptor(Matchers.annotatedWith(Transactional.class),
>
> Matchers.not(Matchers.annotatedWith(NotTransactional.class)),
>                 transactionalMethodInterceptor);
>
>         bindInterceptor(Matchers.any(),
>                 Matchers.annotatedWith(Transactional.class),
>                 transactionalMethodInterceptor);
>
>
> and the transactionMethodInterceptor is responsible for the spring managed
> Transactionhandling.
>
>
> 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 - ignoring! : " + e.getMessage());
>>             }
>>             return result;
>>         } catch (Exception e) {
>>
>>             transactionManager.rollback(transaction);
>>
>>             throw e;
>>         }
>>     }
>>
>> }
>>
>
>
> Best regards
>
>  --
> 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.
>

-- 
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.

Reply via email to