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 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.