Example usage for org.springframework.dao DataIntegrityViolationException getMessage

List of usage examples for org.springframework.dao DataIntegrityViolationException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DataIntegrityViolationException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.apache.fineract.infrastructure.dataexport.service.DataExportWritePlatformServiceImpl.java

/** 
 * Handle any SQL data integrity issue //w w  w  .j  av a 2  s  . c  o  m
 *
 * @param jsonCommand -- JsonCommand object
 * @param dve -- data integrity exception object
 * @return None
 **/
private void handleDataIntegrityIssues(final JsonCommand jsonCommand,
        final DataIntegrityViolationException dve) {
    final Throwable realCause = dve.getMostSpecificCause();

    if (realCause.getMessage().contains(DataExportApiConstants.NAME_PARAM_NAME)) {
        final String name = jsonCommand.stringValueOfParameterNamed(DataExportApiConstants.NAME_PARAM_NAME);
        throw new PlatformDataIntegrityException("error.msg.data.export.duplicate.name",
                "Data export with name `" + name + "` already exists", DataExportApiConstants.NAME_PARAM_NAME,
                name);
    }

    logger.error(dve.getMessage(), dve);

    throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource: " + realCause.getMessage());
}

From source file:org.apache.fineract.infrastructure.dataqueries.service.ReportWritePlatformServiceImpl.java

private void handleReportDataIntegrityIssues(final JsonCommand command,
        final DataIntegrityViolationException dve) {

    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("unq_report_name")) {
        final String name = command.stringValueOfParameterNamed("reportName");
        throw new PlatformDataIntegrityException("error.msg.report.duplicate.name",
                "A report with name '" + name + "' already exists", "name", name);
    }/*from w  w w  .j a va  2s  .c  o m*/

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException("error.msg.report.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource: " + realCause.getMessage());
}

From source file:org.apache.fineract.organisation.staff.service.StaffWritePlatformServiceJpaRepositoryImpl.java

private void handleStaffDataIntegrityIssues(final JsonCommand command,
        final DataIntegrityViolationException dve) {
    final Throwable realCause = dve.getMostSpecificCause();

    if (realCause.getMessage().contains("external_id")) {

        final String externalId = command.stringValueOfParameterNamed("externalId");
        throw new PlatformDataIntegrityException("error.msg.staff.duplicate.externalId",
                "Staff with externalId `" + externalId + "` already exists", "externalId", externalId);
    } else if (realCause.getMessage().contains("display_name")) {
        final String lastname = command.stringValueOfParameterNamed("lastname");
        String displayName = lastname;
        if (!StringUtils.isBlank(displayName)) {
            final String firstname = command.stringValueOfParameterNamed("firstname");
            displayName = lastname + ", " + firstname;
        }/*from w  w  w  .  j av  a2  s.  com*/
        throw new PlatformDataIntegrityException("error.msg.staff.duplicate.displayName",
                "A staff with the given display name '" + displayName + "' already exists", "displayName",
                displayName);
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException("error.msg.staff.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource: " + realCause.getMessage());
}

From source file:org.apache.fineract.portfolio.loanaccount.service.LoanApplicationWritePlatformServiceJpaRepositoryImpl.java

private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) {
    logger.error(dve.getMessage(), dve);
}

From source file:org.mifosplatform.organisation.dsa.service.DsaWritePlatformServiceJpaRepositoryImpl.java

private void handleStaffDataIntegrityIssues(final JsonCommand command,
        final DataIntegrityViolationException dve) {
    final Throwable realCause = dve.getMostSpecificCause();

    if (realCause.getMessage().contains("display_name")) {
        final String lastname = command.stringValueOfParameterNamed("lastname");
        String displayName = lastname;
        if (!StringUtils.isBlank(displayName)) {
            final String firstname = command.stringValueOfParameterNamed("firstname");
            displayName = lastname + ", " + firstname;
        }/*from w ww . j  a  va2s. co m*/
        throw new PlatformDataIntegrityException("error.msg.staff.duplicate.displayName",
                "A Dsa with the given display name '" + displayName + "' already exists", "displayName",
                displayName);
    }

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException("error.msg.staff.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource: " + realCause.getMessage());
}

From source file:org.mifosplatform.portfolio.group.service.GroupWritePlatformServiceJpaRepositoryImpl.java

private void handleGroupDataIntegrityIssues(final JsonCommand command,
        final DataIntegrityViolationException dve, GroupLevel groupLevel) {

    final Throwable realCause = dve.getMostSpecificCause();
    String errorMessageForUser = null;
    String errorMessageForMachine = null;

    if (realCause.getMessage().contains("external_id")) {

        errorMessageForUser = groupLevel.getLevelName() + " with externalId {0} already exists";
        errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase()
                + ".duplicate.externalId";
        throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "externalId",
                command.stringValueOfParameterNamed("externalId"));

    } else if (realCause.getMessage().contains("name")) {

        errorMessageForUser = groupLevel.getLevelName() + " with name {0} already exists";
        errorMessageForMachine = "error.msg." + groupLevel.getLevelName().toLowerCase() + ".duplicate.name";
        throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser, "name",
                command.stringValueOfParameterNamed("name"));

    }// w  w w  .  ja v a  2 s.c  om

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource.");
}

From source file:org.mifosplatform.useradministration.service.AppUserWritePlatformServiceJpaRepositoryImpl.java

private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {

    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("username_org")) {
        final String username = command.stringValueOfParameterNamed("username");
        final StringBuilder defaultMessageBuilder = new StringBuilder("User with username ").append(username)
                .append(" already exists.");
        throw new PlatformDataIntegrityException("error.msg.user.duplicate.username",
                defaultMessageBuilder.toString(), "username", username);
    }//from  w  w w .ja  va  2 s .  c o  m

    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
            "Unknown data integrity issue with resource.");
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addAvailabilityCheck(AvailabilityCheck availabilityCheck) {
    if (log.isDebugEnabled()) {
        log.debug("addAvailabilityCheck( " + availabilityCheck.toString() + ")");
    }/* ww w . j a v a 2 s . com*/

    // entity_ref, scheduled_time

    try {
        JdbcTemplate template = getJdbcTemplate();
        String sql = getStatement("insert.AvailabilityCheck");

        template.update(sql, new Object[] { availabilityCheck.getEntityReference(),
                availabilityCheck.getEntityTypeId(), availabilityCheck.getScheduledTime() });
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addAvailabilityCheck() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addAvailabilityCheck: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    } catch (Exception e) {
        log.warn("addAvailabilityCheck: Error executing query: " + e.getClass() + ":" + e.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addContext(Context context) {
    if (log.isDebugEnabled()) {
        log.debug("addContext( " + context.toString() + ")");
    }/*from  w  w w.  j  a v  a  2  s  . co  m*/

    //  context_id, context_url, context_title

    String sql = getStatement("insert.Context");
    try {
        int rows = getJdbcTemplate().update(sql,
                new Object[] { context.getContextId(), context.getContextUrl(), context.getContextTitle() });
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addContext() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addContext: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    } catch (Exception e) {
        log.warn("addCalendarItem: Error executing query: " + e.getClass() + ":" + e.getMessage());
        return false;
    }
}