Search in sources :

Example 1 with JpaTransactionManager

use of org.springframework.orm.jpa.JpaTransactionManager in project cas by apereo.

the class GoogleAuthenticatorJpaConfiguration method transactionManagerGoogleAuthenticator.

@Autowired
@Bean
public PlatformTransactionManager transactionManagerGoogleAuthenticator(@Qualifier("googleAuthenticatorEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
Also used : JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 2 with JpaTransactionManager

use of org.springframework.orm.jpa.JpaTransactionManager in project cas by apereo.

the class JpaEventsConfiguration method transactionManagerEvents.

@Autowired
@Bean
public PlatformTransactionManager transactionManagerEvents(@Qualifier("eventsEntityManagerFactory") final EntityManagerFactory emf) {
    final JpaTransactionManager mgmr = new JpaTransactionManager();
    mgmr.setEntityManagerFactory(emf);
    return mgmr;
}
Also used : JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Autowired(org.springframework.beans.factory.annotation.Autowired) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 3 with JpaTransactionManager

use of org.springframework.orm.jpa.JpaTransactionManager in project Activiti by Activiti.

the class DatabaseConfiguration method annotationDrivenTransactionManager.

@Bean(name = "transactionManager")
public PlatformTransactionManager annotationDrivenTransactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory());
    return transactionManager;
}
Also used : JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 4 with JpaTransactionManager

use of org.springframework.orm.jpa.JpaTransactionManager in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850OsgpCoreDbApiPersistenceConfig method iec61850OsgpCoreDbApiTransactionManager.

/**
     * Method for creating the Transaction Manager.
     *
     * @return JpaTransactionManager
     * @throws ClassNotFoundException
     *             when class not found
     */
@Bean
public JpaTransactionManager iec61850OsgpCoreDbApiTransactionManager() throws Iec61850CoreDbApiException {
    final JpaTransactionManager transactionManager = new JpaTransactionManager();
    try {
        transactionManager.setEntityManagerFactory(this.iec61850OsgpCoreDbApiEntityManagerFactory().getObject());
        transactionManager.setTransactionSynchronization(JpaTransactionManager.SYNCHRONIZATION_ALWAYS);
    } catch (final ClassNotFoundException e) {
        final String msg = "Error in creating transaction manager bean";
        LOGGER.error(msg, e);
        throw new Iec61850CoreDbApiException(msg, e);
    }
    return transactionManager;
}
Also used : Iec61850CoreDbApiException(com.alliander.osgp.core.db.api.iec61850.exceptions.Iec61850CoreDbApiException) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 5 with JpaTransactionManager

use of org.springframework.orm.jpa.JpaTransactionManager in project spring-framework by spring-projects.

the class PersistenceContextTransactionTests method setUp.

@Before
public void setUp() throws Exception {
    factory = mock(EntityManagerFactory.class);
    manager = mock(EntityManager.class);
    tx = mock(EntityTransaction.class);
    JpaTransactionManager tm = new JpaTransactionManager(factory);
    tt = new TransactionTemplate(tm);
    given(factory.createEntityManager()).willReturn(manager);
    given(manager.getTransaction()).willReturn(tx);
    given(manager.isOpen()).willReturn(true);
    bean = new EntityManagerHoldingBean();
    @SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {

        @Override
        protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) {
            return factory;
        }
    };
    pabpp.postProcessPropertyValues(null, null, bean, "bean");
    assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
    assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Before(org.junit.Before)

Aggregations

JpaTransactionManager (org.springframework.orm.jpa.JpaTransactionManager)76 Bean (org.springframework.context.annotation.Bean)59 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)57 Autowired (org.springframework.beans.factory.annotation.Autowired)12 EntityManagerFactory (javax.persistence.EntityManagerFactory)8 Primary (org.springframework.context.annotation.Primary)7 Test (org.junit.Test)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)4 EntityManagerHolder (org.springframework.orm.jpa.EntityManagerHolder)4 EntityManager (javax.persistence.EntityManager)3 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)3 Stack (java.util.Stack)2 Test (org.junit.jupiter.api.Test)2 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850CoreDbApiException (com.alliander.osgp.core.db.api.iec61850.exceptions.Iec61850CoreDbApiException)1 AugmentableQueryRepositoryFactoryBean (com.thinkbiganalytics.metadata.jpa.feed.AugmentableQueryRepositoryFactoryBean)1 LoggingDelegateTransactionManager (de.invesdwin.context.persistence.jpa.scanning.transaction.LoggingDelegateTransactionManager)1 EntityManager (jakarta.persistence.EntityManager)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 EntityTransaction (jakarta.persistence.EntityTransaction)1