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