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
This commit is contained in:
Radim Vansa 2015-06-08 14:23:16 +02:00 committed by Sanne Grinovero
parent 16ae00a53a
commit cffe71aeba
90 changed files with 701 additions and 694 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 {
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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();
}

View File

@ -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<CollectionCacheKey> {
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<Col
* @param tenantIdentifier the tenant id, or null if multi-tenancy is not being used.
* @return a key which can be used to identify this collection on this same region
*/
public CollectionCacheKey generateCacheKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier);
public Object generateCacheKey(Object id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier);
/**
* Performs reverse operation to {@link #generateCacheKey(Object, CollectionPersister, SessionFactoryImplementor, String)}
*
* @param cacheKey key previously returned from {@link #generateCacheKey(Object, CollectionPersister, SessionFactoryImplementor, String)}
* @return original key passed to {@link #generateCacheKey(Object, CollectionPersister, SessionFactoryImplementor, String)}
*/
public Object getCacheKeyId(Object cacheKey);
/**
* Get the wrapped collection cache region

View File

@ -6,10 +6,7 @@
*/
package org.hibernate.cache.spi.access;
import java.io.Serializable;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.EntityCacheKey;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.EntityPersister;
@ -30,7 +27,7 @@ import org.hibernate.persister.entity.EntityPersister;
* @author Gavin King
* @author Steve Ebersole
*/
public interface EntityRegionAccessStrategy extends RegionAccessStrategy<EntityCacheKey> {
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<EntityC
* @param tenantIdentifier the tenant id, or null if multi-tenancy is not being used.
* @return a key which can be used to identify this entity on this same region
*/
public EntityCacheKey generateCacheKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier);
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier);
/**
* Performs reverse operation to {@link #generateCacheKey(Object, EntityPersister, SessionFactoryImplementor, String)}
*
* @param cacheKey key previously returned from {@link #generateCacheKey(Object, EntityPersister, SessionFactoryImplementor, String)}
* @return original id passed to {@link #generateCacheKey(Object, EntityPersister, SessionFactoryImplementor, String)}
*/
public Object getCacheKeyId(Object cacheKey);
/**
* Get the wrapped entity cache region
@ -61,7 +66,7 @@ public interface EntityRegionAccessStrategy extends RegionAccessStrategy<EntityC
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException;
public boolean insert(Object key, Object value, Object version) throws CacheException;
/**
* Called after an item has been inserted (after the transaction completes),
@ -74,7 +79,7 @@ public interface EntityRegionAccessStrategy extends RegionAccessStrategy<EntityC
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException;
public boolean afterInsert(Object key, Object value, Object version) throws CacheException;
/**
* Called after an item has been updated (before the transaction completes),
@ -88,7 +93,7 @@ public interface EntityRegionAccessStrategy extends RegionAccessStrategy<EntityC
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean update(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion) throws CacheException;
public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException;
/**
* Called after an item has been updated (after the transaction completes),
@ -103,5 +108,5 @@ public interface EntityRegionAccessStrategy extends RegionAccessStrategy<EntityC
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean afterUpdate(EntityCacheKey key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException;
public boolean afterUpdate(Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException;
}

View File

@ -7,7 +7,6 @@
package org.hibernate.cache.spi.access;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.NaturalIdCacheKey;
import org.hibernate.cache.spi.NaturalIdRegion;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
@ -37,7 +36,7 @@ import org.hibernate.persister.entity.EntityPersister;
* @author Steve Ebersole
* @author Eric Dalquist
*/
public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy<NaturalIdCacheKey> {
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<Natu
* @param session
* @return a key which can be used to identify this an element unequivocally on this same region
*/
public NaturalIdCacheKey generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session);
public Object generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session);
/**
* Performs reverse operation to {@link #generateCacheKey(Object[], EntityPersister, SessionImplementor)}, returning
* the original naturalIdValues.
* @param cacheKey key returned from {@link #generateCacheKey(Object[], EntityPersister, SessionImplementor)}
* @return the sequence of values which unequivocally identifies a cached element on this region
*/
public Object[] getNaturalIdValues(Object cacheKey);
/**
* Get the wrapped naturalId cache region
@ -66,7 +73,7 @@ public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy<Natu
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException;
public boolean insert(Object key, Object value) throws CacheException;
/**
* Called after an item has been inserted (after the transaction completes),
@ -78,7 +85,7 @@ public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy<Natu
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean afterInsert(NaturalIdCacheKey key, Object value) throws CacheException;
public boolean afterInsert(Object key, Object value) throws CacheException;
/**
* Called after an item has been updated (before the transaction completes),
@ -90,7 +97,7 @@ public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy<Natu
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propagated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean update(NaturalIdCacheKey key, Object value) throws CacheException;
public boolean update(Object key, Object value) throws CacheException;
/**
* Called after an item has been updated (after the transaction completes),
@ -103,5 +110,5 @@ public interface NaturalIdRegionAccessStrategy extends RegionAccessStrategy<Natu
* @return Were the contents of the cache actual changed by this operation?
* @throws CacheException Propogated from underlying {@link org.hibernate.cache.spi.Region}
*/
public boolean afterUpdate(NaturalIdCacheKey key, Object value, SoftLock lock) throws CacheException;
public boolean afterUpdate(Object key, Object value, SoftLock lock) throws CacheException;
}

