Browse Source

Cache key classes implement Comparable and consistently provide a toString representation

Issue: SPR-14017
pull/1004/head
Juergen Hoeller 9 years ago
parent
commit
54aeb7a5d6
  1. 25
      spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java
  2. 6
      spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
  3. 16
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
  4. 16
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java
  5. 10
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java
  6. 6
      spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java
  7. 2
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java
  8. 21
      spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
  9. 16
      spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java
  10. 33
      spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java
  11. 16
      spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
  12. 13
      spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java
  13. 53
      spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java
  14. 22
      spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java
  15. 21
      spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

25
spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -586,7 +586,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @@ -586,7 +586,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* Simple wrapper class around a Method. Used as the key when
* caching methods, for efficient equals and hashCode comparisons.
*/
private static class MethodCacheKey {
private static final class MethodCacheKey implements Comparable<MethodCacheKey> {
private final Method method;
@ -599,17 +599,28 @@ public class AdvisedSupport extends ProxyConfig implements Advised { @@ -599,17 +599,28 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
MethodCacheKey otherKey = (MethodCacheKey) other;
return (this.method == otherKey.method);
return (this == other || (other instanceof MethodCacheKey &&
this.method == ((MethodCacheKey) other).method));
}
@Override
public int hashCode() {
return this.hashCode;
}
@Override
public String toString() {
return this.method.toString();
}
@Override
public int compareTo(MethodCacheKey other) {
int result = this.method.getName().compareTo(other.method.getName());
if (result == 0) {
result = this.method.toString().compareTo(other.method.toString());
}
return result;
}
}
}

6
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java vendored

