Java 5 code style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.springframework.dao.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Implementation of PersistenceExceptionTranslator that supports chaining,
|
||||
* Implementation of {@link PersistenceExceptionTranslator} that supports chaining,
|
||||
* allowing the addition of PersistenceExceptionTranslator instances in order.
|
||||
* Returns <code>non-null</code> on the first (if any) match.
|
||||
*
|
||||
@@ -35,7 +34,7 @@ import org.springframework.util.Assert;
|
||||
public class ChainedPersistenceExceptionTranslator implements PersistenceExceptionTranslator {
|
||||
|
||||
/** List of PersistenceExceptionTranslators */
|
||||
private final List delegates = new ArrayList(4);
|
||||
private final List<PersistenceExceptionTranslator> delegates = new ArrayList<PersistenceExceptionTranslator>(4);
|
||||
|
||||
|
||||
/**
|
||||
@@ -50,18 +49,18 @@ public class ChainedPersistenceExceptionTranslator implements PersistenceExcepti
|
||||
* Return all registered PersistenceExceptionTranslator delegates (as array).
|
||||
*/
|
||||
public final PersistenceExceptionTranslator[] getDelegates() {
|
||||
return (PersistenceExceptionTranslator[])
|
||||
this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]);
|
||||
return this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]);
|
||||
}
|
||||
|
||||
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||
DataAccessException translatedDex = null;
|
||||
for (Iterator it = this.delegates.iterator(); translatedDex == null && it.hasNext(); ) {
|
||||
PersistenceExceptionTranslator pet = (PersistenceExceptionTranslator) it.next();
|
||||
translatedDex = pet.translateExceptionIfPossible(ex);
|
||||
for (PersistenceExceptionTranslator pet : this.delegates) {
|
||||
DataAccessException translatedDex = pet.translateExceptionIfPossible(ex);
|
||||
if (translatedDex != null) {
|
||||
return translatedDex;
|
||||
}
|
||||
}
|
||||
return translatedDex;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.dao.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
@@ -119,15 +118,15 @@ public class PersistenceExceptionTranslationInterceptor
|
||||
*/
|
||||
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
|
||||
// Find all translators, being careful not to activate FactoryBeans.
|
||||
Map pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
|
||||
beanFactory, PersistenceExceptionTranslator.class, false, false);
|
||||
if (pets.isEmpty()) {
|
||||
throw new IllegalStateException(
|
||||
"No persistence exception translators found in bean factory. Cannot perform exception translation.");
|
||||
}
|
||||
ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
|
||||
for (Iterator it = pets.values().iterator(); it.hasNext();) {
|
||||
cpet.addDelegate((PersistenceExceptionTranslator) it.next());
|
||||
for (PersistenceExceptionTranslator pet : pets.values()) {
|
||||
cpet.addDelegate(pet);
|
||||
}
|
||||
return cpet;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.transaction.interceptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class MethodMapTransactionAttributeSource
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
/** Map from method name to attribute value */
|
||||
private Map methodMap;
|
||||
private Map<String, TransactionAttribute> methodMap;
|
||||
|
||||
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
|
||||
|
||||
@@ -59,10 +58,11 @@ public class MethodMapTransactionAttributeSource
|
||||
private boolean initialized = false;
|
||||
|
||||
/** Map from Method to TransactionAttribute */
|
||||
private final Map transactionAttributeMap = new HashMap();
|
||||
private final Map<Method, TransactionAttribute> transactionAttributeMap =
|
||||
new HashMap<Method, TransactionAttribute>();
|
||||
|
||||
/** Map from Method to name pattern used for registration */
|
||||
private final Map methodNameMap = new HashMap();
|
||||
private final Map<Method, String> methodNameMap = new HashMap<Method, String>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -77,7 +77,7 @@ public class MethodMapTransactionAttributeSource
|
||||
* @see TransactionAttribute
|
||||
* @see TransactionAttributeEditor
|
||||
*/
|
||||
public void setMethodMap(Map methodMap) {
|
||||
public void setMethodMap(Map<String, TransactionAttribute> methodMap) {
|
||||
this.methodMap = methodMap;
|
||||
}
|
||||
|
||||
@@ -100,35 +100,12 @@ public class MethodMapTransactionAttributeSource
|
||||
/**
|
||||
* Initialize the specified {@link #setMethodMap(java.util.Map) "methodMap"}, if any.
|
||||
* @param methodMap Map from method names to <code>TransactionAttribute</code> instances
|
||||
* (or Strings to be converted to <code>TransactionAttribute</code> instances)
|
||||
* @see #setMethodMap
|
||||
*/
|
||||
protected void initMethodMap(Map methodMap) {
|
||||
protected void initMethodMap(Map<String, TransactionAttribute> methodMap) {
|
||||
if (methodMap != null) {
|
||||
Iterator it = methodMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Object key = entry.getKey();
|
||||
if (!(key instanceof String)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid method map key [" + key + "]: only Strings allowed");
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
// Check whether we need to convert from String to TransactionAttribute.
|
||||
TransactionAttribute attr = null;
|
||||
if (value instanceof TransactionAttribute) {
|
||||
attr = (TransactionAttribute) value;
|
||||
}
|
||||
else if (value instanceof String) {
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.setAsText((String) value);
|
||||
attr = (TransactionAttribute) editor.getValue();
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Value [" + value + "] is neither of type [" +
|
||||
TransactionAttribute.class.getName() + "] nor a String");
|
||||
}
|
||||
addTransactionalMethod((String) key, attr);
|
||||
for (Map.Entry<String, TransactionAttribute> entry : methodMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,14 +142,11 @@ public class MethodMapTransactionAttributeSource
|
||||
Assert.notNull(mappedName, "Mapped name must not be null");
|
||||
String name = clazz.getName() + '.' + mappedName;
|
||||
|
||||
// TODO address method overloading? At present this will
|
||||
// simply match all methods that have the given name.
|
||||
// Consider EJB syntax (int, String) etc.?
|
||||
Method[] methods = clazz.getDeclaredMethods();
|
||||
List matchingMethods = new ArrayList();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (isMatch(methods[i].getName(), mappedName)) {
|
||||
matchingMethods.add(methods[i]);
|
||||
List<Method> matchingMethods = new ArrayList<Method>();
|
||||
for (Method method : methods) {
|
||||
if (isMatch(method.getName(), mappedName)) {
|
||||
matchingMethods.add(method);
|
||||
}
|
||||
}
|
||||
if (matchingMethods.isEmpty()) {
|
||||
@@ -181,9 +155,8 @@ public class MethodMapTransactionAttributeSource
|
||||
}
|
||||
|
||||
// register all matching methods
|
||||
for (Iterator it = matchingMethods.iterator(); it.hasNext();) {
|
||||
Method method = (Method) it.next();
|
||||
String regMethodName = (String) this.methodNameMap.get(method);
|
||||
for (Method method : matchingMethods) {
|
||||
String regMethodName = this.methodNameMap.get(method);
|
||||
if (regMethodName == null || (!regMethodName.equals(name) && regMethodName.length() <= name.length())) {
|
||||
// No already registered method name, or more specific
|
||||
// method name specification now -> (re-)register method.
|
||||
@@ -195,7 +168,7 @@ public class MethodMapTransactionAttributeSource
|
||||
addTransactionalMethod(method, attr);
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled() && regMethodName != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Keeping attribute for transactional method [" + method + "]: current name '" +
|
||||
name + "' is not more specific than '" + regMethodName + "'");
|
||||
}
|
||||
@@ -233,7 +206,7 @@ public class MethodMapTransactionAttributeSource
|
||||
|
||||
public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
|
||||
if (this.eagerlyInitialized) {
|
||||
return (TransactionAttribute) this.transactionAttributeMap.get(method);
|
||||
return this.transactionAttributeMap.get(method);
|
||||
}
|
||||
else {
|
||||
synchronized (this.transactionAttributeMap) {
|
||||
@@ -241,7 +214,7 @@ public class MethodMapTransactionAttributeSource
|
||||
initMethodMap(this.methodMap);
|
||||
this.initialized = true;
|
||||
}
|
||||
return (TransactionAttribute) this.transactionAttributeMap.get(method);
|
||||
return this.transactionAttributeMap.get(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
protected static final Log logger = LogFactory.getLog(NameMatchTransactionAttributeSource.class);
|
||||
|
||||
/** Keys are method names; values are TransactionAttributes */
|
||||
private Map nameMap = new HashMap();
|
||||
private Map<String, TransactionAttribute> nameMap = new HashMap<String, TransactionAttribute>();
|
||||
|
||||
|
||||
/**
|
||||
@@ -57,24 +57,9 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
* @see TransactionAttribute
|
||||
* @see TransactionAttributeEditor
|
||||
*/
|
||||
public void setNameMap(Map nameMap) {
|
||||
Iterator it = nameMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
String name = (String) entry.getKey();
|
||||
|
||||
// Check whether we need to convert from String to TransactionAttribute.
|
||||
TransactionAttribute attr = null;
|
||||
if (entry.getValue() instanceof TransactionAttribute) {
|
||||
attr = (TransactionAttribute) entry.getValue();
|
||||
}
|
||||
else {
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.setAsText(entry.getValue().toString());
|
||||
attr = (TransactionAttribute) editor.getValue();
|
||||
}
|
||||
|
||||
addTransactionalMethod(name, attr);
|
||||
public void setNameMap(Map<String, TransactionAttribute> nameMap) {
|
||||
for (Map.Entry<String, TransactionAttribute> entry : nameMap.entrySet()) {
|
||||
addTransactionalMethod(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +72,9 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
*/
|
||||
public void setProperties(Properties transactionAttributes) {
|
||||
TransactionAttributeEditor tae = new TransactionAttributeEditor();
|
||||
for (Iterator it = transactionAttributes.keySet().iterator(); it.hasNext(); ) {
|
||||
String methodName = (String) it.next();
|
||||
Enumeration propNames = transactionAttributes.propertyNames();
|
||||
while (propNames.hasMoreElements()) {
|
||||
String methodName = (String) propNames.nextElement();
|
||||
String value = transactionAttributes.getProperty(methodName);
|
||||
tae.setAsText(value);
|
||||
TransactionAttribute attr = (TransactionAttribute) tae.getValue();
|
||||
@@ -114,16 +100,15 @@ public class NameMatchTransactionAttributeSource implements TransactionAttribute
|
||||
public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) {
|
||||
// look for direct name match
|
||||
String methodName = method.getName();
|
||||
TransactionAttribute attr = (TransactionAttribute) this.nameMap.get(methodName);
|
||||
TransactionAttribute attr = this.nameMap.get(methodName);
|
||||
|
||||
if (attr == null) {
|
||||
// Look for most specific name match.
|
||||
String bestNameMatch = null;
|
||||
for (Iterator it = this.nameMap.keySet().iterator(); it.hasNext();) {
|
||||
String mappedName = (String) it.next();
|
||||
for (String mappedName : this.nameMap.keySet()) {
|
||||
if (isMatch(methodName, mappedName) &&
|
||||
(bestNameMatch == null || bestNameMatch.length() <= mappedName.length())) {
|
||||
attr = (TransactionAttribute) this.nameMap.get(mappedName);
|
||||
attr = this.nameMap.get(mappedName);
|
||||
bestNameMatch = mappedName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
/** Static for optimal serializability */
|
||||
private static final Log logger = LogFactory.getLog(RuleBasedTransactionAttribute.class);
|
||||
|
||||
private List rollbackRules;
|
||||
private List<RollbackRuleAttribute> rollbackRules;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,7 +77,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
*/
|
||||
public RuleBasedTransactionAttribute(RuleBasedTransactionAttribute other) {
|
||||
super(other);
|
||||
this.rollbackRules = new ArrayList(other.rollbackRules);
|
||||
this.rollbackRules = new ArrayList<RollbackRuleAttribute>(other.rollbackRules);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +90,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* @see #setTimeout
|
||||
* @see #setReadOnly
|
||||
*/
|
||||
public RuleBasedTransactionAttribute(int propagationBehavior, List rollbackRules) {
|
||||
public RuleBasedTransactionAttribute(int propagationBehavior, List<RollbackRuleAttribute> rollbackRules) {
|
||||
super(propagationBehavior);
|
||||
this.rollbackRules = rollbackRules;
|
||||
}
|
||||
@@ -103,7 +102,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* @see RollbackRuleAttribute
|
||||
* @see NoRollbackRuleAttribute
|
||||
*/
|
||||
public void setRollbackRules(List rollbackRules) {
|
||||
public void setRollbackRules(List<RollbackRuleAttribute> rollbackRules) {
|
||||
this.rollbackRules = rollbackRules;
|
||||
}
|
||||
|
||||
@@ -111,9 +110,9 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
* Return the list of <code>RollbackRuleAttribute</code> objects
|
||||
* (never <code>null</code>).
|
||||
*/
|
||||
public List getRollbackRules() {
|
||||
public List<RollbackRuleAttribute> getRollbackRules() {
|
||||
if (this.rollbackRules == null) {
|
||||
this.rollbackRules = new LinkedList();
|
||||
this.rollbackRules = new LinkedList<RollbackRuleAttribute>();
|
||||
}
|
||||
return this.rollbackRules;
|
||||
}
|
||||
@@ -135,8 +134,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
int deepest = Integer.MAX_VALUE;
|
||||
|
||||
if (this.rollbackRules != null) {
|
||||
for (Iterator it = this.rollbackRules.iterator(); it.hasNext();) {
|
||||
RollbackRuleAttribute rule = (RollbackRuleAttribute) it.next();
|
||||
for (RollbackRuleAttribute rule : this.rollbackRules) {
|
||||
int depth = rule.getDepth(ex);
|
||||
if (depth >= 0 && depth < deepest) {
|
||||
deepest = depth;
|
||||
@@ -163,8 +161,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i
|
||||
public String toString() {
|
||||
StringBuilder result = getDefinitionDescription();
|
||||
if (this.rollbackRules != null) {
|
||||
for (Iterator it = this.rollbackRules.iterator(); it.hasNext();) {
|
||||
RollbackRuleAttribute rule = (RollbackRuleAttribute) it.next();
|
||||
for (RollbackRuleAttribute rule : this.rollbackRules) {
|
||||
String sign = (rule instanceof NoRollbackRuleAttribute ? PREFIX_COMMIT_RULE : PREFIX_ROLLBACK_RULE);
|
||||
result.append(',').append(sign).append(rule.getExceptionName());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.transaction.interceptor;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.util.Iterator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.beans.propertyeditors.PropertiesEditor;
|
||||
@@ -59,14 +59,13 @@ public class TransactionAttributeSourceEditor extends PropertyEditorSupport {
|
||||
|
||||
// Now we have properties, process each one individually.
|
||||
TransactionAttributeEditor tae = new TransactionAttributeEditor();
|
||||
for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
Enumeration propNames = props.propertyNames();
|
||||
while (propNames.hasMoreElements()) {
|
||||
String name = (String) propNames.nextElement();
|
||||
String value = props.getProperty(name);
|
||||
|
||||
// Convert value to a transaction attribute.
|
||||
tae.setAsText(value);
|
||||
TransactionAttribute attr = (TransactionAttribute) tae.getValue();
|
||||
|
||||
// Register name and attribute.
|
||||
source.addTransactionalMethod(name, attr);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.transaction.support;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -471,7 +470,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
if (isValidateExistingTransaction()) {
|
||||
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
|
||||
Integer currentIsolationLevel = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
|
||||
if (currentIsolationLevel == null || currentIsolationLevel.intValue() != definition.getIsolationLevel()) {
|
||||
if (currentIsolationLevel == null || currentIsolationLevel != definition.getIsolationLevel()) {
|
||||
Constants isoConstants = DefaultTransactionDefinition.constants;
|
||||
throw new IllegalTransactionStateException("Participating transaction with definition [" +
|
||||
definition + "] specifies isolation level which is incompatible with existing transaction: " +
|
||||
@@ -505,7 +504,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
TransactionSynchronizationManager.setActualTransactionActive(transaction != null);
|
||||
TransactionSynchronizationManager.setCurrentTransactionIsolationLevel(
|
||||
(definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) ?
|
||||
new Integer(definition.getIsolationLevel()) : null);
|
||||
definition.getIsolationLevel() : null);
|
||||
TransactionSynchronizationManager.setCurrentTransactionReadOnly(definition.isReadOnly());
|
||||
TransactionSynchronizationManager.setCurrentTransactionName(definition.getName());
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
@@ -637,10 +636,11 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
* synchronization for the current thread.
|
||||
* @return the List of suspended TransactionSynchronization objects
|
||||
*/
|
||||
private List doSuspendSynchronization() {
|
||||
List suspendedSynchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
for (Iterator it = suspendedSynchronizations.iterator(); it.hasNext();) {
|
||||
((TransactionSynchronization) it.next()).suspend();
|
||||
private List<TransactionSynchronization> doSuspendSynchronization() {
|
||||
List<TransactionSynchronization> suspendedSynchronizations =
|
||||
TransactionSynchronizationManager.getSynchronizations();
|
||||
for (TransactionSynchronization synchronization : suspendedSynchronizations) {
|
||||
synchronization.suspend();
|
||||
}
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
return suspendedSynchronizations;
|
||||
@@ -651,10 +651,9 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
|
||||
* and resume all given synchronizations.
|
||||
* @param suspendedSynchronizations List of TransactionSynchronization objects
|
||||
*/
|
||||
private void doResumeSynchronization(List suspendedSynchronizations) {
|
||||
private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
for (Iterator it = suspendedSynchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : suspendedSynchronizations) {
|
||||
synchronization.resume();
|
||||
TransactionSynchronizationManager.registerSynchronization(synchronization);
|
||||
}
|
||||
|
||||
@@ -77,25 +77,25 @@ public abstract class TransactionSynchronizationManager {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TransactionSynchronizationManager.class);
|
||||
|
||||
private static final Comparator synchronizationComparator = new OrderComparator();
|
||||
private static final Comparator<Object> synchronizationComparator = new OrderComparator();
|
||||
|
||||
private static final ThreadLocal resources =
|
||||
new NamedThreadLocal("Transactional resources");
|
||||
private static final ThreadLocal<Map<Object, Object>> resources =
|
||||
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
|
||||
|
||||
private static final ThreadLocal synchronizations =
|
||||
new NamedThreadLocal("Transaction synchronizations");
|
||||
private static final ThreadLocal<List<TransactionSynchronization>> synchronizations =
|
||||
new NamedThreadLocal<List<TransactionSynchronization>>("Transaction synchronizations");
|
||||
|
||||
private static final ThreadLocal currentTransactionName =
|
||||
new NamedThreadLocal("Current transaction name");
|
||||
private static final ThreadLocal<String> currentTransactionName =
|
||||
new NamedThreadLocal<String>("Current transaction name");
|
||||
|
||||
private static final ThreadLocal currentTransactionReadOnly =
|
||||
new NamedThreadLocal("Current transaction read-only status");
|
||||
private static final ThreadLocal<Boolean> currentTransactionReadOnly =
|
||||
new NamedThreadLocal<Boolean>("Current transaction read-only status");
|
||||
|
||||
private static final ThreadLocal currentTransactionIsolationLevel =
|
||||
new NamedThreadLocal("Current transaction isolation level");
|
||||
private static final ThreadLocal<Integer> currentTransactionIsolationLevel =
|
||||
new NamedThreadLocal<Integer>("Current transaction isolation level");
|
||||
|
||||
private static final ThreadLocal actualTransactionActive =
|
||||
new NamedThreadLocal("Actual transaction active");
|
||||
private static final ThreadLocal<Boolean> actualTransactionActive =
|
||||
new NamedThreadLocal<Boolean>("Actual transaction active");
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -111,9 +111,9 @@ public abstract class TransactionSynchronizationManager {
|
||||
* currently no resources bound
|
||||
* @see #hasResource
|
||||
*/
|
||||
public static Map getResourceMap() {
|
||||
Map map = (Map) resources.get();
|
||||
return (map != null ? Collections.unmodifiableMap(map) : Collections.EMPTY_MAP);
|
||||
public static Map<Object, Object> getResourceMap() {
|
||||
Map<Object, Object> map = resources.get();
|
||||
return (map != null ? Collections.unmodifiableMap(map) : Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +149,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* Actually check the value of the resource that is bound for the given key.
|
||||
*/
|
||||
private static Object doGetResource(Object actualKey) {
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -172,10 +172,10 @@ public abstract class TransactionSynchronizationManager {
|
||||
public static void bindResource(Object key, Object value) throws IllegalStateException {
|
||||
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
|
||||
Assert.notNull(value, "Value must not be null");
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
// set ThreadLocal Map if none found
|
||||
if (map == null) {
|
||||
map = new HashMap();
|
||||
map = new HashMap<Object, Object>();
|
||||
resources.set(map);
|
||||
}
|
||||
if (map.put(actualKey, value) != null) {
|
||||
@@ -219,7 +219,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* Actually remove the value of the resource that is bound for the given key.
|
||||
*/
|
||||
private static Object doUnbindResource(Object actualKey) {
|
||||
Map map = (Map) resources.get();
|
||||
Map<Object, Object> map = resources.get();
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -259,7 +259,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
throw new IllegalStateException("Cannot activate transaction synchronization - already active");
|
||||
}
|
||||
logger.trace("Initializing transaction synchronization");
|
||||
synchronizations.set(new LinkedList());
|
||||
synchronizations.set(new LinkedList<TransactionSynchronization>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,8 +279,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Transaction synchronization is not active");
|
||||
}
|
||||
List synchs = (List) synchronizations.get();
|
||||
synchs.add(synchronization);
|
||||
synchronizations.get().add(synchronization);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,17 +289,17 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @throws IllegalStateException if synchronization is not active
|
||||
* @see TransactionSynchronization
|
||||
*/
|
||||
public static List getSynchronizations() throws IllegalStateException {
|
||||
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
|
||||
if (!isSynchronizationActive()) {
|
||||
throw new IllegalStateException("Transaction synchronization is not active");
|
||||
}
|
||||
List synchs = (List) synchronizations.get();
|
||||
List<TransactionSynchronization> synchs = synchronizations.get();
|
||||
// Sort lazily here, not in registerSynchronization.
|
||||
Collections.sort(synchs, synchronizationComparator);
|
||||
// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
|
||||
// while iterating and invoking synchronization callbacks that in turn
|
||||
// might register further synchronizations.
|
||||
return Collections.unmodifiableList(new ArrayList(synchs));
|
||||
return Collections.unmodifiableList(new ArrayList<TransactionSynchronization>(synchs));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,7 +337,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @see org.springframework.transaction.TransactionDefinition#getName()
|
||||
*/
|
||||
public static String getCurrentTransactionName() {
|
||||
return (String) currentTransactionName.get();
|
||||
return currentTransactionName.get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,7 +408,7 @@ public abstract class TransactionSynchronizationManager {
|
||||
* @see org.springframework.transaction.TransactionDefinition#getIsolationLevel()
|
||||
*/
|
||||
public static Integer getCurrentTransactionIsolationLevel() {
|
||||
return (Integer) currentTransactionIsolationLevel.get();
|
||||
return currentTransactionIsolationLevel.get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.transaction.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -67,8 +66,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#beforeCommit(boolean)
|
||||
*/
|
||||
public static void triggerBeforeCommit(boolean readOnly) {
|
||||
for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) {
|
||||
synchronization.beforeCommit(readOnly);
|
||||
}
|
||||
}
|
||||
@@ -78,8 +76,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#beforeCompletion()
|
||||
*/
|
||||
public static void triggerBeforeCompletion() {
|
||||
for (Iterator it = TransactionSynchronizationManager.getSynchronizations().iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) {
|
||||
try {
|
||||
synchronization.beforeCompletion();
|
||||
}
|
||||
@@ -96,8 +93,7 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#afterCommit()
|
||||
*/
|
||||
public static void triggerAfterCommit() {
|
||||
List synchronizations = TransactionSynchronizationManager.getSynchronizations();
|
||||
invokeAfterCommit(synchronizations);
|
||||
invokeAfterCommit(TransactionSynchronizationManager.getSynchronizations());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,19 +102,10 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @param synchronizations List of TransactionSynchronization objects
|
||||
* @see TransactionSynchronization#afterCommit()
|
||||
*/
|
||||
public static void invokeAfterCommit(List synchronizations) {
|
||||
public static void invokeAfterCommit(List<TransactionSynchronization> synchronizations) {
|
||||
if (synchronizations != null) {
|
||||
for (Iterator it = synchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
try {
|
||||
synchronization.afterCommit();
|
||||
}
|
||||
catch (AbstractMethodError tserr) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Spring 2.0's TransactionSynchronization.afterCommit method not implemented in " +
|
||||
"synchronization class [" + synchronization.getClass().getName() + "]", tserr);
|
||||
}
|
||||
}
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
synchronization.afterCommit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,10 +136,9 @@ public abstract class TransactionSynchronizationUtils {
|
||||
* @see TransactionSynchronization#STATUS_ROLLED_BACK
|
||||
* @see TransactionSynchronization#STATUS_UNKNOWN
|
||||
*/
|
||||
public static void invokeAfterCompletion(List synchronizations, int completionStatus) {
|
||||
public static void invokeAfterCompletion(List<TransactionSynchronization> synchronizations, int completionStatus) {
|
||||
if (synchronizations != null) {
|
||||
for (Iterator it = synchronizations.iterator(); it.hasNext();) {
|
||||
TransactionSynchronization synchronization = (TransactionSynchronization) it.next();
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
try {
|
||||
synchronization.afterCompletion(completionStatus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user