use of org.glassfish.connectors.config.PersistenceManagerFactoryResource in project Payara by payara.
the class PersistenceManagerFactoryResourceMigrator method postConstruct.
public void postConstruct() {
Collection<PersistenceManagerFactoryResource> pmfResources = resources.getResources(PersistenceManagerFactoryResource.class);
for (final PersistenceManagerFactoryResource pmfResource : pmfResources) {
String jdbcResourceName = pmfResource.getJdbcResourceJndiName();
final JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jdbcResourceName);
try {
ConfigSupport.apply(new SingleConfigCode<Resources>() {
public Object run(Resources resources) throws PropertyVetoException, TransactionFailure {
// delete the persitence-manager-factory resource
resources.getResources().remove(pmfResource);
// create a jdbc resource which points to same connection pool and has same jndi name as pmf resource.
JdbcResource newResource = resources.createChild(JdbcResource.class);
newResource.setJndiName(pmfResource.getJndiName());
newResource.setDescription("Created to migrate persistence-manager-factory-resource from V2 domain");
newResource.setPoolName(jdbcResource.getPoolName());
newResource.setEnabled("true");
resources.getResources().add(newResource);
return newResource;
}
}, resources);
} catch (TransactionFailure tf) {
Logger.getAnonymousLogger().log(Level.SEVERE, "Failure while upgrading persistence-manager-factory-resource", tf);
throw new RuntimeException(tf);
}
}
// end of iteration
}
Aggregations