org.springframework.orm.jpa.JpaTransactionManager Java Examples

The following examples show how to use org.springframework.orm.jpa.JpaTransactionManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShardingTransactionProxyConfiguration.java    From opensharding-spi-impl with Apache License 2.0 6 votes vote down vote up
/**
 * Build hibernate transaction manager.
 *
 * @param transactionManagerCustomizers transaction manager customizers
 * @return jpa transaction manager
 */
@Bean
@ConditionalOnMissingBean(PlatformTransactionManager.class)
@ConditionalOnClass(value = LocalContainerEntityManagerFactoryBean.class, name = "javax.persistence.EntityManager")
public PlatformTransactionManager jpaTransactionManager(final ObjectProvider<TransactionManagerCustomizers> transactionManagerCustomizers) {
    JpaTransactionManager result = new JpaTransactionManager();
    if (null != transactionManagerCustomizers.getIfAvailable()) {
        transactionManagerCustomizers.getIfAvailable().customize(result);
    }
    return result;
}
 
Example #2
Source File: PersistenceContextTransactionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setup() {
	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(@Nullable String unitName, String requestingBeanName) {
			return factory;
		}
	};
	pabpp.postProcessProperties(null, bean, "bean");

	assertTrue(TransactionSynchronizationManager.getResourceMap().isEmpty());
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
 
Example #3
Source File: PersistenceContextTransactionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: PersistenceContextTransactionTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
    JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
    jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());
    jpaTransactionManager.afterPropertiesSet();
    return jpaTransactionManager;
}
 
Example #6
Source File: DefaultTaskConfigurer.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public PlatformTransactionManager getTransactionManager() {
	if (this.transactionManager == null) {
		if (isDataSourceAvailable()) {
			try {
				Class.forName("javax.persistence.EntityManager");
				if (this.context != null && this.context
						.getBeanNamesForType(EntityManager.class).length > 0) {
					logger.debug(
							"EntityManager was found, using JpaTransactionManager");
					this.transactionManager = new JpaTransactionManager();
				}
			}
			catch (ClassNotFoundException ignore) {
				logger.debug(
						"No EntityManager was found, using DataSourceTransactionManager");
			}
			finally {
				if (this.transactionManager == null) {
					this.transactionManager = new DataSourceTransactionManager(
							this.dataSource);
				}
			}
		}
		else {
			logger.debug(
					"No DataSource was found, using ResourcelessTransactionManager");
			this.transactionManager = new ResourcelessTransactionManager();
		}
	}

	return this.transactionManager;
}
 
Example #7
Source File: UnitTestUtils.java    From statefulj with Apache License 2.0 5 votes vote down vote up
public static void startTransaction(JpaTransactionManager transactionManager) {
	DefaultTransactionDefinition def = new DefaultTransactionDefinition();
	def.setName("SomeTxName");
	def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
	TransactionStatus status = transactionManager.getTransaction(def);
	tl.set(status);
}
 
Example #8
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
    JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
    jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());
    jpaTransactionManager.afterPropertiesSet();
    return jpaTransactionManager;
}
 
Example #9
Source File: PersistenceUserConfiguration.java    From tutorials with MIT License 5 votes vote down vote up
@Primary
@Bean
public PlatformTransactionManager userTransactionManager() {
    final JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(userEntityManager().getObject());
    return transactionManager;
}
 
Example #10
Source File: DatabaseConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() throws SQLException {
    JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
    jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
    jpaTransactionManager.afterPropertiesSet();
    return jpaTransactionManager;
}
 
Example #11
Source File: FileConversionServiceTestConfiguration.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Bean
public PlatformTransactionManager jpaTransactionManager() {

    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
    return transactionManager;
}
 
Example #12
Source File: FileConversionServiceTestConfiguration.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Bean
public PlatformTransactionManager jpaTransactionManager() {

    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
    return transactionManager;
}
 
Example #13
Source File: DaoSpringModuleConfig.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Our Spring JPA transaction manager that will manage the JPA transactions.
 *
 * @return the JPA transaction manager.
 */
