public AggregatedClassLoader run() { return new AggregatedClassLoader( orderedClassLoaderSet, lookupPrecedence ); } } );
@Override public Object getService(Bundle requestingBundle, ServiceRegistration registration) { final OsgiClassLoader osgiClassLoader = new OsgiClassLoader(); // First, add the client bundle that's requesting the OSGi services. osgiClassLoader.addBundle( requestingBundle ); // Then, automatically add hibernate-core. These are needed to load resources // contained in the core jar. osgiClassLoader.addBundle( FrameworkUtil.getBundle(SessionFactory.class) ); // Some "boot time" code does still rely on TCCL. "run time" code should all be using // ClassLoaderService now. final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader(); LinkedHashSet<ClassLoader> newTcclDelegates = new LinkedHashSet<>(); newTcclDelegates.add( osgiClassLoader ); newTcclDelegates.add( originalTccl ); final ClassLoader newTccl = new AggregatedClassLoader( newTcclDelegates, TcclLookupPrecedence.NEVER ); Thread.currentThread().setContextClassLoader( newTccl ); try { return buildSessionFactory( requestingBundle, osgiClassLoader ); } finally { Thread.currentThread().setContextClassLoader( originalTccl ); } }
@Override public Object getService(Bundle requestingBundle, ServiceRegistration registration) { final OsgiClassLoader osgiClassLoader = new OsgiClassLoader(); // First, add the client bundle that's requesting the OSGi services. osgiClassLoader.addBundle( requestingBundle ); // Then, automatically add hibernate-core and hibernate-entitymanager. These are needed to load resources // contained in those jars, such as em's persistence.xml schemas. osgiClassLoader.addBundle( FrameworkUtil.getBundle( SessionFactory.class ) ); osgiClassLoader.addBundle( FrameworkUtil.getBundle( HibernateEntityManagerFactory.class ) ); // Some "boot time" code does still rely on TCCL. "run time" code should all be using // ClassLoaderService now. final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader(); LinkedHashSet<ClassLoader> newTcclDelegates = new LinkedHashSet<>(); newTcclDelegates.add( osgiClassLoader ); newTcclDelegates.add( originalTccl ); final ClassLoader newTccl = new AggregatedClassLoader( newTcclDelegates, TcclLookupPrecedence.NEVER ); Thread.currentThread().setContextClassLoader( newTccl ); try { return new OsgiPersistenceProvider( osgiClassLoader, osgiJtaPlatform, osgiServiceUtil, requestingBundle ); } finally { Thread.currentThread().setContextClassLoader( originalTccl ); } }
public AggregatedClassLoader run() { return new AggregatedClassLoader( orderedClassLoaderSet, lookupPrecedence ); } } );