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 f744f89bd3
commit 7daab773ce
5 changed files with 19 additions and 25 deletions

View File

@ -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 );

View File

@ -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, SessionImplementor 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

View File

@ -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 SessionImplementor session) {
@ -139,12 +136,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 );

View File

@ -34,7 +34,7 @@ public class SimpleCacheKeysFactory implements CacheKeysFactory {
@Override
public Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor 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();
}
}

View File

@ -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());