@Bean
public JpaTransactionManager herdTransactionManager()
{
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setDataSource(getHerdDataSource());
    transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
    return transactionManager;
}
 
Example #14
Source File: PersistanceConfig.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Transaction manager.
 *
 * @return the platform transaction manager
 */
@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager tm = new JpaTransactionManager();
    tm.setEntityManagerFactory(this.entityManagerFactory().getObject());
    return tm;
}
 
Example #15
Source File: RadmanDbConfiguration.java    From radman with MIT License 5 votes vote down vote up
@Primary
@Bean(name = "txRadman")
PlatformTransactionManager radmanTransactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(radmanEntityManager().getObject());
    return transactionManager;
}
 
Example #16
Source File: DataSourceTransactionConfig.java    From SuperBoot with MIT License 4 votes vote down vote up
/**
 * 配置事物管理器
 *
 * @return
 */
@Bean(name = "dataTransactionManager")
@Primary
public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
    return new JpaTransactionManager(entityManagerFactory(builder));
}
 
Example #17
Source File: PersistenceJNDIConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) {
    return new JpaTransactionManager(emf);
}
 
Example #18
Source File: TestJpaConfiguration.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean(name = "transactionManager")
public PlatformTransactionManager getTransactionManager() {
    final PlatformTransactionManager manager = new JpaTransactionManager(getEntityManagerFactory());
    return manager;
}
 
Example #19
Source File: PersistenceProductConfiguration.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public PlatformTransactionManager productTransactionManager() {
    final JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(productEntityManager().getObject());
    return transactionManager;
}
 
Example #20
Source File: WorkerNodeServiceTest.java    From score with Apache License 2.0 4 votes vote down vote up
@Bean
PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
    return new JpaTransactionManager(emf);
}
 
Example #21
Source File: AppConfig.java    From Spring-Framework-Essentials with MIT License 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
    return new JpaTransactionManager(emf);
}
 
Example #22
Source File: TestConfiguration.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager getTransactionManager(LocalContainerEntityManagerFactoryBean factoryBean) {
    return new JpaTransactionManager(factoryBean.getObject());
}
 
Example #23
Source File: JpaConfig.java    From spring4-sandbox with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {
	return new JpaTransactionManager(entityManagerFactory().getObject());
}
 
Example #24
Source File: EclipseLinkConfig.java    From logging-log4j-audit with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager txManager = new JpaTransactionManager();
    txManager.setEntityManagerFactory(entityManagerFactory());
    return txManager;
}
 
Example #25
Source File: TaskDbConfig.java    From app-engine with Apache License 2.0 4 votes vote down vote up
@Bean
PlatformTransactionManager taskTransactionManager() {
    return new JpaTransactionManager(taskEntityManagerFactory().getObject());
}
 
Example #26
Source File: TestContextConfiguration8.java    From spring-boot-starter-quartz with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager secondTransactionManager(LocalContainerEntityManagerFactoryBean entityManagerFactory) {
	JpaTransactionManager transactionManager = new JpaTransactionManager();
	transactionManager.setEntityManagerFactory(entityManagerFactory.getObject());
	return transactionManager;
}
 
Example #27
Source File: PartitionTemplateWithEmfTest.java    From score with Apache License 2.0 4 votes vote down vote up
@Bean
PlatformTransactionManager transactionManager(EntityManagerFactory emf) throws Exception {
    return new JpaTransactionManager(emf);
}
 
Example #28
Source File: JpaConfig.java    From spring4-sandbox with Apache License 2.0 4 votes vote down vote up
@Bean
public PlatformTransactionManager transactionManager() {
	return new JpaTransactionManager(entityManagerFactory().getObject());
}
 
Example #29
Source File: OrderConfig.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
@Bean
PlatformTransactionManager orderTransactionManager() {
	return new JpaTransactionManager(orderEntityManagerFactory().getObject());
}
 
Example #30
Source File: DatabaseConfiguration.java    From patient-batch-loader with GNU General Public License v3.0 4 votes vote down vote up
@Bean(name = "batchTransactionManager")
public PlatformTransactionManager transactionManager() {
    return new JpaTransactionManager(batchEntityManagerFactory().getObject());
}