Skip to content

Instantly share code, notes, and snippets.

@azell
Last active April 11, 2020 19:05
Show Gist options
  • Select an option

  • Save azell/5655888 to your computer and use it in GitHub Desktop.

Select an option

Save azell/5655888 to your computer and use it in GitHub Desktop.
Attempting to integrate Spring Transaction with jOOQ 3.7.0
public class SpringExceptionTranslationExecuteListener
extends DefaultExecuteListener {
/** {@inheritDoc} */
@Override
public void exception(ExecuteContext ctx) {
SQLDialect dialect = ctx.configuration().dialect();
SQLExceptionTranslator translator = (dialect != null)
? new SQLErrorCodeSQLExceptionTranslator(dialect.name())
: new SQLStateSQLExceptionTranslator();
ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException()));
}
}
public class SpringTransactionConnectionProvider implements ConnectionProvider {
private final DataSource ds;
public SpringTransactionConnectionProvider(DataSource ds) {
super();
this.ds = ds;
}
/** {@inheritDoc} */
@Override
public Connection acquire() {
try {
return DataSourceUtils.getConnection(ds);
} catch (CannotGetJdbcConnectionException e) {
throw new DataAccessException(
"Error getting connection from data source " + ds, e);
}
}
/** {@inheritDoc} */
@Override
public void release(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
throw new DataAccessException("Error closing connection " + conn, e);
}
}
}
}
@lukaseder
Copy link

Visitors of this gist:

Please do also consider the jOOQ manual's official tutorial on how to integrate jOOQ with Spring:

http://www.jooq.org/doc/latest/manual/getting-started/tutorials/jooq-with-spring/

@ivarasg
Copy link

ivarasg commented Mar 14, 2019

Visitors of this gist:

Please do also consider the jOOQ manual's official tutorial on how to integrate jOOQ with Spring:

http://www.jooq.org/doc/latest/manual/getting-started/tutorials/jooq-with-spring/

Is there any particular reason for your recommendation of using that method over this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment