protected ClassLoader createTempLoader( Collection col, boolean shouldOverrideLoadClassForCollectionMembers) { if (!shouldCreateInternalLoader) { return Thread.currentThread().getContextClassLoader(); } ClassLoader currentLoader = Thread.currentThread().getContextClassLoader(); if (!(currentLoader instanceof URLClassLoader)) { // we can't create a TempEntityLoader so just use the current one // shouldn't be a problem (and should only occur) in JavaSE return currentLoader; } URL[] urlPath = ((URLClassLoader) currentLoader).getURLs(); ClassLoader tempLoader = new TempEntityLoader( urlPath, currentLoader, col, shouldOverrideLoadClassForCollectionMembers); AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_tempLoader_created", tempLoader); AbstractSessionLog.getLog() .log( SessionLog.FINER, "cmp_init_shouldOverrideLoadClassForCollectionMembers", new Boolean(shouldOverrideLoadClassForCollectionMembers)); return tempLoader; }
public static ClassLoader getMainLoader() { return Thread.currentThread().getContextClassLoader(); }
/** * INTERNAL predeploy (with deploy) is one of the two steps required in deployment of entities * This method will prepare to call predeploy, call it and finally register the transformer * returned to be used for weaving. */ protected boolean callPredeploy( SEPersistenceUnitInfo persistenceUnitInfo, Map m, PersistenceInitializationActivator persistenceActivator) { ClassLoader tempLoader = null; // we will only attempt to deploy when TopLink is specified as the provider or the provider is // unspecified String providerClassName = persistenceUnitInfo.getPersistenceProviderClassName(); if (persistenceActivator.isPersistenceProviderSupported(providerClassName)) { EntityManagerSetupImpl emSetupImpl = EntityManagerFactoryProvider.getEntityManagerSetupImpl( persistenceUnitInfo.getPersistenceUnitRootUrl() + persistenceUnitInfo.getPersistenceUnitName()); // if we already have an EntityManagerSetupImpl this PU has already been processed. Use the // existing one if (emSetupImpl != null && !emSetupImpl.isUndeployed()) { return false; } Set tempLoaderSet = PersistenceUnitProcessor.buildClassSet( persistenceUnitInfo, Thread.currentThread().getContextClassLoader()); Map mergedProperties = EntityManagerFactoryProvider.mergeMaps(m, persistenceUnitInfo.getProperties()); String weaving = EntityManagerFactoryProvider.getConfigPropertyAsString( TopLinkProperties.WEAVING, mergedProperties, null); // Bug#4452468 When globalInstrumentation is null, there is no weaving if (globalInstrumentation == null) { if (weaving == null) { mergedProperties.put(TopLinkProperties.WEAVING, "false"); weaving = "false"; } else if (weaving.equalsIgnoreCase("true")) { throw new PersistenceException(EntityManagerSetupException.wrongWeavingPropertyValue()); } } // Bug#2741: If weaving disabled then use regular loader, not a temp one if (weaving != null && (weaving.equalsIgnoreCase("false") || weaving.equalsIgnoreCase("static"))) { shouldCreateInternalLoader = false; } // Create the temp loader that will not cache classes for entities in our persistence unit tempLoader = createTempLoader(tempLoaderSet); persistenceUnitInfo.setNewTempClassLoader(tempLoader); persistenceUnitInfo.setClassLoader(getMainLoader()); if (emSetupImpl == null) { emSetupImpl = new EntityManagerSetupImpl(); EntityManagerFactoryProvider.addEntityManagerSetupImpl( persistenceUnitInfo.getPersistenceUnitRootUrl() + persistenceUnitInfo.getPersistenceUnitName(), emSetupImpl); } // Make the callback AbstractSessionLog.getLog() .log( SessionLog.FINER, "cmp_init_invoke_predeploy", persistenceUnitInfo.getPersistenceUnitName()); // A call to predeploy will partially build the session we will use final ClassTransformer transformer = emSetupImpl.predeploy(persistenceUnitInfo, mergedProperties); // If we got a transformer then register it if ((transformer != null) && (globalInstrumentation != null)) { AbstractSessionLog.getLog() .log( SessionLog.FINER, "cmp_init_register_transformer", persistenceUnitInfo.getPersistenceUnitName()); globalInstrumentation.addTransformer( new ClassFileTransformer() { // adapt ClassTransformer to ClassFileTransformer interface public byte[] transform( ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { return transformer.transform( loader, className, classBeingRedefined, protectionDomain, classfileBuffer); } }); } else if (transformer == null) { AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_transformer_is_null"); } else if (globalInstrumentation == null) { AbstractSessionLog.getLog().log(SessionLog.FINER, "cmp_init_globalInstrumentation_is_null"); } return true; } return false; }