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:com.gst.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override// w w  w .j  a  va 2  s.com
public CommandProcessingResult submitApplication(final JsonCommand command) {
    try {
        this.savingsAccountDataValidator.validateForSubmit(command.json());
        final AppUser submittedBy = this.context.authenticatedUser();

        final SavingsAccount account = this.savingAccountAssembler.assembleFrom(command, submittedBy);
        this.savingAccountRepository.save(account);

        generateAccountNumber(account);

        final Long savingsId = account.getId();
        if (command.parameterExists(SavingsApiConstants.datatables)) {
            this.entityDatatableChecksWritePlatformService.saveDatatables(
                    StatusEnum.CREATE.getCode().longValue(), EntityTables.SAVING.getName(), savingsId,
                    account.productId(), command.arrayOfParameterNamed(SavingsApiConstants.datatables));
        }
        this.entityDatatableChecksWritePlatformService.runTheCheckForProduct(savingsId,
                EntityTables.SAVING.getName(), StatusEnum.CREATE.getCode().longValue(),
                EntityTables.SAVING.getForeignKeyColumnNameOnDatatable(), account.productId());

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(savingsId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(savingsId) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:de.forsthaus.webui.security.groupright.AddGrouprightDialogCtrl.java

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

    if (textbox_AddGroupRightDialog_GroupName.getValue().isEmpty()) {
        return;
    } else if (textbox_AddGroupRightDialog_RightName.getValue().isEmpty()) {
        return;
    }

    SecGroupright groupRight = getSecurityService().getNewSecGroupright();
    groupRight.setSecGroup(getGroup());
    groupRight.setSecRight(getRight());

    /* check if already in table */
    SecGroupright gr = getSecurityService().getGroupRightByGroupAndRight(getGroup(), getRight());

    if (gr == null) {

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

            btnCtrl.setBtnStatus_Save();
        }

    }

    btnCtrl.setBtnStatus_Save();

}

From source file:com.gst.portfolio.savings.service.SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//from w w w  .  j av a 2  s  .  co  m
public CommandProcessingResult modifyApplication(final Long savingsId, final JsonCommand command) {
    try {
        this.savingsAccountDataValidator.validateForUpdate(command.json());

        final Map<String, Object> changes = new LinkedHashMap<>(20);

        final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId);
        checkClientOrGroupActive(account);
        account.modifyApplication(command, changes);
        account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(), SAVINGS_ACCOUNT_RESOURCE_NAME);
        account.validateAccountValuesWithProduct();

        if (!changes.isEmpty()) {

            if (changes.containsKey(SavingsApiConstants.clientIdParamName)) {
                final Long clientId = command.longValueOfParameterNamed(SavingsApiConstants.clientIdParamName);
                if (clientId != null) {
                    final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
                    if (client.isNotActive()) {
                        throw new ClientNotActiveException(clientId);
                    }
                    account.update(client);
                } else {
                    final Client client = null;
                    account.update(client);
                }
            }

            if (changes.containsKey(SavingsApiConstants.groupIdParamName)) {
                final Long groupId = command.longValueOfParameterNamed(SavingsApiConstants.groupIdParamName);
                if (groupId != null) {
                    final Group group = this.groupRepository.findOne(groupId);
                    if (group == null) {
                        throw new GroupNotFoundException(groupId);
                    }
                    if (group.isNotActive()) {
                        if (group.isCenter()) {
                            throw new CenterNotActiveException(groupId);
                        }
                        throw new GroupNotActiveException(groupId);
                    }
                    account.update(group);
                } else {
                    final Group group = null;
                    account.update(group);
                }
            }

            if (changes.containsKey(SavingsApiConstants.productIdParamName)) {
                final Long productId = command
                        .longValueOfParameterNamed(SavingsApiConstants.productIdParamName);
                final SavingsProduct product = this.savingsProductRepository.findOne(productId);
                if (product == null) {
                    throw new SavingsProductNotFoundException(productId);
                }

                account.update(product);
            }

            if (changes.containsKey(SavingsApiConstants.fieldOfficerIdParamName)) {
                final Long fieldOfficerId = command
                        .longValueOfParameterNamed(SavingsApiConstants.fieldOfficerIdParamName);
                Staff fieldOfficer = null;
                if (fieldOfficerId != null) {
                    fieldOfficer = this.staffRepository.findOneWithNotFoundDetection(fieldOfficerId);
                } else {
                    changes.put(SavingsApiConstants.fieldOfficerIdParamName, "");
                }
                account.update(fieldOfficer);
            }

            if (changes.containsKey("charges")) {
                final Set<SavingsAccountCharge> charges = this.savingsAccountChargeAssembler
                        .fromParsedJson(command.parsedJson(), account.getCurrency().getCode());
                final boolean updated = account.update(charges);
                if (!updated) {
                    changes.remove("charges");
                }
            }

            this.savingAccountRepository.saveAndFlush(account);
        }

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(savingsId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(savingsId) //
                .with(changes) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return new CommandProcessingResult(Long.valueOf(-1));
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:de.forsthaus.webui.security.group.SecGroupDialogCtrl.java

/**
 * Saves the components to table. <br>
 * // ww  w . jav a 2 s.  com
 * @throws InterruptedException
 */
public void doSave() throws InterruptedException {

    final SecGroup aGroup = getGroup();

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

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

    // save it to database
    try {
        getSecurityService().saveOrUpdate(aGroup);
    } 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) listBoxSecGroups.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(aGroup) == -1) {
        lml.add(aGroup);
    } else {
        lml.set(lml.indexOf(aGroup), aGroup);
    }

    doReadOnly();
    btnCtrl.setBtnStatus_Save();

    // init the old values vars new
    doStoreInitValues();
}

