Example usage for org.springframework.dao DataAccessException getMostSpecificCause

List of usage examples for org.springframework.dao DataAccessException getMostSpecificCause

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMostSpecificCause.

Prototype

public Throwable getMostSpecificCause() 

Source Link

Document

Retrieve the most specific cause of this exception, that is, either the innermost cause (root cause) or this exception itself.

Usage

From source file:de.forsthaus.webui.order.OrderDialogCtrl.java

/**
 * Saves the components to table. <br>
 * //from  w  ww.  j  a  v a  2  s.  c  o  m
 * @throws InterruptedException
 */
public void doSave() throws InterruptedException {

    Order anOrder = getOrder();
    Customer aCustomer = getCustomer();

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // force validation, if on, than execute by component.getValue()
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if (!isValidationOn()) {
        doSetValidation();
    }

    kunNr.getValue();
    kunName1.getValue();
    // bbox_Orders_CustomerSearch.getValue();

    // fill the order object with the components data
    anOrder.setCustomer(aCustomer);
    anOrder.setAufNr(aufNr.getValue());
    anOrder.setAufBezeichnung(aufBezeichnung.getValue());

    // save it to database
    try {
        getOrderService().saveOrUpdate(anOrder);
    } catch (DataAccessException e) {
        ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());

        // Reset to init values
        doResetInitValues();

        doReadOnly();
        btnCtrl.setBtnStatus_Save();
        return;
    }

    // now synchronize the offices listBox
    ListModelList lml = (ListModelList) listBoxOrder.getListModel();

    // Check if the object is new or updated
    // -1 means that the object is not in the list, so its new.
    if (lml.indexOf(anOrder) == -1) {
        lml.add(anOrder);
    } else {
        lml.set(lml.indexOf(anOrder), anOrder);
    }

    // bind the vars new for updating the components
    // officeCtrl.doBindNew();

    doReadOnly();
    btnCtrl.setBtnStatus_Save();
    // init the old values vars new
    doStoreInitValues();
}

From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java

@Override
public CommandProcessingResult createPPIEntry(final String dataTableName, final Long appTableId,
        final JsonCommand command) {

    try {//  ww  w.  ja  v  a 2  s .  c  o m
        final String appTable = queryForApplicationTableName(dataTableName);
        final CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable,
                appTableId);

        final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService
                .fillResultsetColumnHeaders(dataTableName);

        final Type typeOfMap = new TypeToken<Map<String, String>>() {
        }.getType();
        final Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json());

        final String sql = getAddSqlWithScore(columnHeaders, dataTableName, getFKField(appTable), appTableId,
                dataParams);

        this.jdbcTemplate.update(sql);

        return commandProcessingResult; //

    } catch (final DataAccessException dve) {
        final Throwable cause = dve.getCause();
        final Throwable realCause = dve.getMostSpecificCause();
        if (realCause.getMessage().contains("Duplicate entry")
                || cause.getMessage().contains("Duplicate entry")) {
            throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate",
                    "An entry already exists for datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        }

        logAsErrorUnexpectedDataIntegrityException(dve);
        throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
                "Unknown data integrity issue with resource.");
    } catch (final PersistenceException dve) {
        final Throwable cause = dve.getCause();
        if (cause.getMessage().contains("Duplicate entry")) {
            throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate",
                    "An entry already exists for datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        }

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

From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java

@Transactional
@Override// w w w. j  a v a  2  s . co  m
public CommandProcessingResult createNewDatatableEntry(final String dataTableName, final Long appTableId,
        final String json) {
    try {
        final String appTable = queryForApplicationTableName(dataTableName);
        final CommandProcessingResult commandProcessingResult = checkMainResourceExistsWithinScope(appTable,
                appTableId);

        final List<ResultsetColumnHeaderData> columnHeaders = this.genericDataService
                .fillResultsetColumnHeaders(dataTableName);

        final Type typeOfMap = new TypeToken<Map<String, String>>() {
        }.getType();
        final Map<String, String> dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, json);

        final String sql = getAddSql(columnHeaders, dataTableName, getFKField(appTable), appTableId,
                dataParams);

        this.jdbcTemplate.update(sql);

        return commandProcessingResult; //

    } catch (final DataAccessException dve) {
        final Throwable cause = dve.getCause();
        final Throwable realCause = dve.getMostSpecificCause();
        if (realCause.getMessage().contains("Duplicate entry")
                || cause.getMessage().contains("Duplicate entry")) {
            throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate",
                    "An entry already exists for datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        } else if (realCause.getMessage().contains("doesn't have a default value")
                || cause.getMessage().contains("doesn't have a default value")) {
            throw new PlatformDataIntegrityException(
                    "error.msg.datatable.no.value.provided.for.required.fields",
                    "No values provided for the datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        }

        logAsErrorUnexpectedDataIntegrityException(dve);
        throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
                "Unknown data integrity issue with resource.");
    } catch (final PersistenceException e) {
        final Throwable cause = e.getCause();
        if (cause.getMessage().contains("Duplicate entry")) {
            throw new PlatformDataIntegrityException("error.msg.datatable.entry.duplicate",
                    "An entry already exists for datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        } else if (cause.getMessage().contains("doesn't have a default value")) {
            throw new PlatformDataIntegrityException(
                    "error.msg.datatable.no.value.provided.for.required.fields",
                    "No values provided for the datatable `" + dataTableName
                            + "` and application table with identifier `" + appTableId + "`.",
                    "dataTableName", dataTableName, appTableId);
        }

        logAsErrorUnexpectedDataIntegrityException(e);
        throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue",
                "Unknown data integrity issue with resource.");

    }
}

From source file:id.ac.idu.webui.security.user.UserDialogCtrl.java

/**
 * Saves the components to table. <br>
 *
 * @throws InterruptedException/*from  w  w w .j a v  a  2  s .c o  m*/
 */
public void doSave() throws InterruptedException {

    final SecUser anUser = getUser();

    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // force validation, if on, than execute by component.getValue()
    // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if (!isValidationOn()) {
        doSetValidation();
    }

    // fill the object with the components data
    doWriteComponentsToBean(anUser);

    // validate password again
    usrPassword.getValue();
    usrPasswordRetype.getValue();

    /* if a language is selected get the object from the listbox */
    Listitem item = lbox_usrLocale.getSelectedItem();

    if (item != null) {
        ListModelList lml1 = (ListModelList) lbox_usrLocale.getListModel();
        Language lang = (Language) lml1.get(item.getIndex());
        anUser.setUsrLocale(lang.getLanLocale());
    }

    // save it to database
    try {
        getUserService().saveOrUpdate(anUser);
    } catch (DataAccessException e) {
        ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());

        // Reset to init values
        doResetInitValues();

        doReadOnly();
        btnCtrl.setBtnStatus_Save();
        return;
    }

    // now synchronize the listBox
    ListModelList lml = (ListModelList) listBoxUser.getListModel();

    // Check if the object is new or updated
    // -1 means that the obj is not in the list, so it's new.
    if (lml.indexOf(anUser) == -1) {
        lml.add(anUser);
    } else {
        lml.set(lml.indexOf(anUser), anUser);
    }

    doReadOnly();
    btnCtrl.setBtnStatus_Save();
    // init the old values vars new
    doStoreInitValues();
}

