Hi all (or Jerome),
I have (or have adopted) this method that adds a child element to a Config object if it isn't present during an upgrade:
private NetworkConfig getNetworkConfig(Config baseConfig) throws TransactionFailure {
NetworkConfig config = baseConfig.getNetworkConfig();
if (config == null) {
config = (NetworkConfig) ConfigSupport.apply(new SingleConfigCode<Config>() {
public Object run(Config param) throws PropertyVetoException, TransactionFailure {
final NetworkConfig child = param.createChild(NetworkConfig.class);
param.setNetworkConfig(child);
return child;
}
}, baseConfig);
}
return config;
}
In one case I want to access this within another method that is also locking on the config object. Something like (pseudo code):
ConfigSupport.apply(new SingleConfigCode<Config>() {
public Object run(Config param) throws TransactionFailure {
// other code
NetworkConfig nc = getNetworkConfig(param);
// other code
return null;
}
}, config);
But of course the config bean is already locked and the apply() call fails with: "Config bean already locked GlassFishConfigBean.com.sun.enterprise.config.serverbeans.Config"
Can someone tell me how I'm supposed to handle this? In the case of the pseudo code above I can just not call the getNetworkConfig method, but then I'm repeating myself. In the getNetworkConfig method I tried checking the Config object for a transaction, and if not null, enrolling the child object:
Transaction tx = Transaction.getTransaction(baseConfig);
if (tx != null) {
// have tried both of the following lines separately
config = tx.enroll(baseConfig.createChild(NetworkConfig.class));
config = baseConfig.createChild(NetworkConfig.class);
baseConfig.setNetworkConfig(config);
return config;
}
But when I try this I run into a "NetworkConfig object already locked" issue. So I'm open to suggestions on what I should do here. If I can go the simple route and just avoid doing anything hk2-y during the original tx, I'll go with that.
Thanks,
Bobby