public class EMFProviderSpring extends java.lang.Object implements EMFProviderInterface
EntityManagerFactory
and JpaTransactionManager
in spring application context. For this implementation to work these declarations should be in spring application context file:ApplicationContext
: <bean id="springApplicationContextProvider" class="com.isomorphic.spring.SpringApplicationContextProvider" />To acquire
EntityManagerFactory
: <bean id="REFERENCE_TO_ENTITY_MANAGER_FACTORY" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> ... </bean> To acquire JpaTransactionManager
: <bean id="REFERENCE_TO_TRANSACTION_MANAGER" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="REFERENCE_TO_ENTITY_MANAGER_FACTORY" /> </bean>Modifier and Type | Field and Description |
---|---|
protected javax.persistence.EntityManagerFactory | emf Holds EntityManagerFactory . |
protected org.springframework.orm.jpa.JpaTransactionManager | txm Holds JpaTransactionManager . |
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 |
---|
EMFProviderSpring() Creates new EMF provider. |
EMFProviderSpring(java.util.Properties config) Creates new EMF provider. |
EMFProviderSpring(java.lang.String entityManagerFactory, java.lang.String transaction) 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 . |
javax.persistence.EntityManager | getEntityManager() Returns EntityManager created using factory. |
java.lang.Object | getTransaction(javax.persistence.EntityManager em) Returns started transaction. Acquires transaction via JpaTransactionManager.getTransaction (null) . |
void | returnEntityManager(javax.persistence.EntityManager em) Closes EntityManager . |
void | rollbackTransaction(java.lang.Object tx) Rolls back specified transaction. |
protected javax.persistence.EntityManagerFactory emf
EntityManagerFactory
.protected org.springframework.orm.jpa.JpaTransactionManager txm
JpaTransactionManager
.public EMFProviderSpring()
EntityManagerFactory
and JpaTransactionManager
in spring application context.public EMFProviderSpring(java.util.Properties config)
EntityManagerFactory
and JpaTransactionManager
in spring application context.config
- Properties
for provider configuration.public EMFProviderSpring(java.lang.String entityManagerFactory, java.lang.String transaction)
entityManagerFactory
- String
name of context reference to entity manager factory.transaction
- String
name of context reference to transaction manager.public javax.persistence.EntityManagerFactory get()
EntityManagerFactory
.get
in interface EMFProviderInterface
EntityManagerFactory
acquired from spring application context.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
JpaTransactionManager.getTransaction (null)
.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
commitTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be committed.java.lang.Exception
- occurred while committing transaction.public void rollbackTransaction(java.lang.Object tx)
rollbackTransaction
in interface EMFProviderInterface
tx
- Object
transaction to be rolled back.