@Override public void registerEMF(String unitName, String persistenceRootUri, RootDeploymentDescriptor containingBundle, EntityManagerFactory emf) { // We register the EMF into the bundle that declared the corresponding PU. This limits visibility of the emf // to containing module. // See EMFWrapper.lookupEntityManagerFactory() for corresponding look up logic if (containingBundle.isApplication()) { // ear level pu assert containingBundle instanceof Application; Application.class.cast(containingBundle).addEntityManagerFactory( unitName, persistenceRootUri, emf); } else { assert containingBundle instanceof BundleDescriptor; BundleDescriptor.class.cast(containingBundle).addEntityManagerFactory( unitName, emf); } }
private String getModuleID(RootDeploymentDescriptor rdd) { //V3: Can we use this : return rdd.getModuleID(); /*V3:Comment if (rdd instanceof Application) { return TOP_LEVEL; } else if (rdd instanceof BundleDescriptor) { return ((BundleDescriptor) rdd).getModuleDescriptor().getArchiveUri(); } else { // cannot happen unless glassfish code is changed throw new AssertionError(rdd.getClass() + " is not a known descriptor type"); }*/ if (rdd.isApplication()) { return TOP_LEVEL; } else if (rdd.getModuleDescriptor() != null) { return rdd.getModuleDescriptor().getArchiveUri(); } else { // cannot happen unless glassfish code is changed throw new AssertionError(rdd.getClass() + " is not a known descriptor type"); } }
/** * This is a utility method which calculates the absolute path of the * root of a PU. Absolute path is not the path with regards to * root of file system. It is the path from the root of the Java EE * application this persistence unit belongs to. * Like {@link #getPuRoot()} returned path always uses '/' as path separator. * @return the absolute path of the root of this persistence unit * @see #getPuRoot() */ public String getAbsolutePuRoot() { RootDeploymentDescriptor rootDD = getParent(); if(rootDD.isApplication()){ return getPuRoot(); } else { ModuleDescriptor module = BundleDescriptor.class.cast(rootDD). getModuleDescriptor(); if(module.isStandalone()) { return getPuRoot(); } else { final String moduleLocation = module.getArchiveUri(); return moduleLocation + '/' + getPuRoot(); // see we always '/' } } }
/** * This method calculates the absolute path of the root of a PU. * Absolute path is not the path with regards to root of file system. * It is the path from the root of the Java EE application this * persistence unit belongs to. * Returned path always uses '/' as path separator. * @return the absolute path of the root of this persistence unit */ private String getAbsolutePuRootWithinApplication() { // TODO shift this into PersistenceUnitDescriptor to better encapsulate RootDeploymentDescriptor rootDD = persistenceUnitDescriptor.getParent(). getParent(); String puRoot = persistenceUnitDescriptor.getPuRoot(); if(rootDD.isApplication()){ return puRoot; } else { ModuleDescriptor module = BundleDescriptor.class.cast(rootDD). getModuleDescriptor(); if(module.isStandalone()) { return puRoot; } else { // The module is embedded in an ear (an ejb jar or war) final String moduleLocation = // Would point to the directory where module is expanded. For example myejb_jar DeploymentUtils.getRelativeEmbeddedModulePath( providerContainerContractInfo.getApplicationLocation(), module.getArchiveUri()); return moduleLocation + '/' + puRoot; // see we always '/' } } }