this.context.setAttribute("position", null); } catch (SQLException e) { throw new UnableToExecuteStatementException( String.format( "Exception while binding positional param at (0 based) position %d", "the JDBC 'start at 1' scheme) has been set.", named_param, i, i + 1); throw new UnableToExecuteStatementException(msg, context);
private Optional<List<KeyRecord>> getLocalKeys(Account destination, String deviceIdSelector) { try { if (deviceIdSelector.equals("*")) { return keys.get(destination.getNumber()); } long deviceId = Long.parseLong(deviceIdSelector); for (int i=0;i<20;i++) { try { return keys.get(destination.getNumber(), deviceId); } catch (UnableToExecuteStatementException e) { logger.info(e.getMessage()); } } throw new WebApplicationException(Response.status(500).build()); } catch (NumberFormatException e) { throw new WebApplicationException(Response.status(422).build()); } } }
public void save(String project, ABTestingReport report) { if (report.id != -1) { throw new RakamException("Report already has an id.", HttpResponseStatus.BAD_REQUEST); } try (Handle handle = dbi.open()) { handle.createStatement("INSERT INTO ab_testing (project, name, variants, collection_name, connector_field, goals, options)" + " VALUES (:project, :name, :variants, :collection_name, :goals, :options)") .bind("project", project) .bind("name", report.name) .bind("collection_name", report.collectionName) .bind("variants", JsonHelper.encode(report.variants)) .bind("goals", JsonHelper.encode(ImmutableList.of(report.goal))) .bind("options", JsonHelper.encode(report.options, false)) .execute(); } catch (UnableToExecuteStatementException e) { if (e.getCause() instanceof SQLException && ((SQLException) e.getCause()).getSQLState().equals("23505")) { // TODO: replace throw new RakamException("Report already exists", HttpResponseStatus.BAD_REQUEST); } } }
public <T> T catchConflict(NewResourceAction<T> function, String messageFormat, Object... messageParameters) throws ResourceConflictException { try { return function.call(); } catch (UnableToExecuteStatementException ex) { if (ex.getCause() instanceof SQLException) { SQLException sqlEx = (SQLException) ex.getCause(); if (isConflictException(sqlEx)) { throw new ResourceConflictException("Resource already exists: " + String.format(messageFormat, messageParameters)); } } throw ex; } }
public <T> T catchForeignKeyNotFound(NewResourceAction<T> function, String messageFormat, Object... messageParameters) throws ResourceNotFoundException, ResourceConflictException { try { return function.call(); } catch (UnableToExecuteStatementException ex) { if (ex.getCause() instanceof SQLException) { SQLException sqlEx = (SQLException) ex.getCause(); if (isForeignKeyException(sqlEx)) { throw new ResourceNotFoundException("Resource not found: " + String.format(messageFormat, messageParameters)); } } throw ex; } }
protected final void afterExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.afterExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", new LocalDate(DateTimeZone.UTC)); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
protected final void cleanup() { for (StatementCustomizer customizer : customizers) { try { customizer.cleanup(context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Could not clean up", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", new DateTime(DateTimeZone.UTC)); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
protected final void beforeExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.beforeExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", new LocalDate(DateTimeZone.UTC)); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
protected final void beforeExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.beforeExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", new DateTime(DateTimeZone.UTC)); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
protected final void afterExecution(final PreparedStatement stmt) { for (StatementCustomizer customizer : customizers) { try { customizer.afterExecution(stmt, context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Exception thrown in statement customization", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", DateTimeZone.UTC); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
protected final void cleanup() { for (StatementCustomizer customizer : customizers) { try { customizer.cleanup(context); } catch (SQLException e) { throw new UnableToExecuteStatementException("Could not clean up", e, context); } } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", Bier.ipa); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
private String[] getStatements() { final String script; final StatementContext ctx = new ConcreteStatementContext(globalStatementAttributes); try { script = locator.locate(name, ctx); } catch (Exception e) { throw new UnableToExecuteStatementException(String.format("Error while loading script [%s]", name), e, ctx); } return script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", DateTimeZone.UTC); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
/** * Execute this script in a batch statement * * @return an array of ints which are the results of each statement in the script */ public int[] execute() { final String script; final StatementContext ctx = new ConcreteStatementContext(globalStatementAttributes); try { script = locator.locate(name, ctx); } catch (Exception e) { throw new UnableToExecuteStatementException(String.format("Error while loading script [%s]", name), e, ctx); } final String[] statements = script.replaceAll("\n", " ").replaceAll("\r", "").split(";"); Batch b = handle.createBatch(); for (String s : statements) { if ( ! WHITESPACE_ONLY.matcher(s).matches() ) { b.add(s); } } return b.execute(); } }