com.isomorphic.jpa

## Class EMFProviderLMT

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

- All Implemented Interfaces:
    EMFProviderInterface
  Direct Known Subclasses:
    EMFProviderNoTransactions

      public class EMFProviderLMT
      extends java.lang.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 and Description
    --- | ---
    `protected javax.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 and Description
    `EMFProviderLMT()` Creates new EMF provider.
    `EMFProviderLMT(java.util.Properties config)` Creates new EMF provider.
    `EMFProviderLMT(java.lang.String persistenceUnitName)` Creates new EMF provider with specified persistence unit name.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `commitTransaction(java.lang.Object tx)` Commits specified transaction.
    `javax.persistence.EntityManagerFactory` | `get()` Returns `EntityManagerFactory`.
    `javax.persistence.EntityManager` | `getEntityManager()` Returns `EntityManager` created using factory.
    `java.lang.Object` | `getTransaction(javax.persistence.EntityManager em)` Returns started transaction. Creates transaction with `em.getTransaction ()` and starts it.
    `void` | `returnEntityManager(javax.persistence.EntityManager em)` Closes `EntityManager`.
    `void` | `rollbackTransaction(java.lang.Object tx)` Rolls back specified transaction.

- - ### Field Detail

    - #### emf

          protected javax.persistence.EntityManagerFactory emf

      Holds `EntityManagerFactory`.

  - ### Constructor Detail

    - #### EMFProviderLMT

          public EMFProviderLMT()

      Creates new EMF provider. Name of persistence unit is read from jpa.persistenceUnitName property.

    - #### EMFProviderLMT

          public EMFProviderLMT(java.util.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(java.lang.String persistenceUnitName)

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

  - ### Method Detail

    - #### get

          public javax.persistence.EntityManagerFactory get()

      Returns `EntityManagerFactory`.
      Specified by:
        `get` in interface `EMFProviderInterface`
      Returns:
        `EntityManagerFactory` for locally managed transactions.

    - #### getEntityManager

          public javax.persistence.EntityManager getEntityManager()
                                                           throws javax.persistence.PersistenceException

      Returns `EntityManager` created using factory.
      Specified by:
        `getEntityManager` in interface `EMFProviderInterface`
      Returns:
        `EntityManager` for persistence operations.
      Throws:
        `javax.persistence.PersistenceException` - if unable to acquire `EntityManager`.

    - #### returnEntityManager

          public void returnEntityManager(javax.persistence.EntityManager em)

      Closes `EntityManager`.

      Specified by:
        `returnEntityManager` in interface `EMFProviderInterface`
      Parameters:
        `em` - `EntityManager` which should be closed.

    - #### getTransaction

          public java.lang.Object getTransaction(javax.persistence.EntityManager em)
                                          throws java.lang.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:
        `javax.persistence.PersistenceException` - if unable to acquire or open transaction.
        `java.lang.Exception` - if unable to acquire or open transaction.

    - #### commitTransaction

          public void commitTransaction(java.lang.Object tx)
                                 throws java.lang.Exception

      Commits specified transaction. Issues `tx.commit ()`.
      Specified by:
        `commitTransaction` in interface `EMFProviderInterface`
      Parameters:
        `tx` - `Object` transaction to be commited.
      Throws:
        `java.lang.Exception` - occured while committing transaction.

    - #### rollbackTransaction

          public void rollbackTransaction(java.lang.Object tx)

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