FileDocCategorySizeDatePackage
PersistenceUnitLoaderImpl.javaAPI DocGlassfish v2 API9672Thu Jul 19 11:29:40 BST 2007com.sun.enterprise.server

PersistenceUnitLoaderImpl

public class PersistenceUnitLoaderImpl extends Object implements PersistenceUnitLoader
{@inheritDoc}
author
Sanjeeb.Sahoo@Sun.COM

Fields Summary
private static Logger
logger
logger to log loader messages
private String
applicationLocation
private com.sun.enterprise.loader.InstrumentableClassLoader
classLoader
private Application
application
private static Map
integrationProperties
Constructors Summary
Methods Summary
private voidcloseEMFs(java.util.Collection entityManagerFactories)

        logger.logp(Level.FINE, "PersistenceUnitLoaderImpl", "closeEMFs", // NOI18N
                "entityManagerFactories.size() = {0}", // NOI18N
                entityManagerFactories.size());
        for (EntityManagerFactory emf : entityManagerFactories) {
            try {
                logger.logp(Level.FINE, "PersistenceUnitLoaderImpl",
                        "closeEMFs", "emf = {0}", emf);
                emf.close();
            } catch (Exception e) {
                logger.log(Level.WARNING, e.getMessage(), e);
            }
        }
    
public voidload(ApplicationInfo appInfo)
{@inheritDoc}


          
        
        application = appInfo.getApplication();
        applicationLocation = appInfo.getApplicationLocation();
        classLoader = appInfo.getClassLoader();
        if(logger.isLoggable(Level.FINE)) {
            logger.fine("Loading persistence units for application: " +
                    applicationLocation);
        }
        for(PersistenceUnitDescriptor pu : appInfo.getReferencedPUs()) {
            load(pu);
        }
        if(logger.isLoggable(Level.FINE)) {
            logger.fine("Finished loading persistence units for application: " +
                    applicationLocation);
        }
    
private voidload(PersistenceUnitDescriptor pud)
Loads an individual PersistenceUnitDescriptor and registers the EntityManagerFactory in appropriate DOL structure.

param
pud PersistenceUnitDescriptor to be loaded.

        if(logger.isLoggable(Level.FINE)) {
            logger.fine("loading pud " + pud.getPuRoot()); // NOI18N
        }
        PersistenceUnitInfo pInfo = new PersistenceUnitInfoImpl(
                pud,
                applicationLocation,
                classLoader);
        if(logger.isLoggable(Level.FINE)) {
            logger.fine("PersistenceInfo for this pud is :\n" + pInfo); // NOI18N
        }
        PersistenceProvider provider;
        try {
            // See we use application CL as opposed to system CL to load
            // provider. This allows user to get hold of provider specific
            // implementation classes in their code. But this also means
            // provider must not use appserver implementation classes directly
            // because once we implement isolation in our class loader hierarchy
            // the only classes available to application class loader would be
            // our appserver interface classes. By Sahoo
            provider =
                    PersistenceProvider.class.cast(
                    ClassLoader.class.cast(classLoader)
                    .loadClass(pInfo.getPersistenceProviderClassName())
                    .newInstance());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        EntityManagerFactory emf = provider.createContainerEntityManagerFactory(
                pInfo, integrationProperties);
        logger.logp(Level.FINE, "PersistenceUnitLoaderImpl", "load", // NOI18N
                    "emf = {0}", emf); // NOI18N

        RootDeploymentDescriptor rootDD = pud.getParent().getParent();
        if (rootDD.isApplication()) {
            Application.class.cast(rootDD).addEntityManagerFactory(
                    pInfo.getPersistenceUnitName(), pud.getPuRoot(), emf);
        } else {
            BundleDescriptor.class.cast(rootDD).addEntityManagerFactory(
                    pInfo.getPersistenceUnitName(), emf);
        }
    
public voidunload(ApplicationInfo appInfo)
{@inheritDoc}

        application = appInfo.getApplication();
        applicationLocation = appInfo.getApplicationLocation();
        classLoader = appInfo.getClassLoader();
        final boolean fineMsgLoggable = logger.isLoggable(Level.FINE);
        if(fineMsgLoggable) {
            logger.fine("Unloading persistence units for application: " + // NOI18N
                    applicationLocation);
        }
        closeEMFs(appInfo.getEntityManagerFactories());
        if(fineMsgLoggable) {
            logger.fine("Finished unloading persistence units for application: " + // NOI18N
                    applicationLocation);
        }