Skip to content

Commit fa8e940

Browse files
rvansagalderz
authored andcommitted
HHH-9988 Separate transaction manager used for Hibernate and caches
1 parent c952a84 commit fa8e940

File tree

9 files changed

+44
-25
lines changed

9 files changed

+44
-25
lines changed

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import org.infinispan.util.logging.Log;
6868
import org.infinispan.util.logging.LogFactory;
6969

70+
import javax.transaction.TransactionManager;
71+
7072
/**
7173
* A {@link RegionFactory} for <a href="http://www.jboss.org/infinispan">Infinispan</a>-backed cache
7274
* regions.
@@ -219,6 +221,7 @@ public class InfinispanRegionFactory implements RegionFactory {
219221
private final Set<String> definedConfigurations = new HashSet<String>();
220222

221223
private org.infinispan.transaction.lookup.TransactionManagerLookup transactionManagerlookup;
224+
private TransactionManager transactionManager;
222225

223226
private List<String> regionNames = new ArrayList<String>();
224227
private SessionFactoryOptions settings;
@@ -247,7 +250,7 @@ public CollectionRegion buildCollectionRegion(
247250
log.debug( "Building collection cache region [" + regionName + "]" );
248251
}
249252
final AdvancedCache cache = getCache( regionName, COLLECTION_KEY, properties, metadata);
250-
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory() );
253+
final CollectionRegionImpl region = new CollectionRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
251254
startRegion( region, regionName );
252255
return region;
253256
}
@@ -264,7 +267,7 @@ public EntityRegion buildEntityRegion(String regionName, Properties properties,
264267
);
265268
}
266269
final AdvancedCache cache = getCache( regionName, metadata.isMutable() ? ENTITY_KEY : IMMUTABLE_ENTITY_KEY, properties, metadata );
267-
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory() );
270+
final EntityRegionImpl region = new EntityRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory() );
268271
startRegion( region, regionName );
269272
return region;
270273
}
@@ -276,7 +279,7 @@ public NaturalIdRegion buildNaturalIdRegion(String regionName, Properties proper
276279
log.debug("Building natural id cache region [" + regionName + "]");
277280
}
278281
final AdvancedCache cache = getCache( regionName, NATURAL_ID_KEY, properties, metadata);
279-
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, metadata, this, buildCacheKeysFactory());
282+
final NaturalIdRegionImpl region = new NaturalIdRegionImpl( cache, regionName, transactionManager, metadata, this, buildCacheKeysFactory());
280283
startRegion( region, regionName );
281284
return region;
282285
}
@@ -294,7 +297,7 @@ public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties
294297
}
295298

296299
final AdvancedCache cache = getCache( cacheName, QUERY_KEY, properties, null);
297-
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, this );
300+
final QueryResultsRegionImpl region = new QueryResultsRegionImpl( cache, regionName, transactionManager, this );
298301
startRegion( region, regionName );
299302
return region;
300303
}
@@ -358,6 +361,7 @@ public void start(SessionFactoryOptions settings, Properties properties) throws
358361
log.debug( "Starting Infinispan region factory" );
359362
try {
360363
transactionManagerlookup = createTransactionManagerLookup( settings, properties );
364+
transactionManager = transactionManagerlookup.getTransactionManager();
361365
manager = createCacheManager( properties, settings.getServiceRegistry() );
362366
this.settings = settings;
363367
initGenericDataTypeOverrides();
@@ -602,7 +606,7 @@ private void defineGenericDataTypeCacheConfigurations(Properties properties) {
602606
}
603607
}
604608

605-
private AdvancedCache getCache(String regionName, String typeKey, Properties properties, CacheDataDescription metadata) {
609+
protected AdvancedCache getCache(String regionName, String typeKey, Properties properties, CacheDataDescription metadata) {
606610
TypeOverrides regionOverride = typeOverrides.get( regionName );
607611
if ( !definedConfigurations.contains( regionName ) ) {
608612
final String templateCacheName;

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/access/PutFromLoadValidator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,26 @@ public class PutFromLoadValidator {
114114
* Creates a new put from load validator instance.
115115
*
116116
* @param cache Cache instance on which to store pending put information.
117+
* @param transactionManager Transaction manager
117118
*/
118-
public PutFromLoadValidator(AdvancedCache cache) {
119-
this( cache, NAKED_PUT_INVALIDATION_PERIOD );
119+
public PutFromLoadValidator(AdvancedCache cache, TransactionManager transactionManager) {
120+
this( cache, transactionManager, NAKED_PUT_INVALIDATION_PERIOD );
120121
}
121122

122123
/**
123124
* Constructor variant for use by unit tests; allows control of various timeouts by the test.
124125
*
125126
* @param cache Cache instance on which to store pending put information.
127+
* @param transactionManager Transaction manager
126128
* @param nakedPutInvalidationPeriod Period (in ms) after a removal during which a call to
127129
* {@link #acquirePutFromLoadLock(Object)} that hasn't been
128130
* {@link #registerPendingPut(Object) pre-registered} (aka a "naked put")
129131
* will return false.
130132
*/
131133
public PutFromLoadValidator(
132-
AdvancedCache cache,
134+
AdvancedCache cache, TransactionManager transactionManager,
133135
long nakedPutInvalidationPeriod) {
134-
this(cache, cache.getCacheManager(), cache.getTransactionManager(),
136+
this(cache, cache.getCacheManager(), transactionManager,
135137
nakedPutInvalidationPeriod
136138
);
137139
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/CollectionRegionImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy;
1818
import org.infinispan.AdvancedCache;
1919

20+
import javax.transaction.TransactionManager;
21+
2022
/**
2123
* Collection region implementation
2224
*
@@ -31,14 +33,15 @@ public class CollectionRegionImpl extends BaseTransactionalDataRegion implements
3133
*
3234
* @param cache instance to store collection instances
3335
* @param name of collection type
36+
* @param transactionManager
3437
* @param metadata for the collection type
3538
* @param factory for the region
3639
* @param cacheKeysFactory factory for cache keys
3740
*/
3841
public CollectionRegionImpl(
39-
AdvancedCache cache, String name,
42+
AdvancedCache cache, String name, TransactionManager transactionManager,
4043
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
41-
super( cache, name, metadata, factory, cacheKeysFactory );
44+
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory );
4245
}
4346

4447
@Override
@@ -52,7 +55,7 @@ public CollectionRegionAccessStrategy buildAccessStrategy(AccessType accessType)
5255
}
5356

5457
public PutFromLoadValidator getPutFromLoadValidator() {
55-
return new PutFromLoadValidator( cache );
58+
return new PutFromLoadValidator( cache, getTransactionManager() );
5659
}
5760

5861
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/EntityRegionImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.infinispan.AdvancedCache;
2020

21+
import javax.transaction.TransactionManager;
22+
2123
/**
2224
* Entity region implementation
2325
*
@@ -32,14 +34,15 @@ public class EntityRegionImpl extends BaseTransactionalDataRegion implements Ent
3234
*
3335
* @param cache instance to store entity instances
3436
* @param name of entity type
37+
* @param transactionManager
3538
* @param metadata for the entity type
3639
* @param factory for the region
3740
* @param cacheKeysFactory factory for cache keys
3841
*/
3942
public EntityRegionImpl(
40-
AdvancedCache cache, String name,
43+
AdvancedCache cache, String name, TransactionManager transactionManager,
4144
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
42-
super( cache, name, metadata, factory, cacheKeysFactory);
45+
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory);
4346
}
4447

