Example usage for org.springframework.orm ObjectOptimisticLockingFailureException getMessage

List of usage examples for org.springframework.orm ObjectOptimisticLockingFailureException getMessage

Introduction

In this page you can find the example usage for org.springframework.orm ObjectOptimisticLockingFailureException 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:com.gst.portfolio.savings.api.SavingsAccountTransactionsApiResource.java

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String transaction(@PathParam("savingsId") final Long savingsId,
        @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) {
    try {/*from   ww  w.  j  av a2s .  co m*/
        final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);

        CommandProcessingResult result = null;
        if (is(commandParam, "deposit")) {
            final CommandWrapper commandRequest = builder.savingsAccountDeposit(savingsId).build();
            result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
        } else if (is(commandParam, "withdrawal")) {
            final CommandWrapper commandRequest = builder.savingsAccountWithdrawal(savingsId).build();
            result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
        } else if (is(commandParam, "postInterestAsOn")) {
            final CommandWrapper commandRequest = builder.savingsAccountInterestPosting(savingsId).build();
            result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
        }

        if (result == null) {
            //
            throw new UnrecognizedQueryParamException("command", commandParam,
                    new Object[] { "deposit", "withdrawal" });
        }

        return this.toApiJsonSerializer.serialize(result);
    } catch (ObjectOptimisticLockingFailureException lockingFailureException) {
        throw new PlatformDataIntegrityException("error.msg.savings.concurrent.operations",
                "Concurrent Transactions being made on this savings account: "
                        + lockingFailureException.getMessage());
    } catch (CannotAcquireLockException cannotAcquireLockException) {
        throw new PlatformDataIntegrityException(
                "error.msg.savings.concurrent.operations.unable.to.acquire.lock",
                "Unable to acquir lock for this transaction: " + cannotAcquireLockException.getMessage());
    }
}

From source file:aiai.ai.launchpad.experiment.ExperimentService.java