View File

@ -8,14 +8,13 @@ package org.hibernate.cache.spi.access;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheKey;
/**
* Base access strategy for all regions.
*
* @author Gail Badner
*/
public interface RegionAccessStrategy<T extends CacheKey> {
public interface RegionAccessStrategy {
/**
* Attempt to retrieve an object from the cache. Mainly used in attempting
@ -26,7 +25,7 @@ public interface RegionAccessStrategy<T extends CacheKey> {
* @return the cached object or <tt>null</tt>
* @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<T extends CacheKey> {
* @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<T extends CacheKey> {
* @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<T extends CacheKey> {
* @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<T extends CacheKey> {
* @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<T extends CacheKey> {
* @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<T extends CacheKey> {
* @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

View File

@ -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 <T extends CacheKey> Serializable fromSharedCache(
public static Serializable fromSharedCache(
SessionImplementor session,
T cacheKey,
RegionAccessStrategy<T> cacheAccessStrategy) {
Object cacheKey,
RegionAccessStrategy cacheAccessStrategy) {
final SessionEventListenerManager eventListenerManager = session.getEventListenerManager();
Serializable cachedValue = null;
eventListenerManager.cacheGetStart();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<String, RegionAccessStrategy> 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<String,EntityPersister>();
Map cacheAccessStrategiesMap = new HashMap();
Map<String,ClassMetadata> inFlightClassMetadataMap = new HashMap<String,ClassMetadata>();
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<String,Set<String>> 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();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<T extends EhcacheTransactionalDataRegion, K extends CacheKey> {
abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion> {
private final T region;
private final SessionFactoryOptions settings;
@ -66,7 +55,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object)
*/
public final boolean putFromLoad(K key, Object value, long txTimestamp, Object version) throws CacheException {
public final boolean putFromLoad(Object key, Object value, long txTimestamp, Object version) throws CacheException {
return putFromLoad( key, value, txTimestamp, version, settings.isMinimalPutsEnabled() );
}
@ -77,7 +66,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#putFromLoad(java.lang.Object, java.lang.Object, long, java.lang.Object, boolean)
*/
public abstract boolean putFromLoad(K key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
public abstract boolean putFromLoad(Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException;
/**
@ -110,7 +99,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#remove(java.lang.Object)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#remove(java.lang.Object)
*/
public void remove(K key) throws CacheException {
public void remove(Object key) throws CacheException {
}
/**
@ -131,7 +120,7 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#evict(java.lang.Object)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#evict(java.lang.Object)
*/
public final void evict(K key) throws CacheException {
public final void evict(Object key) throws CacheException {
region.remove( key );
}
@ -145,16 +134,4 @@ abstract class AbstractEhcacheAccessStrategy<T extends EhcacheTransactionalDataR
public final void evictAll() throws CacheException {
region.clear();
}
public CollectionCacheKey generateCacheKey(Serializable id, CollectionPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return DefaultCacheKeysFactory.createCollectionKey( id, persister, factory, tenantIdentifier );
}
public EntityCacheKey generateCacheKey(Serializable id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return DefaultCacheKeysFactory.createEntityKey( id, persister, factory, tenantIdentifier );
}
public NaturalIdCacheKey generateCacheKey(Object[] naturalIdValues, EntityPersister persister, SessionImplementor session) {
return DefaultCacheKeysFactory.createNaturalIdKey( naturalIdValues, persister, session );
}
}

View File

@ -15,7 +15,6 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.EhCacheMessageLogger;
import org.hibernate.cache.ehcache.internal.regions.EhcacheTransactionalDataRegion;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.cache.spi.access.SoftLock;
import org.jboss.logging.Logger;
@ -27,8 +26,8 @@ import org.jboss.logging.Logger;
* @author Chris Dennis
* @author Alex Snaps
*/
abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion, K extends CacheKey>
extends AbstractEhcacheAccessStrategy<T, K> {
abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransactionalDataRegion>
extends AbstractEhcacheAccessStrategy<T> {
private static final EhCacheMessageLogger LOG = Logger.getMessageLogger(
EhCacheMessageLogger.class,
@ -55,7 +54,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#get(java.lang.Object, long)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#get(java.lang.Object, long)
*/
public final Object get(K key, long txTimestamp) throws CacheException {
public final Object get(Object key, long txTimestamp) throws CacheException {
readLockIfNeeded( key );
try {
final Lockable item = (Lockable) region().get( key );
@ -82,7 +81,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
*/
@Override
public final boolean putFromLoad(
K key,
Object key,
Object value,
long txTimestamp,
Object version,
@ -111,7 +110,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#lockItem(java.lang.Object, java.lang.Object)
*/
public final SoftLock lockItem(K key, Object version) throws CacheException {
public final SoftLock lockItem(Object key, Object version) throws CacheException {
region().writeLock( key );
try {
final Lockable item = (Lockable) region().get( key );
@ -135,7 +134,7 @@ abstract class AbstractReadWriteEhcacheAccessStrategy<T extends EhcacheTransacti
* @see org.hibernate.cache.spi.access.EntityRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
* @see org.hibernate.cache.spi.access.CollectionRegionAccessStrategy#unlockItem(java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
*/
public final void unlockItem(K key, SoftLock lock) throws CacheException {
public final void unlockItem(Object key, SoftLock lock) throws CacheException {
region().writeLock( key );
try {
final Lockable item = (Lockable) region().get( key );

View File

@ -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 non-strict read/write collection region access strategy
@ -21,7 +23,7 @@ import org.hibernate.cache.spi.access.SoftLock;
* @author Alex Snaps
*/
public class NonStrictReadWriteEhcacheCollectionRegionAccessStrategy
extends AbstractEhcacheAccessStrategy<EhcacheCollectionRegion,CollectionCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheCollectionRegion>
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);
}
}

View File

@ -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<EhcacheEntityRegion,EntityCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheEntityRegion>
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 <code>false</code> 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 <code>false</code> 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);
}
}

View File

@ -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<EhcacheNaturalIdRegion,NaturalIdCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheNaturalIdRegion>
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 <code>false</code> 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 <code>false</code> 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);
}
}

View File

@ -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<EhcacheCollectionRegion,CollectionCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheCollectionRegion>
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);
}
}

View File

@ -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<EhcacheEntityRegion,EntityCacheKey>
public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy<EhcacheEntityRegion>
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);
}
}

View File

@ -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<EhcacheNaturalIdRegion,NaturalIdCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheNaturalIdRegion>
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);
}
}

View File

@ -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<EhcacheCollectionRegion,CollectionCacheKey>
extends AbstractReadWriteEhcacheAccessStrategy<EhcacheCollectionRegion>
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);
}
}

