From cffe71aeba38977f526b5ce7e870609ea419471c Mon Sep 17 00:00:00 2001 From: Radim Vansa Date: Mon, 8 Jun 2015 14:23:16 +0200 Subject: [PATCH] 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 --- .../action/internal/CollectionAction.java | 7 ++-- .../action/internal/EntityDeleteAction.java | 5 +-- .../action/internal/EntityInsertAction.java | 9 ++--- .../action/internal/EntityUpdateAction.java | 9 ++--- .../internal/CollectionCacheInvalidator.java | 3 +- .../internal/DefaultCacheKeysFactory.java | 22 +++++++---- .../internal/OldCacheKeyImplementation.java | 38 +++++-------------- .../cache/internal/OldNaturalIdCacheKey.java | 3 +- .../org/hibernate/cache/spi/CacheKey.java | 18 --------- .../cache/spi/CollectionCacheKey.java | 26 ------------- .../hibernate/cache/spi/EntityCacheKey.java | 26 ------------- .../cache/spi/NaturalIdCacheKey.java | 23 ----------- .../CollectionRegionAccessStrategy.java | 15 +++++--- .../access/EntityRegionAccessStrategy.java | 23 ++++++----- .../access/NaturalIdRegionAccessStrategy.java | 21 ++++++---- .../spi/access/RegionAccessStrategy.java | 17 ++++----- .../engine/internal/CacheHelper.java | 7 ++-- .../internal/NaturalIdXrefDelegate.java | 7 ++-- .../internal/StatefulPersistenceContext.java | 7 ++-- .../engine/internal/TwoPhaseLoad.java | 3 +- .../internal/CollectionLoadContext.java | 4 +- .../hibernate/engine/spi/BatchFetchQueue.java | 6 +-- .../spi/SessionFactoryDelegatingImpl.java | 28 +++++++------- .../engine/spi/SessionFactoryImplementor.java | 15 ++++++++ .../AbstractLockUpgradeEventListener.java | 3 +- ...aultInitializeCollectionEventListener.java | 3 +- .../internal/DefaultLoadEventListener.java | 5 +-- .../internal/DefaultRefreshEventListener.java | 3 +- .../org/hibernate/internal/CacheImpl.java | 10 ++--- .../internal/SessionFactoryImpl.java | 14 ++++++- .../internal/StatelessSessionImpl.java | 3 +- .../java/org/hibernate/loader/Loader.java | 3 +- .../entity/AbstractEntityPersister.java | 5 +-- ...oncurrentNaturalIdCacheStatisticsImpl.java | 11 ++++-- ...currentSecondLevelCacheStatisticsImpl.java | 27 +++++++++---- .../internal/ConcurrentStatisticsImpl.java | 20 +++++++++- .../cache/spi/NaturalIdCacheKeyTest.java | 19 +++++----- .../test/filter/DynamicFilterTest.java | 5 +-- ...opAwareCollectionRegionAccessStrategy.java | 24 ++++++------ ...onstopAwareEntityRegionAccessStrategy.java | 33 ++++++++-------- ...topAwareNaturalIdRegionAccessStrategy.java | 30 ++++++++------- .../AbstractEhcacheAccessStrategy.java | 33 +++------------- ...bstractReadWriteEhcacheAccessStrategy.java | 13 +++---- ...EhcacheCollectionRegionAccessStrategy.java | 26 +++++++++---- ...riteEhcacheEntityRegionAccessStrategy.java | 33 +++++++++------- ...eEhcacheNaturalIdRegionAccessStrategy.java | 31 +++++++++------ ...EhcacheCollectionRegionAccessStrategy.java | 24 +++++++++--- ...OnlyEhcacheEntityRegionAccessStrategy.java | 32 +++++++++++----- ...yEhcacheNaturalIdRegionAccessStrategy.java | 32 +++++++++++----- ...EhcacheCollectionRegionAccessStrategy.java | 17 ++++++++- ...riteEhcacheEntityRegionAccessStrategy.java | 24 +++++++++--- ...eEhcacheNaturalIdRegionAccessStrategy.java | 24 +++++++++--- ...EhcacheCollectionRegionAccessStrategy.java | 26 ++++++++----- ...onalEhcacheEntityRegionAccessStrategy.java | 35 +++++++++++------ ...lEhcacheNaturalIdRegionAccessStrategy.java | 34 +++++++++++------ .../collection/TransactionalAccess.java | 26 +++++++------ .../infinispan/entity/ReadOnlyAccess.java | 5 +-- .../entity/TransactionalAccess.java | 33 ++++++++-------- .../infinispan/naturalid/ReadOnlyAccess.java | 5 +-- .../naturalid/TransactionalAccess.java | 29 +++++++------- ...bstractEntityCollectionRegionTestCase.java | 3 +- .../AbstractGeneralDataRegionTestCase.java | 11 +++--- .../AbstractRegionImplTestCase.java | 7 ++-- ...ollectionRegionAccessStrategyTestCase.java | 21 ++++------ .../CollectionRegionImplTestCase.java | 11 +++--- .../TransactionalExtraAPITestCase.java | 3 +- ...actEntityRegionAccessStrategyTestCase.java | 21 +++++----- .../AbstractReadOnlyAccessTestCase.java | 7 ++-- .../AbstractTransactionalAccessTestCase.java | 8 ++-- .../entity/EntityRegionImplTestCase.java | 11 +++--- .../entity/TransactionalExtraAPITestCase.java | 5 +-- .../EntityCollectionInvalidationTestCase.java | 16 +++----- .../NaturalIdInvalidationTestCase.java | 15 +++----- .../infinispan/util/TestingKeyFactory.java | 29 ++------------ .../AbstractReadWriteAccessStrategy.java | 11 +++--- .../BaseCollectionRegionAccessStrategy.java | 12 +++--- .../cache/BaseEntityRegionAccessStrategy.java | 19 +++++----- .../BaseNaturalIdRegionAccessStrategy.java | 22 +++++------ .../cache/BaseRegionAccessStrategy.java | 17 ++++----- ...adWriteCollectionRegionAccessStrategy.java | 5 +-- ...ctReadWriteEntityRegionAccessStrategy.java | 13 +++---- ...eadWriteNaturalIdRegionAccessStrategy.java | 11 +++--- .../ReadOnlyEntityRegionAccessStrategy.java | 11 +++--- ...ReadOnlyNaturalIdRegionAccessStrategy.java | 3 +- ...adWriteCollectionRegionAccessStrategy.java | 10 +++-- .../ReadWriteEntityRegionAccessStrategy.java | 18 +++++---- ...eadWriteNaturalIdRegionAccessStrategy.java | 18 +++++---- ...ctionalCollectionRegionAccessStrategy.java | 3 +- ...ansactionalEntityRegionAccessStrategy.java | 9 ++--- ...actionalNaturalIdRegionAccessStrategy.java | 3 +- 90 files changed, 701 insertions(+), 694 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/cache/spi/CacheKey.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/cache/spi/CollectionCacheKey.java delete mode 100755 hibernate-core/src/main/java/org/hibernate/cache/spi/EntityCacheKey.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java index 3c070df5ba..eab5916640 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java @@ -12,7 +12,6 @@ import org.hibernate.action.spi.AfterTransactionCompletionProcess; import org.hibernate.action.spi.BeforeTransactionCompletionProcess; import org.hibernate.action.spi.Executable; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.collection.spi.PersistentCollection; @@ -78,7 +77,7 @@ public abstract class CollectionAction implements Executable, Serializable, Comp // the database (this action is responsible for second-level cache invalidation only) if ( persister.hasCache() ) { final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final CollectionCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), @@ -131,7 +130,7 @@ public abstract class CollectionAction implements Executable, Serializable, Comp protected final void evict() throws CacheException { if ( persister.hasCache() ) { final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final CollectionCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), @@ -175,7 +174,7 @@ public abstract class CollectionAction implements Executable, Serializable, Comp @Override public void doAfterTransactionCompletion(boolean success, SessionImplementor session) { final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final CollectionCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( key, persister, session.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java index d2ca5f9b8f..2ac9736be8 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java @@ -10,7 +10,6 @@ import java.io.Serializable; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.engine.spi.EntityEntry; @@ -85,7 +84,7 @@ public class EntityDeleteAction extends EntityAction { version = persister.getVersion( instance ); } - final EntityCacheKey ck; + final Object ck; if ( persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); ck = cache.generateCacheKey( id, persister, session.getFactory(), session.getTenantIdentifier() ); @@ -189,7 +188,7 @@ public class EntityDeleteAction extends EntityAction { EntityPersister entityPersister = getPersister(); if ( entityPersister.hasCache() ) { EntityRegionAccessStrategy cache = entityPersister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( getId(), entityPersister, session.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java index 4061fa29bc..8b64f155c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java @@ -10,7 +10,6 @@ import java.io.Serializable; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.engine.internal.Versioning; @@ -118,7 +117,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { ); cacheEntry = persister.getCacheEntryStructure().structure( ce ); final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() ); + final Object ck = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() ); final boolean put = cacheInsert( persister, ck ); @@ -138,7 +137,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { markExecuted(); } - private boolean cacheInsert(EntityPersister persister, EntityCacheKey ck) { + private boolean cacheInsert(EntityPersister persister, Object ck) { try { getSession().getEventListenerManager().cachePutStart(); return persister.getCacheAccessStrategy().insert( ck, cacheEntry, version ); @@ -213,7 +212,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { if ( success && isCachePutEnabled( persister, getSession() ) ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); SessionFactoryImplementor sessionFactoryImplementor = session.getFactory(); - final EntityCacheKey ck = cache.generateCacheKey( getId(), persister, sessionFactoryImplementor, session.getTenantIdentifier() ); + final Object ck = cache.generateCacheKey( getId(), persister, sessionFactoryImplementor, session.getTenantIdentifier() ); final boolean put = cacheAfterInsert( cache, ck ); if ( put && sessionFactoryImplementor.getStatistics().isStatisticsEnabled() ) { @@ -224,7 +223,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { postCommitInsert( success ); } - private boolean cacheAfterInsert(EntityRegionAccessStrategy cache, EntityCacheKey ck) { + private boolean cacheAfterInsert(EntityRegionAccessStrategy cache, Object ck) { final SessionEventListenerManager eventListenerManager = getSession().getEventListenerManager(); try { eventListenerManager.cachePutStart(); diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java index 4bffb3afb0..ea449655fa 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java @@ -11,7 +11,6 @@ import java.io.Serializable; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.entry.CacheEntry; @@ -127,7 +126,7 @@ public final class EntityUpdateAction extends EntityAction { previousVersion = persister.getVersion( instance ); } - final EntityCacheKey ck; + final Object ck; if ( persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); ck = cache.generateCacheKey( @@ -216,7 +215,7 @@ public final class EntityUpdateAction extends EntityAction { } } - private boolean cacheUpdate(EntityPersister persister, Object previousVersion, EntityCacheKey ck) { + private boolean cacheUpdate(EntityPersister persister, Object previousVersion, Object ck) { try { getSession().getEventListenerManager().cachePutStart(); return persister.getCacheAccessStrategy().update( ck, cacheEntry, nextVersion, previousVersion ); @@ -312,7 +311,7 @@ public final class EntityUpdateAction extends EntityAction { final EntityPersister persister = getPersister(); if ( persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( getId(), persister, session.getFactory(), @@ -334,7 +333,7 @@ public final class EntityUpdateAction extends EntityAction { postCommitUpdate( success ); } - private boolean cacheAfterUpdate(EntityRegionAccessStrategy cache, EntityCacheKey ck) { + private boolean cacheAfterUpdate(EntityRegionAccessStrategy cache, Object ck) { SessionEventListenerManager eventListenerManager = getSession().getEventListenerManager(); try { eventListenerManager.cachePutStart(); diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java index 83b5254a2a..773ce619e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java @@ -10,7 +10,6 @@ import java.io.Serializable; import java.util.Set; import org.hibernate.boot.Metadata; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.event.service.spi.EventListenerRegistry; @@ -141,7 +140,7 @@ public class CollectionCacheInvalidator LOG.debug( "Evict CollectionRegion " + collectionPersister.getRole() + " for id " + id ); } CollectionRegionAccessStrategy cache = collectionPersister.getCacheAccessStrategy(); - CollectionCacheKey key = cache.generateCacheKey( + Object key = cache.generateCacheKey( id, collectionPersister, session.getFactory(), 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 fcc060dd6f..d70bca553e 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 @@ -6,11 +6,6 @@ */ package org.hibernate.cache.internal; -import java.io.Serializable; - -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.persister.collection.CollectionPersister; @@ -44,16 +39,27 @@ import org.hibernate.persister.entity.EntityPersister; */ public class DefaultCacheKeysFactory { - public static CollectionCacheKey createCollectionKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public static Object createCollectionKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return new OldCacheKeyImplementation( id, persister.getKeyType(), persister.getRole(), tenantIdentifier, factory ); } - public static EntityCacheKey createEntityKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public static Object createEntityKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return new OldCacheKeyImplementation( id, persister.getIdentifierType(), persister.getRootEntityName(), tenantIdentifier, factory ); } - public static NaturalIdCacheKey createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + public static Object createNaturalIdKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { return new OldNaturalIdCacheKey( naturalIdValues, persister, session ); } + public static Object getEntityId(Object cacheKey) { + return ((OldCacheKeyImplementation) cacheKey).getId(); + } + + public static Object getCollectionId(Object cacheKey) { + return ((OldCacheKeyImplementation) cacheKey).getId(); + } + + public static Object[] getNaturalIdValues(Object cacheKey) { + return ((OldNaturalIdCacheKey) cacheKey).getNaturalIdValues(); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java index 2b2a00c2ce..20098a1d89 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/OldCacheKeyImplementation.java @@ -8,8 +8,6 @@ package org.hibernate.cache.internal; import java.io.Serializable; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.compare.EqualsHelper; import org.hibernate.type.Type; @@ -25,8 +23,8 @@ import org.hibernate.type.Type; * @author Steve Ebersole */ @Deprecated -final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCacheKey, Serializable { - private final Serializable key; +final class OldCacheKeyImplementation implements Serializable { + private final Object id; private final Type type; private final String entityOrRoleName; private final String tenantId; @@ -44,12 +42,12 @@ final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCache * @param factory The session factory for which we are caching */ OldCacheKeyImplementation( - final Serializable id, + final Object id, final Type type, final String entityOrRoleName, final String tenantId, final SessionFactoryImplementor factory) { - this.key = id; + this.id = id; this.type = type; this.entityOrRoleName = entityOrRoleName; this.tenantId = tenantId; @@ -57,31 +55,13 @@ final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCache } private int calculateHashCode(Type type, SessionFactoryImplementor factory) { - int result = type.getHashCode( key, factory ); + int result = type.getHashCode(id, factory ); result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0); return result; } - @Override - public Serializable getKey() { - return key; - } - - @Override - public String getEntityName() { - //defined exclusively on EntityCacheKey - return entityOrRoleName; - } - - @Override - public String getCollectionRole() { - //defined exclusively on CollectionCacheKey - return entityOrRoleName; - } - - @Override - public String getTenantId() { - return tenantId; + public Object getId() { + return id; } @Override @@ -98,7 +78,7 @@ final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCache } final OldCacheKeyImplementation that = (OldCacheKeyImplementation) other; return EqualsHelper.equals( entityOrRoleName, that.entityOrRoleName ) - && type.isEqual( key, that.key ) + && type.isEqual(id, that.id) && EqualsHelper.equals( tenantId, that.tenantId ); } @@ -110,6 +90,6 @@ final class OldCacheKeyImplementation implements EntityCacheKey, CollectionCache @Override public String toString() { // Used to be required for OSCache - return entityOrRoleName + '#' + key.toString(); + return entityOrRoleName + '#' + id.toString(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java index 8d3ca82f56..8acf9de9f9 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/OldNaturalIdCacheKey.java @@ -11,7 +11,6 @@ import java.io.ObjectInputStream; import java.io.Serializable; import java.util.Arrays; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.util.ValueHolder; @@ -30,7 +29,7 @@ import org.hibernate.type.Type; * @author Steve Ebersole */ @Deprecated -public class OldNaturalIdCacheKey implements NaturalIdCacheKey, Serializable { +public class OldNaturalIdCacheKey implements Serializable { private final Serializable[] naturalIdValues; private final String entityName; private final String tenantId; diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheKey.java deleted file mode 100644 index d6583060d4..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheKey.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.cache.spi; - -/** - * Allows multiple entity roles to be stored in the same cache region. Also allows for composite - * keys which do not properly implement equals()/hashCode(). - * - * @author Gavin King - * @author Steve Ebersole - */ -public interface CacheKey { - -} diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/CollectionCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/CollectionCacheKey.java deleted file mode 100644 index 7a9154b795..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/CollectionCacheKey.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.cache.spi; - -import java.io.Serializable; - -/** - * Allows multiple collection roles to be stored in the same cache region. Also allows for composite - * keys which do not properly implement equals()/hashCode(). - * - * @author Sanne Grinovero - * @since 5.0 - */ -public interface CollectionCacheKey extends CacheKey { - - public Serializable getKey(); - - public String getCollectionRole(); - - public String getTenantId(); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/EntityCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/EntityCacheKey.java deleted file mode 100755 index cee5a9319b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/EntityCacheKey.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.cache.spi; - -import java.io.Serializable; - -/** - * Allows multiple entity roles to be stored in the same cache region. Also allows for composite - * keys which do not properly implement equals()/hashCode(). - * - * @author Gavin King - * @author Steve Ebersole - */ -public interface EntityCacheKey extends CacheKey { - - public Serializable getKey(); - - public String getEntityName(); - - public String getTenantId(); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java deleted file mode 100644 index 0f22f37e7b..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/NaturalIdCacheKey.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.cache.spi; - -/** - * Defines a key for caching natural identifier resolutions into the second level cache. - * - * @author Sanne Grinovero - * @since 5.0 - */ -public interface NaturalIdCacheKey extends CacheKey { - - String getEntityName(); - - Object[] getNaturalIdValues(); - - String getTenantId(); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/CollectionRegionAccessStrategy.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/CollectionRegionAccessStrategy.java index 8813d6a2cd..621dc3c992 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/access/CollectionRegionAccessStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/access/CollectionRegionAccessStrategy.java @@ -6,9 +6,6 @@ */ package org.hibernate.cache.spi.access; -import java.io.Serializable; - -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.collection.CollectionPersister; @@ -26,7 +23,7 @@ import org.hibernate.persister.collection.CollectionPersister; * @author Gavin King * @author Steve Ebersole */ -public interface CollectionRegionAccessStrategy extends RegionAccessStrategy { +public interface CollectionRegionAccessStrategy extends RegionAccessStrategy { /** * To create instances of CollectionCacheKey for this region, Hibernate will invoke this method @@ -37,7 +34,15 @@ public interface CollectionRegionAccessStrategy extends RegionAccessStrategy { +public interface EntityRegionAccessStrategy extends RegionAccessStrategy { /** * To create instances of EntityCacheKey for this region, Hibernate will invoke this method @@ -41,7 +38,15 @@ public interface EntityRegionAccessStrategy extends RegionAccessStrategy { +public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy { /** * To create instances of NaturalIdCacheKey for this region, Hibernate will invoke this method @@ -47,7 +46,15 @@ public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy { +public interface RegionAccessStrategy { /** * Attempt to retrieve an object from the cache. Mainly used in attempting @@ -26,7 +25,7 @@ public interface RegionAccessStrategy { * @return the cached object or null * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ - Object get(T key, long txTimestamp) throws CacheException; + Object get(Object key, long txTimestamp) throws CacheException; /** * Attempt to cache an object, after loading from the database. @@ -39,7 +38,7 @@ public interface RegionAccessStrategy { * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ boolean putFromLoad( - T key, + Object key, Object value, long txTimestamp, Object version) throws CacheException; @@ -57,7 +56,7 @@ public interface RegionAccessStrategy { * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ boolean putFromLoad( - T key, + Object key, Object value, long txTimestamp, Object version, @@ -76,7 +75,7 @@ public interface RegionAccessStrategy { * @return A representation of our lock on the item; or null. * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ - SoftLock lockItem(T key, Object version) throws CacheException; + SoftLock lockItem(Object key, Object version) throws CacheException; /** * Lock the entire region @@ -95,7 +94,7 @@ public interface RegionAccessStrategy { * @param lock The lock previously obtained from {@link #lockItem} * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ - void unlockItem(T key, SoftLock lock) throws CacheException; + void unlockItem(Object key, SoftLock lock) throws CacheException; /** * Called after we have finished the attempted invalidation of the entire @@ -113,7 +112,7 @@ public interface RegionAccessStrategy { * @param key The key of the item to remove * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ - void remove(T key) throws CacheException; + void remove(Object key) throws CacheException; /** * Called to evict data from the entire region @@ -129,7 +128,7 @@ public interface RegionAccessStrategy { * @param key The key of the item to remove * @throws org.hibernate.cache.CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region} */ - void evict(T key) throws CacheException; + void evict(Object key) throws CacheException; /** * Forcibly evict all items from the cache immediately without regard for transaction diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/CacheHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/CacheHelper.java index 06cfcc0cb8..6eb0ff52da 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/CacheHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/CacheHelper.java @@ -8,7 +8,6 @@ package org.hibernate.engine.internal; import java.io.Serializable; -import org.hibernate.cache.spi.CacheKey; import org.hibernate.cache.spi.access.RegionAccessStrategy; import org.hibernate.engine.spi.SessionEventListenerManager; import org.hibernate.engine.spi.SessionImplementor; @@ -22,10 +21,10 @@ public final class CacheHelper { private CacheHelper() { } - public static Serializable fromSharedCache( + public static Serializable fromSharedCache( SessionImplementor session, - T cacheKey, - RegionAccessStrategy cacheAccessStrategy) { + Object cacheKey, + RegionAccessStrategy cacheAccessStrategy) { final SessionEventListenerManager eventListenerManager = session.getEventListenerManager(); Serializable cachedValue = null; eventListenerManager.cacheGetStart(); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/NaturalIdXrefDelegate.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/NaturalIdXrefDelegate.java index bc1f9f5040..0ef204f9c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/NaturalIdXrefDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/NaturalIdXrefDelegate.java @@ -15,7 +15,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.hibernate.AssertionFailure; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -110,12 +109,12 @@ public class NaturalIdXrefDelegate { if ( persister.hasNaturalIdCache() ) { final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister .getNaturalIdCacheAccessStrategy(); - final NaturalIdCacheKey naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); + final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); naturalIdCacheAccessStrategy.evict( naturalIdCacheKey ); if ( sessionCachedNaturalIdValues != null && !Arrays.equals( sessionCachedNaturalIdValues, naturalIdValues ) ) { - final NaturalIdCacheKey sessionNaturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( sessionCachedNaturalIdValues, persister, session() ); + final Object sessionNaturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( sessionCachedNaturalIdValues, persister, session() ); naturalIdCacheAccessStrategy.evict( sessionNaturalIdCacheKey ); } } @@ -240,7 +239,7 @@ public class NaturalIdXrefDelegate { // Try resolution from second-level cache final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); - final NaturalIdCacheKey naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); + final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session() ); pk = CacheHelper.fromSharedCache( session(), naturalIdCacheKey, naturalIdCacheAccessStrategy ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index b6b1d8cec6..becb76f8b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -31,7 +31,6 @@ import org.hibernate.NonUniqueObjectException; import org.hibernate.PersistentObjectException; import org.hibernate.TransientObjectException; import org.hibernate.action.spi.AfterTransactionCompletionProcess; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.collection.spi.PersistentCollection; @@ -1738,7 +1737,7 @@ public class StatefulPersistenceContext implements PersistenceContext { Object[] previousNaturalIdValues, CachedNaturalIdValueSource source) { final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); - final NaturalIdCacheKey naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); + final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); final SessionFactoryImplementor factory = session.getFactory(); @@ -1793,7 +1792,7 @@ public class StatefulPersistenceContext implements PersistenceContext { break; } case UPDATE: { - final NaturalIdCacheKey previousCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( previousNaturalIdValues, persister, session ); + final Object previousCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( previousNaturalIdValues, persister, session ); if ( naturalIdCacheKey.equals( previousCacheKey ) ) { // prevent identical re-caching, solves HHH-7309 return; @@ -1877,7 +1876,7 @@ public class StatefulPersistenceContext implements PersistenceContext { persister = locateProperPersister( persister ); final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); - final NaturalIdCacheKey naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); + final Object naturalIdCacheKey = naturalIdCacheAccessStrategy.generateCacheKey( naturalIdValues, persister, session ); naturalIdCacheAccessStrategy.evict( naturalIdCacheKey ); // if ( sessionCachedNaturalIdValues != null diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java index 444612d0c5..432610c58c 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java @@ -13,7 +13,6 @@ import org.hibernate.CacheMode; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.engine.spi.EntityEntry; @@ -185,7 +184,7 @@ public final class TwoPhaseLoad { final Object version = Versioning.getVersion( hydratedState, persister ); final CacheEntry entry = persister.buildCacheEntry( entity, hydratedState, version, session ); final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey cacheKey = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() ); + final Object cacheKey = cache.generateCacheKey( id, persister, factory, session.getTenantIdentifier() ); // explicit handling of caching for rows just inserted and then somehow forced to be read // from the database *within the same transaction*. usually this is done by diff --git a/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java b/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java index 0d13051b82..af8624032a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java @@ -17,8 +17,6 @@ import java.util.Set; import org.hibernate.CacheMode; import org.hibernate.EntityMode; import org.hibernate.HibernateException; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.entry.CollectionCacheEntry; import org.hibernate.collection.spi.PersistentCollection; @@ -335,7 +333,7 @@ public class CollectionLoadContext { final CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister ); final CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final CollectionCacheKey cacheKey = cache.generateCacheKey( + final Object cacheKey = cache.generateCacheKey( lce.getKey(), persister, session.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java index 245b0ae98b..b28669d43b 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java @@ -14,8 +14,6 @@ import java.util.Map; import java.util.Map.Entry; import org.hibernate.EntityMode; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.collection.spi.PersistentCollection; @@ -207,7 +205,7 @@ public class BatchFetchQueue { final SessionImplementor session = context.getSession(); if ( context.getSession().getCacheMode().isGetEnabled() && persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey key = cache.generateCacheKey( + final Object key = cache.generateCacheKey( entityKey.getIdentifier(), persister, session.getFactory(), @@ -323,7 +321,7 @@ public class BatchFetchQueue { SessionImplementor session = context.getSession(); if ( session.getCacheMode().isGetEnabled() && persister.hasCache() ) { CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - CollectionCacheKey cacheKey = cache.generateCacheKey( + Object cacheKey = cache.generateCacheKey( collectionKey, persister, session.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java index 6dc65a61a2..86cd592ba9 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryDelegatingImpl.java @@ -6,29 +6,19 @@ */ package org.hibernate.engine.spi; +import javax.naming.NamingException; +import javax.naming.Reference; import java.sql.Connection; import java.util.Map; import java.util.Properties; import java.util.Set; -import javax.naming.NamingException; -import javax.naming.Reference; -import org.hibernate.Cache; -import org.hibernate.CustomEntityDirtinessStrategy; -import org.hibernate.EntityNameResolver; -import org.hibernate.HibernateException; -import org.hibernate.Interceptor; -import org.hibernate.MappingException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.SessionFactoryObserver; -import org.hibernate.StatelessSession; -import org.hibernate.StatelessSessionBuilder; -import org.hibernate.TypeHelper; +import org.hibernate.*; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.spi.QueryCache; import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.UpdateTimestampsCache; +import org.hibernate.cache.spi.access.RegionAccessStrategy; import org.hibernate.cfg.Settings; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.dialect.Dialect; @@ -292,11 +282,21 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor, return delegate.getSecondLevelCacheRegion( regionName ); } + @Override + public RegionAccessStrategy getSecondLevelCacheRegionAccessStrategy(String regionName) { + return delegate.getSecondLevelCacheRegionAccessStrategy(regionName); + } + @Override public Region getNaturalIdCacheRegion(String regionName) { return delegate.getNaturalIdCacheRegion( regionName ); } + @Override + public RegionAccessStrategy getNaturalIdCacheRegionAccessStrategy(String regionName) { + return delegate.getNaturalIdCacheRegionAccessStrategy(regionName); + } + @Override public Map getAllSecondLevelCacheRegions() { return delegate.getAllSecondLevelCacheRegions(); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java index a889d82dc4..6bb7ae38fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionFactoryImplementor.java @@ -22,6 +22,7 @@ import org.hibernate.SessionFactoryObserver; import org.hibernate.cache.spi.QueryCache; import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.UpdateTimestampsCache; +import org.hibernate.cache.spi.access.RegionAccessStrategy; import org.hibernate.cfg.Settings; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.dialect.Dialect; @@ -190,6 +191,13 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory { * @return The region */ Region getSecondLevelCacheRegion(String regionName); + + /** + * Get access strategy to second-level cache region + * @param regionName + * @return + */ + RegionAccessStrategy getSecondLevelCacheRegionAccessStrategy(String regionName); /** * Get a named naturalId cache region @@ -199,6 +207,13 @@ public interface SessionFactoryImplementor extends Mapping, SessionFactory { */ Region getNaturalIdCacheRegion(String regionName); + /** + * Get access strategy to naturalId cache region + * @param regionName + * @return + */ + RegionAccessStrategy getNaturalIdCacheRegionAccessStrategy(String regionName); + /** * Get a map of all the second level cache regions currently maintained in * this session factory. The map is structured with the region name as the diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractLockUpgradeEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractLockUpgradeEventListener.java index bcf05f8147..66169048d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractLockUpgradeEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractLockUpgradeEventListener.java @@ -9,7 +9,6 @@ package org.hibernate.event.internal; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.ObjectDeletedException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.engine.spi.EntityEntry; @@ -64,7 +63,7 @@ public abstract class AbstractLockUpgradeEventListener extends AbstractReassocia final boolean cachingEnabled = persister.hasCache(); SoftLock lock = null; - EntityCacheKey ck = null; + Object ck = null; try { if ( cachingEnabled ) { EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java index 55bc6e10ff..2118ecd20b 100755 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java @@ -9,7 +9,6 @@ package org.hibernate.event.internal; import java.io.Serializable; import org.hibernate.HibernateException; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.entry.CollectionCacheEntry; import org.hibernate.collection.spi.PersistentCollection; @@ -118,7 +117,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle final SessionFactoryImplementor factory = source.getFactory(); final CollectionRegionAccessStrategy cacheAccessStrategy = persister.getCacheAccessStrategy(); - final CollectionCacheKey ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() ); + final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() ); final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() ); if ( factory.getStatistics().isStatisticsEnabled() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java index 23d8dfdc08..135ea67787 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java @@ -14,7 +14,6 @@ import org.hibernate.NonUniqueObjectException; import org.hibernate.PersistentObjectException; import org.hibernate.TypeMismatchException; import org.hibernate.WrongClassException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.cache.spi.entry.CacheEntry; @@ -358,7 +357,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i final LoadEventListener.LoadType options, final SessionImplementor source) { SoftLock lock = null; - final EntityCacheKey ck; + final Object ck; final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); if ( persister.hasCache() ) { ck = cache.generateCacheKey( @@ -576,7 +575,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i final SessionFactoryImplementor factory = source.getFactory(); final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( event.getEntityId(), persister, factory, diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java index 6ba772ef59..6ca71fe98d 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java @@ -13,7 +13,6 @@ import java.util.Map; import org.hibernate.HibernateException; import org.hibernate.PersistentObjectException; import org.hibernate.UnresolvableObjectException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.engine.internal.Cascade; import org.hibernate.engine.internal.CascadePoint; @@ -138,7 +137,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener { if ( persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - EntityCacheKey ck = cache.generateCacheKey( + Object ck = cache.generateCacheKey( id, persister, source.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CacheImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/CacheImpl.java index 25fe300463..dfac9b16a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CacheImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CacheImpl.java @@ -14,8 +14,6 @@ import java.util.concurrent.ConcurrentMap; import org.hibernate.HibernateException; import org.hibernate.boot.spi.SessionFactoryOptions; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.QueryCache; import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.RegionFactory; @@ -78,7 +76,7 @@ public class CacheImpl implements CacheImplementor { EntityPersister p = sessionFactory.getEntityPersister( entityName ); if ( p.hasCache() ) { EntityRegionAccessStrategy cache = p.getCacheAccessStrategy(); - EntityCacheKey key = cache.generateCacheKey( identifier, p, sessionFactory, null ); // have to assume non tenancy + Object key = cache.generateCacheKey( identifier, p, sessionFactory, null ); // have to assume non tenancy return cache.getRegion().contains( key ); } else { @@ -102,7 +100,7 @@ public class CacheImpl implements CacheImplementor { ); } EntityRegionAccessStrategy cache = p.getCacheAccessStrategy(); - EntityCacheKey key = cache.generateCacheKey( identifier, p, sessionFactory, null ); // have to assume non tenancy + Object key = cache.generateCacheKey( identifier, p, sessionFactory, null ); // have to assume non tenancy cache.evict( key ); } } @@ -158,7 +156,7 @@ public class CacheImpl implements CacheImplementor { CollectionPersister p = sessionFactory.getCollectionPersister( role ); if ( p.hasCache() ) { CollectionRegionAccessStrategy cache = p.getCacheAccessStrategy(); - CollectionCacheKey key = cache.generateCacheKey( ownerIdentifier, p, sessionFactory, null ); // have to assume non tenancy + Object key = cache.generateCacheKey( ownerIdentifier, p, sessionFactory, null ); // have to assume non tenancy return cache.getRegion().contains( key ); } else { @@ -177,7 +175,7 @@ public class CacheImpl implements CacheImplementor { ); } CollectionRegionAccessStrategy cache = p.getCacheAccessStrategy(); - CollectionCacheKey key = cache.generateCacheKey( ownerIdentifier, p, sessionFactory, null ); // have to assume non tenancy + Object key = cache.generateCacheKey( ownerIdentifier, p, sessionFactory, null ); // have to assume non tenancy cache.evict( key ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index d77fbb730f..2671565053 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.hibernate.cache.spi.access.RegionAccessStrategy; import org.jboss.logging.Logger; import org.hibernate.AssertionFailure; @@ -201,6 +202,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { private final transient TypeResolver typeResolver; private final transient TypeHelper typeHelper; private final transient SessionFactoryOptions sessionFactoryOptions; + private final transient Map cacheAccessStrategiesMap = new HashMap(); public SessionFactoryImpl(final MetadataImplementor metadata, SessionFactoryOptions options) { LOG.debug( "Building session factory" ); @@ -320,7 +322,6 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { // todo : similar for CollectionPersister/CollectionMetadata this.entityPersisters = new HashMap(); - Map cacheAccessStrategiesMap = new HashMap(); Map inFlightClassMetadataMap = new HashMap(); this.entityProxyInterfaceMap = CollectionHelper.concurrentMap( metadata.getEntityBindings().size() ); for ( final PersistentClass model : metadata.getEntityBindings() ) { @@ -430,6 +431,7 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { roles.add( persister.getRole() ); } } + this.collectionMetadata = Collections.unmodifiableMap( tmpCollectionMetadata ); for ( Map.Entry> entityToCollectionRoleMapEntry : inFlightEntityToCollectionRoleMap.entrySet() ) { @@ -1130,10 +1132,20 @@ public final class SessionFactoryImpl implements SessionFactoryImplementor { return cacheAccess.getSecondLevelCacheRegion( regionName ); } + @Override + public RegionAccessStrategy getSecondLevelCacheRegionAccessStrategy(String regionName) { + return cacheAccessStrategiesMap.get(regionName); + } + public Region getNaturalIdCacheRegion(String regionName) { return cacheAccess.getNaturalIdCacheRegion( regionName ); } + @Override + public RegionAccessStrategy getNaturalIdCacheRegionAccessStrategy(String regionName) { + return cacheAccessStrategiesMap.get(regionName); + } + @SuppressWarnings( {"unchecked"}) public Map getAllSecondLevelCacheRegions() { return cacheAccess.getAllSecondLevelCacheRegions(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index 62f719e9ff..9c2c425072 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -28,7 +28,6 @@ import org.hibernate.SessionException; import org.hibernate.StatelessSession; import org.hibernate.Transaction; import org.hibernate.UnresolvableObjectException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.internal.SessionEventListenerManagerImpl; @@ -272,7 +271,7 @@ public class StatelessSessionImpl extends AbstractSessionImpl implements Statele if ( persister.hasCache() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( id, persister, getFactory(), getTenantIdentifier() ); + final Object ck = cache.generateCacheKey( id, persister, getFactory(), getTenantIdentifier() ); cache.evict( ck ); } String previousFetchProfile = this.getLoadQueryInfluencers().getInternalFetchProfile(); diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 8a89ab38c0..51bc9b9a2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -32,7 +32,6 @@ import org.hibernate.ScrollableResults; import org.hibernate.Session; import org.hibernate.StaleObjectStateException; import org.hibernate.WrongClassException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.FilterKey; import org.hibernate.cache.spi.QueryCache; import org.hibernate.cache.spi.QueryKey; @@ -1623,7 +1622,7 @@ public abstract class Loader { // see if the entity defines reference caching, and if so use the cached reference (if one). if ( session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries() ) { final EntityRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( + final Object ck = cache.generateCacheKey( key.getIdentifier(), persister, session.getFactory(), diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 499ffbdfdc..3d4ea3adc7 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -36,7 +36,6 @@ import org.hibernate.StaleStateException; import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor; import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer; import org.hibernate.bytecode.spi.EntityInstrumentationMetadata; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.entry.CacheEntry; @@ -907,7 +906,7 @@ public abstract class AbstractEntityPersister if ( session.getCacheMode().isGetEnabled() && hasCache() ) { final EntityRegionAccessStrategy cache = getCacheAccessStrategy(); - final EntityCacheKey cacheKey = cache.generateCacheKey(id, this, session.getFactory(), session.getTenantIdentifier() ); + final Object cacheKey = cache.generateCacheKey(id, this, session.getFactory(), session.getTenantIdentifier() ); final Object ce = CacheHelper.fromSharedCache( session, cacheKey, cache ); if ( ce != null ) { final CacheEntry cacheEntry = (CacheEntry) getCacheEntryStructure().destructure( ce, factory ); @@ -4271,7 +4270,7 @@ public abstract class AbstractEntityPersister // check to see if it is in the second-level cache if ( session.getCacheMode().isGetEnabled() && hasCache() ) { final EntityRegionAccessStrategy cache = getCacheAccessStrategy(); - final EntityCacheKey ck = cache.generateCacheKey( id, this, session.getFactory(), session.getTenantIdentifier() ); + final Object ck = cache.generateCacheKey( id, this, session.getFactory(), session.getTenantIdentifier() ); final Object ce = CacheHelper.fromSharedCache( session, ck, getCacheAccessStrategy() ); if ( ce != null ) { return Boolean.FALSE; diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentNaturalIdCacheStatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentNaturalIdCacheStatisticsImpl.java index db14beb0c1..7eedbe4676 100644 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentNaturalIdCacheStatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentNaturalIdCacheStatisticsImpl.java @@ -13,8 +13,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.Region; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.stat.NaturalIdCacheStatistics; /** @@ -25,6 +25,7 @@ import org.hibernate.stat.NaturalIdCacheStatistics; public class ConcurrentNaturalIdCacheStatisticsImpl extends CategorizedStatistics implements NaturalIdCacheStatistics { private static final long serialVersionUID = 1L; private final transient Region region; + private final transient NaturalIdRegionAccessStrategy accessStrategy; private final AtomicLong hitCount = new AtomicLong(); private final AtomicLong missCount = new AtomicLong(); private final AtomicLong putCount = new AtomicLong(); @@ -35,15 +36,17 @@ public class ConcurrentNaturalIdCacheStatisticsImpl extends CategorizedStatistic private final Lock readLock; private final Lock writeLock; + { final ReadWriteLock lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); } - ConcurrentNaturalIdCacheStatisticsImpl(Region region) { + ConcurrentNaturalIdCacheStatisticsImpl(Region region, NaturalIdRegionAccessStrategy accessStrategy) { super( region.getName() ); this.region = region; + this.accessStrategy = accessStrategy; } @Override @@ -126,8 +129,8 @@ public class ConcurrentNaturalIdCacheStatisticsImpl extends CategorizedStatistic public Map getEntries() { final Map map = new HashMap(); for ( Object o : this.region.toMap().entrySet() ) { - final Map.Entry me = (Map.Entry) o; - map.put( ( (NaturalIdCacheKey) me.getKey() ).getNaturalIdValues(), me.getValue() ); + Map.Entry me = (Map.Entry) o; + map.put( accessStrategy.getNaturalIdValues(me.getKey()), me.getValue() ); } return map; } diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentSecondLevelCacheStatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentSecondLevelCacheStatisticsImpl.java index 8c4518352b..a6bce5e32b 100644 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentSecondLevelCacheStatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentSecondLevelCacheStatisticsImpl.java @@ -7,12 +7,12 @@ package org.hibernate.stat.internal; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.Region; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.stat.SecondLevelCacheStatistics; /** @@ -22,13 +22,19 @@ import org.hibernate.stat.SecondLevelCacheStatistics; */ public class ConcurrentSecondLevelCacheStatisticsImpl extends CategorizedStatistics implements SecondLevelCacheStatistics { private final transient Region region; + private final transient EntityRegionAccessStrategy entityRegionAccessStrategy; + private final transient CollectionRegionAccessStrategy collectionRegionAccessStrategy; private AtomicLong hitCount = new AtomicLong(); private AtomicLong missCount = new AtomicLong(); private AtomicLong putCount = new AtomicLong(); - ConcurrentSecondLevelCacheStatisticsImpl(Region region) { + ConcurrentSecondLevelCacheStatisticsImpl(Region region, + EntityRegionAccessStrategy entityRegionAccessStrategy, + CollectionRegionAccessStrategy collectionRegionAccessStrategy) { super( region.getName() ); this.region = region; + this.entityRegionAccessStrategy = entityRegionAccessStrategy; + this.collectionRegionAccessStrategy = collectionRegionAccessStrategy; } public long getHitCount() { @@ -57,10 +63,17 @@ public class ConcurrentSecondLevelCacheStatisticsImpl extends CategorizedStatist public Map getEntries() { Map map = new HashMap(); - Iterator iter = region.toMap().entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry me = (Map.Entry) iter.next(); - map.put(((EntityCacheKey) me.getKey()).getKey(), me.getValue()); + for (Object o : region.toMap().entrySet()) { + Map.Entry me = (Map.Entry) o; + Object id; + if (entityRegionAccessStrategy != null) { + id = entityRegionAccessStrategy.getCacheKeyId(me.getKey()); + } else if (collectionRegionAccessStrategy != null) { + id = collectionRegionAccessStrategy.getCacheKeyId(me.getKey()); + } else { + id = me.getKey(); + } + map.put(id, me.getValue()); } return map; } diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java index b9b6e87dee..16b5478fb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/ConcurrentStatisticsImpl.java @@ -11,6 +11,10 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; import org.hibernate.cache.spi.Region; +import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; +import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; +import org.hibernate.cache.spi.access.RegionAccessStrategy; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.collections.ArrayHelper; @@ -299,7 +303,10 @@ public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service if ( region == null ) { return null; } - nics = new ConcurrentNaturalIdCacheStatisticsImpl( region ); + NaturalIdRegionAccessStrategy accessStrategy + = (NaturalIdRegionAccessStrategy) sessionFactory.getNaturalIdCacheRegionAccessStrategy(regionName); + + nics = new ConcurrentNaturalIdCacheStatisticsImpl( region, accessStrategy ); ConcurrentNaturalIdCacheStatisticsImpl previous; if ( ( previous = (ConcurrentNaturalIdCacheStatisticsImpl) naturalIdCacheStatistics.putIfAbsent( regionName, nics @@ -328,7 +335,16 @@ public class ConcurrentStatisticsImpl implements StatisticsImplementor, Service if ( region == null ) { return null; } - slcs = new ConcurrentSecondLevelCacheStatisticsImpl( region ); + RegionAccessStrategy accessStrategy = sessionFactory.getSecondLevelCacheRegionAccessStrategy(regionName); + + EntityRegionAccessStrategy entityRegionAccessStrategy + = accessStrategy instanceof EntityRegionAccessStrategy ? + (EntityRegionAccessStrategy) accessStrategy : null; + CollectionRegionAccessStrategy collectionRegionAccessStrategy + = accessStrategy instanceof CollectionRegionAccessStrategy ? + (CollectionRegionAccessStrategy) accessStrategy : null; + + slcs = new ConcurrentSecondLevelCacheStatisticsImpl( region, entityRegionAccessStrategy, collectionRegionAccessStrategy ); ConcurrentSecondLevelCacheStatisticsImpl previous; if ( ( previous = (ConcurrentSecondLevelCacheStatisticsImpl) secondLevelCacheStatistics.putIfAbsent( regionName, slcs 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 771c92fcf6..9143c57f20 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 @@ -6,19 +6,13 @@ */ package org.hibernate.cache.spi; -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertArrayEquals; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.hibernate.cache.internal.DefaultCacheKeysFactory; +import org.hibernate.cache.internal.OldNaturalIdCacheKey; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.persister.entity.EntityPersister; @@ -27,6 +21,13 @@ import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class NaturalIdCacheKeyTest { @Test public void testSerializationRoundTrip() throws Exception { @@ -60,14 +61,14 @@ public class NaturalIdCacheKeyTest { } }); - final NaturalIdCacheKey key = DefaultCacheKeysFactory.createNaturalIdKey( new Object[] {"a", "b", "c"}, entityPersister, sessionImplementor ); + final OldNaturalIdCacheKey key = (OldNaturalIdCacheKey) DefaultCacheKeysFactory.createNaturalIdKey( 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 NaturalIdCacheKey keyClone = (NaturalIdCacheKey)ois.readObject(); + final OldNaturalIdCacheKey keyClone = (OldNaturalIdCacheKey) ois.readObject(); assertEquals(key, keyClone); assertEquals(key.hashCode(), keyClone.hashCode()); diff --git a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java index f28cf9c336..2357c70716 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/filter/DynamicFilterTest.java @@ -20,7 +20,6 @@ import org.hibernate.FetchMode; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.entry.CollectionCacheEntry; import org.hibernate.cfg.AvailableSettings; @@ -102,7 +101,7 @@ public class DynamicFilterTest extends BaseNonConfigCoreFunctionalTestCase { CollectionPersister persister = sessionFactory().getCollectionPersister( Salesperson.class.getName() + ".orders" ); assertTrue( "No cache for collection", persister.hasCache() ); CollectionRegionAccessStrategy cache = persister.getCacheAccessStrategy(); - CollectionCacheKey cacheKey = cache.generateCacheKey( + Object cacheKey = cache.generateCacheKey( testData.steveId, persister, sessionFactory(), @@ -121,7 +120,7 @@ public class DynamicFilterTest extends BaseNonConfigCoreFunctionalTestCase { .uniqueResult(); assertEquals( "Filtered-collection not bypassing 2L-cache", 1, sp.getOrders().size() ); - CollectionCacheKey cacheKey2 = cache.generateCacheKey( + Object cacheKey2 = cache.generateCacheKey( testData.steveId, persister, sessionFactory(), diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareCollectionRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareCollectionRegionAccessStrategy.java index 94b6457767..ffa8c52fef 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareCollectionRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareCollectionRegionAccessStrategy.java @@ -6,13 +6,9 @@ */ package org.hibernate.cache.ehcache.internal.nonstop; -import java.io.Serializable; - import net.sf.ehcache.constructs.nonstop.NonStopCacheException; - import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -49,7 +45,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public void evict(CollectionCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { try { actualStrategy.evict( key ); } @@ -69,7 +65,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public Object get(CollectionCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { return actualStrategy.get( key, txTimestamp ); } @@ -80,7 +76,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public SoftLock lockItem(CollectionCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { try { return actualStrategy.lockItem( key, version ); } @@ -102,7 +98,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); @@ -114,7 +110,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version ); } @@ -125,7 +121,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { actualStrategy.remove( key ); } @@ -145,7 +141,7 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { try { actualStrategy.unlockItem( key, lock ); } @@ -165,8 +161,12 @@ public class NonstopAwareCollectionRegionAccessStrategy implements CollectionReg } @Override - public CollectionCacheKey generateCacheKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); } + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareEntityRegionAccessStrategy.java index ca3795e1f9..7371faaf89 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareEntityRegionAccessStrategy.java @@ -6,13 +6,9 @@ */ package org.hibernate.cache.ehcache.internal.nonstop; -import java.io.Serializable; - import net.sf.ehcache.constructs.nonstop.NonStopCacheException; - import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -49,7 +45,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { try { return actualStrategy.afterInsert( key, value, version ); } @@ -60,7 +56,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { try { return actualStrategy.afterUpdate( key, value, currentVersion, previousVersion, lock ); @@ -72,7 +68,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public void evict(EntityCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { try { actualStrategy.evict( key ); } @@ -92,7 +88,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public Object get(EntityCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { return actualStrategy.get( key, txTimestamp ); } @@ -103,7 +99,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { try { return actualStrategy.insert( key, value, version ); } @@ -114,7 +110,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public SoftLock lockItem(EntityCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { try { return actualStrategy.lockItem( key, version ); } @@ -136,7 +132,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); @@ -148,7 +144,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version ); } @@ -159,7 +155,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { actualStrategy.remove( key ); } @@ -179,7 +175,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { try { actualStrategy.unlockItem( key, lock ); } @@ -199,7 +195,7 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { try { return actualStrategy.update( key, value, currentVersion, previousVersion ); @@ -211,7 +207,12 @@ public class NonstopAwareEntityRegionAccessStrategy implements EntityRegionAcces } @Override - public EntityCacheKey generateCacheKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier ); } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java index 22202fe7e3..67d3283830 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/nonstop/NonstopAwareNaturalIdRegionAccessStrategy.java @@ -7,10 +7,8 @@ package org.hibernate.cache.ehcache.internal.nonstop; import net.sf.ehcache.constructs.nonstop.NonStopCacheException; - import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -42,7 +40,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { try { return actualStrategy.insert( key, value ); } @@ -53,7 +51,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { try { return actualStrategy.afterInsert( key, value ); } @@ -64,7 +62,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { try { return actualStrategy.update( key, value ); } @@ -75,7 +73,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { try { return actualStrategy.afterUpdate( key, value, lock ); } @@ -91,7 +89,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public void evict(NaturalIdCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { try { actualStrategy.evict( key ); } @@ -111,7 +109,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public Object get(NaturalIdCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { return actualStrategy.get( key, txTimestamp ); } @@ -122,7 +120,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public SoftLock lockItem(NaturalIdCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { try { return actualStrategy.lockItem( key, version ); } @@ -144,7 +142,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); @@ -156,7 +154,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { try { return actualStrategy.putFromLoad( key, value, txTimestamp, version ); } @@ -167,7 +165,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { actualStrategy.remove( key ); } @@ -187,7 +185,7 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { try { actualStrategy.unlockItem( key, lock ); } @@ -207,8 +205,12 @@ public class NonstopAwareNaturalIdRegionAccessStrategy implements NaturalIdRegio } @Override - public NaturalIdCacheKey generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { return DefaultCacheKeysFactory.createNaturalIdKey( naturalIdValues, persister, session ); } + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/AbstractEhcacheAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/AbstractEhcacheAccessStrategy.java index 8ec4bda1a2..63ed4faf24 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/AbstractEhcacheAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/AbstractEhcacheAccessStrategy.java @@ -6,21 +6,10 @@ */ package org.hibernate.cache.ehcache.internal.strategy; -import java.io.Serializable; - import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheTransactionalDataRegion; -import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.CacheKey; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.SoftLock; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.engine.spi.SessionImplementor; -import org.hibernate.persister.collection.CollectionPersister; -import org.hibernate.persister.entity.EntityPersister; /** * Ultimate superclass for all Ehcache specific Hibernate AccessStrategy implementations. @@ -30,7 +19,7 @@ import org.hibernate.persister.entity.EntityPersister; * @author Chris Dennis * @author Alex Snaps */ -abstract class AbstractEhcacheAccessStrategy { +abstract class AbstractEhcacheAccessStrategy { private final T region; private final SessionFactoryOptions settings; @@ -66,7 +55,7 @@ abstract class AbstractEhcacheAccessStrategy - extends AbstractEhcacheAccessStrategy { +abstract class AbstractReadWriteEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy { private static final EhCacheMessageLogger LOG = Logger.getMessageLogger( EhCacheMessageLogger.class, @@ -55,7 +54,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements CollectionRegionAccessStrategy { /** @@ -40,12 +42,12 @@ public class NonStrictReadWriteEhcacheCollectionRegionAccessStrategy } @Override - public Object get(CollectionCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -62,7 +64,7 @@ public class NonStrictReadWriteEhcacheCollectionRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public SoftLock lockItem(CollectionCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -72,12 +74,22 @@ public class NonStrictReadWriteEhcacheCollectionRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { region().remove( key ); } @Override - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { region().remove( key ); } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheEntityRegionAccessStrategy.java index e68abd03c3..54e5af723a 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheEntityRegionAccessStrategy.java @@ -6,12 +6,10 @@ */ package org.hibernate.cache.ehcache.internal.strategy; -import java.io.Serializable; - import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheEntityRegion; -import org.hibernate.cache.spi.EntityCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -25,7 +23,7 @@ import org.hibernate.persister.entity.EntityPersister; * @author Alex Snaps */ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements EntityRegionAccessStrategy { /** @@ -44,12 +42,12 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy } @Override - public Object get(EntityCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -66,7 +64,7 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public SoftLock lockItem(EntityCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -76,7 +74,7 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { region().remove( key ); } @@ -86,7 +84,7 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy * Returns false since this is an asynchronous cache access strategy. */ @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; } @@ -96,7 +94,7 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy * Returns false since this is a non-strict read/write cache access strategy */ @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { return false; } @@ -106,22 +104,31 @@ public class NonStrictReadWriteEhcacheEntityRegionAccessStrategy * Removes the entry since this is a non-strict read/write cache strategy. */ @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { remove( key ); return false; } @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { unlockItem( key, lock ); return false; } @Override - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { region().remove( key ); } + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy.java index 5537087253..2999c3d3a3 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy.java @@ -9,7 +9,7 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheNaturalIdRegion; -import org.hibernate.cache.spi.NaturalIdCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -23,7 +23,7 @@ import org.hibernate.persister.entity.EntityPersister; * @author Alex Snaps */ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements NaturalIdRegionAccessStrategy { /** @@ -42,12 +42,12 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy } @Override - public Object get(NaturalIdCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -64,7 +64,7 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public SoftLock lockItem(NaturalIdCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -74,7 +74,7 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { region().remove( key ); } @@ -84,7 +84,7 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy * Returns false since this is an asynchronous cache access strategy. */ @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return false; } @@ -94,7 +94,7 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy * Returns false since this is a non-strict read/write cache access strategy */ @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { return false; } @@ -104,20 +104,29 @@ public class NonStrictReadWriteEhcacheNaturalIdRegionAccessStrategy * Removes the entry since this is a non-strict read/write cache strategy. */ @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { remove( key ); return false; } @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { unlockItem( key, lock ); return false; } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { region().remove( key ); } + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + return DefaultCacheKeysFactory.createNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java index 0b048b24fd..7de3b272ed 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java @@ -9,10 +9,12 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion; -import org.hibernate.cache.spi.CollectionCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.collection.CollectionPersister; /** * Ehcache specific read-only collection region access strategy @@ -21,7 +23,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Alex Snaps */ public class ReadOnlyEhcacheCollectionRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements CollectionRegionAccessStrategy { /** @@ -40,12 +42,12 @@ public class ReadOnlyEhcacheCollectionRegionAccessStrategy } @Override - public Object get(CollectionCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -57,7 +59,7 @@ public class ReadOnlyEhcacheCollectionRegionAccessStrategy } @Override - public SoftLock lockItem(CollectionCacheKey key, Object version) throws UnsupportedOperationException { + public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { return null; } @@ -67,6 +69,16 @@ public class ReadOnlyEhcacheCollectionRegionAccessStrategy * A no-op since this cache is read-only */ @Override - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { + } + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java index a09bbafb30..43d16d3f70 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java @@ -9,10 +9,12 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheEntityRegion; -import org.hibernate.cache.spi.EntityCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * Ehcache specific read-only entity region access strategy @@ -20,7 +22,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Chris Dennis * @author Alex Snaps */ -public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy +public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy implements EntityRegionAccessStrategy { /** @@ -39,12 +41,12 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc } @Override - public Object get(EntityCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -56,7 +58,7 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc } @Override - public SoftLock lockItem(EntityCacheKey key, Object version) throws UnsupportedOperationException { + public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { return null; } @@ -66,7 +68,7 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc * A no-op since this cache is read-only */ @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } @@ -76,12 +78,12 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc * This cache is asynchronous hence a no-op */ @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { region().put( key, value ); return true; } @@ -94,7 +96,7 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc * @throws UnsupportedOperationException always */ @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws UnsupportedOperationException { throw new UnsupportedOperationException( "Can't write to a readonly object" ); } @@ -107,8 +109,18 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc * @throws UnsupportedOperationException always */ @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws UnsupportedOperationException { throw new UnsupportedOperationException( "Can't write to a readonly object" ); } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java index 0a0e26cfff..35926666b9 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java @@ -9,10 +9,12 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheNaturalIdRegion; -import org.hibernate.cache.spi.NaturalIdCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * Ehcache specific read-only NaturalId region access strategy @@ -21,7 +23,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Alex Snaps */ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements NaturalIdRegionAccessStrategy { /** @@ -40,12 +42,12 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy } @Override - public Object get(NaturalIdCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return region().get( key ); } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( minimalPutOverride && region().contains( key ) ) { return false; @@ -57,7 +59,7 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy } @Override - public SoftLock lockItem(NaturalIdCacheKey key, Object version) throws UnsupportedOperationException { + public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { return null; } @@ -67,7 +69,7 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy * A no-op since this cache is read-only */ @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { region().remove( key ); } @@ -77,12 +79,12 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy * This cache is asynchronous hence a no-op */ @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return false; } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { region().put( key, value ); return true; } @@ -95,7 +97,7 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy * @throws UnsupportedOperationException always */ @Override - public boolean update(NaturalIdCacheKey key, Object value) throws UnsupportedOperationException { + public boolean update(Object key, Object value) throws UnsupportedOperationException { throw new UnsupportedOperationException( "Can't write to a readonly object" ); } @@ -107,7 +109,17 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy * @throws UnsupportedOperationException always */ @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws UnsupportedOperationException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws UnsupportedOperationException { throw new UnsupportedOperationException( "Can't write to a readonly object" ); } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + return DefaultCacheKeysFactory.createNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheCollectionRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheCollectionRegionAccessStrategy.java index acd70b5018..2402e372f3 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheCollectionRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheCollectionRegionAccessStrategy.java @@ -8,9 +8,11 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion; -import org.hibernate.cache.spi.CollectionCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.collection.CollectionPersister; /** * Ehcache specific read/write collection region access strategy @@ -19,7 +21,7 @@ import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; * @author Alex Snaps */ public class ReadWriteEhcacheCollectionRegionAccessStrategy - extends AbstractReadWriteEhcacheAccessStrategy + extends AbstractReadWriteEhcacheAccessStrategy implements CollectionRegionAccessStrategy { /** @@ -36,4 +38,15 @@ public class ReadWriteEhcacheCollectionRegionAccessStrategy public CollectionRegion getRegion() { return region(); } + + + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheEntityRegionAccessStrategy.java index 7b0a088ba8..a691e2bc9a 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheEntityRegionAccessStrategy.java @@ -9,10 +9,12 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheEntityRegion; -import org.hibernate.cache.spi.EntityCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * Ehcache specific read/write entity region access strategy @@ -21,7 +23,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Alex Snaps */ public class ReadWriteEhcacheEntityRegionAccessStrategy - extends AbstractReadWriteEhcacheAccessStrategy + extends AbstractReadWriteEhcacheAccessStrategy implements EntityRegionAccessStrategy { /** @@ -45,7 +47,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy * A no-op since this is an asynchronous cache access strategy. */ @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; } @@ -55,7 +57,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy * Inserts will only succeed if there is no existing value mapped to this key. */ @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { region().writeLock( key ); try { final Lockable item = (Lockable) region().get( key ); @@ -78,7 +80,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy * A no-op since this is an asynchronous cache access strategy. */ @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { return false; } @@ -91,7 +93,7 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy * the course of this transaction. */ @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { //what should we do with previousVersion here? region().writeLock( key ); @@ -118,4 +120,14 @@ public class ReadWriteEhcacheEntityRegionAccessStrategy region().writeUnlock( key ); } } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createEntityKey(id, persister, factory, tenantIdentifier); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheNaturalIdRegionAccessStrategy.java index 86629de1da..61fcb06a7d 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadWriteEhcacheNaturalIdRegionAccessStrategy.java @@ -9,10 +9,12 @@ package org.hibernate.cache.ehcache.internal.strategy; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheNaturalIdRegion; -import org.hibernate.cache.spi.NaturalIdCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * Ehcache specific read/write NaturalId region access strategy @@ -21,7 +23,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Alex Snaps */ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy - extends AbstractReadWriteEhcacheAccessStrategy + extends AbstractReadWriteEhcacheAccessStrategy implements NaturalIdRegionAccessStrategy { /** @@ -45,7 +47,7 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy * A no-op since this is an asynchronous cache access strategy. */ @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return false; } @@ -55,7 +57,7 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy * Inserts will only succeed if there is no existing value mapped to this key. */ @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { region().writeLock( key ); try { final Lockable item = (Lockable) region().get( key ); @@ -78,7 +80,7 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy * A no-op since this is an asynchronous cache access strategy. */ @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { return false; } @@ -90,7 +92,7 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy * the course of this transaction. */ @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { //what should we do with previousVersion here? region().writeLock( key ); try { @@ -116,4 +118,14 @@ public class ReadWriteEhcacheNaturalIdRegionAccessStrategy region().writeUnlock( key ); } } + + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + return DefaultCacheKeysFactory.createNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheCollectionRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheCollectionRegionAccessStrategy.java index fa474b770d..c23efe9a94 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheCollectionRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheCollectionRegionAccessStrategy.java @@ -6,15 +6,12 @@ */ package org.hibernate.cache.ehcache.internal.strategy; -import java.io.Serializable; - import net.sf.ehcache.Ehcache; import net.sf.ehcache.Element; - import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheCollectionRegion; -import org.hibernate.cache.spi.CollectionCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -29,7 +26,7 @@ import org.hibernate.persister.collection.CollectionPersister; * @author Alex Snaps */ public class TransactionalEhcacheCollectionRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements CollectionRegionAccessStrategy { private final Ehcache ehcache; @@ -50,7 +47,7 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy } @Override - public Object get(CollectionCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { final Element element = ehcache.get( key ); return element == null ? null : element.getObjectValue(); @@ -66,13 +63,13 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy } @Override - public SoftLock lockItem(CollectionCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @Override public boolean putFromLoad( - CollectionCacheKey key, + Object key, Object value, long txTimestamp, Object version, @@ -91,7 +88,7 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy } @Override - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { ehcache.remove( key ); } @@ -101,8 +98,17 @@ public class TransactionalEhcacheCollectionRegionAccessStrategy } @Override - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { // no-op } + @Override + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheEntityRegionAccessStrategy.java index 9f38d620c8..1cc4a2e504 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheEntityRegionAccessStrategy.java @@ -8,14 +8,15 @@ package org.hibernate.cache.ehcache.internal.strategy; import net.sf.ehcache.Ehcache; import net.sf.ehcache.Element; - import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheEntityRegion; -import org.hibernate.cache.spi.EntityCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * JTA EntityRegionAccessStrategy. @@ -24,7 +25,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Ludovic Orban * @author Alex Snaps */ -public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy +public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy implements EntityRegionAccessStrategy { private final Ehcache ehcache; @@ -45,17 +46,17 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) { + public boolean afterInsert(Object key, Object value, Object version) { return false; } @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { return false; } @Override - public Object get(EntityCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { final Element element = ehcache.get( key ); return element == null ? null : element.getObjectValue(); @@ -71,7 +72,7 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca } @Override - public boolean insert(EntityCacheKey key, Object value, Object version) + public boolean insert(Object key, Object value, Object version) throws CacheException { //OptimisticCache? versioning? try { @@ -84,13 +85,13 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca } @Override - public SoftLock lockItem(EntityCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @Override public boolean putFromLoad( - EntityCacheKey key, + Object key, Object value, long txTimestamp, Object version, @@ -109,7 +110,7 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca } @Override - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { ehcache.remove( key ); } @@ -119,13 +120,13 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca } @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { // no-op } @Override public boolean update( - EntityCacheKey key, + Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { @@ -137,4 +138,14 @@ public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhca throw new CacheException( e ); } } + + @Override + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createEntityKey(id, persister, factory, tenantIdentifier); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheNaturalIdRegionAccessStrategy.java index 64b1606fed..a840c23250 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/TransactionalEhcacheNaturalIdRegionAccessStrategy.java @@ -8,14 +8,15 @@ package org.hibernate.cache.ehcache.internal.strategy; import net.sf.ehcache.Ehcache; import net.sf.ehcache.Element; - import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.cache.CacheException; import org.hibernate.cache.ehcache.internal.regions.EhcacheNaturalIdRegion; -import org.hibernate.cache.spi.NaturalIdCacheKey; +import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.persister.entity.EntityPersister; /** * JTA NaturalIdRegionAccessStrategy. @@ -25,7 +26,7 @@ import org.hibernate.cache.spi.access.SoftLock; * @author Alex Snaps */ public class TransactionalEhcacheNaturalIdRegionAccessStrategy - extends AbstractEhcacheAccessStrategy + extends AbstractEhcacheAccessStrategy implements NaturalIdRegionAccessStrategy { private final Ehcache ehcache; @@ -46,17 +47,17 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) { + public boolean afterInsert(Object key, Object value) { return false; } @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) { + public boolean afterUpdate(Object key, Object value, SoftLock lock) { return false; } @Override - public Object get(NaturalIdCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { try { final Element element = ehcache.get( key ); return element == null ? null : element.getObjectValue(); @@ -72,7 +73,7 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { //OptimisticCache? versioning? try { ehcache.put( new Element( key, value ) ); @@ -84,13 +85,13 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } @Override - public SoftLock lockItem(NaturalIdCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @Override public boolean putFromLoad( - NaturalIdCacheKey key, + Object key, Object value, long txTimestamp, Object version, @@ -109,7 +110,7 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { try { ehcache.remove( key ); } @@ -119,12 +120,12 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { // no-op } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { try { ehcache.put( new Element( key, value ) ); return true; @@ -134,4 +135,13 @@ public class TransactionalEhcacheNaturalIdRegionAccessStrategy } } + @Override + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + return DefaultCacheKeysFactory.createNaturalIdKey(naturalIdValues, persister, session); + } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java index 7f928e859e..a72a093c01 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/TransactionalAccess.java @@ -6,12 +6,9 @@ */ package org.hibernate.cache.infinispan.collection; -import java.io.Serializable; - import org.hibernate.cache.CacheException; import org.hibernate.cache.infinispan.access.TransactionalAccessDelegate; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -36,7 +33,7 @@ class TransactionalAccess implements CollectionRegionAccessStrategy { this.delegate = new TransactionalAccessDelegate( region, region.getPutFromLoadValidator() ); } - public void evict(CollectionCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { delegate.evict( key ); } @@ -44,20 +41,20 @@ class TransactionalAccess implements CollectionRegionAccessStrategy { delegate.evictAll(); } - public Object get(CollectionCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return delegate.get( key, txTimestamp ); } - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version ); } - public boolean putFromLoad(CollectionCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); } - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { delegate.remove( key ); } @@ -69,7 +66,7 @@ class TransactionalAccess implements CollectionRegionAccessStrategy { return region; } - public SoftLock lockItem(CollectionCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -77,15 +74,20 @@ class TransactionalAccess implements CollectionRegionAccessStrategy { return null; } - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { } public void unlockRegion(SoftLock lock) throws CacheException { } @Override - public CollectionCacheKey generateCacheKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { - return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createCollectionKey(id, persister, factory, tenantIdentifier); + } + + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); } } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java index a034899fcb..38da0a84b5 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java @@ -7,7 +7,6 @@ package org.hibernate.cache.infinispan.entity; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -26,14 +25,14 @@ class ReadOnlyAccess extends TransactionalAccess { @Override public boolean update( - EntityCacheKey key, Object value, Object currentVersion, + Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); } @Override public boolean afterUpdate( - EntityCacheKey key, Object value, Object currentVersion, + Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java index 2d5bf83193..15f408144d 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/TransactionalAccess.java @@ -6,12 +6,9 @@ */ package org.hibernate.cache.infinispan.entity; -import java.io.Serializable; - import org.hibernate.cache.CacheException; import org.hibernate.cache.infinispan.access.TransactionalAccessDelegate; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -36,7 +33,7 @@ class TransactionalAccess implements EntityRegionAccessStrategy { this.delegate = new TransactionalAccessDelegate( region, region.getPutFromLoadValidator() ); } - public void evict(EntityCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { delegate.evict( key ); } @@ -44,7 +41,7 @@ class TransactionalAccess implements EntityRegionAccessStrategy { delegate.evictAll(); } - public Object get(EntityCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return delegate.get( key, txTimestamp ); } @@ -52,20 +49,20 @@ class TransactionalAccess implements EntityRegionAccessStrategy { return this.region; } - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return delegate.insert( key, value, version ); } - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version ); } - public boolean putFromLoad(EntityCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); } - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { delegate.remove( key ); } @@ -73,12 +70,12 @@ class TransactionalAccess implements EntityRegionAccessStrategy { delegate.removeAll(); } - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { return delegate.update( key, value, currentVersion, previousVersion ); } - public SoftLock lockItem(EntityCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -86,24 +83,28 @@ class TransactionalAccess implements EntityRegionAccessStrategy { return null; } - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { } public void unlockRegion(SoftLock lock) throws CacheException { } - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { return false; } - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { return false; } @Override - public EntityCacheKey generateCacheKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { - return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier ); + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + return DefaultCacheKeysFactory.createEntityKey(id, persister, factory, tenantIdentifier); } + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java index bef04363d1..adccce120b 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java @@ -7,7 +7,6 @@ package org.hibernate.cache.infinispan.naturalid; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -20,12 +19,12 @@ class ReadOnlyAccess extends TransactionalAccess { } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); } @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/TransactionalAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/TransactionalAccess.java index bd0ba14fbf..8817b39e34 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/TransactionalAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/TransactionalAccess.java @@ -9,7 +9,6 @@ package org.hibernate.cache.infinispan.naturalid; import org.hibernate.cache.CacheException; import org.hibernate.cache.infinispan.access.TransactionalAccessDelegate; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -29,12 +28,12 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return delegate.insert( key, value, null ); } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { return delegate.update( key, value, null, null ); } @@ -44,7 +43,7 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public void evict(NaturalIdCacheKey key) throws CacheException { + public void evict(Object key) throws CacheException { delegate.evict( key ); } @@ -54,23 +53,23 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public Object get(NaturalIdCacheKey key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return delegate.get( key, txTimestamp ); } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version ); } @Override - public boolean putFromLoad(NaturalIdCacheKey key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { return delegate.putFromLoad( key, value, txTimestamp, version, minimalPutOverride ); } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { delegate.remove( key ); } @@ -80,7 +79,7 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public SoftLock lockItem(NaturalIdCacheKey key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @@ -90,7 +89,7 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { } @Override @@ -98,18 +97,22 @@ class TransactionalAccess implements NaturalIdRegionAccessStrategy { } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { return false; } @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { return false; } @Override - public NaturalIdCacheKey generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { return DefaultCacheKeysFactory.createNaturalIdKey( naturalIdValues, persister, session ); } + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java index fd48bbb4e1..b08b0718e8 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractEntityCollectionRegionTestCase.java @@ -12,7 +12,6 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.CacheKey; import org.hibernate.cache.spi.RegionFactory; import org.hibernate.cache.spi.TransactionalDataRegion; import org.hibernate.cache.spi.access.AccessType; @@ -29,7 +28,7 @@ import static org.junit.Assert.assertTrue; * @author Galder Zamarreño * @since 3.5 */ -public abstract class AbstractEntityCollectionRegionTestCase extends AbstractRegionImplTestCase { +public abstract class AbstractEntityCollectionRegionTestCase extends AbstractRegionImplTestCase { @Test public void testSupportedAccessTypes() throws Exception { supportedAccessTypeTest(); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java index e41e243e93..2de5a570c9 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractGeneralDataRegionTestCase.java @@ -12,16 +12,15 @@ import java.util.Set; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.infinispan.InfinispanRegionFactory; -import org.hibernate.cache.spi.CacheKey; import org.hibernate.cache.spi.GeneralDataRegion; import org.hibernate.cache.spi.QueryResultsRegion; import org.hibernate.cache.spi.Region; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; -import org.junit.Ignore; -import org.junit.Test; import org.infinispan.AdvancedCache; import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.jboss.logging.Logger; +import org.junit.Ignore; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -32,7 +31,7 @@ import static org.junit.Assert.assertNull; * @author Galder Zamarreño * @since 3.5 */ -public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionImplTestCase { +public abstract class AbstractGeneralDataRegionTestCase extends AbstractRegionImplTestCase { private static final Logger log = Logger.getLogger( AbstractGeneralDataRegionTestCase.class ); protected static final String KEY = "Key"; @@ -50,12 +49,12 @@ public abstract class AbstractGeneralDataRegionTestCase exte } @Override - protected void putInRegion(Region region, T key, Object value) { + protected void putInRegion(Region region, Object key, Object value) { ((GeneralDataRegion) region).put( key, value ); } @Override - protected void removeFromRegion(Region region, T key) { + protected void removeFromRegion(Region region, Object key) { ((GeneralDataRegion) region).evict( key ); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractRegionImplTestCase.java index 23c59bf62e..2daf5ad2e0 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/AbstractRegionImplTestCase.java @@ -11,7 +11,6 @@ import java.util.Properties; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.CacheKey; import org.hibernate.cache.spi.Region; import org.hibernate.internal.util.compare.ComparableComparator; import org.infinispan.AdvancedCache; @@ -22,15 +21,15 @@ import org.infinispan.AdvancedCache; * @author Galder Zamarreño * @since 3.5 */ -public abstract class AbstractRegionImplTestCase extends AbstractNonFunctionalTestCase { +public abstract class AbstractRegionImplTestCase extends AbstractNonFunctionalTestCase { protected abstract AdvancedCache getInfinispanCache(InfinispanRegionFactory regionFactory); protected abstract Region createRegion(InfinispanRegionFactory regionFactory, String regionName, Properties properties, CacheDataDescription cdd); - protected abstract void putInRegion(Region region, T key, Object value); + protected abstract void putInRegion(Region region, Object key, Object value); - protected abstract void removeFromRegion(Region region, T key); + protected abstract void removeFromRegion(Region region, Object key); protected CacheDataDescription getCacheDataDescription() { return new CacheDataDescriptionImpl(true, true, ComparableComparator.INSTANCE); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java index efa2eb66d0..1d85372e99 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/AbstractCollectionRegionAccessStrategyTestCase.java @@ -6,6 +6,7 @@ */ package org.hibernate.test.cache.infinispan.collection; +import javax.transaction.TransactionManager; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; @@ -13,8 +14,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import javax.transaction.TransactionManager; - +import junit.framework.AssertionFailedError; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.infinispan.access.PutFromLoadValidator; @@ -23,7 +23,6 @@ import org.hibernate.cache.infinispan.collection.CollectionRegionImpl; import org.hibernate.cache.infinispan.util.Caches; import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.internal.util.compare.ComparableComparator; @@ -31,16 +30,13 @@ import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.AssertionFailedError; - import org.infinispan.test.CacheManagerCallable; import org.infinispan.test.fwk.TestCacheManagerFactory; import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.jboss.logging.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.infinispan.test.TestingUtil.withCacheManager; import static org.junit.Assert.assertEquals; @@ -56,7 +52,6 @@ import static org.junit.Assert.assertTrue; */ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends AbstractNonFunctionalTestCase { private static final Logger log = Logger.getLogger( AbstractCollectionRegionAccessStrategyTestCase.class ); - public static final String REGION_NAME = "test/com.foo.test"; public static final String KEY_BASE = "KEY"; public static final String VALUE1 = "VALUE1"; @@ -232,7 +227,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs private void putFromLoadTest(final boolean useMinimalAPI) throws Exception { - final CollectionCacheKey KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); final CountDownLatch writeLatch1 = new CountDownLatch( 1 ); final CountDownLatch writeLatch2 = new CountDownLatch( 1 ); @@ -384,7 +379,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs private void evictOrRemoveTest(final boolean evict) throws Exception { - final CollectionCacheKey KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); assertNull( "local is clean", localAccessStrategy.get( KEY, System.currentTimeMillis() ) ); assertNull( "remote is clean", remoteAccessStrategy.get( KEY, System.currentTimeMillis() ) ); @@ -415,7 +410,7 @@ public abstract class AbstractCollectionRegionAccessStrategyTestCase extends Abs private void evictOrRemoveAllTest(final boolean evict) throws Exception { - final CollectionCacheKey KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateCollectionCacheKey( KEY_BASE + testCount++ ); assertEquals( 0, getValidKeyCount( localCollectionRegion.getCache().keySet() ) ); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/CollectionRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/CollectionRegionImplTestCase.java index 88373f3f65..a26b2581cd 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/CollectionRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/CollectionRegionImplTestCase.java @@ -6,11 +6,12 @@ */ package org.hibernate.test.cache.infinispan.collection; +import java.util.Properties; + import org.hibernate.cache.CacheException; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.RegionFactory; @@ -19,8 +20,6 @@ import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.test.cache.infinispan.AbstractEntityCollectionRegionTestCase; import org.infinispan.AdvancedCache; -import java.util.Properties; - import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; @@ -29,7 +28,7 @@ import static org.junit.Assert.fail; * * @author Galder Zamarreño */ -public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegionTestCase { +public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegionTestCase { private static CacheDataDescription MUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl(true, false, null); @@ -62,13 +61,13 @@ public class CollectionRegionImplTestCase extends AbstractEntityCollectionRegion } @Override - protected void putInRegion(Region region, CollectionCacheKey key, Object value) { + protected void putInRegion(Region region, Object key, Object value) { CollectionRegionAccessStrategy strategy = ((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL); strategy.putFromLoad(key, value, System.currentTimeMillis(), new Integer(1)); } @Override - protected void removeFromRegion(Region region, CollectionCacheKey key) { + protected void removeFromRegion(Region region, Object key) { ((CollectionRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java index b8b63c473f..61503cb1ff 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/collection/TransactionalExtraAPITestCase.java @@ -8,7 +8,6 @@ package org.hibernate.test.cache.infinispan.collection; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.infinispan.InfinispanRegionFactory; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -31,7 +30,7 @@ import static org.junit.Assert.assertNull; public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase { public static final String REGION_NAME = "test/com.foo.test"; - public static final CollectionCacheKey KEY = TestingKeyFactory.generateCollectionCacheKey( "KEY" ); + public static final Object KEY = TestingKeyFactory.generateCollectionCacheKey( "KEY" ); public static final String VALUE1 = "VALUE1"; public static final String VALUE2 = "VALUE2"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java index 90e0a81782..da336ff0d9 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractEntityRegionAccessStrategyTestCase.java @@ -11,13 +11,13 @@ import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import junit.framework.AssertionFailedError; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.infinispan.entity.EntityRegionImpl; import org.hibernate.cache.infinispan.util.Caches; import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.internal.util.compare.ComparableComparator; @@ -25,16 +25,13 @@ import org.hibernate.test.cache.infinispan.AbstractNonFunctionalTestCase; import org.hibernate.test.cache.infinispan.NodeEnvironment; import org.hibernate.test.cache.infinispan.util.CacheTestUtil; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import junit.framework.AssertionFailedError; - import org.infinispan.Cache; import org.infinispan.test.TestingUtil; import org.infinispan.transaction.tm.BatchModeTransactionManager; import org.jboss.logging.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -194,7 +191,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac */ private void putFromLoadTest(final boolean useMinimalAPI) throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); final CountDownLatch writeLatch1 = new CountDownLatch(1); final CountDownLatch writeLatch2 = new CountDownLatch(1); @@ -298,7 +295,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac @Test public void testInsert() throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); final CountDownLatch readLatch = new CountDownLatch(1); final CountDownLatch commitLatch = new CountDownLatch(1); @@ -387,7 +384,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac @Test public void testUpdate() throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); // Set up initial state localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1)); @@ -503,7 +500,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac } private void evictOrRemoveTest(final boolean evict) throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); assertEquals(0, getValidKeyCount(localEntityRegion.getCache().keySet())); assertEquals(0, getValidKeyCount(remoteEntityRegion.getCache().keySet())); @@ -532,7 +529,7 @@ public abstract class AbstractEntityRegionAccessStrategyTestCase extends Abstrac } private void evictOrRemoveAllTest(final boolean evict) throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); assertEquals(0, getValidKeyCount(localEntityRegion.getCache().keySet())); assertEquals(0, getValidKeyCount(remoteEntityRegion.getCache().keySet())); assertNull("local is clean", localAccessStrategy.get(KEY, System.currentTimeMillis())); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractReadOnlyAccessTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractReadOnlyAccessTestCase.java index d6dd77ff13..d3a4dbce37 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractReadOnlyAccessTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractReadOnlyAccessTestCase.java @@ -6,11 +6,10 @@ */ package org.hibernate.test.cache.infinispan.entity; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; -import org.junit.Test; import org.infinispan.transaction.tm.BatchModeTransactionManager; +import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -42,7 +41,7 @@ public abstract class AbstractReadOnlyAccessTestCase extends AbstractEntityRegio private void putFromLoadTest(boolean minimal) throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); long txTimestamp = System.currentTimeMillis(); BatchModeTransactionManager.getInstance().begin(); @@ -64,7 +63,7 @@ public abstract class AbstractReadOnlyAccessTestCase extends AbstractEntityRegio @Test(expected = UnsupportedOperationException.class) @Override public void testUpdate() throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); localAccessStrategy.update( KEY, VALUE2, 2, 1); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java index 87e549a18d..fd3dce0257 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/AbstractTransactionalAccessTestCase.java @@ -10,12 +10,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import junit.framework.AssertionFailedError; - -import org.infinispan.transaction.tm.BatchModeTransactionManager; -import org.jboss.logging.Logger; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.test.cache.infinispan.util.TestingKeyFactory; +import org.infinispan.transaction.tm.BatchModeTransactionManager; +import org.jboss.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -36,7 +34,7 @@ public abstract class AbstractTransactionalAccessTestCase extends AbstractEntity public void testContestedPutFromLoad() throws Exception { - final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); + final Object KEY = TestingKeyFactory.generateEntityCacheKey( KEY_BASE + testCount++ ); localAccessStrategy.putFromLoad(KEY, VALUE1, System.currentTimeMillis(), new Integer(1)); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java index 0ba2b2310e..2752a41507 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java @@ -6,11 +6,12 @@ */ package org.hibernate.test.cache.infinispan.entity; +import java.util.Properties; + import org.hibernate.cache.CacheException; import org.hibernate.cache.infinispan.InfinispanRegionFactory; import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.CacheDataDescription; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.Region; import org.hibernate.cache.spi.RegionFactory; @@ -18,8 +19,6 @@ import org.hibernate.cache.spi.access.AccessType; import org.hibernate.test.cache.infinispan.AbstractEntityCollectionRegionTestCase; import org.infinispan.AdvancedCache; -import java.util.Properties; - import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; @@ -29,7 +28,7 @@ import static org.junit.Assert.fail; * @author Galder Zamarreño * @since 3.5 */ -public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTestCase { +public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTestCase { private static CacheDataDescription MUTABLE_NON_VERSIONED = new CacheDataDescriptionImpl(true, false, null); @@ -52,12 +51,12 @@ public class EntityRegionImplTestCase extends AbstractEntityCollectionRegionTest } @Override - protected void putInRegion(Region region, EntityCacheKey key, Object value) { + protected void putInRegion(Region region, Object key, Object value) { ((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).insert(key, value, 1); } @Override - protected void removeFromRegion(Region region, EntityCacheKey key) { + protected void removeFromRegion(Region region, Object key) { ((EntityRegion) region).buildAccessStrategy(AccessType.TRANSACTIONAL).remove(key); } diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java index cb86be8a48..61fb89aa3e 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/TransactionalExtraAPITestCase.java @@ -7,9 +7,8 @@ package org.hibernate.test.cache.infinispan.entity; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.infinispan.InfinispanRegionFactory; -import org.hibernate.cache.spi.EntityCacheKey; +import org.hibernate.cache.internal.CacheDataDescriptionImpl; import org.hibernate.cache.spi.access.AccessType; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -36,7 +35,7 @@ import static org.junit.Assert.assertNull; */ public class TransactionalExtraAPITestCase extends AbstractNonFunctionalTestCase { public static final String REGION_NAME = "test/com.foo.test"; - public static final EntityCacheKey KEY = TestingKeyFactory.generateEntityCacheKey( "KEY" ); + public static final Object KEY = TestingKeyFactory.generateEntityCacheKey( "KEY" ); public static final String VALUE1 = "VALUE1"; public static final String VALUE2 = "VALUE2"; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java index f6e6ef39da..2a8ba6baf0 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java @@ -6,12 +6,15 @@ */ package org.hibernate.test.cache.infinispan.functional.cluster; +import javax.transaction.TransactionManager; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import javax.transaction.TransactionManager; - +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.test.cache.infinispan.functional.Contact; +import org.hibernate.test.cache.infinispan.functional.Customer; import org.infinispan.Cache; import org.infinispan.manager.CacheContainer; import org.infinispan.notifications.Listener; @@ -21,11 +24,6 @@ import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; import org.jboss.util.collection.ConcurrentSet; import org.junit.Test; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cache.spi.EntityCacheKey; -import org.hibernate.test.cache.infinispan.functional.Contact; -import org.hibernate.test.cache.infinispan.functional.Customer; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -345,9 +343,7 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase { public void nodeVisited(CacheEntryVisitedEvent event) { log.debug( event.toString() ); if ( !event.isPre() ) { - EntityCacheKey cacheKey = (EntityCacheKey) event.getKey(); - Integer primKey = (Integer) cacheKey.getKey(); - String key = cacheKey.getEntityName() + '#' + primKey; + String key = String.valueOf(event.getKey()); log.debug( "MyListener[" + name + "] - Visiting key " + key ); // String name = fqn.toString(); String token = ".functional."; diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java index 2b1891de0b..dd6099b010 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/cluster/NaturalIdInvalidationTestCase.java @@ -6,11 +6,14 @@ */ package org.hibernate.test.cache.infinispan.functional.cluster; +import javax.transaction.TransactionManager; +import java.util.Set; +import java.util.concurrent.Callable; + import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.criterion.Restrictions; import org.hibernate.test.cache.infinispan.functional.Citizen; import org.hibernate.test.cache.infinispan.functional.NaturalIdOnManyToOne; @@ -23,15 +26,8 @@ import org.infinispan.notifications.cachelistener.event.CacheEntryVisitedEvent; import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; import org.jboss.util.collection.ConcurrentSet; -import org.junit.After; import org.junit.Test; -import javax.transaction.TransactionManager; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Callable; - -import static org.infinispan.test.TestingUtil.tmpDirectory; import static org.infinispan.test.TestingUtil.withTx; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -263,8 +259,7 @@ public class NaturalIdInvalidationTestCase extends DualNodeTestCase { public void nodeVisited(CacheEntryVisitedEvent event) { log.debug( event.toString() ); if ( !event.isPre() ) { - NaturalIdCacheKey cacheKey = (NaturalIdCacheKey) event.getKey(); - visited.add(cacheKey.toString()); + visited.add(event.getKey().toString()); // Integer primKey = (Integer) cacheKey.getKey(); // String key = (String) cacheKey.getEntityOrRoleName() + '#' + primKey; // log.debug( "MyListener[" + name + "] - Visiting key " + key ); diff --git a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/TestingKeyFactory.java b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/TestingKeyFactory.java index 61b3dbe14f..26c695d8b1 100644 --- a/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/TestingKeyFactory.java +++ b/hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/util/TestingKeyFactory.java @@ -8,25 +8,22 @@ package org.hibernate.test.cache.infinispan.util; import java.io.Serializable; -import org.hibernate.cache.spi.CollectionCacheKey; -import org.hibernate.cache.spi.EntityCacheKey; - public class TestingKeyFactory { private TestingKeyFactory() { //Not to be constructed } - public static EntityCacheKey generateEntityCacheKey(String id) { + public static Object generateEntityCacheKey(String id) { return new TestingEntityCacheKey( id ); } - public static CollectionCacheKey generateCollectionCacheKey(String id) { + public static Object generateCollectionCacheKey(String id) { return new TestingEntityCacheKey( id ); } //For convenience implement both interfaces. - private static class TestingEntityCacheKey implements EntityCacheKey, CollectionCacheKey, Serializable { + private static class TestingEntityCacheKey implements Serializable { private final String id; @@ -34,26 +31,6 @@ public class TestingKeyFactory { this.id = id; } - @Override - public Serializable getKey() { - return null; - } - - @Override - public String getEntityName() { - return null; - } - - @Override - public String getCollectionRole() { - return null; - } - - @Override - public String getTenantId() { - return null; - } - @Override public int hashCode() { final int prime = 31; diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/AbstractReadWriteAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/AbstractReadWriteAccessStrategy.java index e62c826ad4..ec2c2713cf 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/AbstractReadWriteAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/AbstractReadWriteAccessStrategy.java @@ -13,7 +13,6 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantReadWriteLock; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.CacheKey; import org.hibernate.cache.spi.access.SoftLock; import org.jboss.logging.Logger; @@ -21,7 +20,7 @@ import org.jboss.logging.Logger; /** * @author Strong Liu */ -abstract class AbstractReadWriteAccessStrategy extends BaseRegionAccessStrategy { +abstract class AbstractReadWriteAccessStrategy extends BaseRegionAccessStrategy { private static final Logger LOG = Logger.getLogger( AbstractReadWriteAccessStrategy.class.getName() ); private final UUID uuid = UUID.randomUUID(); @@ -35,7 +34,7 @@ abstract class AbstractReadWriteAccessStrategy extends BaseR * after the start of this transaction. */ @Override - public final Object get(T key, long txTimestamp) throws CacheException { + public final Object get(Object key, long txTimestamp) throws CacheException { LOG.debugf( "getting key[%s] from region[%s]", key, getInternalRegion().getName() ); try { readLock.lock(); @@ -69,7 +68,7 @@ abstract class AbstractReadWriteAccessStrategy extends BaseR */ @Override public final boolean putFromLoad( - T key, + Object key, Object value, long txTimestamp, Object version, @@ -109,7 +108,7 @@ abstract class AbstractReadWriteAccessStrategy extends BaseR * Soft-lock a cache item. */ @Override - public final SoftLock lockItem(T key, Object version) throws CacheException { + public final SoftLock lockItem(Object key, Object version) throws CacheException { try { LOG.debugf( "locking key[%s] in region[%s]", key, getInternalRegion().getName() ); @@ -133,7 +132,7 @@ abstract class AbstractReadWriteAccessStrategy extends BaseR * Soft-unlock a cache item. */ @Override - public final void unlockItem(T key, SoftLock lock) throws CacheException { + public final void unlockItem(Object key, SoftLock lock) throws CacheException { try { LOG.debugf( "unlocking key[%s] in region[%s]", key, getInternalRegion().getName() ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java index 20884b0703..973b7dd501 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java @@ -6,10 +6,7 @@ */ package org.hibernate.testing.cache; -import java.io.Serializable; - import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -18,7 +15,7 @@ import org.hibernate.persister.collection.CollectionPersister; /** * @author Strong Liu */ -class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements CollectionRegionAccessStrategy { +class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements CollectionRegionAccessStrategy { private final CollectionRegionImpl region; @@ -42,8 +39,13 @@ class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy { +class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy { private final EntityRegionImpl region; @@ -34,23 +31,23 @@ class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements NaturalIdRegionAccessStrategy { +class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy implements NaturalIdRegionAccessStrategy { private final NaturalIdRegionImpl region; @Override @@ -41,22 +36,22 @@ class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy implements RegionAccessStrategy { +abstract class BaseRegionAccessStrategy implements RegionAccessStrategy { private static final Logger LOG = Logger.getLogger( BaseRegionAccessStrategy.class ); @@ -24,17 +23,17 @@ abstract class BaseRegionAccessStrategy implements RegionAcc protected abstract boolean isDefaultMinimalPutOverride(); @Override - public Object get(T key, long txTimestamp) throws CacheException { + public Object get(Object key, long txTimestamp) throws CacheException { return getInternalRegion().get( key ); } @Override - public boolean putFromLoad(T key, Object value, long txTimestamp, Object version) throws CacheException { + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException { return putFromLoad( key, value, txTimestamp, version, isDefaultMinimalPutOverride() ); } @Override - public boolean putFromLoad(T key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) + public boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException { if ( key == null || value == null ) { @@ -75,12 +74,12 @@ abstract class BaseRegionAccessStrategy implements RegionAcc } @Override - public SoftLock lockItem(T key, Object version) throws CacheException { + public SoftLock lockItem(Object key, Object version) throws CacheException { return null; } @Override - public void unlockItem(T key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { } @@ -91,7 +90,7 @@ abstract class BaseRegionAccessStrategy implements RegionAcc * @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#remove(java.lang.Object) */ @Override - public void remove(T key) throws CacheException { + public void remove(Object key) throws CacheException { } /** @@ -107,7 +106,7 @@ abstract class BaseRegionAccessStrategy implements RegionAcc } @Override - public void evict(T key) throws CacheException { + public void evict(Object key) throws CacheException { getInternalRegion().evict( key ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteCollectionRegionAccessStrategy.java index 58a288ca29..4b261979a1 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteCollectionRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -19,12 +18,12 @@ class NonstrictReadWriteCollectionRegionAccessStrategy extends BaseCollectionReg } @Override - public void unlockItem(CollectionCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } @Override - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteEntityRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteEntityRegionAccessStrategy.java index 6435c9356f..70c9c8623d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteEntityRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteEntityRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -22,7 +21,7 @@ class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityRegionAcces * Since this is a non-strict read/write strategy item locking is not used. */ @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } @@ -30,7 +29,7 @@ class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityRegionAcces * Returns false since this is an asynchronous cache access strategy. */ @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; } @@ -38,7 +37,7 @@ class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityRegionAcces * Returns false since this is a non-strict read/write cache access strategy */ @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { return false; } @@ -46,21 +45,21 @@ class NonstrictReadWriteEntityRegionAccessStrategy extends BaseEntityRegionAcces * Removes the entry since this is a non-strict read/write cache strategy. */ @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { evict( key ); return false; } @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { unlockItem( key, lock ); return false; } @Override - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteNaturalIdRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteNaturalIdRegionAccessStrategy.java index 830d37269e..3f23270588 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteNaturalIdRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/NonstrictReadWriteNaturalIdRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -19,27 +18,27 @@ class NonstrictReadWriteNaturalIdRegionAccessStrategy extends BaseNaturalIdRegio } @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); } @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return false; } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { return false; } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { remove( key ); return false; } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java index a3aa01ba1f..18bfb5d5bf 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.SoftLock; import org.jboss.logging.Logger; @@ -26,18 +25,18 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy * This cache is asynchronous hence a no-op */ @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; //wait until tx complete, see afterInsert(). } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { getInternalRegion().put( key, value ); //save into cache since the tx is completed return true; } @Override - public void unlockItem(EntityCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } @@ -47,7 +46,7 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy * @throws UnsupportedOperationException always */ @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { LOG.info( "Illegal attempt to update item cached as read-only : " + key ); throw new UnsupportedOperationException( "Can't write to a readonly object" ); @@ -59,7 +58,7 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy * @throws UnsupportedOperationException always */ @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { LOG.info( "Illegal attempt to update item cached as read-only : " + key ); throw new UnsupportedOperationException( "Can't write to a readonly object" ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java index 3b3a064c17..93f3b9b7ec 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -19,7 +18,7 @@ class ReadOnlyNaturalIdRegionAccessStrategy extends BaseNaturalIdRegionAccessStr } @Override - public void unlockItem(NaturalIdCacheKey key, SoftLock lock) throws CacheException { + public void unlockItem(Object key, SoftLock lock) throws CacheException { evict( key ); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteCollectionRegionAccessStrategy.java index ed4389f84d..d73eeb81d7 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteCollectionRegionAccessStrategy.java @@ -6,11 +6,9 @@ */ package org.hibernate.testing.cache; -import java.io.Serializable; import java.util.Comparator; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.CollectionCacheKey; import org.hibernate.cache.spi.CollectionRegion; import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -19,7 +17,7 @@ import org.hibernate.persister.collection.CollectionPersister; /** * @author Strong Liu */ -class ReadWriteCollectionRegionAccessStrategy extends AbstractReadWriteAccessStrategy +class ReadWriteCollectionRegionAccessStrategy extends AbstractReadWriteAccessStrategy implements CollectionRegionAccessStrategy { private final CollectionRegionImpl region; @@ -49,8 +47,12 @@ class ReadWriteCollectionRegionAccessStrategy extends AbstractReadWriteAccessStr } @Override - public CollectionCacheKey generateCacheKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier ); } + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getCollectionId(cacheKey); + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteEntityRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteEntityRegionAccessStrategy.java index 382f98dbb9..42283092b7 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteEntityRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteEntityRegionAccessStrategy.java @@ -6,12 +6,10 @@ */ package org.hibernate.testing.cache; -import java.io.Serializable; import java.util.Comparator; import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.EntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -21,7 +19,7 @@ import org.hibernate.persister.entity.EntityPersister; /** * @author Strong Liu */ -class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrategy +class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrategy implements EntityRegionAccessStrategy { private final EntityRegionImpl region; @@ -30,18 +28,18 @@ class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrateg } @Override - public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean insert(Object key, Object value, Object version) throws CacheException { return false; } @Override - public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) + public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { return false; } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException { + public boolean afterInsert(Object key, Object value, Object version) throws CacheException { try { writeLock.lock(); @@ -61,7 +59,7 @@ class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrateg @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { try { writeLock.lock(); @@ -110,8 +108,12 @@ class ReadWriteEntityRegionAccessStrategy extends AbstractReadWriteAccessStrateg } @Override - public EntityCacheKey generateCacheKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { + public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier ); } + @Override + public Object getCacheKeyId(Object cacheKey) { + return DefaultCacheKeysFactory.getEntityId(cacheKey); + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteNaturalIdRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteNaturalIdRegionAccessStrategy.java index 2cb429c6d6..caefe030e7 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteNaturalIdRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadWriteNaturalIdRegionAccessStrategy.java @@ -10,7 +10,6 @@ import java.util.Comparator; import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; -import org.hibernate.cache.spi.NaturalIdCacheKey; import org.hibernate.cache.spi.NaturalIdRegion; import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; @@ -20,7 +19,7 @@ import org.hibernate.persister.entity.EntityPersister; /** * @author Eric Dalquist */ -class ReadWriteNaturalIdRegionAccessStrategy extends AbstractReadWriteAccessStrategy +class ReadWriteNaturalIdRegionAccessStrategy extends AbstractReadWriteAccessStrategy implements NaturalIdRegionAccessStrategy { private final NaturalIdRegionImpl region; @@ -30,17 +29,17 @@ class ReadWriteNaturalIdRegionAccessStrategy extends AbstractReadWriteAccessStra } @Override - public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean insert(Object key, Object value) throws CacheException { return false; } @Override - public boolean update(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean update(Object key, Object value) throws CacheException { return false; } @Override - public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException { + public boolean afterInsert(Object key, Object value) throws CacheException { try { writeLock.lock(); @@ -60,7 +59,7 @@ class ReadWriteNaturalIdRegionAccessStrategy extends AbstractReadWriteAccessStra @Override - public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException { + public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException { try { writeLock.lock(); Lockable item = (Lockable) region.get( key ); @@ -107,7 +106,12 @@ class ReadWriteNaturalIdRegionAccessStrategy extends AbstractReadWriteAccessStra } @Override - public NaturalIdCacheKey generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { + public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) { return DefaultCacheKeysFactory.createNaturalIdKey( naturalIdValues, persister, session ); } + + @Override + public Object[] getNaturalIdValues(Object cacheKey) { + return DefaultCacheKeysFactory.getNaturalIdValues(cacheKey); + } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalCollectionRegionAccessStrategy.java index 35c510cb81..f789f70fea 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalCollectionRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.CollectionCacheKey; /** * @author Strong Liu @@ -18,7 +17,7 @@ class TransactionalCollectionRegionAccessStrategy extends BaseCollectionRegionAc } @Override - public void remove(CollectionCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalEntityRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalEntityRegionAccessStrategy.java index 502b2745de..56507eaf00 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalEntityRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalEntityRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.EntityCacheKey; import org.hibernate.cache.spi.access.SoftLock; /** @@ -19,23 +18,23 @@ class TransactionalEntityRegionAccessStrategy extends BaseEntityRegionAccessStra } @Override - public boolean afterInsert(EntityCacheKey key, Object value, Object version) { + public boolean afterInsert(Object key, Object value, Object version) { return false; } @Override - public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { + public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) { return false; } @Override - public void remove(EntityCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); } @Override public boolean update( - EntityCacheKey key, Object value, Object currentVersion, + Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { return insert( key, value, currentVersion ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalNaturalIdRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalNaturalIdRegionAccessStrategy.java index 3ddfa1fa66..23e6444578 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalNaturalIdRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/TransactionalNaturalIdRegionAccessStrategy.java @@ -7,7 +7,6 @@ package org.hibernate.testing.cache; import org.hibernate.cache.CacheException; -import org.hibernate.cache.spi.NaturalIdCacheKey; /** * @author Eric Dalquist @@ -18,7 +17,7 @@ class TransactionalNaturalIdRegionAccessStrategy extends BaseNaturalIdRegionAcce } @Override - public void remove(NaturalIdCacheKey key) throws CacheException { + public void remove(Object key) throws CacheException { evict( key ); }