Package com.isomorphic.jpa

# Class EMFProviderBMT

java.lang.Object
com.isomorphic.jpa.EMFProviderBMT

All Implemented Interfaces:
  `EMFProviderInterface`

public class EMFProviderBMT extends Object implements EMFProviderInterface
EMF provider for Bean Managed Transactions (BMT).

Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locate `EntityManager` and `EntityManagerFactory` and transaction in container's environment context. For this implementation to work in /WEB-INF/web.xml should be these declarations:
To acquire `EntityManager`:

      <persistence-context-ref>
          <persistence-context-ref-name>REFERENCE_TO_ENTITY_MANAGER</persistence-context-ref-name>
          <persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
      </persistence-context-ref>

To acquire `EntityManagerFactory`:

      <persistence-unit-ref>
          <persistence-unit-ref-name>REFERENCE_TO_ENTITY_MANAGER_FACTORY</persistence-unit-ref-name>
          <persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
      </persistence-unit-ref>

`getTransaction()` will return instance of `UserTransaction` located in "java:comp/UserTransaction" in JNDI.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `String`
  `entityManagerFactoryRef`
  Name of the reference to managed entity manager factory.
  `String`
  `entityManagerRef`
  Name of the reference to container managed entity manager.

  ### Fields inherited from interface com.isomorphic.jpa.EMFProviderInterface

  `ENTITY_MANAGER, ENTITY_MANAGER_FACTORY, JPA_ENTITY_MANAGER, JPA_ENTITY_MANAGER_FACTORY, JPA_PERSISTENCE_UNIT_NAME, JPA_TRANSACTION, PERSISTENCE_UNIT_NAME, TRANSACTION`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `EMFProviderBMT()`
  Creates new EMF provider.
  `EMFProviderBMT(String entityManagerRef, String entityManagerFactoryRef)`
  Creates new EMF provider with specified context reference names.
  `EMFProviderBMT(Properties config)`
  Creates new EMF provider.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `commitTransaction(Object tx)`
  Commits specified transaction.
  `jakarta.persistence.EntityManagerFactory`
  `get()`
  Returns `EntityManagerFactory` found in container's environment context.
  `jakarta.persistence.EntityManager`
  `getEntityManager()`
  Returns `EntityManager` found in container's environment context.
  `Object`
  `getTransaction(jakarta.persistence.EntityManager em)`
  Returns `UserTransaction` found in container's environment context.
  `void`
  `returnEntityManager(jakarta.persistence.EntityManager em)`
  Does nothing - container will close `EntityManager`.
  `void`
  `rollbackTransaction(Object tx)`
  Rolls back specified transaction.

- ## Field Details

  - ### entityManagerRef

    public String entityManagerRef
    Name of the reference to container managed entity manager.

  - ### entityManagerFactoryRef

    public String entityManagerFactoryRef
    Name of the reference to managed entity manager factory.

- ## Constructor Details

  - ### EMFProviderBMT

    public EMFProviderBMT()
    Creates new EMF provider. Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locate `EntityManager` and `EntityManagerFactory` in container's environment context.

  - ### EMFProviderBMT

    public EMFProviderBMT(Properties config)
    Creates new EMF provider. Values from provided properties entityManager and entityManagerFactory are used to locate `EntityManager` and `EntityManagerFactory` in container's environment context.
    Parameters:
      `config` - `Properties` for provider configuration.

  - ### EMFProviderBMT

    public EMFProviderBMT(String entityManagerRef, String entityManagerFactoryRef)
    Creates new EMF provider with specified context reference names.
    Parameters:
      `entityManagerRef` - `String` name of context reference to entity manager.
      `entityManagerFactoryRef` - `String` name of context reference to entity manager factory.

- ## Method Details

  - ### get

    public jakarta.persistence.EntityManagerFactory get()
    Returns `EntityManagerFactory` found in container's environment context.
    Specified by:
      `get` in interface `EMFProviderInterface`
    Returns:
      `EntityManagerFactory` can be used to acquire meta-data (for JPA 2.0) or implement "application managed entity manager" pattern.

  - ### getEntityManager

    public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceException
    Returns `EntityManager` found in container's environment context.
    Specified by:
      `getEntityManager` in interface `EMFProviderInterface`
    Returns:
      `EntityManager` for persistence operations.
    Throws:
      `jakarta.persistence.PersistenceException` - if unable to acquire `EntityManager`.

  - ### returnEntityManager

    public void returnEntityManager(jakarta.persistence.EntityManager em)
    Does nothing - container will close `EntityManager`.
    Specified by:
      `returnEntityManager` in interface `EMFProviderInterface`
    Parameters:
      `em` - `EntityManager` which should be closed.

  - ### getTransaction

    public Object getTransaction(jakarta.persistence.EntityManager em) throws Exception
    Returns `UserTransaction` found in container's environment context.
    Specified by:
      `getTransaction` in interface `EMFProviderInterface`
    Parameters:
      `em` - `EntityManager` needed if joining to existing transaction or null.
    Returns:
      `Object` Transaction for persistence operations.
    Throws:
      `jakarta.persistence.PersistenceException` - if unable to acquire or open transaction.
      `Exception` - if unable to acquire or open transaction.

  - ### commitTransaction

    public void commitTransaction(Object tx) throws Exception
    Commits specified transaction. Issues `tx.commit()`. Throws `PersistenceException` if transaction already rolled back.
    Specified by:
      `commitTransaction` in interface `EMFProviderInterface`
    Parameters:
      `tx` - `Object` transaction to be committed.
    Throws:
      `Exception` - occurred while committing transaction.

  - ### rollbackTransaction

    public void rollbackTransaction(Object tx)
    Rolls back specified transaction. Issues `tx.rollback()`.
    Specified by:
      `rollbackTransaction` in interface `EMFProviderInterface`
    Parameters:
      `tx` - `Object` transaction to be rolled back.