private EmbeddedCacheManager createCustomCacheManager(URL configUrl, JtaPlatform platform) {
TransactionManagerLookupDelegator transactionManagerLookupDelegator = new TransactionManagerLookupDelegator( platform );
try {
InputStream configurationFile = configUrl.openStream();
try {
EmbeddedCacheManager tmpCacheManager = new DefaultCacheManager( configurationFile, false );
AdvancedExternalizer<?> entityKeyExternalizer = EntityKeyExternalizer.INSTANCE;
AdvancedExternalizer<?> associationKeyExternalizer = AssociationKeyExternalizer.INSTANCE;
AdvancedExternalizer<?> rowKeyExternalizer = RowKeyExternalizer.INSTANCE;
AdvancedExternalizer<?> entityKeyMetadataExternalizer = EntityKeyMetadataExternalizer.INSTANCE;
AdvancedExternalizer<?> idGeneratorKeyExternalizer = IdSourceKeyExternalizer.INSTANCE;
// override global configuration from the config file to inject externalizers
GlobalConfiguration globalConfiguration = new GlobalConfigurationBuilder()
.read( tmpCacheManager.getCacheManagerConfiguration() )
.serialization()
.addAdvancedExternalizer( entityKeyExternalizer.getId(), entityKeyExternalizer )
.addAdvancedExternalizer( associationKeyExternalizer.getId(), associationKeyExternalizer )
.addAdvancedExternalizer( rowKeyExternalizer.getId(), rowKeyExternalizer )
.addAdvancedExternalizer( entityKeyMetadataExternalizer.getId(), entityKeyMetadataExternalizer )
.addAdvancedExternalizer( idGeneratorKeyExternalizer.getId(), idGeneratorKeyExternalizer )
.build();
cacheManager = new DefaultCacheManager( globalConfiguration, false );
// override the named cache configuration defined in the configuration file to
// inject the platform TransactionManager
for (String cacheName : tmpCacheManager.getCacheNames() ) {
Configuration originalCfg = tmpCacheManager.getCacheConfiguration( cacheName );
Configuration newCfg = new ConfigurationBuilder()
.read( originalCfg )
.transaction()
.transactionManagerLookup( transactionManagerLookupDelegator )
.build();