From source file:kr.co.aim.nanoframe.exception.ErrorSignal.java

public static nanoFrameDBErrorSignal getNotifyException(DataAccessException e) {
    Throwable cause = e.getMostSpecificCause();
    //      Throwable cause = e.getCause();
    if (cause != null && cause instanceof SQLException) {
        return getNotifyException((SQLException) cause, null, null);
    }//w  w  w . j a va2s.  c  o m
    return new nanoFrameDBErrorSignal(ErrorSignal.DataAccessException, e);
}

From source file:kr.co.aim.nanoframe.exception.ErrorSignal.java

public static nanoFrameDBErrorSignal getNotifyException(DataAccessException e, String sql) {
    Throwable cause = e.getMostSpecificCause();
    //      Throwable cause = e.getCause();
    if (cause != null && cause instanceof SQLException) {
        return getNotifyException((SQLException) cause, null, sql);
    }/*from  ww  w.  ja  v a 2  s  .c  o m*/
    return new nanoFrameDBErrorSignal(ErrorSignal.DataAccessException, sql, e);
}

From source file:kr.co.aim.nanoframe.exception.ErrorSignal.java

public static nanoFrameDBErrorSignal getNotifyException(DataAccessException e, String bindSet, String sql) {
    Throwable cause = e.getMostSpecificCause();
    //      Throwable cause = e.getCause();
    if (cause != null && cause instanceof SQLException) {
        return getNotifyException((SQLException) cause, bindSet, sql);
    }/*from   w  ww . j av a2 s  .co m*/
    return new nanoFrameDBErrorSignal(ErrorSignal.DataAccessException, bindSet, sql, e);
}

From source file:org.apache.fineract.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

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

    final StringBuilder errorCodeBuilder = new StringBuilder("error.msg.")
            .append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);

    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("sa_account_no_UNIQUE")) {
        final String accountNo = command.stringValueOfParameterNamed("accountNo");
        errorCodeBuilder.append(".duplicate.accountNo");
        throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
                "Savings account with accountNo " + accountNo + " already exists", "accountNo", accountNo);

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

        final String externalId = command.stringValueOfParameterNamed("externalId");
        errorCodeBuilder.append(".duplicate.externalId");
        throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
                "Savings account with externalId " + externalId + " already exists", "externalId", externalId);
    }/*www . jav a 2s .  c om*/

    errorCodeBuilder.append(".unknown.data.integrity.issue");
    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
            "Unknown data integrity issue with savings account.");
}

