From bf08752d3ab483d9413a434c5b3abba9160520d6 Mon Sep 17 00:00:00 2001 From: Radim Vansa Date: Tue, 22 Nov 2016 13:01:53 +0100 Subject: [PATCH] HHH-11083 Un-deprecate OldCacheKeyImplementation and OldNaturalCacheKey --- ...plementation.java => CacheKeyImplementation.java} | 11 ++++------- .../cache/internal/DefaultCacheKeysFactory.java | 12 ++++++------ ...NaturalIdCacheKey.java => NaturalIdCacheKey.java} | 11 ++++------- .../cache/internal/SimpleCacheKeysFactory.java | 4 ++-- .../hibernate/cache/spi/NaturalIdCacheKeyTest.java | 6 +++--- 5 files changed, 19 insertions(+), 25 deletions(-) rename hibernate-core/src/main/java/org/hibernate/cache/internal/{OldCacheKeyImplementation.java => CacheKeyImplementation.java} (88%) rename hibernate-core/src/main/java/org/hibernate/cache/internal/{OldNaturalIdCacheKey.java => NaturalIdCacheKey.java} (94%) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java similarity index 88% rename from hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java rename to hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java index 45b9d5cd6a..272e26aa04 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java @@ -21,11 +21,8 @@ import org.hibernate.type.Type; * * @author Gavin King * @author Steve Ebersole - * - * @deprecated In optimized implementations, wrapping the id is not necessary. */ -@Deprecated -final class OldCacheKeyImplementation implements Serializable { +final class CacheKeyImplementation implements Serializable { private final Object id; private final Type type; private final String entityOrRoleName; @@ -43,7 +40,7 @@ final class OldCacheKeyImplementation implements Serializable { * @param tenantId The tenant identifier associated this data. * @param factory The session factory for which we are caching */ - OldCacheKeyImplementation( + CacheKeyImplementation( final Object id, final Type type, final String entityOrRoleName, @@ -74,11 +71,11 @@ final class OldCacheKeyImplementation implements Serializable { if ( this == other ) { return true; } - if ( hashCode != other.hashCode() || !( other instanceof OldCacheKeyImplementation ) ) { + if ( hashCode != other.hashCode() || !( other instanceof CacheKeyImplementation) ) { //hashCode is part of this check since it is pre-calculated and hash must match for equals to be true return false; } - final OldCacheKeyImplementation that = (OldCacheKeyImplementation) other; + final CacheKeyImplementation that = (CacheKeyImplementation) other; return EqualsHelper.equals( entityOrRoleName, that.entityOrRoleName ) && type.isEqual( id, that.id) && EqualsHelper.equals( tenantId, that.tenantId ); diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java index 88a903bf5c..432cdf657c 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java @@ -43,27 +43,27 @@ public class DefaultCacheKeysFactory implements CacheKeysFactory { public static final DefaultCacheKeysFactory INSTANCE = new DefaultCacheKeysFactory(); public static Object staticCreateCollectionKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { - return new OldCacheKeyImplementation( id, persister.getKeyType(), persister.getRole(), tenantIdentifier, factory ); + return new CacheKeyImplementation( id, persister.getKeyType(), persister.getRole(), tenantIdentifier, factory ); } public static Object staticCreateEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { - return new OldCacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory ); + return new CacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory ); } public static Object staticCreateNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { - return new OldNaturalIdCacheKey( naturalIdValues, persister.getPropertyTypes(), persister.getNaturalIdentifierProperties(), persister.getRootEntityName(), session ); + return new NaturalIdCacheKey( naturalIdValues, persister.getPropertyTypes(), persister.getNaturalIdentifierProperties(), persister.getRootEntityName(), session ); } public static Object staticGetEntityId(Object cacheKey) { - return ((OldCacheKeyImplementation) cacheKey).getId(); + return ((CacheKeyImplementation) cacheKey).getId(); } public static Object staticGetCollectionId(Object cacheKey) { - return ((OldCacheKeyImplementation) cacheKey).getId(); + return ((CacheKeyImplementation) cacheKey).getId(); } public static Object[] staticGetNaturalIdValues(Object cacheKey) { - return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues(); + return ((NaturalIdCacheKey) cacheKey).getNaturalIdValues(); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/NaturalIdCacheKey.java similarity index 94% rename from hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java rename to hibernate-core/src/main/java/org/hibernate/cache/internal/NaturalIdCacheKey.java index 1a30741b04..11204d882f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/NaturalIdCacheKey.java @@ -26,11 +26,8 @@ import org.hibernate.type.Type; * * @author Eric Dalquist * @author Steve Ebersole - * - * @deprecated Cache implementation should provide optimized key. */ -@Deprecated -public class OldNaturalIdCacheKey implements Serializable { +public class NaturalIdCacheKey implements Serializable { private final Serializable[] naturalIdValues; private final String entityName; private final String tenantId; @@ -45,7 +42,7 @@ public class OldNaturalIdCacheKey implements Serializable { * @param naturalIdPropertyIndexes * @param session The originating session */ - public OldNaturalIdCacheKey( + public NaturalIdCacheKey( final Object[] naturalIdValues, Type[] propertyTypes, int[] naturalIdPropertyIndexes, final String entityName, final SharedSessionContractImplementor session) { @@ -140,12 +137,12 @@ public class OldNaturalIdCacheKey implements Serializable { return true; } - if ( hashCode != o.hashCode() || !( o instanceof OldNaturalIdCacheKey ) ) { + if ( hashCode != o.hashCode() || !( o instanceof NaturalIdCacheKey) ) { //hashCode is part of this check since it is pre-calculated and hash must match for equals to be true return false; } - final OldNaturalIdCacheKey other = (OldNaturalIdCacheKey) o; + final NaturalIdCacheKey other = (NaturalIdCacheKey) o; return EqualsHelper.equals( entityName, other.entityName ) && EqualsHelper.equals( tenantId, other.tenantId ) && Arrays.deepEquals( this.naturalIdValues, other.naturalIdValues ); diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/SimpleCacheKeysFactory.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/SimpleCacheKeysFactory.java index 4e05d95f40..f5e68f899f 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/SimpleCacheKeysFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/SimpleCacheKeysFactory.java @@ -34,7 +34,7 @@ public class SimpleCacheKeysFactory implements CacheKeysFactory { @Override public Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { // natural ids always need to be wrapped - return new OldNaturalIdCacheKey(naturalIdValues, persister.getPropertyTypes(), persister.getNaturalIdentifierProperties(), null, session); + return new NaturalIdCacheKey(naturalIdValues, persister.getPropertyTypes(), persister.getNaturalIdentifierProperties(), null, session); } @Override @@ -49,6 +49,6 @@ public class SimpleCacheKeysFactory implements CacheKeysFactory { @Override public Object[] getNaturalIdValues(Object cacheKey) { - return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues(); + return ((NaturalIdCacheKey) cacheKey).getNaturalIdValues(); } } diff --git a/hibernate-core/src/test/java/org/hibernate/cache/spi/NaturalIdCacheKeyTest.java b/hibernate-core/src/test/java/org/hibernate/cache/spi/NaturalIdCacheKeyTest.java index e9796e424e..a631b7a296 100644 --- a/hibernate-core/src/test/java/org/hibernate/cache/spi/NaturalIdCacheKeyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/cache/spi/NaturalIdCacheKeyTest.java @@ -12,7 +12,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.internal.OldNaturalIdCacheKey; +import org.hibernate.cache.internal.NaturalIdCacheKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.persister.entity.EntityPersister; @@ -61,14 +61,14 @@ public class NaturalIdCacheKeyTest { } }); - final OldNaturalIdCacheKey key = (OldNaturalIdCacheKey) DefaultCacheKeysFactory.staticCreateNaturalIdKey( new Object[] {"a", "b", "c"}, entityPersister, sessionImplementor ); + final NaturalIdCacheKey key = (NaturalIdCacheKey) DefaultCacheKeysFactory.staticCreateNaturalIdKey( new Object[] {"a", "b", "c"}, entityPersister, sessionImplementor ); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(key); final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - final OldNaturalIdCacheKey keyClone = (OldNaturalIdCacheKey) ois.readObject(); + final NaturalIdCacheKey keyClone = (NaturalIdCacheKey) ois.readObject(); assertEquals(key, keyClone); assertEquals(key.hashCode(), keyClone.hashCode());