1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.transaction;
  17. /**
  18. * Exception that represents a transaction failure caused by heuristics.
  19. * @author Rod Johnson
  20. * @author Juergen Hoeller
  21. * @since 17-Mar-2003
  22. * @version $Revision: 1.2 $
  23. */
  24. public class HeuristicCompletionException extends TransactionException {
  25. /**
  26. * Values for the outcome state of a heuristically completed transaction.
  27. */
  28. public static final int STATE_UNKNOWN = 0;
  29. public static final int STATE_COMMITTED = 1;
  30. public static final int STATE_ROLLED_BACK = 2;
  31. public static final int STATE_MIXED = 3;
  32. /**
  33. * The outcome state of the transaction: have some or all resources been committed?
  34. */
  35. private int outcomeState = STATE_UNKNOWN;
  36. public static String getStateString(int state) {
  37. switch (state) {
  38. case STATE_COMMITTED:
  39. return "committed";
  40. case STATE_ROLLED_BACK:
  41. return "rolled back";
  42. case STATE_MIXED:
  43. return "mixed";
  44. default:
  45. return "unknown";
  46. }
  47. }
  48. public HeuristicCompletionException(int outcomeState, Throwable ex) {
  49. super("Heuristic completion: outcome state is " + getStateString(outcomeState), ex);
  50. this.outcomeState = outcomeState;
  51. }
  52. public int getOutcomeState() {
  53. return outcomeState;
  54. }
  55. }