org.glassfish.osgijpa.extension
Class HybridPersistenceProviderResolver

java.lang.Object
  extended by org.glassfish.osgijpa.extension.HybridPersistenceProviderResolver
All Implemented Interfaces:
javax.persistence.spi.PersistenceProviderResolver

public class HybridPersistenceProviderResolver
extends java.lang.Object
implements javax.persistence.spi.PersistenceProviderResolver

This is a custom implementation of PersistenceProviderResolver which has the ability to discover providers that are part of OSGi bundles. As you know, a thread's context loader (TCL) is very widely assumed to represent what an application can see. This is no different in JPA as well. However, there exists some technologies like OSGi, which do not want to rely on Thread's context loader to denote visibility scope of an application. In order to accommodate these diverse technologies, it first attempts to discover providers using TCL. If some providers are visible to the TCL, it considers them as the only set of providers that are supposed to be visible to the current thread and hence returns that list. If TCL can't find any providers, then it assumes that it is invoked in a context which is not relying on TCL to limit visibility, hence it goes onto discover all providers installed in the current framework. To discover providers installed by OSGi bundles, it currently relies on provider bundles to have META-INF/services/javax.persistence.PersistenceProvider file as every JPA compliant provider bundles such a resource. In future, we can even enhance this class to discover PersistenceProvider service registered by OSGi/JPA compliant bundles.

As per the requirement of JPA spec, this implementation is thread-safe. Please note, this class comes into picture even in Java EE mode usage of JPA via PersistenceProvider.getProviderUtil(), which is the only way to call methods like ProviderUtil.isLoaded(Object). So, it is important for this class to be performant. So, this class also supports caching mode which can be explicitly enabled at construction time. Caching should only be enabled in environment where providers are not installed/uninstalled dynamically.

Author:
Sanjeeb.Sahoo@Sun.COM

Constructor Summary
HybridPersistenceProviderResolver(boolean cachingEnabled)
           
 
Method Summary
 void clearCachedProviders()
           
 java.util.List<javax.persistence.spi.PersistenceProvider> getPersistenceProviders()
           
 boolean isCachingEnabled()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HybridPersistenceProviderResolver

public HybridPersistenceProviderResolver(boolean cachingEnabled)
Method Detail

getPersistenceProviders

public java.util.List<javax.persistence.spi.PersistenceProvider> getPersistenceProviders()
Specified by:
getPersistenceProviders in interface javax.persistence.spi.PersistenceProviderResolver

clearCachedProviders

public void clearCachedProviders()
Specified by:
clearCachedProviders in interface javax.persistence.spi.PersistenceProviderResolver

isCachingEnabled

public boolean isCachingEnabled()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2011 GlassFish Community. All Rights Reserved.