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 EntityManagerFactory | emf Holds EntityManagerFactory. |
protected 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. |
EntityManagerFactory | get() Returns EntityManagerFactory. |
EntityManager | getEntityManager() Returns EntityManager created using factory. |
java.lang.Object | getTransaction(EntityManager em) Returns started transaction. Acquires transaction via JpaTransactionManager.getTransaction (null). |
void | returnEntityManager(EntityManager em) Closes EntityManager. |
void | rollbackTransaction(java.lang.Object tx) Rolls back specified transaction. |
protected EntityManagerFactory emf
EntityManagerFactory.protected 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 EntityManagerFactory get()
EntityManagerFactory.get in interface EMFProviderInterfaceEntityManagerFactory acquired from spring application context.public EntityManager getEntityManager()
throws PersistenceException EntityManager created using factory.getEntityManager in interface EMFProviderInterfaceEntityManager for persistence operations.PersistenceException - if unable to acquire EntityManager.public void returnEntityManager(EntityManager em)
EntityManager.returnEntityManager in interface EMFProviderInterfaceem - EntityManager which should be closed.public java.lang.Object getTransaction(EntityManager em)
throws java.lang.Exception JpaTransactionManager.getTransaction (null).getTransaction in interface EMFProviderInterfaceem - EntityManager needed if joining to existing transaction or starting transaction locally.Object Already started transaction for persistence operations.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 EMFProviderInterfacetx - Object transaction to be committed.java.lang.Exception - occurred while committing transaction.public void rollbackTransaction(java.lang.Object tx)
rollbackTransaction in interface EMFProviderInterfacetx - Object transaction to be rolled back.