@Override protected void logException(long id, DBIException exception) { final Throwable cause = exception.getCause(); if (cause instanceof SQLException) { for (Throwable throwable : (SQLException) cause) { logger.error(formatLogMessage(id, throwable), throwable); } } else { logger.error(formatLogMessage(id, exception), exception); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); somethingSqlDao.create(1, "pierre", UUID.randomUUID().toString()); try { somethingSqlDao.getUniqueId(1); Assert.fail(); } catch (final DBIException e) { Assert.assertEquals(e.getMessage(), "No mapper registered for java.util.UUID"); } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); somethingSqlDao.create(1, "pierre", UUID.randomUUID().toString()); try { somethingSqlDao.getUniqueId(1); Assert.fail(); } catch (final DBIException e) { Assert.assertEquals(e.getMessage(), "No mapper registered for java.util.UUID"); } }
public static <T> T runTransaction(IDBI dbi, TransactionCallback<T> callback) { try { return dbi.inTransaction(callback); } catch (DBIException e) { propagateIfInstanceOf(e.getCause(), PrestoException.class); throw metadataError(e); } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); somethingSqlDao.create(1, "pierre", 12); try { somethingSqlDao.getSomething(1); Assert.fail(); } catch (final DBIException e) { Assert.assertEquals(e.getMessage(), "No mapper registered for com.ning.billing.commons.jdbi.mapper.TestLowerToCamelBeanMapper$SomethingBean"); } }
@Override protected void logException(long id, DBIException exception) { final Throwable cause = exception.getCause(); if (cause instanceof SQLException) { for (Throwable throwable : (SQLException) cause) { logger.error(formatLogMessage(id, throwable), throwable); } } else { logger.error(formatLogMessage(id, exception), exception); } }
@Override public String getMessage() { String base = super.getMessage(); StatementContext ctx = getStatementContext(); if (ctx == null) { return base; } else { return String.format("%s [statement:\"%s\", located:\"%s\", rewritten:\"%s\", arguments:%s]", base, ctx.getRawSql(), ctx.getLocatedSql(), ctx.getRewrittenSql(), ctx.getBinding()); } } }
@Override public String getMessage() { String base = super.getMessage(); StatementContext ctx = getStatementContext(); if (ctx == null) { return base; } else { return String.format("%s [statement:\"%s\", located:\"%s\", rewritten:\"%s\", arguments:%s]", base, ctx.getRawSql(), ctx.getLocatedSql(), ctx.getRewrittenSql(), ctx.getBinding()); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); somethingSqlDao.create(1, "pierre", 12); try { somethingSqlDao.getSomething(1); Assert.fail(); } catch (final DBIException e) { Assert.assertEquals(e.getMessage(), "No mapper registered for org.killbill.commons.jdbi.mapper.TestLowerToCamelBeanMapper$SomethingBean"); } }
/** * Execute a block (database operation) with a new handle * * @param block representing a database operation * @return The result of a given database operation */ private Object perform(HandleBlock block) { Handle handle = getHandle(); try { return block.value(handle); } catch (DBIException ex) { Exception inner = (Exception) ex.getCause(); if (inner != null) { throw remapMySQLException((SQLException) inner); } throw ex; } finally { // Close the handle (internally this call releases the JDBC connection to the pool) close(handle); } }