01: /*
02: * Copyright 2002-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.transaction.interceptor;
18:
19: import java.io.Serializable;
20: import java.lang.reflect.Method;
21:
22: import org.springframework.util.ObjectUtils;
23:
24: /**
25: * Very simple implementation of TransactionAttributeSource which will always return
26: * the same TransactionAttribute for all methods fed to it. The TransactionAttribute
27: * may be specified, but will otherwise default to PROPAGATION_REQUIRED. This may be
28: * used in the cases where you want to use the same transaction attribute with all
29: * methods being handled by a transaction interceptor.
30: *
31: * @author Colin Sampaleanu
32: * @since 15.10.2003
33: * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
34: * @see org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
35: */
36: public class MatchAlwaysTransactionAttributeSource implements
37: TransactionAttributeSource, Serializable {
38:
39: private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();
40:
41: /**
42: * Allows a transaction attribute to be specified, using the String form, for
43: * example, "PROPAGATION_REQUIRED".
44: * @param transactionAttribute The String form of the transactionAttribute to use.
45: * @see org.springframework.transaction.interceptor.TransactionAttributeEditor
46: */
47: public void setTransactionAttribute(
48: TransactionAttribute transactionAttribute) {
49: this .transactionAttribute = transactionAttribute;
50: }
51:
52: public TransactionAttribute getTransactionAttribute(Method method,
53: Class targetClass) {
54: return this .transactionAttribute;
55: }
56:
57: public boolean equals(Object other) {
58: if (this == other) {
59: return true;
60: }
61: if (!(other instanceof MatchAlwaysTransactionAttributeSource)) {
62: return false;
63: }
64: MatchAlwaysTransactionAttributeSource otherTas = (MatchAlwaysTransactionAttributeSource) other;
65: return ObjectUtils.nullSafeEquals(this .transactionAttribute,
66: otherTas.transactionAttribute);
67: }
68:
69: public int hashCode() {
70: return MatchAlwaysTransactionAttributeSource.class.hashCode();
71: }
72:
73: public String toString() {
74: return getClass().getName() + ": " + this.transactionAttribute;
75: }
76:
77: }
|