001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.transaction; 018 019/** 020 * Exception that represents a transaction failure caused by a heuristic 021 * decision on the side of the transaction coordinator. 022 * 023 * @author Rod Johnson 024 * @author Juergen Hoeller 025 * @since 17.03.2003 026 */ 027@SuppressWarnings("serial") 028public class HeuristicCompletionException extends TransactionException { 029 030 /** 031 * Unknown outcome state. 032 */ 033 public static final int STATE_UNKNOWN = 0; 034 035 /** 036 * Committed outcome state. 037 */ 038 public static final int STATE_COMMITTED = 1; 039 040 /** 041 * Rolledback outcome state. 042 */ 043 public static final int STATE_ROLLED_BACK = 2; 044 045 /** 046 * Mixed outcome state. 047 */ 048 public static final int STATE_MIXED = 3; 049 050 051 public static String getStateString(int state) { 052 switch (state) { 053 case STATE_COMMITTED: 054 return "committed"; 055 case STATE_ROLLED_BACK: 056 return "rolled back"; 057 case STATE_MIXED: 058 return "mixed"; 059 default: 060 return "unknown"; 061 } 062 } 063 064 065 /** 066 * The outcome state of the transaction: have some or all resources been committed? 067 */ 068 private final int outcomeState; 069 070 071 /** 072 * Constructor for HeuristicCompletionException. 073 * @param outcomeState the outcome state of the transaction 074 * @param cause the root cause from the transaction API in use 075 */ 076 public HeuristicCompletionException(int outcomeState, Throwable cause) { 077 super("Heuristic completion: outcome state is " + getStateString(outcomeState), cause); 078 this.outcomeState = outcomeState; 079 } 080 081 /** 082 * Return the outcome state of the transaction state, 083 * as one of the constants in this class. 084 * @see #STATE_UNKNOWN 085 * @see #STATE_COMMITTED 086 * @see #STATE_ROLLED_BACK 087 * @see #STATE_MIXED 088 */ 089 public int getOutcomeState() { 090 return this.outcomeState; 091 } 092 093}