View File

@ -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<EhcacheEntityRegion,EntityCacheKey>
extends AbstractReadWriteEhcacheAccessStrategy<EhcacheEntityRegion>
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);
}
}

View File

@ -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<EhcacheNaturalIdRegion,NaturalIdCacheKey>
extends AbstractReadWriteEhcacheAccessStrategy<EhcacheNaturalIdRegion>
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);
}
}

View File

@ -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<EhcacheCollectionRegion,CollectionCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheCollectionRegion>
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);
}
}

View File

@ -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<EhcacheEntityRegion,EntityCacheKey>
public class TransactionalEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAccessStrategy<EhcacheEntityRegion>
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);
}
}

View File

@ -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<EhcacheNaturalIdRegion,NaturalIdCacheKey>
extends AbstractEhcacheAccessStrategy<EhcacheNaturalIdRegion>
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);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<T extends CacheKey> extends AbstractRegionImplTestCase<T> {
public abstract class AbstractEntityCollectionRegionTestCase extends AbstractRegionImplTestCase {
@Test
public void testSupportedAccessTypes() throws Exception {
supportedAccessTypeTest();

View File

@ -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<T extends CacheKey> extends AbstractRegionImplTestCase<T> {
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<T extends CacheKey> 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 );
}

View File

@ -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<T extends CacheKey> 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);

View File

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

View File

@ -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<CollectionCacheKey> {
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);
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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<EntityCacheKey> {
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);
}

