HHH-11083 Un-deprecate OldCacheKeyImplementation and OldNaturalCacheKey

This commit is contained in:
Radim Vansa 2016-11-22 13:01:53 +01:00 committed by Gail Badner
parent 9c376a39f9
commit bf08752d3a
5 changed files with 19 additions and 25 deletions

View File

@ -21,11 +21,8 @@ import org.hibernate.type.Type;
* *
* @author Gavin King * @author Gavin King
* @author Steve Ebersole * @author Steve Ebersole
*
* @deprecated In optimized implementations, wrapping the id is not necessary.
*/ */
@Deprecated final class CacheKeyImplementation implements Serializable {
final class OldCacheKeyImplementation implements Serializable {
private final Object id; private final Object id;
private final Type type; private final Type type;
private final String entityOrRoleName; private final String entityOrRoleName;
@ -43,7 +40,7 @@ final class OldCacheKeyImplementation implements Serializable {
* @param tenantId The tenant identifier associated this data. * @param tenantId The tenant identifier associated this data.
* @param factory The session factory for which we are caching * @param factory The session factory for which we are caching
*/ */
OldCacheKeyImplementation( CacheKeyImplementation(
final Object id, final Object id,
final Type type, final Type type,
final String entityOrRoleName, final String entityOrRoleName,
@ -74,11 +71,11 @@ final class OldCacheKeyImplementation implements Serializable {
if ( this == other ) { if ( this == other ) {
return true; 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 //hashCode is part of this check since it is pre-calculated and hash must match for equals to be true
return false; return false;
} }
final OldCacheKeyImplementation that = (OldCacheKeyImplementation) other; final CacheKeyImplementation that = (CacheKeyImplementation) other;
return EqualsHelper.equals( entityOrRoleName, that.entityOrRoleName ) return EqualsHelper.equals( entityOrRoleName, that.entityOrRoleName )
&& type.isEqual( id, that.id) && type.isEqual( id, that.id)
&& EqualsHelper.equals( tenantId, that.tenantId ); && EqualsHelper.equals( tenantId, that.tenantId );

View File

@ -43,27 +43,27 @@ public class DefaultCacheKeysFactory implements CacheKeysFactory {
public static final DefaultCacheKeysFactory INSTANCE = new DefaultCacheKeysFactory(); public static final DefaultCacheKeysFactory INSTANCE = new DefaultCacheKeysFactory();
public static Object staticCreateCollectionKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { 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) { 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) { 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) { public static Object staticGetEntityId(Object cacheKey) {
return ((OldCacheKeyImplementation) cacheKey).getId(); return ((CacheKeyImplementation) cacheKey).getId();
} }
public static Object staticGetCollectionId(Object cacheKey) { public static Object staticGetCollectionId(Object cacheKey) {
return ((OldCacheKeyImplementation) cacheKey).getId(); return ((CacheKeyImplementation) cacheKey).getId();
} }
public static Object[] staticGetNaturalIdValues(Object cacheKey) { public static Object[] staticGetNaturalIdValues(Object cacheKey) {
return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues(); return ((NaturalIdCacheKey) cacheKey).getNaturalIdValues();
} }
@Override @Override

View File

@ -26,11 +26,8 @@ import org.hibernate.type.Type;
* *
* @author Eric Dalquist * @author Eric Dalquist
* @author Steve Ebersole * @author Steve Ebersole
*
* @deprecated Cache implementation should provide optimized key.
*/ */
@Deprecated public class NaturalIdCacheKey implements Serializable {
public class OldNaturalIdCacheKey implements Serializable {
private final Serializable[] naturalIdValues; private final Serializable[] naturalIdValues;
private final String entityName; private final String entityName;
private final String tenantId; private final String tenantId;
@ -45,7 +42,7 @@ public class OldNaturalIdCacheKey implements Serializable {
* @param naturalIdPropertyIndexes * @param naturalIdPropertyIndexes
* @param session The originating session * @param session The originating session
*/ */
public OldNaturalIdCacheKey( public NaturalIdCacheKey(
final Object[] naturalIdValues, final Object[] naturalIdValues,
Type[] propertyTypes, int[] naturalIdPropertyIndexes, final String entityName, Type[] propertyTypes, int[] naturalIdPropertyIndexes, final String entityName,
final SharedSessionContractImplementor session) { final SharedSessionContractImplementor session) {
@ -140,12 +137,12 @@ public class OldNaturalIdCacheKey implements Serializable {
return true; 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 //hashCode is part of this check since it is pre-calculated and hash must match for equals to be true
return false; return false;
} }
final OldNaturalIdCacheKey other = (OldNaturalIdCacheKey) o; final NaturalIdCacheKey other = (NaturalIdCacheKey) o;
return EqualsHelper.equals( entityName, other.entityName ) return EqualsHelper.equals( entityName, other.entityName )
&& EqualsHelper.equals( tenantId, other.tenantId ) && EqualsHelper.equals( tenantId, other.tenantId )
&& Arrays.deepEquals( this.naturalIdValues, other.naturalIdValues ); && Arrays.deepEquals( this.naturalIdValues, other.naturalIdValues );

View File

@ -34,7 +34,7 @@ public class SimpleCacheKeysFactory implements CacheKeysFactory {
@Override @Override
public Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) { public Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SharedSessionContractImplementor session) {
// natural ids always need to be wrapped // 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 @Override
@ -49,6 +49,6 @@ public class SimpleCacheKeysFactory implements CacheKeysFactory {
@Override @Override
public Object[] getNaturalIdValues(Object cacheKey) { public Object[] getNaturalIdValues(Object cacheKey) {
return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues(); return ((NaturalIdCacheKey) cacheKey).getNaturalIdValues();
} }
} }

View File

@ -12,7 +12,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import org.hibernate.cache.internal.DefaultCacheKeysFactory; 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.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister; 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 ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(key); oos.writeObject(key);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); 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, keyClone);
assertEquals(key.hashCode(), keyClone.hashCode()); assertEquals(key.hashCode(), keyClone.hashCode());