From source file:de.forsthaus.webui.security.role.SecRoleDialogCtrl.java

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

    final SecRole aRole = getRole();

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

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

    // save it to database
    try {
        getSecurityService().saveOrUpdate(aRole);
    } 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) listBoxSecRoles.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(aRole) == -1) {
        lml.add(aRole);
    } else {
        lml.set(lml.indexOf(aRole), aRole);
    }

    doReadOnly();
    btnCtrl.setBtnStatus_Save();

    // init the old values vars new
    doStoreInitValues();
}

From source file:de.forsthaus.webui.guestbook.GuestBookDialogCtrl.java

/**
 * Saves the components to table. <br>
 * //from  w  w  w .j a v a2  s .com
 * @throws InterruptedException
 */
@Secured({ btnCtroller_ClassPrefix + "btnSave" })
public void doSave() throws InterruptedException {
    System.out.println("doSave");

    GuestBook aGuestBook = getGuestBook();

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

    // fill the objects with the components data
    doWriteComponentsToBean(aGuestBook);

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

        // Reset to init values
        doResetInitValues();

        doReadOnly();
        // manually settings
        // btnCtrl.setBtnStatus_Save();
        btnSave.setVisible(false);
        // btnCancel.setVisible(false);
        btnClose.setVisible(true);

        return;
    }

    // now synchronize the branches listBox
    ListModelList lml = (ListModelList) this.listbox_GuestBookList.getListModel();

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

    doReadOnly();

    // manually settings
    // btnCtrl.setBtnStatus_Save();

    // init the old values vars new
    doStoreInitValues();

    btnSave.setVisible(false);
    // btnCancel.setVisible(false);
    btnClose.setVisible(true);
}

From source file:de.forsthaus.webui.security.groupright.SecGrouprightCtrl.java

/**
 * doSave(). This method saves the status of the checkboxed right-item.<br>
 * <br>/*ww w . j  a v a 2  s .  co  m*/
 * 1. we iterate over all items in the listbox <br>
 * 2. for each 'checked item' we must check if it is 'newly' checked <br>
 * 3. if newly than get a new object first and <b>save</b> it to DB. <br>
 * 4. for each 'unchecked item' we must check if it newly unchecked <br>
 * 5. if newly unchecked we must <b>delete</b> this item from DB. <br>
 * 
 * @throws InterruptedException
 */
