public class EMFProviderBMT extends java.lang.Object implements EMFProviderInterface
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.Modifier and Type | Field and Description |
---|---|
java.lang.String | entityManagerFactoryRef Name of the reference to managed entity manager factory. |
java.lang.String | entityManagerRef Name of the reference to container managed entity manager. |
ENTITY_MANAGER, ENTITY_MANAGER_FACTORY, JPA_ENTITY_MANAGER, JPA_ENTITY_MANAGER_FACTORY, JPA_PERSISTENCE_UNIT_NAME, JPA_TRANSACTION, PERSISTENCE_UNIT_NAME, TRANSACTION
Constructor and Description |
---|
EMFProviderBMT() Creates new EMF provider. |
EMFProviderBMT(java.util.Properties config) Creates new EMF provider. |
EMFProviderBMT(java.lang.String entityManagerRef, java.lang.String entityManagerFactoryRef) Creates new EMF provider with specified context reference names. |
Modifier and Type | Method and Description |
---|---|
void | commitTransaction(java.lang.Object tx) Commits specified transaction. |
javax.persistence.EntityManagerFactory | get() Returns EntityManagerFactory found in container's environment context. |
javax.persistence.EntityManager | getEntityManager() Returns EntityManager found in container's environment context. |
java.lang.Object | getTransaction(javax.persistence.EntityManager em) Returns UserTransaction found in container's environment context. |
void | returnEntityManager(javax.persistence.EntityManager em) Does nothing - container will close EntityManager . |
void | rollbackTransaction(java.lang.Object tx) Rolls back specified transaction. |
public java.lang.String entityManagerRef
public java.lang.String entityManagerFactoryRef
public EMFProviderBMT()
EntityManager
and EntityManagerFactory
in container's environment context.public EMFProviderBMT(java.util.Properties config)
EntityManager
and EntityManagerFactory
in container's environment context.config
- Properties
for provider configuration.public EMFProviderBMT(java.lang.String entityManagerRef, java.lang.String entityManagerFactoryRef)
entityManagerRef
- String
name of context reference to entity manager.entityManagerFactoryRef
- String
name of context reference to entity manager factory.public javax.persistence.EntityManagerFactory get()
EntityManagerFactory
found in container's environment context.get
in interface EMFProviderInterface
EntityManagerFactory
can be used to acquire meta-data (for JPA 2.0) or implement "application managed entity manager" pattern.public javax.persistence.EntityManager getEntityManager() throws javax.persistence.PersistenceException
EntityManager
found in container's environment context.getEntityManager
in interface EMFProviderInterface
EntityManager
for persistence operations.javax.persistence.PersistenceException
- if unable to acquire EntityManager
.public void returnEntityManager(javax.persistence.EntityManager em)
EntityManager
.returnEntityManager
in interface EMFProviderInterface
em
- EntityManager
which should be closed.public java.lang.Object getTransaction(javax.persistence.EntityManager em) throws java.lang.Exception
UserTransaction
found in container's environment context.getTransaction
in interface EMFProviderInterface
em
- EntityManager
needed if joining to existing transaction or null.Object
Transaction for persistence operations.javax.persistence.PersistenceException
- if unable to acquire or open transaction.java.lang.Exception
- if unable to acquire or open transaction.public void commitTransaction(java.lang.Object tx) throws java.lang.Exception
tx.commit()
. Throws PersistenceException
if transaction already rolled back.commitTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be committed.java.lang.Exception
- occurred while committing transaction.public void rollbackTransaction(java.lang.Object tx)
tx.rollback()
.rollbackTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be rolled back.