import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import java.util.function.Supplier;
public class TAssert {
public static boolean notEquals(int expectedSize, int actualSize) {
return actualSize != expectedSize;
}
public static void throwsIfNotEquals(int expectedSize, int actualSize, String message) {
if (notEquals(expectedSize, actualSize))
throw new DataRetrievalFailureException(message);
}
public static <T extends RuntimeException> void throwsIfNotEquals(int expectedSize, int actualSize, Supplier<T> exceptionSupplier) {
if (notEquals(expectedSize, actualSize))
throw exceptionSupplier.get();
}
public static void throwsIfNotEquals(int expectedSize, int actualSize) {
if (notEquals(expectedSize, actualSize))
throw new IncorrectResultSizeDataAccessException(expectedSize, expectedSize);
}
public static boolean rollBackIfNotEquals(int expectedSize, int actualSize) {
if (notEquals(expectedSize, actualSize)) {
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return true;
}
return false;
}
}