com.isomorphic.jpa

## Class EMF

- com.isomorphic.jpa.EMF

-     public class EMF

  Singleton factory for `EntityManager` and transaction with helper methods.

  Configuration is read from server.properties file. Value of property jpa.emfProvider specifies actual implementation. Methods hiding `EntityManager` and transaction object initialization are used by `JPADataSource`:
  - `getEntityManager`
  - `returnEntityManager`
  - `getTransaction`
  - `commitTransaction`
  - `rollbackTransaction`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `EMF_PROVIDER` Name of sub property for JPA EMF provider implementation.
    `static java.lang.String` | `JPA_EMF_PROVIDER` Name of property for JPA EMF provider implementation.
    `static java.lang.String` | `JPA_PREFIX` Name of prefix for JPA EMF provider block.
    `static java.lang.String` | `TRANSACTION_ATTR` Attribute name for RPCManager.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `commitTransaction(java.lang.Object tx)` Commits specified transaction.
    `static void` | `commitTransaction(java.lang.String configName, java.lang.Object tx)` Commits specified transaction.
    `static javax.persistence.EntityManagerFactory` | `get()` Returns `EntityManagerFactory`.
    `static javax.persistence.EntityManagerFactory` | `get(java.lang.String configName)` Returns `EntityManagerFactory`.
    `static javax.persistence.EntityManager` | `getEntityManager()` Returns `EntityManager` for persistence operations.
    `static javax.persistence.EntityManager` | `getEntityManager(java.lang.String configName)` Returns `EntityManager` for persistence operations.
    `static java.lang.Object` | `getTransaction(javax.persistence.EntityManager em)` Returns started transaction.
    `static java.lang.Object` | `getTransaction(java.lang.String configName, javax.persistence.EntityManager em)` Returns started transaction.
    `static void` | `returnEntityManager(javax.persistence.EntityManager em)` Closes `EntityManager`.
    `static void` | `returnEntityManager(java.lang.String configName, javax.persistence.EntityManager em)` Closes `EntityManager`.
    `static void` | `rollbackTransaction(java.lang.Object tx)` Rolls back specified transaction.
    `static void` | `rollbackTransaction(java.lang.String configName, java.lang.Object tx)` Rolls back specified transaction.

- - ### Field Detail

    - #### JPA_PREFIX

          public static final java.lang.String JPA_PREFIX

      Name of prefix for JPA EMF provider block.
      See Also:
        Constant Field Values

    - #### EMF_PROVIDER

          public static final java.lang.String EMF_PROVIDER

      Name of sub property for JPA EMF provider implementation.
      See Also:
        Constant Field Values

    - #### JPA_EMF_PROVIDER

          public static final java.lang.String JPA_EMF_PROVIDER

      Name of property for JPA EMF provider implementation.
      See Also:
        Constant Field Values

    - #### TRANSACTION_ATTR

          public static final java.lang.String TRANSACTION_ATTR

      Attribute name for RPCManager. Under this attribute current transaction is stored.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### get

          public static javax.persistence.EntityManagerFactory get()

      Returns `EntityManagerFactory`. Using default configuration.
      Returns:
        `EntityManagerFactory` or null.

    - #### get

          public static javax.persistence.EntityManagerFactory get(java.lang.String configName)

      Returns `EntityManagerFactory`.
      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
      Returns:
        `EntityManagerFactory` or null.

    - #### getEntityManager

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

      Returns `EntityManager` for persistence operations. Using default configuration.
      Returns:
        `EntityManager` for persistence operations.
      Throws:
        `javax.persistence.PersistenceException` - if unable to acquire `EntityManager`.

    - #### getEntityManager

          public static javax.persistence.EntityManager getEntityManager(java.lang.String configName)
                                                                  throws javax.persistence.PersistenceException

      Returns `EntityManager` for persistence operations.

      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
      Returns:
        `EntityManager` for persistence operations.
      Throws:
        `javax.persistence.PersistenceException` - if unable to acquire `EntityManager`.

    - #### returnEntityManager

          public static void returnEntityManager(javax.persistence.EntityManager em)

      Closes `EntityManager`. Using default configuration.
      Parameters:
        `em` - `EntityManager` which should be closed.

    - #### returnEntityManager

          public static void returnEntityManager(java.lang.String configName,
                                 javax.persistence.EntityManager em)

      Closes `EntityManager`.
      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
        `em` - `EntityManager` which should be closed.

    - #### getTransaction

          public static java.lang.Object getTransaction(javax.persistence.EntityManager em)
                                                 throws java.lang.Exception

      Returns started transaction. Using default configuration.
      Parameters:
        `em` - `EntityManager` needed if joining to existing transaction or starting transaction locally.
      Returns:
        `Object` Already started transaction for persistence operations.
      Throws:
        `java.lang.Exception` - if unable to acquire or open transaction.

    - #### getTransaction

          public static java.lang.Object getTransaction(java.lang.String configName,
                                        javax.persistence.EntityManager em)
                                                 throws java.lang.Exception

      Returns started transaction.
      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
        `em` - `EntityManager` needed if joining to existing transaction or starting transaction locally.
      Returns:
        `Object` Already started transaction for persistence operations.
      Throws:
        `java.lang.Exception` - if unable to acquire or open transaction.

    - #### commitTransaction

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

      Commits specified transaction. Using default configuration.
      Parameters:
        `tx` - `Object` transaction to be commited.
      Throws:
        `java.lang.Exception` - occured while committing transaction.

    - #### commitTransaction

          public static void commitTransaction(java.lang.String configName,
                               java.lang.Object tx)
                                        throws java.lang.Exception

      Commits specified transaction.
      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
        `tx` - `Object` transaction to be commited.
      Throws:
        `java.lang.Exception` - occured while committing transaction.

    - #### rollbackTransaction

          public static void rollbackTransaction(java.lang.Object tx)

      Rolls back specified transaction. Using default configuration.
      Parameters:
        `tx` - `Object` transaction to be rolled back.

    - #### rollbackTransaction

          public static void rollbackTransaction(java.lang.String configName,
                                 java.lang.Object tx)

      Rolls back specified transaction.
      Parameters:
        `configName` - `String` configuration name. Default provider is used if `null` or empty string is passed.
        `tx` - `Object` transaction to be rolled back.