001/* 002 * Copyright 2015-2022 Transmogrify LLC, 2022-2026 Revetware LLC. 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 * http://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 com.pyranid; 018 019import org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.NotThreadSafe; 022 023import static java.lang.String.format; 024import static java.util.Objects.requireNonNull; 025 026/** 027 * Thrown when a post-transaction operation fails. 028 * <p> 029 * The {@link #getTransactionResult()} value describes how the transaction completed before the post-transaction operation 030 * failed. For example, {@link TransactionResult#COMMITTED} means the transaction commit completed successfully, even though 031 * a post-transaction operation failed afterwards. 032 * 033 * @author <a href="https://www.revetkn.com">Mark Allen</a> 034 * @since 4.2.0 035 */ 036@NotThreadSafe 037public class PostTransactionOperationException extends RuntimeException { 038 @NonNull 039 private final TransactionResult transactionResult; 040 041 /** 042 * Creates a {@code PostTransactionOperationException} for a failed post-transaction operation. 043 * 044 * @param transactionResult the transaction result supplied to the failed post-transaction operation 045 * @param cause the post-transaction operation failure 046 */ 047 public PostTransactionOperationException(@NonNull TransactionResult transactionResult, 048 @NonNull Throwable cause) { 049 super(format("Post-transaction operation failed after transaction result %s", requireNonNull(transactionResult)), 050 requireNonNull(cause)); 051 052 this.transactionResult = transactionResult; 053 } 054 055 /** 056 * @return the transaction result supplied to the failed post-transaction operation 057 */ 058 @NonNull 059 public TransactionResult getTransactionResult() { 060 return this.transactionResult; 061 } 062}