Skip to content

Commit 149da82

Browse files
committed
HHH-15610 Remove internal CacheKeyValueDescriptor uses from Type and JavaType
1 parent 08d1d97 commit 149da82

File tree

61 files changed

+182
-717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+182
-717
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyImplementation.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
@Internal
2727
public final class CacheKeyImplementation implements Serializable {
2828
private final Object id;
29-
private final CacheKeyValueDescriptor cacheKeyValueDescriptor;
3029
private final String entityOrRoleName;
3130
private final String tenantId;
3231
private final int hashCode;
@@ -49,24 +48,14 @@ public CacheKeyImplementation(
4948
final String entityOrRoleName,
5049
final String tenantId,
5150
final SessionFactoryImplementor factory) {
52-
this.id = id;
51+
this.id = type.disassemble( id, factory );
5352
this.entityOrRoleName = entityOrRoleName;
5453
this.tenantId = tenantId;
55-
final CacheKeyValueDescriptor cacheKeyValueDescriptor = type.toCacheKeyDescriptor( factory );
56-
// Optimization for the very common case Integer/Long etc. which use the default cache key descriptor
57-
// Doing this helps to avoid megamorphic call sites and reduces the cache key serialization size
58-
if ( cacheKeyValueDescriptor == DefaultCacheKeyValueDescriptor.INSTANCE ) {
59-
this.cacheKeyValueDescriptor = null;
60-
this.hashCode = Objects.hashCode( id );
61-
}
62-
else {
63-
this.cacheKeyValueDescriptor = cacheKeyValueDescriptor;
64-
this.hashCode = calculateHashCode();
65-
}
54+
this.hashCode = calculateHashCode( id, type, tenantId );
6655
}
6756

68-
private int calculateHashCode() {
69-
int result = cacheKeyValueDescriptor.getHashCode( id );
57+
private static int calculateHashCode(Object id, Type type, String tenantId) {
58+
int result = type.getHashCode( id );
7059
result = 31 * result + ( tenantId != null ? tenantId.hashCode() : 0 );
7160
return result;
7261
}
@@ -88,18 +77,9 @@ public boolean equals(Object other) {
8877
return false;
8978
}
9079
final CacheKeyImplementation that = (CacheKeyImplementation) other;
91-
if ( !entityOrRoleName.equals( that.entityOrRoleName ) ) {
92-
return false;
93-
}
94-
if ( cacheKeyValueDescriptor == null ) {
95-
if ( !Objects.equals( id, that.id ) ) {
96-
return false;
97-
}
98-
}
99-
else if ( !cacheKeyValueDescriptor.isEqual( id, that.id ) ) {
100-
return false;
101-
}
102-
return Objects.equals( tenantId, that.tenantId );
80+
return entityOrRoleName.equals( that.entityOrRoleName )
81+
&& Objects.deepEquals( id, that.id )
82+
&& Objects.equals( tenantId, that.tenantId );
10383
}
10484

10585
@Override

hibernate-core/src/main/java/org/hibernate/cache/internal/CacheKeyValueDescriptor.java

Lines changed: 0 additions & 19 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/cache/internal/ComponentCacheKeyValueDescriptor.java

Lines changed: 0 additions & 97 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/cache/internal/CustomComponentCacheKeyValueDescriptor.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeyValueDescriptor.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/cache/internal/JavaTypeCacheKeyValueDescriptor.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

hibernate-core/src/main/java/org/hibernate/type/AbstractType.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public Serializable disassemble(Object value, SharedSessionContractImplementor s
6161
}
6262
}
6363

64+
@Override
65+
public Serializable disassemble(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
66+
if ( value == null ) {
67+
return null;
68+
}
69+
else {
70+
return (Serializable) deepCopy( value, sessionFactory );
71+
}
72+
}
73+
6474
@Override
6575
public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner)
6676
throws HibernateException {

hibernate-core/src/main/java/org/hibernate/type/AnyType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ public Serializable disassemble(Object value, SharedSessionContractImplementor s
300300
}
301301
}
302302

