Skip to content

Instantly share code, notes, and snippets.

@azell
Last active April 11, 2020 19:05
Show Gist options
  • Save azell/5655888 to your computer and use it in GitHub Desktop.
Save azell/5655888 to your computer and use it in GitHub Desktop.

Revisions

  1. azell renamed this gist Oct 9, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. azell revised this gist Oct 9, 2015. 1 changed file with 1 addition and 19 deletions.
    20 changes: 1 addition & 19 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ public class SpringExceptionTranslationExecuteListener
    SQLException e = ctx.sqlException();

    if (e != null) {
    String name = productName(ctx.configuration().dialect());
    String name = ctx.configuration().dialect().thirdParty().springDbName();

    /* Prefer product name, if available. */
    SQLExceptionTranslator translator = (name != null)
    @@ -17,24 +17,6 @@ public class SpringExceptionTranslationExecuteListener
    ctx.exception(translator.translate("jOOQ", ctx.sql(), e));
    }
    }

    // This will be simplified in 3.7.0
    // https://github.com/jOOQ/jOOQ/issues/4252
    protected String productName(SQLDialect dialect) {
    String name = null;

    if (dialect == SQLDialect.HSQLDB) {
    name = "HSQL";
    } else if (dialect == SQLDialect.POSTGRES) {
    name = "PostgreSQL";
    } else if (dialect == SQLDialect.MARIADB) {
    name = SQLDialect.MYSQL.getName();
    } else if (dialect != null) {
    name = dialect.getName();
    }

    return name;
    }
    }

    public class SpringTransactionConnectionProvider implements ConnectionProvider {
  3. azell revised this gist Aug 28, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,8 @@ public class SpringExceptionTranslationExecuteListener
    }
    }

    // This will be simplified in 3.7.0
    // https://github.com/jOOQ/jOOQ/issues/4252
    protected String productName(SQLDialect dialect) {
    String name = null;

  4. azell revised this gist Jul 19, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ public class SpringExceptionTranslationExecuteListener
    : new SQLStateSQLExceptionTranslator();

    ctx.exception(translator.translate("jOOQ", ctx.sql(), e));
    }
    }

    protected String productName(SQLDialect dialect) {
  5. azell revised this gist Jul 19, 2014. 1 changed file with 9 additions and 6 deletions.
    15 changes: 9 additions & 6 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -4,14 +4,17 @@ public class SpringExceptionTranslationExecuteListener
    /** {@inheritDoc} */
    @Override
    public void exception(ExecuteContext ctx) {
    String name = productName(ctx.configuration().dialect());
    SQLException e = ctx.sqlException();

    /* Prefer product name, if available. */
    SQLExceptionTranslator translator = (name != null)
    ? new SQLErrorCodeSQLExceptionTranslator(name)
    : new SQLStateSQLExceptionTranslator();
    if (e != null) {
    String name = productName(ctx.configuration().dialect());

    ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException()));
    /* Prefer product name, if available. */
    SQLExceptionTranslator translator = (name != null)
    ? new SQLErrorCodeSQLExceptionTranslator(name)
    : new SQLStateSQLExceptionTranslator();

    ctx.exception(translator.translate("jOOQ", ctx.sql(), e));
    }

    protected String productName(SQLDialect dialect) {
  6. azell revised this gist Feb 11, 2014. 1 changed file with 21 additions and 3 deletions.
    24 changes: 21 additions & 3 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,31 @@ public class SpringExceptionTranslationExecuteListener
    /** {@inheritDoc} */
    @Override
    public void exception(ExecuteContext ctx) {
    SQLDialect dialect = ctx.configuration().dialect();
    SQLExceptionTranslator translator = (dialect != null)
    ? new SQLErrorCodeSQLExceptionTranslator(dialect.name())
    String name = productName(ctx.configuration().dialect());

    /* Prefer product name, if available. */
    SQLExceptionTranslator translator = (name != null)
    ? new SQLErrorCodeSQLExceptionTranslator(name)
    : new SQLStateSQLExceptionTranslator();

    ctx.exception(translator.translate("jOOQ", ctx.sql(), ctx.sqlException()));
    }

    protected String productName(SQLDialect dialect) {
    String name = null;

    if (dialect == SQLDialect.HSQLDB) {
    name = "HSQL";
    } else if (dialect == SQLDialect.POSTGRES) {
    name = "PostgreSQL";
    } else if (dialect == SQLDialect.MARIADB) {
    name = SQLDialect.MYSQL.getName();
    } else if (dialect != null) {
    name = dialect.getName();
    }

    return name;
    }
    }

    public class SpringTransactionConnectionProvider implements ConnectionProvider {
  7. azell revised this gist Aug 12, 2013. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -46,18 +46,15 @@ public class JooqTransactionFactory {
    private final Configuration config = new DefaultConfiguration();

    public JooqTransactionFactory(DataSource ds, SQLDialect dialect) {
    this(ds, dialect, null);
    this(ds, dialect, new Settings().withRenderSchema(false));
    }

    public JooqTransactionFactory(DataSource ds, SQLDialect dialect,
    Settings settings) {
    config.set(new SpringTransactionConnectionProvider(ds)).set(dialect).set(
    settings).set(
    new DefaultExecuteListenerProvider(
    new SpringExceptionTranslationExecuteListener()));

    if (settings != null) {
    config.set(settings);
    }
    }

    public DSLContext context() {
  8. azell revised this gist Jun 6, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,6 @@ public class JooqTransactionFactory {

    public JooqTransactionFactory(DataSource ds, SQLDialect dialect,
    Settings settings) {
    super();
    config.set(new SpringTransactionConnectionProvider(ds)).set(dialect).set(
    new DefaultExecuteListenerProvider(
    new SpringExceptionTranslationExecuteListener()));
  9. azell revised this gist Jun 6, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,6 @@ public class SpringTransactionConnectionProvider implements ConnectionProvider {
    private final DataSource ds;

    public SpringTransactionConnectionProvider(DataSource ds) {
    super();
    this.ds = ds;
    }

  10. azell revised this gist May 28, 2013. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -42,3 +42,27 @@ public class SpringTransactionConnectionProvider implements ConnectionProvider {
    }
    }
    }

    public class JooqTransactionFactory {
    private final Configuration config = new DefaultConfiguration();

    public JooqTransactionFactory(DataSource ds, SQLDialect dialect) {
    this(ds, dialect, null);
    }

    public JooqTransactionFactory(DataSource ds, SQLDialect dialect,
    Settings settings) {
    super();
    config.set(new SpringTransactionConnectionProvider(ds)).set(dialect).set(
    new DefaultExecuteListenerProvider(
    new SpringExceptionTranslationExecuteListener()));

    if (settings != null) {
    config.set(settings);
    }
    }

    public DSLContext context() {
    return DSL.using(config);
    }
    }
  11. azell revised this gist May 28, 2013. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -25,8 +25,8 @@ public class SpringTransactionConnectionProvider implements ConnectionProvider {
    @Override
    public Connection acquire() {
    try {
    return DataSourceUtils.getConnection(ds);
    } catch (CannotGetJdbcConnectionException e) {
    return DataSourceUtils.doGetConnection(ds);
    } catch (SQLException e) {
    throw new DataAccessException(
    "Error getting connection from data source " + ds, e);
    }
    @@ -35,12 +35,10 @@ public class SpringTransactionConnectionProvider implements ConnectionProvider {
    /** {@inheritDoc} */
    @Override
    public void release(Connection conn) {
    if (conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    throw new DataAccessException("Error closing connection " + conn, e);
    }
    try {
    DataSourceUtils.doReleaseConnection(conn, ds);
    } catch (SQLException e) {
    throw new DataAccessException("Error closing connection " + conn, e);
    }
    }
    }
  12. azell created this gist May 27, 2013.
    46 changes: 46 additions & 0 deletions Spring Txn and jOOQ 3
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    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);
    }
    }
    }
    }