@SuppressWarnings("unchecked")
public void doSave() throws InterruptedException {

    List<Listitem> li = null;

    if (tab_SecGroupRight_AllRights.isSelected()) {
        li = listBoxSecGroupRight.getItems();

    } else if (tab_SecGroupRight_Details.isSelected()) {
        li = listBoxSecGroupRight_Details.getItems();

    }

    for (Listitem listitem : li) {

        Listcell lc = (Listcell) listitem.getFirstChild();
        Checkbox cb = (Checkbox) lc.getFirstChild();

        if (cb != null) {

            if (cb.isChecked() == true) {

                // Get the object by casting
                SecRight right = (SecRight) listitem.getAttribute("data");
                // get the group
                SecGroup group = getSelectedGroup();

                // check if the item is newly checked. If so we cannot found
                // it in the SecGroupRight-table
                SecGroupright groupRight = getSecurityService().getGroupRightByGroupAndRight(group, right);

                // if new, we make a newly Object
                if (groupRight == null) {
                    groupRight = getSecurityService().getNewSecGroupright();
                    groupRight.setSecGroup(group);
                    groupRight.setSecRight(right);
                }

                // save to DB
                try {
                    getSecurityService().saveOrUpdate(groupRight);
                } catch (DataAccessException e) {
                    ZksampleMessageUtils.showErrorMessage(e.getMostSpecificCause().toString());
                }

            } else if (cb.isChecked() == false) {

                // Get the object by casting
                SecRight right = (SecRight) listitem.getAttribute("data");
                // get the group
                SecGroup group = getSelectedGroup();

                // check if the item is newly unChecked. If so we must found
                // it in the SecGroupRight-table
                SecGroupright groupRight = getSecurityService().getGroupRightByGroupAndRight(group, right);

                if (groupRight != null) {
                    // delete from DB
                    getSecurityService().delete(groupRight);
                }
            }
        }
    }

}

