Package com.isomorphic.jpa
Class EMFProviderBMT
java.lang.Object
com.isomorphic.jpa.EMFProviderBMT
- All Implemented Interfaces:
EMFProviderInterface
EMF provider for Bean Managed Transactions (BMT).
Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locate EntityManager and EntityManagerFactory and transaction in container's environment context. For this implementation to work in /WEB-INF/web.xml should be these declarations:
To acquire EntityManager:
<persistence-context-ref>
<persistence-context-ref-name>REFERENCE_TO_ENTITY_MANAGER</persistence-context-ref-name>
<persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
</persistence-context-ref>
To acquire EntityManagerFactory:
<persistence-unit-ref>
<persistence-unit-ref-name>REFERENCE_TO_ENTITY_MANAGER_FACTORY</persistence-unit-ref-name>
<persistence-unit-name>PERSISTENCE_UNIT_NAME</persistence-unit-name>
</persistence-unit-ref>
getTransaction() will return instance of UserTransaction located in "java:comp/UserTransaction" in JNDI.-
Field Summary
FieldsModifier and TypeFieldDescriptionName of the reference to managed entity manager factory.Name of the reference to container managed entity manager.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.EMFProviderBMT(String entityManagerRef, String entityManagerFactoryRef) Creates new EMF provider with specified context reference names.EMFProviderBMT(Properties config) Creates new EMF provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidCommits specified transaction.jakarta.persistence.EntityManagerFactoryget()ReturnsEntityManagerFactoryfound in container's environment context.jakarta.persistence.EntityManagerReturnsEntityManagerfound in container's environment context.getTransaction(jakarta.persistence.EntityManager em) ReturnsUserTransactionfound in container's environment context.voidreturnEntityManager(jakarta.persistence.EntityManager em) Does nothing - container will closeEntityManager.voidRolls back specified transaction.
-
Field Details
-
entityManagerRef
Name of the reference to container managed entity manager. -
entityManagerFactoryRef
Name of the reference to managed entity manager factory.
-
-
Constructor Details
-
EMFProviderBMT
public EMFProviderBMT()Creates new EMF provider. Values from jpa.entityManager and jpa.entityManagerFactory properties are used to locateEntityManagerandEntityManagerFactoryin container's environment context. -
EMFProviderBMT
Creates new EMF provider. Values from provided properties entityManager and entityManagerFactory are used to locateEntityManagerandEntityManagerFactoryin container's environment context.- Parameters:
config-Propertiesfor provider configuration.
-
EMFProviderBMT
Creates new EMF provider with specified context reference names.- Parameters:
entityManagerRef-Stringname of context reference to entity manager.entityManagerFactoryRef-Stringname of context reference to entity manager factory.
-
-
Method Details
-
get
public jakarta.persistence.EntityManagerFactory get()ReturnsEntityManagerFactoryfound in container's environment context.- Specified by:
getin interfaceEMFProviderInterface- Returns:
EntityManagerFactorycan be used to acquire meta-data (for JPA 2.0) or implement "application managed entity manager" pattern.
-
getEntityManager
public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceExceptionReturnsEntityManagerfound in container's environment context.- Specified by:
getEntityManagerin interfaceEMFProviderInterface- Returns:
EntityManagerfor persistence operations.- Throws:
jakarta.persistence.PersistenceException- if unable to acquireEntityManager.
-
returnEntityManager
public void returnEntityManager(jakarta.persistence.EntityManager em) Does nothing - container will closeEntityManager.- Specified by:
returnEntityManagerin interfaceEMFProviderInterface- Parameters:
em-EntityManagerwhich should be closed.
-
getTransaction
ReturnsUserTransactionfound in container's environment context.- Specified by:
getTransactionin interfaceEMFProviderInterface- Parameters:
em-EntityManagerneeded if joining to existing transaction or null.- Returns:
ObjectTransaction 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(). ThrowsPersistenceExceptionif transaction already rolled back.- Specified by:
commitTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be committed.- Throws:
Exception- occurred while committing transaction.
-
rollbackTransaction
Rolls back specified transaction. Issuestx.rollback().- Specified by:
rollbackTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be rolled back.
-