@ -101,6 +101,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -101,6 +101,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, Cacheable cacheable) {
CacheableOperation.Builder builder = new CacheableOperation.Builder();
builder.setName(ae.toString());
builder.setCacheNames(cacheable.cacheNames());
builder.setCondition(cacheable.condition());
builder.setUnless(cacheable.unless());
@ -109,7 +110,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -109,7 +110,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
builder.setCacheManager(cacheable.cacheManager());
builder.setCacheResolver(cacheable.cacheResolver());
builder.setSync(cacheable.sync());
builder.setName(ae.toString());
defaultConfig.applyDefault(builder);
CacheableOperation op = builder.build();
@ -121,6 +121,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -121,6 +121,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CacheEvict cacheEvict) {
CacheEvictOperation.Builder builder = new CacheEvictOperation.Builder();
builder.setName(ae.toString());
builder.setCacheNames(cacheEvict.cacheNames());
builder.setCondition(cacheEvict.condition());
builder.setKey(cacheEvict.key());
@ -129,7 +130,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -129,7 +130,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
builder.setCacheResolver(cacheEvict.cacheResolver());
builder.setCacheWide(cacheEvict.allEntries());
builder.setBeforeInvocation(cacheEvict.beforeInvocation());
builder.setName(ae.toString());
defaultConfig.applyDefault(builder);
CacheEvictOperation op = builder.build();
@ -141,6 +141,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -141,6 +141,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
CacheOperation parsePutAnnotation(AnnotatedElement ae, DefaultCacheConfig defaultConfig, CachePut cachePut) {
CachePutOperation.Builder builder = new CachePutOperation.Builder();
builder.setName(ae.toString());
builder.setCacheNames(cachePut.cacheNames());
builder.setCondition(cachePut.condition());
builder.setUnless(cachePut.unless());
@ -148,7 +149,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria @@ -148,7 +149,6 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
builder.setKeyGenerator(cachePut.keyGenerator());
builder.setCacheManager(cachePut.cacheManager());
builder.setCacheResolver(cachePut.cacheResolver());
builder.setName(ae.toString());
defaultConfig.applyDefault(builder);
CachePutOperation op = builder.build();

16
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java vendored

@ -746,7 +746,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker @@ -746,7 +746,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
private static class CacheOperationCacheKey {
private static final class CacheOperationCacheKey implements Comparable<CacheOperationCacheKey> {
private final CacheOperation cacheOperation;
@ -774,6 +774,20 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker @@ -774,6 +774,20 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
public int hashCode() {
return (this.cacheOperation.hashCode() * 31 + this.methodCacheKey.hashCode());
}
@Override
public String toString() {
return this.cacheOperation + " on " + this.methodCacheKey;
}
@Override
public int compareTo(CacheOperationCacheKey other) {
int result = this.cacheOperation.getName().compareTo(other.cacheOperation.getName());
if (result == 0) {
result = this.methodCacheKey.compareTo(other.methodCacheKey);
}
return result;
}
}
}

16
spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java vendored

@ -29,6 +29,13 @@ public class CacheEvictOperation extends CacheOperation { @@ -29,6 +29,13 @@ public class CacheEvictOperation extends CacheOperation {
private final boolean beforeInvocation;
public CacheEvictOperation(CacheEvictOperation.Builder b) {
super(b);
this.cacheWide = b.cacheWide;
this.beforeInvocation = b.beforeInvocation;
}
public boolean isCacheWide() {
return this.cacheWide;
}
@ -37,12 +44,10 @@ public class CacheEvictOperation extends CacheOperation { @@ -37,12 +44,10 @@ public class CacheEvictOperation extends CacheOperation {
return this.beforeInvocation;
}
public CacheEvictOperation(CacheEvictOperation.Builder b) {
super(b);
this.cacheWide = b.cacheWide;
this.beforeInvocation = b.beforeInvocation;
}
/**
* @since 4.3
*/
public static class Builder extends CacheOperation.Builder {
private boolean cacheWide = false;
@ -71,4 +76,5 @@ public class CacheEvictOperation extends CacheOperation { @@ -71,4 +76,5 @@ public class CacheEvictOperation extends CacheOperation {
return new CacheEvictOperation(this);
}
}
}

10
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java vendored

@ -48,6 +48,7 @@ public abstract class CacheOperation implements BasicOperation { @@ -48,6 +48,7 @@ public abstract class CacheOperation implements BasicOperation {
private final String toString;
protected CacheOperation(Builder b) {
this.name = b.name;
this.cacheNames = b.cacheNames;
@ -59,11 +60,11 @@ public abstract class CacheOperation implements BasicOperation { @@ -59,11 +60,11 @@ public abstract class CacheOperation implements BasicOperation {
this.toString = b.getOperationDescription().toString();
}
public String getName() {
return this.name;
}
@Override
public Set<String> getCacheNames() {
return this.cacheNames;
@ -96,7 +97,6 @@ public abstract class CacheOperation implements BasicOperation { @@ -96,7 +97,6 @@ public abstract class CacheOperation implements BasicOperation {
/**
* This implementation compares the {@code toString()} results.
*
* @see #toString()
*/
@Override
@ -106,7 +106,6 @@ public abstract class CacheOperation implements BasicOperation { @@ -106,7 +106,6 @@ public abstract class CacheOperation implements BasicOperation {
/**
* This implementation returns {@code toString()}'s hash code.
*
* @see #toString()
*/
@Override
@ -118,7 +117,6 @@ public abstract class CacheOperation implements BasicOperation { @@ -118,7 +117,6 @@ public abstract class CacheOperation implements BasicOperation {
* Return an identifying description for this cache operation.
* <p>Returned value is produced by calling {@link Builder#getOperationDescription()}
* during object construction. This method is used in {#hashCode} and {#equals}.
*
* @see Builder#getOperationDescription()
*/
@Override
@ -126,6 +124,10 @@ public abstract class CacheOperation implements BasicOperation { @@ -126,6 +124,10 @@ public abstract class CacheOperation implements BasicOperation {
return this.toString;
}
/**
* @since 4.3
*/
public abstract static class Builder {
private String name = "";

6
spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java vendored

@ -28,6 +28,7 @@ public class CachePutOperation extends CacheOperation { @@ -28,6 +28,7 @@ public class CachePutOperation extends CacheOperation {
private final String unless;
public CachePutOperation(CachePutOperation.Builder b) {
super(b);
this.unless = b.unless;
@ -37,6 +38,10 @@ public class CachePutOperation extends CacheOperation { @@ -37,6 +38,10 @@ public class CachePutOperation extends CacheOperation {
return this.unless;
}
/**
* @since 4.3
*/
public static class Builder extends CacheOperation.Builder {
private String unless;
@ -58,4 +63,5 @@ public class CachePutOperation extends CacheOperation { @@ -58,4 +63,5 @@ public class CachePutOperation extends CacheOperation {
return new CachePutOperation(this);
}
}
}

2
spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java vendored

@ -30,6 +30,7 @@ public class CacheableOperation extends CacheOperation { @@ -30,6 +30,7 @@ public class CacheableOperation extends CacheOperation {
private boolean sync;
public CacheableOperation(CacheableOperation.Builder b) {
super(b);
this.unless = b.unless;
@ -76,4 +77,5 @@ public class CacheableOperation extends CacheOperation { @@ -76,4 +77,5 @@ public class CacheableOperation extends CacheOperation {
return new CacheableOperation(this);
}
}
}

21
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -286,7 +286,7 @@ public abstract class AbstractApplicationEventMulticaster @@ -286,7 +286,7 @@ public abstract class AbstractApplicationEventMulticaster
/**
* Cache key for ListenerRetrievers, based on event type and source type.
*/
private static class ListenerCacheKey {
private static final class ListenerCacheKey implements Comparable<ListenerCacheKey> {
private final ResolvableType eventType;
@ -311,6 +311,23 @@ public abstract class AbstractApplicationEventMulticaster @@ -311,6 +311,23 @@ public abstract class AbstractApplicationEventMulticaster
public int hashCode() {
return (ObjectUtils.nullSafeHashCode(this.eventType) * 29 + ObjectUtils.nullSafeHashCode(this.sourceType));
}
@Override
public String toString() {
return "ListenerCacheKey [eventType = " + this.eventType + ", sourceType = " + this.sourceType.getName() + "]";
}
@Override
public int compareTo(ListenerCacheKey other) {
int result = 0;
if (this.eventType != null) {
result = this.eventType.toString().compareTo(other.eventType.toString());
}
if (result == 0 && this.sourceType != null) {
result = this.sourceType.getName().compareTo(other.sourceType.getName());
}
return result;
}
}

16
spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java

@ -30,7 +30,7 @@ import org.springframework.util.ObjectUtils; @@ -30,7 +30,7 @@ import org.springframework.util.ObjectUtils;
* @since 4.2
* @see CachedExpressionEvaluator
*/
public final class AnnotatedElementKey {
public final class AnnotatedElementKey implements Comparable<AnnotatedElementKey> {
private final AnnotatedElement element;
@ -66,4 +66,18 @@ public final class AnnotatedElementKey { @@ -66,4 +66,18 @@ public final class AnnotatedElementKey {
return this.element.hashCode() + (this.targetClass != null ? this.targetClass.hashCode() * 29 : 0);
}
@Override
public String toString() {
return this.element + (this.targetClass != null ? " on " + this.targetClass : "");
}
@Override
public int compareTo(AnnotatedElementKey other) {
int result = this.element.toString().compareTo(other.element.toString());
if (result == 0 && this.targetClass != null) {
result = this.targetClass.getName().compareTo(other.targetClass.getName());
}
return result;
}
}

33
spring-context/src/main/java/org/springframework/jmx/access/MBeanClientInterceptor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -63,6 +63,7 @@ import org.springframework.jmx.support.JmxUtils; @@ -63,6 +63,7 @@ import org.springframework.jmx.support.JmxUtils;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
/**
* {@link org.aopalliance.intercept.MethodInterceptor} that routes calls to an
@ -609,7 +610,7 @@ public class MBeanClientInterceptor @@ -609,7 +610,7 @@ public class MBeanClientInterceptor
* Simple wrapper class around a method name and its signature.
* Used as the key when caching methods.
*/
private static class MethodCacheKey {
private static final class MethodCacheKey implements Comparable<MethodCacheKey> {
private final String name;
@ -628,7 +629,7 @@ public class MBeanClientInterceptor @@ -628,7 +629,7 @@ public class MBeanClientInterceptor
@Override
public boolean equals(Object other) {
if (other == this) {
if (this == other) {
return true;
}
MethodCacheKey otherKey = (MethodCacheKey) other;
@ -639,6 +640,32 @@ public class MBeanClientInterceptor @@ -639,6 +640,32 @@ public class MBeanClientInterceptor
public int hashCode() {
return this.name.hashCode();
}
@Override
public String toString() {
return this.name + "(" + StringUtils.arrayToCommaDelimitedString(this.parameterTypes) + ")";
}
@Override
public int compareTo(MethodCacheKey other) {
int result = this.name.compareTo(other.name);
if (result != 0) {
return result;
}
if (this.parameterTypes.length < other.parameterTypes.length) {
return -1;
}
if (this.parameterTypes.length > other.parameterTypes.length) {
return 1;
}
for (int i = 0; i < this.parameterTypes.length; i++) {
result = this.parameterTypes[i].getName().compareTo(other.parameterTypes[i].getName());
if (result != 0) {
return result;
}
}
return 0;
}
}
}

16
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

@ -1802,7 +1802,7 @@ public abstract class AnnotationUtils { @@ -1802,7 +1802,7 @@ public abstract class AnnotationUtils {
/**
* Cache key for the AnnotatedElement cache.
*/
private static class AnnotationCacheKey {
private static final class AnnotationCacheKey implements Comparable<AnnotationCacheKey> {
private final AnnotatedElement element;
@ -1829,6 +1829,20 @@ public abstract class AnnotationUtils { @@ -1829,6 +1829,20 @@ public abstract class AnnotationUtils {
public int hashCode() {
return (this.element.hashCode() * 29 + this.annotationType.hashCode());
}
@Override
public String toString() {
return "@" + this.annotationType + " on " + this.element;
}
@Override
public int compareTo(AnnotationCacheKey other) {
int result = this.element.toString().compareTo(other.element.toString());
if (result == 0) {
result = this.annotationType.getName().compareTo(other.annotationType.getName());
}
return result;
}
}

13
spring-core/src/main/java/org/springframework/core/convert/support/GenericConversionService.java

@ -435,7 +435,7 @@ public class GenericConversionService implements ConfigurableConversionService { @@ -435,7 +435,7 @@ public class GenericConversionService implements ConfigurableConversionService {
/**
* Key for use with the converter cache.
*/
private static final class ConverterCacheKey {
private static final class ConverterCacheKey implements Comparable<ConverterCacheKey> {
private final TypeDescriptor sourceType;
@ -470,6 +470,17 @@ public class GenericConversionService implements ConfigurableConversionService { @@ -470,6 +470,17 @@ public class GenericConversionService implements ConfigurableConversionService {
return ("ConverterCacheKey [sourceType = " + this.sourceType +
", targetType = " + this.targetType + "]");
}
@Override
public int compareTo(ConverterCacheKey other) {
int result = this.sourceType.getResolvableType().toString().compareTo(
other.sourceType.getResolvableType().toString());
if (result == 0) {
result = this.targetType.getResolvableType().toString().compareTo(
other.targetType.getResolvableType().toString());
}
return result;
}
}

53
spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectivePropertyAccessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -33,7 +33,6 @@ import org.springframework.asm.MethodVisitor; @@ -33,7 +33,6 @@ import org.springframework.asm.MethodVisitor;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.Property;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.style.ToStringCreator;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.EvaluationException;
@ -70,11 +69,14 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -70,11 +69,14 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
}
private final Map<CacheKey, InvokerPair> readerCache = new ConcurrentHashMap<CacheKey, InvokerPair>(64);
private final Map<PropertyCacheKey, InvokerPair> readerCache =
new ConcurrentHashMap<PropertyCacheKey, InvokerPair>(64);
private final Map<CacheKey, Member> writerCache = new ConcurrentHashMap<CacheKey, Member>(64);
private final Map<PropertyCacheKey, Member> writerCache =
new ConcurrentHashMap<PropertyCacheKey, Member>(64);
private final Map<CacheKey, TypeDescriptor> typeDescriptorCache = new ConcurrentHashMap<CacheKey, TypeDescriptor>(64);
private final Map<PropertyCacheKey, TypeDescriptor> typeDescriptorCache =
new ConcurrentHashMap<PropertyCacheKey, TypeDescriptor>(64);
private InvokerPair lastReadInvokerPair;
@ -96,7 +98,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -96,7 +98,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (type.isArray() && name.equals("length")) {
return true;
}
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
if (this.readerCache.containsKey(cacheKey)) {
return true;
}
@ -140,7 +142,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -140,7 +142,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return new TypedValue(Array.getLength(target));
}
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
InvokerPair invoker = this.readerCache.get(cacheKey);
lastReadInvokerPair = invoker;
@ -202,7 +204,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -202,7 +204,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return false;
}
Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass());
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
if (this.writerCache.containsKey(cacheKey)) {
return true;
}
@ -244,7 +246,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -244,7 +246,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
throw new AccessException("Type conversion failure", evaluationException);
}
}
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
Member cachedMember = this.writerCache.get(cacheKey);
if (cachedMember == null || cachedMember instanceof Method) {
@ -301,7 +303,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -301,7 +303,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (type.isArray() && name.equals("length")) {
return TypeDescriptor.valueOf(Integer.TYPE);
}
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
TypeDescriptor typeDescriptor = this.typeDescriptorCache.get(cacheKey);
if (typeDescriptor == null) {
// attempt to populate the cache entry
@ -466,7 +468,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -466,7 +468,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return this;
}
CacheKey cacheKey = new CacheKey(type, name, target instanceof Class);
PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class);
InvokerPair invocationTarget = this.readerCache.get(cacheKey);
if (invocationTarget == null || invocationTarget.member instanceof Method) {
@ -520,17 +522,17 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -520,17 +522,17 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
}
private static class CacheKey {
private static final class PropertyCacheKey implements Comparable<PropertyCacheKey> {
private final Class<?> clazz;
private final String name;
private final String property;
private boolean targetIsClass;
public CacheKey(Class<?> clazz, String name, boolean targetIsClass) {
public PropertyCacheKey(Class<?> clazz, String name, boolean targetIsClass) {
this.clazz = clazz;
this.name = name;
this.property = name;
this.targetIsClass = targetIsClass;
}
@ -539,23 +541,32 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { @@ -539,23 +541,32 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (this == other) {
return true;
}
if (!(other instanceof CacheKey)) {
if (!(other instanceof PropertyCacheKey)) {
return false;
}
CacheKey otherKey = (CacheKey) other;
return (this.clazz.equals(otherKey.clazz) && this.name.equals(otherKey.name) &&
PropertyCacheKey otherKey = (PropertyCacheKey) other;
return (this.clazz == otherKey.clazz && this.property.equals(otherKey.property) &&
this.targetIsClass == otherKey.targetIsClass);
}
@Override
public int hashCode() {
return (this.clazz.hashCode() * 29 + this.name.hashCode());
return (this.clazz.hashCode() * 29 + this.property.hashCode());
}
@Override
public String toString() {
return new ToStringCreator(this).append("clazz", this.clazz).append("name",
this.name).append("targetIsClass", this.targetIsClass).toString();
return "CacheKey [clazz=" + this.clazz.getName() + ", property=" + this.property + ", " +
this.property + ", targetIsClass=" + this.targetIsClass + "]";
}
@Override
public int compareTo(PropertyCacheKey other) {
int result = this.clazz.getName().compareTo(other.clazz.getName());
if (result == 0) {
result = this.property.compareTo(other.property);
}
return result;
}
}

22
spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -509,7 +509,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @@ -509,7 +509,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
* Simple wrapper class around a Destination reference.
* Used as the cache key when caching MessageProducer objects.
*/
private static class DestinationCacheKey {
private static class DestinationCacheKey implements Comparable<DestinationCacheKey> {
private final Destination destination;
@ -537,7 +537,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @@ -537,7 +537,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
public boolean equals(Object other) {
// Effectively checking object equality as well as toString equality.
// On WebSphere MQ, Destination objects do not implement equals...
return (other == this || destinationEquals((DestinationCacheKey) other));
return (this == other || destinationEquals((DestinationCacheKey) other));
}
@Override
@ -547,6 +547,16 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @@ -547,6 +547,16 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
// for equivalent destinations... Thanks a lot, WebSphere MQ!
return this.destination.getClass().hashCode();
}
@Override
public String toString() {
return getDestinationString();
}
@Override
public int compareTo(DestinationCacheKey other) {
return getDestinationString().compareTo(other.getDestinationString());
}
}
@ -584,6 +594,12 @@ public class CachingConnectionFactory extends SingleConnectionFactory { @@ -584,6 +594,12 @@ public class CachingConnectionFactory extends SingleConnectionFactory {
ObjectUtils.nullSafeEquals(this.subscription, otherKey.subscription) &&
this.durable == otherKey.durable);
}
@Override
public String toString() {
return super.toString() + " [selector=" + this.selector + ", noLocal=" + this.noLocal +
", subscription=" + this.subscription + ", durable=" + this.durable + "]";
}
}
}

21
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -203,7 +203,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran @@ -203,7 +203,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
/**
* Default cache key for the TransactionAttribute cache.
*/
private static class DefaultCacheKey {
private static final class DefaultCacheKey implements Comparable<DefaultCacheKey> {
private final Method method;
@ -231,6 +231,23 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran @@ -231,6 +231,23 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
public int hashCode() {
return this.method.hashCode() + (this.targetClass != null ? this.targetClass.hashCode() * 29 : 0);
}
@Override
public String toString() {
return this.method + (this.targetClass != null ? " on " + this.targetClass : "");
}
@Override
public int compareTo(DefaultCacheKey other) {
int result = this.method.getName().compareTo(other.method.getName());
if (result == 0) {
result = this.method.toString().compareTo(other.method.toString());
if (result == 0 && this.targetClass != null) {
result = this.targetClass.getName().compareTo(other.targetClass.getName());
}
}
return result;
}
}
}

Loading…
Cancel
Save