001/*
002 * Copyright 2002-2012 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.support;
018
019import java.io.Serializable;
020
021import org.springframework.lang.Nullable;
022import org.springframework.transaction.TransactionDefinition;
023import org.springframework.util.Assert;
024
025/**
026 * {@link TransactionDefinition} implementation that delegates all calls to a given target
027 * {@link TransactionDefinition} instance. Abstract because it is meant to be subclassed,
028 * with subclasses overriding specific methods that are not supposed to simply delegate
029 * to the target instance.
030 *
031 * @author Juergen Hoeller
032 * @since 3.0
033 */
034@SuppressWarnings("serial")
035public abstract class DelegatingTransactionDefinition implements TransactionDefinition, Serializable {
036
037        private final TransactionDefinition targetDefinition;
038
039
040        /**
041         * Create a DelegatingTransactionAttribute for the given target attribute.
042         * @param targetDefinition the target TransactionAttribute to delegate to
043         */
044        public DelegatingTransactionDefinition(TransactionDefinition targetDefinition) {
045                Assert.notNull(targetDefinition, "Target definition must not be null");
046                this.targetDefinition = targetDefinition;
047        }
048
049
050        @Override
051        public int getPropagationBehavior() {
052                return this.targetDefinition.getPropagationBehavior();
053        }
054
055        @Override
056        public int getIsolationLevel() {
057                return this.targetDefinition.getIsolationLevel();
058        }
059
060        @Override
061        public int getTimeout() {
062                return this.targetDefinition.getTimeout();
063        }
064
065        @Override
066        public boolean isReadOnly() {
067                return this.targetDefinition.isReadOnly();
068        }
069
070        @Override
071        @Nullable
072        public String getName() {
073                return this.targetDefinition.getName();
074        }
075
076
077        @Override
078        public boolean equals(@Nullable Object other) {
079                return this.targetDefinition.equals(other);
080        }
081
082        @Override
083        public int hashCode() {
084                return this.targetDefinition.hashCode();
085        }
086
087        @Override
088        public String toString() {
089                return this.targetDefinition.toString();
090        }
091
092}