Skip to content

Commit cffe71a

Browse files
rvansaSanne
authored andcommitted
HHH-9840 Change all kinds of CacheKey contract to a raw Object
* Replaced all CacheKey with Object * Because of statistics, added unwrap operation to all AccessStrategies
1 parent 16ae00a commit cffe71a

File tree

90 files changed

+701
-694
lines changed

Some content is hidden

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

90 files changed

+701
-694
lines changed

hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.hibernate.action.spi.BeforeTransactionCompletionProcess;
1313
import org.hibernate.action.spi.Executable;
1414
import org.hibernate.cache.CacheException;
15-
import org.hibernate.cache.spi.CollectionCacheKey;
1615
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
1716
import org.hibernate.cache.spi.access.SoftLock;
1817
import org.hibernate.collection.spi.PersistentCollection;
@@ -78,7 +77,7 @@ public final void beforeExecutions() throws CacheException {
7877
// the database (this action is responsible for second-level cache invalidation only)
7978
if ( persister.hasCache() ) {
8079
final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy();
81-
final CollectionCacheKey ck = cache.generateCacheKey(
80+
final Object ck = cache.generateCacheKey(
8281
key,
8382
persister,
8483
session.getFactory(),
@@ -131,7 +130,7 @@ protected final SessionImplementor getSession() {
131130
protected final void evict() throws CacheException {
132131
if ( persister.hasCache() ) {
133132
final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy();
134-
final CollectionCacheKey ck = cache.generateCacheKey(
133+
final Object ck = cache.generateCacheKey(
135134
key,
136135
persister,
137136
session.getFactory(),
@@ -175,7 +174,7 @@ private CacheCleanupProcess(Serializable key, CollectionPersister persister, Sof
175174
@Override
176175
public void doAfterTransactionCompletion(boolean success, SessionImplementor session) {
177176
final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy();
178-
final CollectionCacheKey ck = cache.generateCacheKey(
177+
final Object ck = cache.generateCacheKey(
179178
key,
180179
persister,
181180
session.getFactory(),

hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.hibernate.AssertionFailure;
1212
import org.hibernate.HibernateException;
13-
import org.hibernate.cache.spi.EntityCacheKey;
1413
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
1514
import org.hibernate.cache.spi.access.SoftLock;
1615
import org.hibernate.engine.spi.EntityEntry;
@@ -85,7 +84,7 @@ public void execute() throws HibernateException {
8584
version = persister.getVersion( instance );
8685
}
8786

88-
final EntityCacheKey ck;
87+
final Object ck;
8988
if ( persister.hasCache() ) {
9089
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
9190
ck = cache.generateCacheKey( id, persister, session.getFactory(), session.getTenantIdentifier() );
@@ -189,7 +188,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
189188
EntityPersister entityPersister = getPersister();
190189
if ( entityPersister.hasCache() ) {
191190
EntityRegionAccessStrategy cache = entityPersister.getCacheAccessStrategy();
192-
final EntityCacheKey ck = cache.generateCacheKey(
191+
final Object ck = cache.generateCacheKey(
193192
getId(),
194193
entityPersister,
195194
session.getFactory(),

hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.hibernate.AssertionFailure;
1212
import org.hibernate.HibernateException;
13-
import org.hibernate.cache.spi.EntityCacheKey;
1413
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
1514
import org.hibernate.cache.spi.entry.CacheEntry;
1615
import org.hibernate.engine.internal.Versioning;
@@ -118,7 +117,7 @@ public void execute() throws HibernateException {
118117
);
119118
cacheEntry = persister.getCacheEntryStructure().structure( ce );
120119
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
121-
final EntityCacheKey ck = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() );
120+
final Object ck = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() );
122121

123122
final boolean put = cacheInsert( persister, ck );
124123

@@ -138,7 +137,7 @@ public void execute() throws HibernateException {
138137
markExecuted();
139138
}
140139

141-
private boolean cacheInsert(EntityPersister persister, EntityCacheKey ck) {
140+
private boolean cacheInsert(EntityPersister persister, Object ck) {
142141
try {
143142
getSession().getEventListenerManager().cachePutStart();
144143
return persister.getCacheAccessStrategy().insert( ck, cacheEntry, version );
@@ -213,7 +212,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
213212
if ( success && isCachePutEnabled( persister, getSession() ) ) {
214213
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
215214
SessionFactoryImplementor sessionFactoryImplementor = session.getFactory();
216-
final EntityCacheKey ck = cache.generateCacheKey( getId(), persister, sessionFactoryImplementor, session.getTenantIdentifier() );
215+
final Object ck = cache.generateCacheKey( getId(), persister, sessionFactoryImplementor, session.getTenantIdentifier() );
217216
final boolean put = cacheAfterInsert( cache, ck );
218217

219218
if ( put && sessionFactoryImplementor.getStatistics().isStatisticsEnabled() ) {
@@ -224,7 +223,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
224223
postCommitInsert( success );
225224
}
226225

227-
private boolean cacheAfterInsert(EntityRegionAccessStrategy cache, EntityCacheKey ck) {
226+
private boolean cacheAfterInsert(EntityRegionAccessStrategy cache, Object ck) {
228227
final SessionEventListenerManager eventListenerManager = getSession().getEventListenerManager();
229228
try {
230229
eventListenerManager.cachePutStart();

hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.hibernate.AssertionFailure;
1212
import org.hibernate.HibernateException;
1313
import org.hibernate.cache.CacheException;
14-
import org.hibernate.cache.spi.EntityCacheKey;
1514
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
1615
import org.hibernate.cache.spi.access.SoftLock;
1716
import org.hibernate.cache.spi.entry.CacheEntry;
@@ -127,7 +126,7 @@ public void execute() throws HibernateException {
127126
previousVersion = persister.getVersion( instance );
128127
}
129128

130-
final EntityCacheKey ck;
129+
final Object ck;
131130
if ( persister.hasCache() ) {
132131
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
133132
ck = cache.generateCacheKey(
@@ -216,7 +215,7 @@ public void execute() throws HibernateException {
216215
}
217216
}
218217

219-
private boolean cacheUpdate(EntityPersister persister, Object previousVersion, EntityCacheKey ck) {
218+
private boolean cacheUpdate(EntityPersister persister, Object previousVersion, Object ck) {
220219
try {
221220
getSession().getEventListenerManager().cachePutStart();
222221
return persister.getCacheAccessStrategy().update( ck, cacheEntry, nextVersion, previousVersion );
@@ -312,7 +311,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
312311
final EntityPersister persister = getPersister();
313312
if ( persister.hasCache() ) {
314313
final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy();
315-
final EntityCacheKey ck = cache.generateCacheKey(
314+
final Object ck = cache.generateCacheKey(
316315
getId(),
317316
persister,
318317
session.getFactory(),
@@ -334,7 +333,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
334333
postCommitUpdate( success );
335334
}
336335

337-
private boolean cacheAfterUpdate(EntityRegionAccessStrategy cache, EntityCacheKey ck) {
336+
private boolean cacheAfterUpdate(EntityRegionAccessStrategy cache, Object ck) {
338337
SessionEventListenerManager eventListenerManager = getSession().getEventListenerManager();
339338
try {
340339
eventListenerManager.cachePutStart();

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

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

1212
import org.hibernate.boot.Metadata;
13-
import org.hibernate.cache.spi.CollectionCacheKey;
1413
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
1514
import org.hibernate.engine.spi.SessionFactoryImplementor;
1615
import org.hibernate.event.service.spi.EventListenerRegistry;
@@ -141,7 +140,7 @@ private void evict(Serializable id, CollectionPersister collectionPersister, Eve
141140
LOG.debug( "Evict CollectionRegion " + collectionPersister.getRole() + " for id " + id );
142141
}
143142
CollectionRegionAccessStrategy cache = collectionPersister.getCacheAccessStrategy();
144-
CollectionCacheKey key = cache.generateCacheKey(
143+
Object key = cache.generateCacheKey(
145144
id,
146145
collectionPersister,
147146
session.getFactory(),

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
*/
77
package org.hibernate.cache.internal;
88

9-
import java.io.Serializable;
10-
11-
import org.hibernate.cache.spi.CollectionCacheKey;
12-
import org.hibernate.cache.spi.EntityCacheKey;
13-
import org.hibernate.cache.spi.NaturalIdCacheKey;
149
import org.hibernate.engine.spi.SessionFactoryImplementor;
1510
import org.hibernate.engine.spi.SessionImplementor;
1611
import org.hibernate.persister.collection.CollectionPersister;
@@ -44,16 +39,27 @@
4439
*/
4540
public class DefaultCacheKeysFactory {
4641

47-
public static CollectionCacheKey createCollectionKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
42+
public static Object createCollectionKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
4843
return new OldCacheKeyImplementation( id, persister.getKeyType(), persister.getRole(), tenantIdentifier, factory );
4944
}
5045

51-
public static EntityCacheKey createEntityKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
46+
public static Object createEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
5247
return new OldCacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory );
5348
}
5449

55-
public static NaturalIdCacheKey createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) {
50+
public static Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) {
5651
return new OldNaturalIdCacheKey( naturalIdValues, persister, session );
5752
}
5853

54+
public static Object getEntityId(Object cacheKey) {
55+
return ((OldCacheKeyImplementation) cacheKey).getId();
56+
}
57+
58+
public static Object getCollectionId(Object cacheKey) {
59+
return ((OldCacheKeyImplementation) cacheKey).getId();
60+
}
61+
62+
public static Object[] getNaturalIdValues(Object cacheKey) {
63+
return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues();
64+
}
5965
}

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

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import java.io.Serializable;
1010

11-
import org.hibernate.cache.spi.CollectionCacheKey;
12-
import org.hibernate.cache.spi.EntityCacheKey;
1311
import org.hibernate.engine.spi.SessionFactoryImplementor;
1412
import org.hibernate.internal.util.compare.EqualsHelper;
1513
import org.hibernate.type.Type;
@@ -25,8 +23,8 @@
2523
* @author Steve Ebersole
2624
*/
2725
@Deprecated
28-
final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCacheKey, Serializable {
29-
private final Serializable key;
26+
final class OldCacheKeyImplementation implements Serializable {
27+
private final Object id;
3028
private final Type type;
3129
private final String entityOrRoleName;
3230
private final String tenantId;
@@ -44,44 +42,26 @@ final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCache
4442
* @param factory The session factory for which we are caching
4543
*/
4644
OldCacheKeyImplementation(
47-
final Serializable id,
45+
final Object id,
4846
final Type type,
4947
final String entityOrRoleName,
5048
final String tenantId,
5149
final SessionFactoryImplementor factory) {
52-
this.key = id;
50+
this.id = id;
5351
this.type = type;
5452
this.entityOrRoleName = entityOrRoleName;
5553
this.tenantId = tenantId;
5654
this.hashCode = calculateHashCode( type, factory );
5755
}
5856

5957
private int calculateHashCode(Type type, SessionFactoryImplementor factory) {
60-
int result = type.getHashCode( key, factory );
58+
int result = type.getHashCode(id, factory );
6159
result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0);
6260
return result;
6361
}
6462

65-
@Override
66-
public Serializable getKey() {
67-
return key;
68-
}
69-
70-
@Override
71-
public String getEntityName() {
72-
//defined exclusively on EntityCacheKey
73-
return entityOrRoleName;
74-
}
75-
76-
@Override
77-
public String getCollectionRole() {
78-
//defined exclusively on CollectionCacheKey
79-
return entityOrRoleName;
80-
}
81-
82-
@Override
83-
public String getTenantId() {
84-
return tenantId;
63+
public Object getId() {
64+
return id;
8565
}
8666

8767
@Override
@@ -98,7 +78,7 @@ public boolean equals(Object other) {
9878
}
9979
final OldCacheKeyImplementation that = (OldCacheKeyImplementation) other;
10080
return EqualsHelper.equals( entityOrRoleName, that.entityOrRoleName )
101-
&& type.isEqual( key, that.key )
81+
&& type.isEqual(id, that.id)
10282
&& EqualsHelper.equals( tenantId, that.tenantId );
10383
}
10484

@@ -110,6 +90,6 @@ public int hashCode() {
11090
@Override
11191
public String toString() {
11292
// Used to be required for OSCache
113-
return entityOrRoleName + '#' + key.toString();
93+
return entityOrRoleName + '#' + id.toString();
11494
}
11595
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.io.Serializable;
1212
import java.util.Arrays;
1313

14-
import org.hibernate.cache.spi.NaturalIdCacheKey;
1514
import org.hibernate.engine.spi.SessionFactoryImplementor;
1615
import org.hibernate.engine.spi.SessionImplementor;
1716
import org.hibernate.internal.util.ValueHolder;
@@ -30,7 +29,7 @@
3029
* @author Steve Ebersole
3130
*/
3231
@Deprecated
33-
public class OldNaturalIdCacheKey implements NaturalIdCacheKey, Serializable {
32+
public class OldNaturalIdCacheKey implements Serializable {
3433
private final Serializable[] naturalIdValues;
3534
private final String entityName;
3635
private final String tenantId;

hibernate-core/src/main/java/org/hibernate/cache/spi/CacheKey.java

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

hibernate-core/src/main/java/org/hibernate/cache/spi/CollectionCacheKey.java

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

0 commit comments

Comments
 (0)