From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override/*from w  ww .  j  a v  a2 s.co m*/
public CommandProcessingResult submitRDApplication(final JsonCommand command) {
    try {
        this.depositAccountDataValidator.validateRecurringDepositForSubmit(command.json());
        final AppUser submittedBy = this.context.authenticatedUser();

        final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                .isSavingsInterestPostingAtCurrentPeriodEnd();
        final Integer financialYearBeginningMonth = this.configurationDomainService
                .retrieveFinancialYearBeginningMonth();

        final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
                .assembleFrom(command, submittedBy, DepositAccountType.RECURRING_DEPOSIT);

        this.recurringDepositAccountRepository.save(account);

        if (account.isAccountNumberRequiresAutoGeneration()) {
            final AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository
                    .findByAccountType(EntityAccountType.SAVINGS);
            account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat));
        }

        final Long savingsId = account.getId();
        final CalendarInstance calendarInstance = getCalendarInstance(command, account);
        this.calendarInstanceRepository.save(calendarInstance);

        // FIXME: Avoid save separately (Calendar instance requires account
        // details)
        final MathContext mc = MathContext.DECIMAL64;
        final Calendar calendar = calendarInstance.getCalendar();
        final PeriodFrequencyType frequencyType = CalendarFrequencyType
                .from(CalendarUtils.getFrequency(calendar.getRecurrence()));
        Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
        frequency = frequency == -1 ? 1 : frequency;
        account.generateSchedule(frequencyType, frequency, calendar);
        final boolean isPreMatureClosure = false;
        account.updateMaturityDateAndAmount(mc, isPreMatureClosure, isSavingsInterestPostingAtCurrentPeriodEnd,
                financialYearBeginningMonth);
        account.validateApplicableInterestRate();
        this.savingAccountRepository.save(account);

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(savingsId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(savingsId) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//from w  w  w  .  j a v  a2  s . co  m
public CommandProcessingResult submitFDApplication(final JsonCommand command) {
    try {
        this.depositAccountDataValidator.validateFixedDepositForSubmit(command.json());
        final AppUser submittedBy = this.context.authenticatedUser();

        final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                .isSavingsInterestPostingAtCurrentPeriodEnd();
        final Integer financialYearBeginningMonth = this.configurationDomainService
                .retrieveFinancialYearBeginningMonth();

        final FixedDepositAccount account = (FixedDepositAccount) this.depositAccountAssembler
                .assembleFrom(command, submittedBy, DepositAccountType.FIXED_DEPOSIT);

        final MathContext mc = MathContext.DECIMAL64;
        final boolean isPreMatureClosure = false;

        account.updateMaturityDateAndAmountBeforeAccountActivation(mc, isPreMatureClosure,
                isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
        this.fixedDepositAccountRepository.save(account);

        if (account.isAccountNumberRequiresAutoGeneration()) {
            AccountNumberFormat accountNumberFormat = this.accountNumberFormatRepository
                    .findByAccountType(EntityAccountType.CLIENT);
            account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat));

            this.savingAccountRepository.save(account);
        }

        // Save linked account information
        final Long savingsAccountId = command
                .longValueOfParameterNamed(DepositsApiConstants.linkedAccountParamName);
        if (savingsAccountId != null) {
            final SavingsAccount savingsAccount = this.depositAccountAssembler.assembleFrom(savingsAccountId,
                    DepositAccountType.SAVINGS_DEPOSIT);
            this.depositAccountDataValidator.validatelinkedSavingsAccount(savingsAccount, account);
            boolean isActive = true;
            final AccountAssociations accountAssociations = AccountAssociations.associateSavingsAccount(account,
                    savingsAccount, AccountAssociationType.LINKED_ACCOUNT_ASSOCIATION.getValue(), isActive);
            this.accountAssociationsRepository.save(accountAssociations);
        }

        final Long savingsId = account.getId();

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(savingsId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(savingsId) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return CommandProcessingResult.empty();
    }
}

From source file:com.gst.portfolio.savings.service.DepositApplicationProcessWritePlatformServiceJpaRepositoryImpl.java

@Transactional
@Override//  w  w w . ja v a  2s .c  o m
public CommandProcessingResult modifyRDApplication(final Long accountId, final JsonCommand command) {
    try {
        this.depositAccountDataValidator.validateRecurringDepositForUpdate(command.json());

        final boolean isSavingsInterestPostingAtCurrentPeriodEnd = this.configurationDomainService
                .isSavingsInterestPostingAtCurrentPeriodEnd();
        final Integer financialYearBeginningMonth = this.configurationDomainService
                .retrieveFinancialYearBeginningMonth();

        final Map<String, Object> changes = new LinkedHashMap<>(20);

        final RecurringDepositAccount account = (RecurringDepositAccount) this.depositAccountAssembler
                .assembleFrom(accountId, DepositAccountType.RECURRING_DEPOSIT);
        checkClientOrGroupActive(account);
        account.modifyApplication(command, changes);
        account.validateNewApplicationState(DateUtils.getLocalDateOfTenant(),
                DepositAccountType.RECURRING_DEPOSIT.resourceName());

        if (!changes.isEmpty()) {
            updateFDAndRDCommonChanges(changes, command, account);
            final MathContext mc = MathContext.DECIMAL64;
            final CalendarInstance calendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId,
                            CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());
            final Calendar calendar = calendarInstance.getCalendar();
            final PeriodFrequencyType frequencyType = CalendarFrequencyType
                    .from(CalendarUtils.getFrequency(calendar.getRecurrence()));
            Integer frequency = CalendarUtils.getInterval(calendar.getRecurrence());
            frequency = frequency == -1 ? 1 : frequency;
            account.generateSchedule(frequencyType, frequency, calendar);
            final boolean isPreMatureClosure = false;
            account.updateMaturityDateAndAmount(mc, isPreMatureClosure,
                    isSavingsInterestPostingAtCurrentPeriodEnd, financialYearBeginningMonth);
            account.validateApplicableInterestRate();
            this.savingAccountRepository.save(account);

        }

        // update calendar details
        if (!account.isCalendarInherited()) {
            final LocalDate calendarStartDate = account.depositStartDate();
            final Integer frequencyType = command
                    .integerValueSansLocaleOfParameterNamed(recurringFrequencyTypeParamName);
            final PeriodFrequencyType periodFrequencyType = PeriodFrequencyType.fromInt(frequencyType);
            final Integer frequency = command
                    .integerValueSansLocaleOfParameterNamed(recurringFrequencyParamName);
            final Integer repeatsOnDay = calendarStartDate.getDayOfWeek();

            CalendarInstance calendarInstance = this.calendarInstanceRepository
                    .findByEntityIdAndEntityTypeIdAndCalendarTypeId(accountId,
                            CalendarEntityType.SAVINGS.getValue(), CalendarType.COLLECTION.getValue());
            Calendar calendar = calendarInstance.getCalendar();
            calendar.updateRepeatingCalendar(calendarStartDate, CalendarFrequencyType.from(periodFrequencyType),
                    frequency, repeatsOnDay, null);
            this.calendarInstanceRepository.save(calendarInstance);
        }

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withEntityId(accountId) //
                .withOfficeId(account.officeId()) //
                .withClientId(account.clientId()) //
                .withGroupId(account.groupId()) //
                .withSavingsId(accountId) //
                .with(changes) //
                .build();
    } catch (final DataAccessException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return new CommandProcessingResult(Long.valueOf(-1));
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleDataIntegrityIssues(command, throwable, dve);
        return new CommandProcessingResult(Long.valueOf(-1));
    }
}