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.EntityManagerFactory
HoldsEntityManagerFactory
.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 TypeMethodDescriptionvoid
Commits specified transaction.jakarta.persistence.EntityManagerFactory
get()
ReturnsEntityManagerFactory
.jakarta.persistence.EntityManager
ReturnsEntityManager
created using factory.getTransaction
(jakarta.persistence.EntityManager em) Returns started transaction.void
returnEntityManager
(jakarta.persistence.EntityManager em) ClosesEntityManager
.void
Rolls 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
-Properties
for provider configuration.
-
EMFProviderLMT
Creates new EMF provider with specified persistence unit name.- Parameters:
persistenceUnitName
-String
name of persistence unit.
-
-
Method Details
-
get
public jakarta.persistence.EntityManagerFactory get()ReturnsEntityManagerFactory
.- Specified by:
get
in interfaceEMFProviderInterface
- Returns:
EntityManagerFactory
for locally managed transactions.
-
getEntityManager
public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceExceptionReturnsEntityManager
created using factory.- Specified by:
getEntityManager
in interfaceEMFProviderInterface
- Returns:
EntityManager
for persistence operations.- Throws:
jakarta.persistence.PersistenceException
- if unable to acquireEntityManager
.
-
returnEntityManager
public void returnEntityManager(jakarta.persistence.EntityManager em) ClosesEntityManager
.- Specified by:
returnEntityManager
in interfaceEMFProviderInterface
- Parameters:
em
-EntityManager
which should be closed.
-
getTransaction
Returns started transaction.Creates transaction with
em.getTransaction ()
and starts it.- Specified by:
getTransaction
in interfaceEMFProviderInterface
- 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
Commits specified transaction. Issuestx.commit ()
.- Specified by:
commitTransaction
in interfaceEMFProviderInterface
- Parameters:
tx
-Object
transaction to be commited.- Throws:
Exception
- occured while committing transaction.
-
rollbackTransaction
Rolls back specified transaction. Issuestx.rollback ()
.- Specified by:
rollbackTransaction
in interfaceEMFProviderInterface
- Parameters:
tx
-Object
transaction to be rolled back.
-