-
1. Re: What is the best way to inject the TransactionManager into a cache instance?
galder.zamarreno Dec 20, 2011 5:37 AM (in response to nfilotto)In the new config in 5.1.0.CR1, you can do:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.transactionManagerLookup(new DummyTransactionManagerLookup());
So, you can pass a transaction manager lookup instance that accesses your transaction manager. There's no need to construct it via reflection, you can just pass your initialized instance.
The code you suggest is a hack
-
2. Re: What is the best way to inject the TransactionManager into a cache instance?
nfilotto Dec 20, 2011 6:42 AM (in response to galder.zamarreno)Thx Galder for your answer however it doesn't totally fulfill my needs as the transaction manager lookup is not a dynamic configuration parameter and since I don't see any way to inject it before creating the cache instance (I mean manager.getCache(String cacheName, boolean start) doesn't exist), I'm stuck. Maybe there is somthing that I missunderstand as it looks like the new configuration class is immutable so you obviously don't expect that we modify it, if so how can we load first the configuration from the XML files and apply some changes programmatically? I must admit that the new configuration class doesn't seem to be a good news for me since I have many warnings in my code base that I cannot fix with the new configuration class as I rely on dynamic parameters a lot which doesn't seem to be allowed anymore.
-
3. Re: What is the best way to inject the TransactionManager into a cache instance?
galder.zamarreno May 15, 2012 5:57 AM (in response to nfilotto)Nicolas, you can manually parse the configuration from XML (via Parser.parseFile() method), then apply changes to it (by making modifications to the configuration builder in it), and then create the cache manager + caches.
Once the cache has started, some parameters can be modified but does not include the transaction manager.
-
4. Re: What is the best way to inject the TransactionManager into a cache instance?
nfilotto May 15, 2012 6:30 AM (in response to galder.zamarreno)Hi Galder,
It is actually what I already do, indeed I first parse it as next:
Parser parser = new Parser(Thread.currentThread().getContextClassLoader());
// Loads the configuration from the input stream
ConfigurationBuilderHolder holder = parser.parse(configStream);
Then I inject the TM as below:
ConfigurationBuilder confBuilder = holder.getDefaultConfigurationBuilder(); if (tm != null) { TransactionManagerLookup tml = new TransactionManagerLookup() { public TransactionManager getTransactionManager() throws Exception { return tm; } }; confBuilder.transaction().transactionManagerLookup(tml); }