Search in sources :

Example 1 with PersistenceUnitLoader

use of org.glassfish.persistence.jpa.PersistenceUnitLoader in project Payara by payara.

the class AppClientContainer method completePreparation.

/**
 * Gets the ACC ready so the main class can run.
 * This can be followed, immediately or after some time, by either an
 * invocation of {@link #launch(java.lang.String[])  or
 * by the JVM invoking the client's main method (as would happen during
 * a <code>java -jar theClient.jar</code> launch.
 *
 * @throws java.lang.Exception
 */
private void completePreparation(final Instrumentation inst) throws NamingException, IOException, InstantiationException, IllegalAccessException, InjectionException, ClassNotFoundException, SAXParseException, NoSuchMethodException, UserError {
    if (state != State.INSTANTIATED) {
        throw new IllegalStateException();
    }
    /*
         * Attach any names defined in the app client.  Validate the descriptor
         * first, then use it to bind names in the app client.  This order is
         * important - for example, to set up message destination refs correctly.
         */
    client.validateDescriptor();
    final ApplicationClientDescriptor desc = client.getDescriptor(classLoader);
    componentId = componentEnvManager.bindToComponentNamespace(desc);
    /*
         * Arrange for cleanup now instead of during launch() because in some use cases
         * the JVM will invoke the client's main method itself and launch will
         * be skipped.
         */
    cleanup = Cleanup.arrangeForShutdownCleanup(logger, habitat, desc);
    /*
         * Allow pre-destroy handling to work on the main class during clean-up.
         */
    cleanup.setInjectionManager(injectionManager, clientMainClassSetting.clientMainClass);
    /*
         * If this app client contains persistence unit refs, then initialize
         * the PU handling.  
         */
    Collection<? extends PersistenceUnitDescriptor> referencedPUs = desc.findReferencedPUs();
    if (referencedPUs != null && !referencedPUs.isEmpty()) {
        ProviderContainerContractInfoImpl pcci = new ProviderContainerContractInfoImpl((ACCClassLoader) getClassLoader(), inst, client.getAnchorDir(), connectorRuntime);
        for (PersistenceUnitDescriptor puDesc : referencedPUs) {
            PersistenceUnitLoader pul = new PersistenceUnitLoader(puDesc, pcci);
            desc.addEntityManagerFactory(puDesc.getName(), pul.getEMF());
        }
        cleanup.setEMFs(pcci.emfs());
    }
    cleanup.setConnectorRuntime(connectorRuntime);
    prepareURLStreamHandling();
    // This is required for us to enable interrupt jaxws service
    // creation calls
    System.setProperty("javax.xml.ws.spi.Provider", "com.sun.enterprise.webservice.spi.ProviderImpl");
    // InjectionManager's injectClass will be called from getMainMethod
    // Load any managed beans
    ManagedBeanManager managedBeanManager = habitat.getService(ManagedBeanManager.class);
    managedBeanManager.loadManagedBeans(desc.getApplication());
    cleanup.setManagedBeanManager(managedBeanManager);
    /**
     * We don't really need the main method here but we do need the side-effects.
     */
    getMainMethod();
    state = State.PREPARED;
}
Also used : ApplicationClientDescriptor(com.sun.enterprise.deployment.ApplicationClientDescriptor) PersistenceUnitLoader(org.glassfish.persistence.jpa.PersistenceUnitLoader) PersistenceUnitDescriptor(com.sun.enterprise.deployment.PersistenceUnitDescriptor) ManagedBeanManager(com.sun.enterprise.container.common.spi.ManagedBeanManager)

Aggregations

ManagedBeanManager (com.sun.enterprise.container.common.spi.ManagedBeanManager)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 PersistenceUnitDescriptor (com.sun.enterprise.deployment.PersistenceUnitDescriptor)1 PersistenceUnitLoader (org.glassfish.persistence.jpa.PersistenceUnitLoader)1