HHH-9988 Separate transaction manager used for Hibernate and caches
This commit is contained in:
parent
c952a843fa
commit
fa8e94071f
|
@ -67,6 +67,8 @@ import org.infinispan.util.concurrent.IsolationLevel;
|
|||
import org.infinispan.util.logging.Log;
|
||||
import org.infinispan.util.logging.LogFactory;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* A {@link RegionFactory} for <a href="http://www.jboss.org/infinispan">Infinispan</a>-backed cache
|
||||
* regions.
|
||||
|
@ -219,6 +221,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
private final Set<String> definedConfigurations = new HashSet<String>();
|
||||
|
||||
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
|
||||
private TransactionManager transactionManager;
|
||||
|
||||
private List<String> regionNames = new ArrayList<String>();
|
||||
private SessionFactoryOptions settings;
|
||||
|
@ -247,7 +250,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug( "Building collection cache region [" + regionName + "]" );
|
||||
}
|
||||
final AdvancedCache cache = getCache( regionName, COLLECTION_KEY, properties, metadata);
|
||||
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory() );
|
||||
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
|
||||
startRegion( region, regionName );
|
||||
return region;
|
||||
}
|
||||
|
@ -264,7 +267,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
);
|
||||
}
|
||||
final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? ENTITY_KEY : IMMUTABLE_ENTITY_KEY, properties, metadata );
|
||||
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory() );
|
||||
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
|
||||
startRegion( region, regionName );
|
||||
return region;
|
||||
}
|
||||
|
@ -276,7 +279,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug("Building natural id cache region [" + regionName + "]");
|
||||
}
|
||||
final AdvancedCache cache = getCache( regionName, NATURAL_ID_KEY, properties, metadata);
|
||||
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory());
|
||||
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory());
|
||||
startRegion( region, regionName );
|
||||
return region;
|
||||
}
|
||||
|
@ -294,7 +297,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
}
|
||||
|
||||
final AdvancedCache cache = getCache( cacheName, QUERY_KEY, properties, null);
|
||||
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, this );
|
||||
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this );
|
||||
startRegion( region, regionName );
|
||||
return region;
|
||||
}
|
||||
|
@ -358,6 +361,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
log.debug( "Starting Infinispan region factory" );
|
||||
try {
|
||||
transactionManagerlookup = createTransactionManagerLookup( settings, properties );
|
||||
transactionManager = transactionManagerlookup.getTransactionManager();
|
||||
manager = createCacheManager( properties, settings.getServiceRegistry() );
|
||||
this.settings = settings;
|
||||
initGenericDataTypeOverrides();
|
||||
|
@ -602,7 +606,7 @@ public class InfinispanRegionFactory implements RegionFactory {
|
|||
}
|
||||
}
|
||||
|
||||
private AdvancedCache getCache(String regionName, String typeKey, Properties properties, CacheDataDescription metadata) {
|
||||
protected AdvancedCache getCache(String regionName, String typeKey, Properties properties, CacheDataDescription metadata) {
|
||||
TypeOverrides regionOverride = typeOverrides.get( regionName );
|
||||
if ( !definedConfigurations.contains( regionName ) ) {
|
||||
final String templateCacheName;
|
||||
|
|
|
@ -114,24 +114,26 @@ public class PutFromLoadValidator {
|
|||
* Creates a new put from load validator instance.
|
||||
*
|
||||
* @param cache Cache instance on which to store pending put information.
|
||||
* @param transactionManager Transaction manager
|
||||
*/
|
||||
public PutFromLoadValidator(AdvancedCache cache) {
|
||||
this( cache, NAKED_PUT_INVALIDATION_PERIOD );
|
||||
public PutFromLoadValidator(AdvancedCache cache, TransactionManager transactionManager) {
|
||||
this( cache, transactionManager, NAKED_PUT_INVALIDATION_PERIOD );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor variant for use by unit tests; allows control of various timeouts by the test.
|
||||
*
|
||||
* @param cache Cache instance on which to store pending put information.
|
||||
* @param transactionManager Transaction manager
|
||||
* @param nakedPutInvalidationPeriod Period (in ms) after a removal during which a call to
|
||||
* {@link #acquirePutFromLoadLock(Object)} that hasn't been
|
||||
* {@link #registerPendingPut(Object) pre-registered} (aka a "naked put")
|
||||
* will return false.
|
||||
*/
|
||||
public PutFromLoadValidator(
|
||||
AdvancedCache cache,
|
||||
AdvancedCache cache, TransactionManager transactionManager,
|
||||
long nakedPutInvalidationPeriod) {
|
||||
this(cache, cache.getCacheManager(), cache.getTransactionManager(),
|
||||
this(cache, cache.getCacheManager(), transactionManager,
|
||||
nakedPutInvalidationPeriod
|
||||
);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.hibernate.cache.spi.access.AccessType;
|
|||
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
|
||||
import org.infinispan.AdvancedCache;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* Collection region implementation
|
||||
*
|
||||
|
@ -31,14 +33,15 @@ public class CollectionRegionImpl extends BaseTransactionalDataRegion implements
|
|||
*
|
||||
* @param cache instance to store collection instances
|
||||
* @param name of collection type
|
||||
* @param transactionManager
|
||||
* @param metadata for the collection type
|
||||
* @param factory for the region
|
||||
* @param cacheKeysFactory factory for cache keys
|
||||
*/
|
||||
public CollectionRegionImpl(
|
||||
AdvancedCache cache, String name,
|
||||
AdvancedCache cache, String name, TransactionManager transactionManager,
|
||||
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
|
||||
super( cache, name, metadata, factory, cacheKeysFactory );
|
||||
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,7 +55,7 @@ public class CollectionRegionImpl extends BaseTransactionalDataRegion implements
|
|||
}
|
||||
|
||||
public PutFromLoadValidator getPutFromLoadValidator() {
|
||||
return new PutFromLoadValidator( cache );
|
||||
return new PutFromLoadValidator( cache, getTransactionManager() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
|
|||
|
||||
import org.infinispan.AdvancedCache;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* Entity region implementation
|
||||
*
|
||||
|
@ -32,14 +34,15 @@ public class EntityRegionImpl extends BaseTransactionalDataRegion implements Ent
|
|||
*
|
||||
* @param cache instance to store entity instances
|
||||
* @param name of entity type
|
||||
* @param transactionManager
|
||||
* @param metadata for the entity type
|
||||
* @param factory for the region
|
||||
* @param cacheKeysFactory factory for cache keys
|
||||
*/
|
||||
public EntityRegionImpl(
|
||||
AdvancedCache cache, String name,
|
||||
AdvancedCache cache, String name, TransactionManager transactionManager,
|
||||
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
|
||||
super( cache, name, metadata, factory, cacheKeysFactory);
|
||||
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,6 +63,6 @@ public class EntityRegionImpl extends BaseTransactionalDataRegion implements Ent
|
|||
}
|
||||
|
||||
public PutFromLoadValidator getPutFromLoadValidator() {
|
||||
return new PutFromLoadValidator( cache );
|
||||
return new PutFromLoadValidator( cache, getTransactionManager() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public abstract class BaseGeneralDataRegion extends BaseRegion implements Genera
|
|||
public BaseGeneralDataRegion(
|
||||
AdvancedCache cache, String name,
|
||||
RegionFactory factory) {
|
||||
super( cache, name, factory );
|
||||
super( cache, name, null, factory );
|
||||
this.putCache = Caches.ignoreReturnValuesCache( cache );
|
||||
}
|
||||
|
||||
|
|
|
@ -59,12 +59,13 @@ public abstract class BaseRegion implements Region {
|
|||
*
|
||||
* @param cache instance for the region
|
||||
* @param name of the region
|
||||
* @param transactionManager transaction manager may be needed even for non-transactional caches.
|
||||
* @param factory for this region
|
||||
*/
|
||||
public BaseRegion(AdvancedCache cache, String name, RegionFactory factory) {
|
||||
public BaseRegion(AdvancedCache cache, String name, TransactionManager transactionManager, RegionFactory factory) {
|
||||
this.cache = cache;
|
||||
this.name = name;
|
||||
this.tm = cache.getTransactionManager();
|
||||
this.tm = transactionManager;
|
||||
this.factory = factory;
|
||||
this.localAndSkipLoadCache = cache.withFlags(
|
||||
Flag.CACHE_MODE_LOCAL, Flag.ZERO_LOCK_ACQUISITION_TIMEOUT,
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.hibernate.cache.spi.TransactionalDataRegion;
|
|||
|
||||
import org.infinispan.AdvancedCache;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* Support for Inifinispan {@link org.hibernate.cache.spi.TransactionalDataRegion} implementors.
|
||||
*
|
||||
|
@ -31,14 +33,15 @@ public abstract class BaseTransactionalDataRegion
|
|||
*
|
||||
* @param cache instance to store transactional data
|
||||
* @param name of the transactional region
|
||||
* @param transactionManager
|
||||
* @param metadata for the transactional region
|
||||
* @param factory for the transactional region
|
||||
* @param cacheKeysFactory factory for cache keys
|
||||
*/
|
||||
public BaseTransactionalDataRegion(
|
||||
AdvancedCache cache, String name,
|
||||
AdvancedCache cache, String name, TransactionManager transactionManager,
|
||||
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
|
||||
super( cache, name, factory);
|
||||
super( cache, name, transactionManager, factory);
|
||||
this.metadata = metadata;
|
||||
this.cacheKeysFactory = cacheKeysFactory;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.hibernate.cache.spi.access.AccessType;
|
|||
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
|
||||
import org.infinispan.AdvancedCache;
|
||||
|
||||
import javax.transaction.TransactionManager;
|
||||
|
||||
/**
|
||||
* Natural ID cache region
|
||||
*
|
||||
|
@ -31,14 +33,15 @@ public class NaturalIdRegionImpl extends BaseTransactionalDataRegion
|
|||
*
|
||||
* @param cache instance to store natural ids
|
||||
* @param name of natural id region
|
||||
* @param transactionManager
|
||||
* @param metadata for the natural id region
|
||||
* @param factory for the natural id region
|
||||
* @param cacheKeysFactory factory for cache keys
|
||||
*/
|
||||
public NaturalIdRegionImpl(
|
||||
AdvancedCache cache, String name,
|
||||
AdvancedCache cache, String name, TransactionManager transactionManager,
|
||||
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
|
||||
super( cache, name, metadata, factory, cacheKeysFactory );
|
||||
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,7 +57,7 @@ public class NaturalIdRegionImpl extends BaseTransactionalDataRegion
|
|||
}
|
||||
|
||||
public PutFromLoadValidator getPutFromLoadValidator() {
|
||||
return new PutFromLoadValidator( cache );
|
||||
return new PutFromLoadValidator( cache, getTransactionManager() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public class QueryResultsRegionImpl extends BaseTransactionalDataRegion implemen
|
|||
* @param name of the query region
|
||||
* @param factory for the query region
|
||||
*/
|
||||
public QueryResultsRegionImpl(AdvancedCache cache, String name, RegionFactory factory) {
|
||||
super( cache, name, null, factory, null );
|
||||
public QueryResultsRegionImpl(AdvancedCache cache, String name, TransactionManager transactionManager, RegionFactory factory) {
|
||||
super( cache, name, transactionManager, null, factory, null );
|
||||
// If Infinispan is using INVALIDATION for query cache, we don't want to propagate changes.
|
||||
// We use the Timestamps cache to manage invalidation
|
||||
final boolean localOnly = Caches.isInvalidationCache( cache );
|
||||
|
|
Loading…
Reference in New Issue