public void produceTasks(FlowInstance flowInstance, Process process, Experiment experiment,
        Map<String, List<String>> collectedInputs) {
    int totalVariants = 0;

    List<ExperimentSnippet> experimentSnippets = snippetService
            .getTaskSnippetsForExperiment(experiment.getId());
    snippetService.sortSnippetsByType(experimentSnippets);

    List<ExperimentFeature> features = experimentFeatureRepository.findByExperimentId(experiment.getId());
    for (ExperimentFeature feature : features) {
        ExperimentUtils.NumberOfVariants numberOfVariants = ExperimentUtils
                .getNumberOfVariants(feature.getResourceCodes());
        if (!numberOfVariants.status) {
            log.warn("empty list of feature, feature: {}", feature);
            continue;
        }//from   w ww . j a  v  a  2 s . c om
        List<String> inputResourceCodes = numberOfVariants.values;
        Set<String> taskParams = new LinkedHashSet<>();

        for (Task task : taskRepository.findByFlowInstanceId(flowInstance.getId())) {
            if (taskParams.contains(task.getParams())) {
                // delete doubles records
                log.warn("!!! Found doubles. ExperimentId: {}, experimentFeatureId: {}, hyperParams: {}",
                        experiment.getId(), feature.getId(), task.getParams());
                taskRepository.delete(task);
                continue;
            }
            taskParams.add(task.getParams());
        }

        final Map<String, String> map = toMap(experiment.getHyperParams(), experiment.getSeed(),
                experiment.getEpoch());
        final List<HyperParams> allHyperParams = ExperimentUtils.getAllHyperParams(map);

        // there is 2 because we have 2 types of snippets - fit and predict
        totalVariants += allHyperParams.size() * 2;

        final ExperimentUtils.NumberOfVariants ofVariants = ExperimentUtils
                .getNumberOfVariants(feature.getResourceCodes());
        final List<SimpleResourceInfo> simpleFeatureResources = Collections.unmodifiableList(
                ofVariants.values.stream().map(s -> SimpleResourceInfo.of(Enums.BinaryDataType.DATA, s))
                        .collect(Collectors.toList()));

        Map<String, Snippet> localCache = new HashMap<>();
        boolean isNew = false;
        for (HyperParams hyperParams : allHyperParams) {

            int orderAdd = 0;
            for (ExperimentSnippet experimentSnippet : experimentSnippets) {
                TaskParamYaml yaml = new TaskParamYaml();
                yaml.setHyperParams(hyperParams.toSortedMap());
                yaml.inputResourceCodes.computeIfAbsent("feature", k -> new ArrayList<>())
                        .addAll(inputResourceCodes);
                for (Map.Entry<String, List<String>> entry : collectedInputs.entrySet()) {
                    if ("feature".equals(entry.getKey())) {
                        continue;
                    }
                    Process.Meta meta = process.getMetas().stream().filter(o -> o.value.equals(entry.getKey()))
                            .findFirst().orElse(null);
                    if (meta == null) {
                        log.error("Validation of flow #{} was failed. Meta with value {} wasn't found.",
                                flowInstance.flowId, entry.getKey());
                        continue;
                    }
                    yaml.inputResourceCodes.computeIfAbsent(meta.getKey(), k -> new ArrayList<>())
                            .addAll(entry.getValue());

                }
                final SnippetVersion snippetVersion = SnippetVersion.from(experimentSnippet.getSnippetCode());
                Snippet snippet = localCache.get(experimentSnippet.getSnippetCode());
                if (snippet == null) {
                    snippet = snippetCache.findByNameAndSnippetVersion(snippetVersion.name,
                            snippetVersion.version);
                    if (snippet != null) {
                        localCache.put(experimentSnippet.getSnippetCode(), snippet);
                    }
                }
                if (snippet == null) {
                    log.warn("Snippet wasn't found for code: {}", experimentSnippet.getSnippetCode());
                    continue;
                }
                yaml.snippet = new SimpleSnippet(experimentSnippet.getType(),
                        experimentSnippet.getSnippetCode(), snippet.getFilename(), snippet.checksum,
                        snippet.env, snippet.reportMetrics, snippet.fileProvided, snippet.params);

                String currTaskParams = taskParamYamlUtils.toString(yaml);

                if (taskParams.contains(currTaskParams)) {
                    continue;
                }

                Task task = new Task();
                task.setParams(currTaskParams);
                task.setFlowInstanceId(flowInstance.getId());
                // we can just increment order here
                // because experiment is always last process in flow
                task.setOrder(process.order + (orderAdd++));
                taskRepository.save(task);
                isNew = true;
            }
        }
        if (isNew) {
            boolean isOk = false;
            for (int i = 0; i < 3; i++) {
                try {
                    ExperimentFeature f = experimentFeatureRepository.findById(feature.getId()).orElse(null);
                    if (f == null) {
                        log.error("Unexpected behaviour, feature with id {} wasn't found", feature.getId());
                        break;
                    }
                    f.setFinished(false);
                    experimentFeatureRepository.save(f);
                    isOk = true;
                    break;
                } catch (ObjectOptimisticLockingFailureException e) {
                    log.info("Feature record was changed. {}", e.getMessage());
                }
            }
            if (!isOk) {
                log.warn("The new tasks were produced but feature wasn't changed");
            }
        }
    }
    if (experiment.getNumberOfTask() != totalVariants && experiment.getNumberOfTask() != 0) {
        log.warn("! Number of sequence is different. experiment.getNumberOfTask(): {}, totalVariants: {}",
                experiment.getNumberOfTask(), totalVariants);
    }
    Experiment experimentTemp = experimentCache.findById(experiment.getId());
    if (experimentTemp == null) {
        log.warn("Experiment for id {} doesn't exist anymore", experiment.getId());
        return;
    }
    experimentTemp.setNumberOfTask(totalVariants);
    experimentTemp.setAllTaskProduced(true);
    experimentTemp = experimentCache.save(experimentTemp);
}

From source file:org.apache.fineract.portfolio.savings.api.SavingsAccountTransactionsApiResource.java

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String transaction(@PathParam("savingsId") final Long savingsId,
        @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) {
    try {//from w w  w . j a v  a 2s . c  o m
        final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);

        CommandProcessingResult result = null;
        if (is(commandParam, "deposit")) {
            final CommandWrapper commandRequest = builder.savingsAccountDeposit(savingsId).build();
            result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
        } else if (is(commandParam, "withdrawal")) {
            final CommandWrapper commandRequest = builder.savingsAccountWithdrawal(savingsId).build();
            result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
        }

        if (result == null) {
            //
            throw new UnrecognizedQueryParamException("command", commandParam,
                    new Object[] { "deposit", "withdrawal" });
        }

        return this.toApiJsonSerializer.serialize(result);
    } catch (ObjectOptimisticLockingFailureException lockingFailureException) {
        throw new PlatformDataIntegrityException("error.msg.savings.concurrent.operations",
                "Concurrent Transactions being made on this savings account: "
                        + lockingFailureException.getMessage());
    } catch (CannotAcquireLockException cannotAcquireLockException) {
        throw new PlatformDataIntegrityException(
                "error.msg.savings.concurrent.operations.unable.to.acquire.lock",
                "Unable to acquir lock for this transaction: " + cannotAcquireLockException.getMessage());
    }
}