2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.common.api.data;
10 import java.util.Arrays;
11 import java.util.List;
13 import org.opendaylight.yangtools.yang.common.RpcError;
14 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
15 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
17 import com.google.common.collect.ImmutableList;
21 * Failed commit of asynchronous transaction
23 * This exception is raised and returned when transaction commit
27 public class TransactionCommitFailedException extends Exception {
29 private static final long serialVersionUID = 1L;
31 private final List<RpcError> errorList;
33 public TransactionCommitFailedException(final String message, final RpcError... errors) {
34 this(message, null, errors);
37 public TransactionCommitFailedException(final String message, final Throwable cause,
38 final RpcError... errors) {
39 super(message, cause);
41 if( errors != null && errors.length > 0 ) {
42 errorList = ImmutableList.<RpcError>builder().addAll( Arrays.asList( errors ) ).build();
45 // Add a default RpcError.
46 errorList = ImmutableList.of(RpcResultBuilder.newError(ErrorType.APPLICATION, null,
47 getMessage(), null, null, getCause()));
52 * Returns additional error information about this exception.
54 * @return a List of RpcErrors. There is always at least one RpcError.
56 public List<RpcError> getErrorList() {
61 public String getMessage() {
62 return new StringBuilder( super.getMessage() ).append(", errors: ").append( errorList ).toString();