Package com.isomorphic.jpa

# Class EMF

java.lang.Object
com.isomorphic.jpa.EMF

public class EMF extends Object
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
  Description
  `static final String`
  `EMF_PROVIDER`
  Name of sub property for JPA EMF provider implementation.
  `static final String`
  `JPA_EMF_PROVIDER`
  Name of property for JPA EMF provider implementation.
  `static final String`
  `JPA_PREFIX`
  Name of prefix for JPA EMF provider block.
  `static final String`
  `TRANSACTION_ATTR`
  Attribute name for RPCManager.

- ## Method Summary

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

- ## Field Details

  - ### JPA_PREFIX

    public static final String JPA_PREFIX
    Name of prefix for JPA EMF provider block.
    See Also:
      - Constant Field Values

  - ### EMF_PROVIDER

    public static final String EMF_PROVIDER
    Name of sub property for JPA EMF provider implementation.
    See Also:
      - Constant Field Values

  - ### JPA_EMF_PROVIDER

    public static final String JPA_EMF_PROVIDER
    Name of property for JPA EMF provider implementation.
    See Also:
      - Constant Field Values

  - ### TRANSACTION_ATTR

    public static final String TRANSACTION_ATTR
    Attribute name for RPCManager. Under this attribute current transaction is stored.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### get

    public static jakarta.persistence.EntityManagerFactory get()
    Returns `EntityManagerFactory`. Using default configuration.
    Returns:
      `EntityManagerFactory` or null.

  - ### get

    public static jakarta.persistence.EntityManagerFactory get(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 jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceException
    Returns `EntityManager` for persistence operations. Using default configuration.
    Returns:
      `EntityManager` for persistence operations.
    Throws:
      `jakarta.persistence.PersistenceException` - if unable to acquire `EntityManager`.

  - ### getEntityManager

    public static jakarta.persistence.EntityManager getEntityManager(String configName) throws jakarta.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:
      `jakarta.persistence.PersistenceException` - if unable to acquire `EntityManager`.

  - ### returnEntityManager

    public static void returnEntityManager(jakarta.persistence.EntityManager em)
    Closes `EntityManager`. Using default configuration.
    Parameters:
      `em` - `EntityManager` which should be closed.

  - ### returnEntityManager

    public static void returnEntityManager(String configName, jakarta.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 Object getTransaction(jakarta.persistence.EntityManager em) throws 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:
      `Exception` - if unable to acquire or open transaction.

  - ### getTransaction

    public static Object getTransaction(String configName, jakarta.persistence.EntityManager em) throws 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:
      `Exception` - if unable to acquire or open transaction.

  - ### commitTransaction

    public static void commitTransaction(Object tx) throws Exception
    Commits specified transaction. Using default configuration.
    Parameters:
      `tx` - `Object` transaction to be commited.
    Throws:
      `Exception` - occured while committing transaction.

  - ### commitTransaction

    public static void commitTransaction(String configName, Object tx) throws 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:
      `Exception` - occured while committing transaction.

  - ### rollbackTransaction

    public static void rollbackTransaction(Object tx)
    Rolls back specified transaction. Using default configuration.
    Parameters:
      `tx` - `Object` transaction to be rolled back.

  - ### rollbackTransaction

    public static void rollbackTransaction(String configName, 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.