org.jdbi.v3.core.statement.UnableToExecuteStatementException Java Examples

The following examples show how to use org.jdbi.v3.core.statement.UnableToExecuteStatementException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBWrappedMementoService.java    From trellis with Apache License 2.0 5 votes vote down vote up
private void putTime(final IRI identifier, final Instant instant) {
    try {
        jdbi.useHandle(handle ->
                handle.execute("INSERT INTO memento (subject, moment) VALUES (?, ?)",
                    identifier.getIRIString(), instant.getEpochSecond()));
    } catch (final UnableToExecuteStatementException ex) {
        LOGGER.debug("Unable to insert memento value: {}", ex.getMessage());
    }
}
 
Example #2
Source File: IronTestLoggingExceptionMapper.java    From irontest with Apache License 2.0 5 votes vote down vote up
@Override
public Response toResponse(Throwable exception) {
    long id = logException(exception);
    int status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
    String errorDetails = exception.getMessage();

    //  change error details if the exception is a known DB constraint violation
    if (exception instanceof UnableToExecuteStatementException) {
        SQLException se = (SQLException) exception.getCause();
        if (se.getErrorCode() == ErrorCode.DUPLICATE_KEY_1 &&
                se.getMessage().contains("_" + DB_UNIQUE_NAME_CONSTRAINT_NAME_SUFFIX)) {
            errorDetails = "Duplicate name.";
        } else if (se.getErrorCode() == ErrorCode.CHECK_CONSTRAINT_VIOLATED_1) {
            if (se.getMessage().contains("_" + DB_PROPERTY_NAME_CONSTRAINT_NAME_SUFFIX)) {
                errorDetails = "Property/column name can not be same as preserved names and can only contain letter, digit," +
                        " $ and _ characters, beginning with letter, _ or $.";
            } else if (se.getMessage().contains("_" + DB_USERNAME_CONSTRAINT_NAME_SUFFIX)) {
                errorDetails = "Please enter a valid username: 3+ characters long, characters \"A-Za-z0-9_\".";
            }
        }
    }

    ErrorMessage errorMessage = new ErrorMessage(status, formatErrorMessage(id, exception), errorDetails);
    return Response.status(status)
            .type(MediaType.APPLICATION_JSON_TYPE)
            .entity(errorMessage)
            .build();
}
 
Example #3
Source File: ModeratorAuditHistoryDaoTest.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
@Test
@DataSet(cleanBefore = true, value = "moderator_audit/pre_insert.yml")
void addAuditRecordThrowsIfModeratorNameNotFound() {
  assertThrows(
      UnableToExecuteStatementException.class,
      () ->
          moderatorAuditHistoryDao.addAuditRecord(
              ModeratorAuditHistoryDao.AuditArgs.builder()
                  .moderatorUserId(MODERATOR_ID_DOES_NOT_EXIST)
                  .actionTarget("any-value")
                  .actionName(ModeratorAuditHistoryDao.AuditAction.BAN_USERNAME)
                  .build()));
}