@Override public ClassLoader getClassLoader() { return persistenceUnitInfo.getClassLoader(); }
@Override @SuppressWarnings("unchecked") public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) { final Map settings = generateSettings( properties ); // OSGi ClassLoaders must implement BundleReference settings.put( org.hibernate.cfg.AvailableSettings.SCANNER, new OsgiScanner( ( (BundleReference) info.getClassLoader() ).getBundle() ) ); osgiClassLoader.addClassLoader( info.getClassLoader() ); return Bootstrap.getEntityManagerFactoryBuilder( info, settings, new OSGiClassLoaderServiceImpl( osgiClassLoader, osgiServiceUtil ) ).build(); }
/** * {@inheritDoc} * */ @Override public ClassLoader getClassloader() { return this.puInfo.getClassLoader(); }
/** * {@inheritDoc} * */ @Override public ClassLoader getClassloader() { return this.puInfo.getClassLoader(); }
/** * {@inheritDoc} * */ @Override public ClassLoader getClassloader() { return this.puInfo.getClassLoader(); }
@Override public ClassLoader getClassLoader() { return delegator.getClassLoader(); }
@Override public ClassLoader getClassLoader() { return persistenceUnitInfo.getClassLoader(); }
private Set<Class<?>> findClasses(PersistenceUnitInfo persistenceUnitInfo, URL url, final Set<Class<?>> classes) throws IOException { final JarFile jarFile = new JarFile(url.getFile()); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.isDirectory()) { continue; } final String className = entry.getName().replace('/', '.').replace('\\', '.'); if (className.endsWith(".class")) { final Class<?> clazz = this.isPersistentClass(persistenceUnitInfo.getClassLoader(), className.substring(0, className.length() - 6)); if (clazz != null) { JarAnnotatedClassLocator.LOG.info("Found annotated class {0}", className); classes.add(clazz); } } } return classes; }
/** * Parses the types in the metamodel and in the jar files. * * @param puInfo * the persistence unit info * * @since 2.0.0 */ public void parse(PersistenceUnitInfo puInfo) { final ClassLoader classloader = puInfo.getClassLoader(); final Set<Class<?>> classes = BaseAnnotatedClassLocator.locatePersistentClasses(puInfo); for (final Class<?> clazz : classes) { if (!this.entityMap.containsKey(clazz.getName()) && !this.entityMap.containsKey(clazz.getSimpleName())) { this.entityMap.put(clazz.getName(), null); } } this.parse(classloader); } }
/** * INTERNAL: * Returns the ServerSession that the Factory will be using and initializes it if it is not available. * This method makes use of the partially constructed session stored in our setupImpl and * completes its construction */ public synchronized ServerSession getServerSession(){ if (serverSession == null){ ClassLoader realLoader = setupImpl.getPersistenceUnitInfo().getClassLoader(); // the call top setupImpl.deploy() finishes the session creation serverSession = setupImpl.deploy(realLoader, properties); } return this.serverSession; }
/** * Build a set that contains all the class names at a URL. * @return a Set of class name strings */ public static Set<String> buildClassSet(PersistenceUnitInfo persistenceUnitInfo, Map properties){ Set<String> set = new HashSet<String>(); set.addAll(persistenceUnitInfo.getManagedClassNames()); ClassLoader loader = persistenceUnitInfo.getClassLoader(); Iterator i = persistenceUnitInfo.getJarFileUrls().iterator(); while (i.hasNext()) { set.addAll(getClassNamesFromURL((URL)i.next(), loader, properties)); } if (!persistenceUnitInfo.excludeUnlistedClasses()){ set.addAll(getClassNamesFromURL(persistenceUnitInfo.getPersistenceUnitRootUrl(), loader, properties)); } // No longer need to add classes from XML, as temp class loader is only used for sessions.xml. return set; }
public Class<?> transform(final PersistenceUnitInfo unitInfo, final String className, final byte[] bytecode) { final List<ClassTransformer> transformers = PersistenceUnitInfoImpl.class .cast(unitInfo).getTransformers(); final ClassLoader classLoader = unitInfo.getClassLoader(); final ClassLoader targetLoader = getTargetClassLoader(classLoader); byte[] bytes = bytecode; for (final ClassTransformer transformer : transformers) { bytes = transform(transformer, targetLoader, className, bytes); } return ClassLoaderUtil.defineClass(targetLoader, className, bytes, 0, bytes.length); }
@Override /** * SAP NetWeaver does not support dynamic byte code weaving. We return the original class loader * in order to prevent dynamic weaving. */ public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) { ClassLoader realClassLoader = puInfo.getClassLoader(); AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_sap_temp_classloader_bypassed",// puInfo.getPersistenceUnitName(), realClassLoader); return new JPAClassLoaderHolder(realClassLoader, NO_TEMP_CLASS_LOADER); } }
@Override /** * SAP NetWeaver does not support dynamic byte code weaving. We return the original class loader * in order to prevent dynamic weaving. */ public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) { ClassLoader realClassLoader = puInfo.getClassLoader(); AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_sap_temp_classloader_bypassed",// puInfo.getPersistenceUnitName(), realClassLoader); return new JPAClassLoaderHolder(realClassLoader, NO_TEMP_CLASS_LOADER); } }
/** * {@inheritDoc} * */ @Override public Set<Class<?>> locateClasses(PersistenceUnitInfo persistenceUnitInfo, URL url) { final String root = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(url.getFile())); ClassloaderAnnotatedClassLocator.LOG.info("Checking persistence root {0} for persistence classes...", root); final HashSet<Class<?>> classes = Sets.newHashSet(); try { return this.findClasses(persistenceUnitInfo.getClassLoader(), classes, root, root); } finally { ClassloaderAnnotatedClassLocator.LOG.info("Found persistent classes {0}", classes.toString()); } } }
/** * {@inheritDoc} * */ @Override public Set<Class<?>> locateClasses(PersistenceUnitInfo persistenceUnitInfo, URL url) { final String root = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(url.getFile())); ClassloaderAnnotatedClassLocator.LOG.info("Checking persistence root {0} for persistence classes...", root); final HashSet<Class<?>> classes = Sets.newHashSet(); try { return this.findClasses(persistenceUnitInfo.getClassLoader(), classes, root, root); } finally { ClassloaderAnnotatedClassLocator.LOG.info("Found persistent classes {0}", classes.toString()); } } }
/** * {@inheritDoc} * */ @Override public Set<Class<?>> locateClasses(PersistenceUnitInfo persistenceUnitInfo, URL url) { final String root = FilenameUtils.separatorsToUnix(FilenameUtils.normalize(url.getFile())); ClassloaderAnnotatedClassLocator.LOG.info("Checking persistence root {0} for persistence classes...", root); final HashSet<Class<?>> classes = Sets.newHashSet(); try { return this.findClasses(persistenceUnitInfo.getClassLoader(), classes, root, root); } finally { ClassloaderAnnotatedClassLocator.LOG.info("Found persistent classes {0}", classes.toString()); } } }
/** * INTERNAL: * JIRA EJBTHREE-572 requires that we use the real classLoader in place of the getNewTempClassLoader(). * The override code should stay in place until the UCL3 loader does not throw a NPE on loadClass() * * @param puInfo - the persistence unit info * @return ClassLoaderHolder - a composite object containing the classLoader and the flag * that is true if the classLoader returned is temporary * * @see org.eclipse.persistence.internal.helper.JPAClassLoaderHolder */ public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) { // Bug 6460732: Use real classLoader instead of getNewTempClassLoader for now to avoid a JBoss NPE on loadClass() ClassLoader realClassLoader = puInfo.getClassLoader(); AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_jboss_temp_classloader_bypassed",// puInfo.getPersistenceUnitName(), realClassLoader); return new JPAClassLoaderHolder(realClassLoader, false); }
/** * INTERNAL: * JIRA EJBTHREE-572 requires that we use the real classLoader in place of the getNewTempClassLoader(). * The override code should stay in place until the UCL3 loader does not throw a NPE on loadClass() * * @param puInfo - the persistence unit info * @return ClassLoaderHolder - a composite object containing the classLoader and the flag * that is true if the classLoader returned is temporary * * @see org.eclipse.persistence.internal.helper.JPAClassLoaderHolder */ public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) { // Bug 6460732: Use real classLoader instead of getNewTempClassLoader for now to avoid a JBoss NPE on loadClass() ClassLoader realClassLoader = puInfo.getClassLoader(); AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_jboss_temp_classloader_bypassed",// puInfo.getPersistenceUnitName(), realClassLoader); return new JPAClassLoaderHolder(realClassLoader, false); }
/** * INTERNAL: * JIRA EJBTHREE-572 requires that we use the real classLoader in place of the getNewTempClassLoader(). * The override code should stay in place until the UCL3 loader does not throw a NPE on loadClass() * * @param puInfo - the persistence unit info * @return ClassLoaderHolder - a composite object containing the classLoader and the flag * that is true if the classLoader returned is temporary * * @see org.eclipse.persistence.internal.helper.ClassLoaderHolder */ public JPAClassLoaderHolder getNewTempClassLoader(PersistenceUnitInfo puInfo) { // Bug 6460732: Use real classLoader instead of getNewTempClassLoader for now to avoid a JBoss NPE on loadClass() ClassLoader realClassLoader = puInfo.getClassLoader(); AbstractSessionLog.getLog().log(AbstractSessionLog.WARNING, "persistence_unit_processor_jboss_temp_classloader_bypassed",// puInfo.getPersistenceUnitName(), realClassLoader); return new JPAClassLoaderHolder(realClassLoader, false); } }