303+
@Override
304+
public Serializable disassemble(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
305+
throw new UnsupportedOperationException( "AnyType not supported as part of cache key!" );
306+
}
307+
303308
@Override
304309
public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner, Map<Object, Object> copyCache)
305310
throws HibernateException {

hibernate-core/src/main/java/org/hibernate/type/BasicType.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.util.List;
1111

1212
import org.hibernate.Incubating;
13-
import org.hibernate.cache.internal.CacheKeyValueDescriptor;
1413
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1514
import org.hibernate.mapping.IndexedConsumer;
1615
import org.hibernate.metamodel.mapping.BasicValuedMapping;
@@ -29,7 +28,7 @@
2928
*
3029
* @author Steve Ebersole
3130
*/
32-
public interface BasicType<T> extends Type, BasicDomainType<T>, MappingType, BasicValuedMapping, JdbcMapping, CacheKeyValueDescriptor {
31+
public interface BasicType<T> extends Type, BasicDomainType<T>, MappingType, BasicValuedMapping, JdbcMapping {
3332
/**
3433
* Get the names under which this type should be registered in the type registry.
3534
*

hibernate-core/src/main/java/org/hibernate/type/CollectionType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public Serializable disassemble(Object value, SharedSessionContractImplementor s
258258
return key == null ? null : getPersister( session ).getKeyType().disassemble( key, session, owner );
259259
}
260260

261+
@Override
262+
public Serializable disassemble(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
263+
throw new UnsupportedOperationException( "CollectionType not supported as part of cache key!" );
264+
}
265+
261266
@Override
262267
public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner)
263268
throws HibernateException {

hibernate-core/src/main/java/org/hibernate/type/ComponentType.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import org.hibernate.PropertyNotFoundException;
2222
import org.hibernate.boot.spi.MetadataBuildingContext;
2323
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
24-
import org.hibernate.cache.internal.CacheKeyValueDescriptor;
25-
import org.hibernate.cache.internal.ComponentCacheKeyValueDescriptor;
26-
import org.hibernate.cache.internal.CustomComponentCacheKeyValueDescriptor;
2724
import org.hibernate.engine.spi.CascadeStyle;
2825
import org.hibernate.engine.spi.Mapping;
2926
import org.hibernate.engine.spi.SessionFactoryImplementor;
@@ -67,7 +64,6 @@ public class ComponentType extends AbstractType implements CompositeTypeImplemen
6764
private final CompositeUserType<Object> compositeUserType;
6865

6966
private EmbeddableValuedModelPart mappingModelPart;
70-
private transient CacheKeyValueDescriptor cacheKeyValueDescriptor;
7167

7268
public ComponentType(Component component, int[] originalPropertyOrder, MetadataBuildingContext buildingContext) {
7369
this.componentClass = component.isDynamic()
@@ -630,6 +626,23 @@ else if ( compositeUserType != null ) {
630626
}
631627
}
632628

629+
@Override
630+
public Serializable disassemble(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
631+
if ( value == null ) {
632+
return null;
633+
}
634+
else if ( compositeUserType != null ) {
635+
return compositeUserType.disassemble( value );
636+
}
637+
else {
638+
Object[] values = getPropertyValues( value );
639+
for ( int i = 0; i < propertyTypes.length; i++ ) {
640+
values[i] = propertyTypes[i].disassemble( values[i], sessionFactory );
641+
}
642+
return values;
643+
}
644+
}
645+
633646
@Override
634647
public Object assemble(Serializable object, SharedSessionContractImplementor session, Object owner)
635648
throws HibernateException {
@@ -703,22 +716,6 @@ public boolean[] toColumnNullness(Object value, Mapping mapping) {
703716
return result;
704717
}
705718

706-
@Override
707-
public CacheKeyValueDescriptor toCacheKeyDescriptor(SessionFactoryImplementor sessionFactory) {
708-
CacheKeyValueDescriptor cacheKeyValueDescriptor = this.cacheKeyValueDescriptor;
709-
if ( cacheKeyValueDescriptor == null ) {
710-
if ( compositeUserType != null ) {
711-
cacheKeyValueDescriptor = new CustomComponentCacheKeyValueDescriptor( compositeUserType );
712-
}
713-
else {
714-
cacheKeyValueDescriptor = new ComponentCacheKeyValueDescriptor( mappingModelPart, sessionFactory );
715-
}
716-
this.cacheKeyValueDescriptor = cacheKeyValueDescriptor;
717-
}
718-
719-
return cacheKeyValueDescriptor;
720-
}
721-
722719
@Override
723720
public boolean isEmbedded() {
724721
return false;

0 commit comments

Comments
 (0)