Package com.isomorphic.jpa
Class EMFProviderSpring
java.lang.Object
com.isomorphic.jpa.EMFProviderSpring
- All Implemented Interfaces:
EMFProviderInterface
EMF provider for Spring framework.
Values from jpa.entityManagerFactory and jpa.transaction properties are used to locate EntityManagerFactory and JpaTransactionManager in spring application context. For this implementation to work these declarations should be in spring application context file:
To acquire spring 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>-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected jakarta.persistence.EntityManagerFactoryHoldsEntityManagerFactory.protected org.springframework.orm.jpa.JpaTransactionManagerHoldsJpaTransactionManager.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.EMFProviderSpring(String entityManagerFactory, String transaction) Creates new EMF provider with specified context reference names.EMFProviderSpring(Properties config) Creates new EMF provider. -
Method Summary
Modifier and TypeMethodDescriptionvoidCommits specified transaction.jakarta.persistence.EntityManagerFactoryget()ReturnsEntityManagerFactory.jakarta.persistence.EntityManagerReturnsEntityManagercreated using factory.getTransaction(jakarta.persistence.EntityManager em) Returns started transaction.voidreturnEntityManager(jakarta.persistence.EntityManager em) ClosesEntityManager.voidRolls back specified transaction.
-
Field Details
-
emf
protected jakarta.persistence.EntityManagerFactory emfHoldsEntityManagerFactory. -
txm
protected org.springframework.orm.jpa.JpaTransactionManager txmHoldsJpaTransactionManager.
-
-
Constructor Details
-
EMFProviderSpring
public EMFProviderSpring()Creates new EMF provider. Values from jpa.entityManagerFactory and jpa.transaction properties are used to locateEntityManagerFactoryandJpaTransactionManagerin spring application context. -
EMFProviderSpring
Creates new EMF provider. Values from provided properties entityManagerFactory and transaction are used to locateEntityManagerFactoryandJpaTransactionManagerin spring application context.- Parameters:
config-Propertiesfor provider configuration.
-
EMFProviderSpring
Creates new EMF provider with specified context reference names.- Parameters:
entityManagerFactory-Stringname of context reference to entity manager factory.transaction-Stringname of context reference to transaction manager.
-
-
Method Details
-
get
public jakarta.persistence.EntityManagerFactory get()ReturnsEntityManagerFactory.- Specified by:
getin interfaceEMFProviderInterface- Returns:
EntityManagerFactoryacquired from spring application context.
-
getEntityManager
public jakarta.persistence.EntityManager getEntityManager() throws jakarta.persistence.PersistenceExceptionReturnsEntityManagercreated using factory.- Specified by:
getEntityManagerin interfaceEMFProviderInterface- Returns:
EntityManagerfor persistence operations.- Throws:
jakarta.persistence.PersistenceException- if unable to acquireEntityManager.
-
returnEntityManager
public void returnEntityManager(jakarta.persistence.EntityManager em) ClosesEntityManager.- Specified by:
returnEntityManagerin interfaceEMFProviderInterface- Parameters:
em-EntityManagerwhich should be closed.
-
getTransaction
Returns started transaction.Acquires transaction via
JpaTransactionManager.getTransaction (null).- Specified by:
getTransactionin interfaceEMFProviderInterface- Parameters:
em-EntityManagerneeded if joining to existing transaction or starting transaction locally.- Returns:
ObjectAlready started transaction 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.- Specified by:
commitTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be committed.- Throws:
Exception- occurred while committing transaction.
-
rollbackTransaction
Rolls back specified transaction.- Specified by:
rollbackTransactionin interfaceEMFProviderInterface- Parameters:
tx-Objecttransaction to be rolled back.
-