Ok, so tying all of these ideas together, I came up with the following code 
that seems to interoperate properly with JTA transactions. Could you please 
have a look and let me know if you see any problems with it? Otherwise, we’re 
off to the races, and I appreciate all of your help.





@Qualifier

@Retention(RUNTIME)

@Target({ FIELD, TYPE, METHOD })

public @interface PlatformDSLContext {

}







public final class PlatformDSLContextProducer {

    @Resource(lookup = "java:jboss/datasources/PlatformDS")

    private DataSource ds;




    @Produces @PlatformDSLContext

    public DSLContext create() {

        return DSL.using(ds, SQLDialect.POSTGRES); // supply a Configuration 
here for further customization if reqd

    }




    private PlatformDSLContextProducer() {

    }

}





@Stateless

public class JooqTest {


    @Inject @PlatformDSLContext

    private DSLContext jooq;




    public void test() {

        jooq.select()…

    }

}

On Fri, Oct 10, 2014 at 12:00 PM, Lukas Eder <[email protected]> wrote:

> 2014-10-10 17:52 GMT+02:00 John Edo <[email protected]>:
>> Thanks all. I’ll give that approach a try.
>>
>> One concern: is the connection returned by the datasource part of the
>> active JTA transaction? e.g. suppose the jOOQ SQL runs fine, but
>> subsequently something else causes the JTA transaction to rollback…will the
>> jOOQ SQL be rolled back too?
>>
> Yes - by default, jOOQ is completely unaware of your transaction
> implementation and just uses org.jooq.ConnectionProviders to acquire JDBC
> Connections from which it then creates PreparedStatements without any
> magic. After statement execution, the Connection is released again to the
> ConnectionProvider
> If you provide jOOQ with a DataSource, you are implicitly using a
> DataSourceConnectionProvider, and the following logic is used to acquire /
> release connections:
> public class DataSourceConnectionProvider implements ConnectionProvider {
>     private final DataSource dataSource;
>     public DataSourceConnectionProvider(DataSource dataSource) {
>         this.dataSource = dataSource;
>     }
>     public DataSource dataSource() {
>         return dataSource;
>     }
>     @Override
>     public Connection acquire() {
>         try {
>             return dataSource.getConnection();
>         }
>         catch (SQLException e) {
>             throw new DataAccessException("Error getting connection from
> data source " + dataSource, e);
>         }
>     }
>     @Override
>     public void release(Connection connection) {
>         try {
>             connection.close();
>         }
>         catch (SQLException e) {
>             throw new DataAccessException("Error closing connection " +
> connection, e);
>         }
>     }
> }
> More details can be seen here:
> http://www.jooq.org/doc/latest/manual/sql-building/dsl-context/connection-vs-datasource/
> Hope this helps,
> Lukas
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "jOOQ User Group" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/jooq-user/xkK48Mrh5so/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
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/d/optout.

Reply via email to