public class EMFProviderLMT implements EMFProviderInterface
EntityManagerFactory
is created in static initialization block and used to create EntityManager
objects.Modifier and Type | Field and Description |
---|---|
protected javax.persistence.EntityManagerFactory | emf Holds EntityManagerFactory . |
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 |
---|
EMFProviderLMT() Creates new EMF provider. |
EMFProviderLMT(java.util.Properties config) Creates new EMF provider. |
EMFProviderLMT(java.lang.String persistenceUnitName) Creates new EMF provider with specified persistence unit name. |
Modifier and Type | Method and Description |
---|---|
void | commitTransaction(java.lang.Object tx) Commits specified transaction. |
javax.persistence.EntityManagerFactory | get() Returns EntityManagerFactory . |
javax.persistence.EntityManager | getEntityManager() Returns EntityManager created using factory. |
java.lang.Object | getTransaction(javax.persistence.EntityManager em) Returns started transaction. Creates transaction with em.getTransaction () and starts it. |
void | returnEntityManager(javax.persistence.EntityManager em) Closes EntityManager . |
void | rollbackTransaction(java.lang.Object tx) Rolls back specified transaction. |
public EMFProviderLMT()
public EMFProviderLMT(java.util.Properties config)
config
- Properties
for provider configuration.public EMFProviderLMT(java.lang.String persistenceUnitName)
persistenceUnitName
- String
name of persistence unit.public javax.persistence.EntityManagerFactory get()
EntityManagerFactory
.get
in interface EMFProviderInterface
EntityManagerFactory
for locally managed transactions.public javax.persistence.EntityManager getEntityManager() throws javax.persistence.PersistenceException
EntityManager
created using factory.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
em.getTransaction ()
and starts it.getTransaction
in interface EMFProviderInterface
em
- EntityManager
needed if joining to existing transaction or starting transaction locally.Object
Already started 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 ()
.commitTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be commited.java.lang.Exception
- occured while committing transaction.public void rollbackTransaction(java.lang.Object tx)
tx.rollback ()
.rollbackTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be rolled back.