View File

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

View File

@ -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.";

View File

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

View File

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

View File

@ -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<T extends CacheKey> extends BaseRegionAccessStrategy<T> {
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<T extends CacheKey> 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<T extends CacheKey> extends BaseR
*/
@Override
public final boolean putFromLoad(
T key,
Object key,
Object value,
long txTimestamp,
Object version,
@ -109,7 +108,7 @@ abstract class AbstractReadWriteAccessStrategy<T extends CacheKey> 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<T extends CacheKey> 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() );

View File

@ -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<CollectionCacheKey> implements CollectionRegionAccessStrategy {
class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements CollectionRegionAccessStrategy {
private final CollectionRegionImpl region;
@ -42,8 +39,13 @@ class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy<Collec
}
@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);
}
}

View File

@ -6,11 +6,8 @@
*/
package org.hibernate.testing.cache;
import java.io.Serializable;
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;
@ -20,7 +17,7 @@ import org.hibernate.persister.entity.EntityPersister;
/**
* @author Strong Liu
*/
class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy<EntityCacheKey> implements EntityRegionAccessStrategy {
class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
private final EntityRegionImpl region;
@ -34,23 +31,23 @@ class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy<EntityCach
}
@Override
public boolean insert(EntityCacheKey key, Object value, Object version) throws CacheException {
public boolean insert(Object key, Object value, Object version) throws CacheException {
return putFromLoad( key, value, 0, version );
}
@Override
public boolean afterInsert(EntityCacheKey key, Object value, Object version) throws CacheException {
public boolean afterInsert(Object key, Object value, Object version) throws CacheException {
return true;
}
@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 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;
}
@ -66,8 +63,12 @@ class BaseEntityRegionAccessStrategy extends BaseRegionAccessStrategy<EntityCach
}
@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);
}
}

View File

@ -6,23 +6,18 @@
*/
package org.hibernate.testing.cache;
import java.io.Serializable;
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;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.Type;
/**
* @author Eric Dalquist
*/
class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy<NaturalIdCacheKey> implements NaturalIdRegionAccessStrategy {
class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy implements NaturalIdRegionAccessStrategy {
private final NaturalIdRegionImpl region;
@Override
@ -41,22 +36,22 @@ class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy<Natural
}
@Override
public boolean insert(NaturalIdCacheKey key, Object value) throws CacheException {
public boolean insert(Object key, Object value) throws CacheException {
return putFromLoad( key, value, 0, null );
}
@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 {
return putFromLoad( key, value, 0, null );
}
@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;
}
@ -65,7 +60,12 @@ class BaseNaturalIdRegionAccessStrategy extends BaseRegionAccessStrategy<Natural
}
@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);
}
}

View File

@ -7,7 +7,6 @@
package org.hibernate.testing.cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CacheKey;
import org.hibernate.cache.spi.access.RegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.jboss.logging.Logger;
@ -15,7 +14,7 @@ import org.jboss.logging.Logger;
/**
* @author Strong Liu
*/
abstract class BaseRegionAccessStrategy<T extends CacheKey> implements RegionAccessStrategy<T> {
abstract class BaseRegionAccessStrategy implements RegionAccessStrategy {
private static final Logger LOG = Logger.getLogger( BaseRegionAccessStrategy.class );
@ -24,17 +23,17 @@ abstract class BaseRegionAccessStrategy<T extends CacheKey> 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<T extends CacheKey> 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<T extends CacheKey> 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<T extends CacheKey> implements RegionAcc
}
@Override
public void evict(T key) throws CacheException {
public void evict(Object key) throws CacheException {
getInternalRegion().evict( key );
}

View File

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

View File

@ -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 <code>false</code> 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 <code>false</code> 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 );
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,6 @@
package org.hibernate.testing.cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.spi.CollectionCacheKey;
/**
* @author Strong Liu <stliu@hibernate.org>
@ -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 );
}

View File

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

View File

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