Search in sources :

Example 1 with PersistenceManagerFactoryResource

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
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) PersistenceManagerFactoryResource(org.glassfish.connectors.config.PersistenceManagerFactoryResource) Resources(com.sun.enterprise.config.serverbeans.Resources)

Aggregations

Resources (com.sun.enterprise.config.serverbeans.Resources)1 PropertyVetoException (java.beans.PropertyVetoException)1 PersistenceManagerFactoryResource (org.glassfish.connectors.config.PersistenceManagerFactoryResource)1 JdbcResource (org.glassfish.jdbc.config.JdbcResource)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1