4548
@Override
@@ -60,6 +63,6 @@ public EntityRegionAccessStrategy buildAccessStrategy(AccessType accessType) thr
6063
}
6164

6265
public PutFromLoadValidator getPutFromLoadValidator() {
63-
return new PutFromLoadValidator( cache );
66+
return new PutFromLoadValidator( cache, getTransactionManager() );
6467
}
6568
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseGeneralDataRegion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class BaseGeneralDataRegion extends BaseRegion implements Genera
3434
public BaseGeneralDataRegion(
3535
AdvancedCache cache, String name,
3636
RegionFactory factory) {
37-
super( cache, name, factory );
37+
super( cache, name, null, factory );
3838
this.putCache = Caches.ignoreReturnValuesCache( cache );
3939
}
4040

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseRegion.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ private enum InvalidateState {
5959
*
6060
* @param cache instance for the region
6161
* @param name of the region
62+
* @param transactionManager transaction manager may be needed even for non-transactional caches.
6263
* @param factory for this region
6364
*/
64-
public BaseRegion(AdvancedCache cache, String name, RegionFactory factory) {
65+
public BaseRegion(AdvancedCache cache, String name, TransactionManager transactionManager, RegionFactory factory) {
6566
this.cache = cache;
6667
this.name = name;
67-
this.tm = cache.getTransactionManager();
68+
this.tm = transactionManager;
6869
this.factory = factory;
6970
this.localAndSkipLoadCache = cache.withFlags(
7071
Flag.CACHE_MODE_LOCAL, Flag.ZERO_LOCK_ACQUISITION_TIMEOUT,

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import org.infinispan.AdvancedCache;
1515

16+
import javax.transaction.TransactionManager;
17+
1618
/**
1719
* Support for Inifinispan {@link org.hibernate.cache.spi.TransactionalDataRegion} implementors.
1820
*
@@ -31,14 +33,15 @@ public abstract class BaseTransactionalDataRegion
3133
*
3234
* @param cache instance to store transactional data
3335
* @param name of the transactional region
36+
* @param transactionManager
3437
* @param metadata for the transactional region
3538
* @param factory for the transactional region
3639
* @param cacheKeysFactory factory for cache keys
3740
*/
3841
public BaseTransactionalDataRegion(
39-
AdvancedCache cache, String name,
42+
AdvancedCache cache, String name, TransactionManager transactionManager,
4043
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
41-
super( cache, name, factory);
44+
super( cache, name, transactionManager, factory);
4245
this.metadata = metadata;
4346
this.cacheKeysFactory = cacheKeysFactory;
4447
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/NaturalIdRegionImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.hibernate.cache.spi.access.NaturalIdRegionAccessStrategy;
1818
import org.infinispan.AdvancedCache;
1919

20+
import javax.transaction.TransactionManager;
21+
2022
/**
2123
* Natural ID cache region
2224
*
@@ -31,14 +33,15 @@ public class NaturalIdRegionImpl extends BaseTransactionalDataRegion
3133
*
3234
* @param cache instance to store natural ids
3335
* @param name of natural id region
36+
* @param transactionManager
3437
* @param metadata for the natural id region
3538
* @param factory for the natural id region
3639
* @param cacheKeysFactory factory for cache keys
3740
*/
3841
public NaturalIdRegionImpl(
39-
AdvancedCache cache, String name,
42+
AdvancedCache cache, String name, TransactionManager transactionManager,
4043
CacheDataDescription metadata, RegionFactory factory, CacheKeysFactory cacheKeysFactory) {
41-
super( cache, name, metadata, factory, cacheKeysFactory );
44+
super( cache, name, transactionManager, metadata, factory, cacheKeysFactory );
4245
}
4346

4447
@Override
@@ -54,7 +57,7 @@ public NaturalIdRegionAccessStrategy buildAccessStrategy(AccessType accessType)
5457
}
5558

5659
public PutFromLoadValidator getPutFromLoadValidator() {
57-
return new PutFromLoadValidator( cache );
60+
return new PutFromLoadValidator( cache, getTransactionManager() );
5861
}
5962

6063
}

hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/query/QueryResultsRegionImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public class QueryResultsRegionImpl extends BaseTransactionalDataRegion implemen
5858
* @param name of the query region
5959
* @param factory for the query region
6060
*/
61-
public QueryResultsRegionImpl(AdvancedCache cache, String name, RegionFactory factory) {
62-
super( cache, name, null, factory, null );
61+
public QueryResultsRegionImpl(AdvancedCache cache, String name, TransactionManager transactionManager, RegionFactory factory) {
62+
super( cache, name, transactionManager, null, factory, null );
6363
// If Infinispan is using INVALIDATION for query cache, we don't want to propagate changes.
6464
// We use the Timestamps cache to manage invalidation
6565
final boolean localOnly = Caches.isInvalidationCache( cache );

0 commit comments

Comments
 (0)