001/*
002 * Copyright 2002-2016 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.cache.interceptor;
018
019/**
020 * Abstract the invocation of a cache operation.
021 *
022 * <p>Does not provide a way to transmit checked exceptions but
023 * provide a special exception that should be used to wrap any
024 * exception that was thrown by the underlying invocation.
025 * Callers are expected to handle this issue type specifically.
026 *
027 * @author Stephane Nicoll
028 * @since 4.1
029 */
030public interface CacheOperationInvoker {
031
032        /**
033         * Invoke the cache operation defined by this instance. Wraps any exception
034         * that is thrown during the invocation in a {@link ThrowableWrapper}.
035         * @return the result of the operation
036         * @throws ThrowableWrapper if an error occurred while invoking the operation
037         */
038        Object invoke() throws ThrowableWrapper;
039
040
041        /**
042         * Wrap any exception thrown while invoking {@link #invoke()}.
043         */
044        @SuppressWarnings("serial")
045        class ThrowableWrapper extends RuntimeException {
046
047                private final Throwable original;
048
049                public ThrowableWrapper(Throwable original) {
050                        super(original.getMessage(), original);
051                        this.original = original;
052                }
053
054                public Throwable getOriginal() {
055                        return this.original;
056                }
057        }
058
059}