org.eclipse.persistence.javax.persistence.osgi

## Class OSGiProviderResolver

- java.lang.Object
- - org.eclipse.persistence.javax.persistence.osgi.OSGiProviderResolver

All Implemented Interfaces:
  PersistenceProvider, PersistenceProviderResolver

    public class OSGiProviderResolver
    extends java.lang.Object
    implements PersistenceProviderResolver, PersistenceProvider

This class acts as the ProviderResolver as well as the PersistenceProvider to the Persistence class.

Author:
  mkeith

### Nested Class Summary

Nested Classes
`class` `OSGiProviderResolver.ForwardingProviderUtil`

### Constructor Summary

Constructors
Constructor and Description
`OSGiProviderResolver(BundleContext ctx)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `clearCachedProviders()` Clear cache of providers.
`EntityManagerFactory` `createContainerEntityManagerFactory(PersistenceUnitInfo info, java.util.Map props)` Called by the container when an `EntityManagerFactory` is to be created.
`EntityManagerFactory` `createEntityManagerFactory(java.lang.String unitName, java.util.Map props)` Called by `Persistence` class when an `EntityManagerFactory` is to be created.
`protected void` `debug(java.lang.String... msgs)`
`void` `generateSchema(PersistenceUnitInfo info, java.util.Map map)` Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.
`boolean` `generateSchema(java.lang.String persistenceUnitName, java.util.Map map)` Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.
`java.util.List<PersistenceProvider>` `getPersistenceProviders()` ProviderResolver API method to get all of the providers.
`ProviderUtil` `getProviderUtil()` Return the utility interface implemented by the persistence provider.
`EntityManagerFactory` `lookupEMF(java.lang.String unitName)` Look up the Entity Manager Factory service based on the unit name.
`EntityManagerFactory` `lookupEMFBuilder(java.lang.String unitName, java.util.Map<?,?> props)` Look up the Entity Manager Factory Builder service based on the unit name.
`java.util.Collection<PersistenceProvider>` `lookupProviders()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### OSGiProviderResolver

    public OSGiProviderResolver(BundleContext ctx)

### Method Detail

#### getPersistenceProviders

    public java.util.List<PersistenceProvider> getPersistenceProviders()

ProviderResolver API method to get all of the providers. We will use this to hook ourselves in through the Persistence class so we can intercept all of the provider calls and redirect them to use OSGi services.

Specified by:
  `getPersistenceProviders` in interface `PersistenceProviderResolver`
Returns:
  list of the persistence providers available in the environment

#### clearCachedProviders

    public void clearCachedProviders()

Description copied from interface: `PersistenceProviderResolver`
Clear cache of providers.

Specified by:
  `clearCachedProviders` in interface `PersistenceProviderResolver`

#### createEntityManagerFactory

    public EntityManagerFactory createEntityManagerFactory(java.lang.String unitName,
                                                           java.util.Map props)

Description copied from interface: `PersistenceProvider`
Called by `Persistence` class when an `EntityManagerFactory` is to be created.

Specified by:
  `createEntityManagerFactory` in interface `PersistenceProvider`
Parameters:
  `unitName` - the name of the persistence unit
  `props` - a Map of properties for use by the persistence provider. These properties may be used to override the values of the corresponding elements in the `persistence.xml` file or specify values for properties not specified in the `persistence.xml` (and may be null if no properties are specified).
Returns:
  EntityManagerFactory for the persistence unit, or null if the provider is not the right provider

#### createContainerEntityManagerFactory

    public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info,
                                                                    java.util.Map props)

Description copied from interface: `PersistenceProvider`
Called by the container when an `EntityManagerFactory` is to be created.

Specified by:
  `createContainerEntityManagerFactory` in interface `PersistenceProvider`
Parameters:
  `info` - metadata for use by the persistence provider
  `props` - a Map of integration-level properties for use by the persistence provider (may be null if no properties are specified). These properties may include properties to control schema generation. If a Bean Validation provider is present in the classpath, the container must pass the `ValidatorFactory` instance in the map with the key `"javax.persistence.validation.factory"`. If the containing archive is a bean archive, the container must pass the BeanManager instance in the map with the key `"javax.persistence.bean.manager"`.
Returns:
  EntityManagerFactory for the persistence unit specified by the metadata

#### getProviderUtil

    public ProviderUtil getProviderUtil()

Description copied from interface: `PersistenceProvider`
Return the utility interface implemented by the persistence provider.

Specified by:
  `getProviderUtil` in interface `PersistenceProvider`
Returns:
  ProviderUtil interface

#### lookupEMF

    public EntityManagerFactory lookupEMF(java.lang.String unitName)

Look up the Entity Manager Factory service based on the unit name.

#### lookupEMFBuilder

    public EntityManagerFactory lookupEMFBuilder(java.lang.String unitName,
                                                 java.util.Map<?,?> props)

Look up the Entity Manager Factory Builder service based on the unit name.

Returns:
  The EntityManagerFactory object that was looked up (or created from the EntityManagerFactoryBuilder)

#### lookupProviders

    public java.util.Collection<PersistenceProvider> lookupProviders()

#### debug

    protected void debug(java.lang.String... msgs)

#### generateSchema

    public void generateSchema(PersistenceUnitInfo info,
                               java.util.Map map)

Description copied from interface: `PersistenceProvider`
Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.

Called by the container when schema generation is to occur as a separate phase from creation of the entity manager factory.

Specified by:
  `generateSchema` in interface `PersistenceProvider`
Parameters:
  `info` - metadata for use by the persistence provider
  `map` - properties for schema generation; these may also include provider-specific properties

#### generateSchema

    public boolean generateSchema(java.lang.String persistenceUnitName,
                                  java.util.Map map)

Description copied from interface: `PersistenceProvider`
Create database schemas and/or tables and/or create DDL scripts as determined by the supplied properties.

Called by the Persistence class when schema generation is to occur as a separate phase from creation of the entity manager factory.

Specified by:
  `generateSchema` in interface `PersistenceProvider`
Parameters:
  `persistenceUnitName` - the name of the persistence unit
  `map` - properties for schema generation; these may also contain provider-specific properties. The value of these properties override any values that may have been configured elsewhere.
Returns:
  true if schema was generated, otherwise false