From source file:org.apache.fineract.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

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

    final StringBuilder errorCodeBuilder = new StringBuilder("error.msg.")
            .append(SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME);

    final Throwable realCause = dve.getMostSpecificCause();
    if (realCause.getMessage().contains("sa_account_no_UNIQUE")) {
        final String accountNo = command.stringValueOfParameterNamed("accountNo");
        errorCodeBuilder.append(".duplicate.accountNo");
        throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
                "Savings account with accountNo " + accountNo + " already exists", "accountNo", accountNo);

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

        final String externalId = command.stringValueOfParameterNamed("externalId");
        errorCodeBuilder.append(".duplicate.externalId");
        throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
                "Savings account with externalId " + externalId + " already exists", "externalId", externalId);
    }//w w  w.j  a  v  a 2  s . com

    errorCodeBuilder.append(".unknown.data.integrity.issue");
    logger.error(dve.getMessage(), dve);
    throw new PlatformDataIntegrityException(errorCodeBuilder.toString(),
            "Unknown data integrity issue with savings account.");
}

From source file:org.kuali.rice.ken.service.impl.ConcurrentJob.java

/**
 * Main processing method which invokes subclass implementations of template methods
 * to obtain available work items, and process them concurrently
 * @return a ProcessingResult object containing the results of processing
 *///from   ww w. ja  va 2s.  com
@SuppressWarnings("unchecked")
public ProcessingResult run() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] STARTING RUN");
    }

    final ProcessingResult result = new ProcessingResult();

    // retrieve list of available work items in a transaction
    Collection<T> items = null;
    try {
        items = (Collection<T>) createNewTransaction().execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus txStatus) {
                return takeAvailableWorkItems();
            }
        });
    } catch (DataAccessException dae) {
        if (dae instanceof OptimisticLockingFailureException
                || dae.contains(OptimisticLockingFailureException.class)
                || dae.contains(OptimisticLockException.class)) {
            // anticipated in the case that another thread is trying to grab items
            LOG.info("Contention while taking work items: " + dae.getMessage());
        } else {
            // in addition to logging a message, should we throw an exception or log a failure here?
            LOG.error("Error taking work items", dae);
            Throwable t = dae.getMostSpecificCause();
            if (t != null && t instanceof SQLException) {
                SQLException sqle = (SQLException) t;
                if (sqle.getErrorCode() == ORACLE_00054
                        && StringUtils.contains(sqle.getMessage(), "resource busy")) {
                    // this is expected and non-fatal given that these jobs will run again
                    LOG.warn("Select for update lock contention encountered: " + sqle.getMessage());
                } else if (sqle.getErrorCode() == ORACLE_00060
                        && StringUtils.contains(sqle.getMessage(), "deadlock detected")) {
                    // this is bad...two parties are waiting forever somewhere...
                    // database is probably wedged now :(
                    LOG.error("Select for update deadlock encountered! " + sqle.getMessage());
                }
            }
        }
        return result;
    } catch (UnexpectedRollbackException ure) {
        LOG.error("UnexpectedRollbackException", ure);
        return result;
    } catch (TransactionException te) {
        LOG.error("Error occurred obtaining available work items", te);
        result.addFailure("Error occurred obtaining available work items: " + te);
        return result;
    }

    Collection<Collection<T>> groupedWorkItems = groupWorkItems(items, result);

    // now iterate over all work groups and process each
    Iterator<Collection<T>> i = groupedWorkItems.iterator();
    List<Future> futures = new ArrayList<Future>();
    while (i.hasNext()) {
        final Collection<T> workUnit = i.next();

        LOG.info("Processing work unit: " + workUnit);
        /* performed within transaction */
        /* executor manages threads to run work items... */
        futures.add(executor.submit(new Callable() {
            public Object call() throws Exception {
                ProcessingResult result = new ProcessingResult();
                try {
                    Collection<?> successes = (Collection<Object>) createNewTransaction()
                            .execute(new TransactionCallback() {
                                public Object doInTransaction(TransactionStatus txStatus) {
                                    return processWorkItems(workUnit);
                                }
                            });
                    result.addAllSuccesses(successes);
                } catch (Exception e) {
                    LOG.error("Error occurred processing work unit " + workUnit, e);
                    for (final T workItem : workUnit) {
                        LOG.error("Error occurred processing work item " + workItem, e);
                        result.addFailure("Error occurred processing work item " + workItem + ": " + e);
                        unlockWorkItemAtomically(workItem);
                    }
                }
                return result;
            }
        }));
    }

    // wait for workers to finish
    for (Future f : futures) {
        try {
            ProcessingResult workResult = (ProcessingResult) f.get();
            result.add(workResult);
        } catch (Exception e) {
            String message = "Error obtaining work result: " + e;
            LOG.error(message, e);
            result.addFailure(message);
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("[" + new Timestamp(System.currentTimeMillis()).toString() + "] FINISHED RUN - " + result);
    }

    return result;
}