Package com.isomorphic.jpa

# Class EMFProviderLMT

java.lang.Object
com.isomorphic.jpa.EMFProviderLMT

All Implemented Interfaces:
  `EMFProviderInterface`

Direct Known Subclasses:
  `EMFProviderNoTransactions`

public class EMFProviderLMT extends Object implements EMFProviderInterface
EMF provider for Locally Managed Transactions (LMT).

Name of persistence unit can be read from jpa.persistenceUnitName property. `EntityManagerFactory` is created in static initialization block and used to create `EntityManager` objects.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected jakarta.persistence.EntityManagerFactory`
  `emf`
  Holds `EntityManagerFactory`.

  ### 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
  `EMFProviderLMT()`
  Creates new EMF provider.
  `EMFProviderLMT(String persistenceUnitName)`
  Creates new EMF provider with specified persistence unit name.
  `EMFProviderLMT(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`.
  `jakarta.persistence.EntityManager`
  `getEntityManager()`
  Returns `EntityManager` created using factory.
  `Object`
  `getTransaction(jakarta.persistence.EntityManager em)`
  Returns started transaction.
  `void`
  `returnEntityManager(jakarta.persistence.EntityManager em)`
  Closes `EntityManager`.
  `void`
  `rollbackTransaction(Object tx)`
  Rolls back specified transaction.

- ## Field Details

  - ### emf

    protected jakarta.persistence.EntityManagerFactory emf
    Holds `EntityManagerFactory`.

- ## Constructor Details

  - ### EMFProviderLMT

    public EMFProviderLMT()
    Creates new EMF provider. Name of persistence unit is read from jpa.persistenceUnitName property.

  - ### EMFProviderLMT

    public EMFProviderLMT(Properties config)
    Creates new EMF provider. Name of persistence unit is read from provided persistenceUnitName property.
    Parameters:
      `config` - `Properties` for provider configuration.

  - ### EMFProviderLMT

    public EMFProviderLMT(String persistenceUnitName)
    Creates new EMF provider with specified persistence unit name.
    Parameters:
      `persistenceUnitName` - `String` name of persistence unit.

- ## Method Details

  - ### get

    public jakarta.persistence.EntityManagerFactory get()
    Returns `EntityManagerFactory`.
    Specified by:
      `get` in interface `EMFProviderInterface`
    Returns:
      `EntityManagerFactory` for locally managed transactions.

  - ### getEntityManager

    public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceException
    Returns `EntityManager` created using factory.
    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)
    Closes `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 started transaction.

    Creates transaction with `em.getTransaction ()` and starts it.

    Specified by:
      `getTransaction` in interface `EMFProviderInterface`
    Parameters:
      `em` - `EntityManager` needed if joining to existing transaction or starting transaction locally.
    Returns:
      `Object` Already started 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 ()`.
    Specified by:
      `commitTransaction` in interface `EMFProviderInterface`
    Parameters:
      `tx` - `Object` transaction to be commited.
    Throws:
      `Exception` - occured 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.