Package com.isomorphic.jpa
Class EMFProviderLMT
java.lang.Object
com.isomorphic.jpa.EMFProviderLMT
- All Implemented Interfaces:
EMFProviderInterface
- Direct Known Subclasses:
EMFProviderNoTransactions
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
FieldsModifier and TypeFieldDescriptionprotected jakarta.persistence.EntityManagerFactoryHoldsEntityManagerFactory.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
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidCommits specified transaction.jakarta.persistence.EntityManagerFactoryget()ReturnsEntityManagerFactory.jakarta.persistence.EntityManagerReturnsEntityManagercreated using factory.getTransaction(jakarta.persistence.EntityManager em) Returns started transaction.voidreturnEntityManager(jakarta.persistence.EntityManager em) ClosesEntityManager.voidRolls back specified transaction.
-
Field Details
-
emf
protected jakarta.persistence.EntityManagerFactory emfHoldsEntityManagerFactory.
-
-
Constructor Details
-
EMFProviderLMT
public EMFProviderLMT()Creates new EMF provider. Name of persistence unit is read from jpa.persistenceUnitName property. -
EMFProviderLMT
Creates new EMF provider. Name of persistence unit is read from provided persistenceUnitName property.- Parameters:
config-Propertiesfor provider configuration.
-
EMFProviderLMT
Creates new EMF provider with specified persistence unit name.- Parameters:
persistenceUnitName-Stringname of persistence unit.
-
-
Method Details
-
get
public jakarta.persistence.EntityManagerFactory get()ReturnsEntityManagerFactory.- Specified by:
getin interfaceEMFProviderInterface- Returns:
EntityManagerFactoryfor locally managed transactions.
-
getEntityManager
public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceExceptionReturnsEntityManagercreated using factory.- Specified by:
getEntityManagerin interfaceEMFProviderInterface- Returns:
EntityManagerfor persistence operations.- Throws:
jakarta.persistence.PersistenceException- if unable to acquireEntityManager.
-
returnEntityManager
public void returnEntityManager(jakarta.persistence.EntityManager em) ClosesEntityManager.- Specified by:
returnEntityManagerin interfaceEMFProviderInterface- Parameters:
em-EntityManagerwhich should be closed.
-
getTransaction
Returns started transaction.Creates transaction with
em.getTransaction ()and starts it.- Specified by:
getTransactionin interfaceEMFProviderInterface- Parameters:
em-EntityManagerneeded if joining to existing transaction or starting transaction locally.- Returns:
ObjectAlready 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
Commits specified transaction. Issuestx.commit ().- Specified by:
commitTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be commited.- Throws:
Exception- occured while committing transaction.
-
rollbackTransaction
Rolls back specified transaction. Issuestx.rollback ().- Specified by:
rollbackTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be rolled back.
-