org.springframework.transaction.jta.UserTransactionAdapter Java Examples

The following examples show how to use org.springframework.transaction.jta.UserTransactionAdapter. 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: ConfigurableJtaPlatform.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, @Nullable UserTransaction ut,
		@Nullable TransactionSynchronizationRegistry tsr) {

	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}
 
Example #2
Source File: ConfigurableJtaPlatform.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, @Nullable UserTransaction ut,
		@Nullable TransactionSynchronizationRegistry tsr) {

	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}
 
Example #3
Source File: JndiJtaTransactionManagerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void doTestJtaTransactionManagerWithDefaultJndiLookups(String tmName, boolean tmFound, boolean defaultUt)
		throws Exception {

	UserTransaction ut = mock(UserTransaction.class);
	TransactionManager tm = mock(TransactionManager.class);
	if (defaultUt) {
		given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}
	else {
		given(tm.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}

	JtaTransactionManager ptm = new JtaTransactionManager();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	if (defaultUt) {
		jndiTemplate.addObject("java:comp/UserTransaction", ut);
	}
	jndiTemplate.addObject(tmName, tm);
	ptm.setJndiTemplate(jndiTemplate);
	ptm.afterPropertiesSet();

	if (tmFound) {
		assertEquals(tm, ptm.getTransactionManager());
	}
	else {
		assertNull(ptm.getTransactionManager());
	}

	if (defaultUt) {
		assertEquals(ut, ptm.getUserTransaction());
	}
	else {
		assertTrue(ptm.getUserTransaction() instanceof UserTransactionAdapter);
		UserTransactionAdapter uta = (UserTransactionAdapter) ptm.getUserTransaction();
		assertEquals(tm, uta.getTransactionManager());
	}

	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			// something transactional
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
		}
	});
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());


	if (defaultUt) {
		verify(ut).begin();
		verify(ut).commit();
	}
	else {
		verify(tm).begin();
		verify(tm).commit();
	}

}
 
Example #4
Source File: JndiJtaTransactionManagerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void doTestJtaTransactionManagerWithDefaultJndiLookups(String tmName, boolean tmFound, boolean defaultUt)
		throws Exception {

	UserTransaction ut = mock(UserTransaction.class);
	TransactionManager tm = mock(TransactionManager.class);
	if (defaultUt) {
		given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}
	else {
		given(tm.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}

	JtaTransactionManager ptm = new JtaTransactionManager();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	if (defaultUt) {
		jndiTemplate.addObject("java:comp/UserTransaction", ut);
	}
	jndiTemplate.addObject(tmName, tm);
	ptm.setJndiTemplate(jndiTemplate);
	ptm.afterPropertiesSet();

	if (tmFound) {
		assertEquals(tm, ptm.getTransactionManager());
	}
	else {
		assertNull(ptm.getTransactionManager());
	}

	if (defaultUt) {
		assertEquals(ut, ptm.getUserTransaction());
	}
	else {
		assertTrue(ptm.getUserTransaction() instanceof UserTransactionAdapter);
		UserTransactionAdapter uta = (UserTransactionAdapter) ptm.getUserTransaction();
		assertEquals(tm, uta.getTransactionManager());
	}

	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			// something transactional
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
		}
	});
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());


	if (defaultUt) {
		verify(ut).begin();
		verify(ut).commit();
	}
	else {
		verify(tm).begin();
		verify(tm).commit();
	}

}
 
Example #5
Source File: JndiJtaTransactionManagerTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void doTestJtaTransactionManagerWithDefaultJndiLookups(String tmName, boolean tmFound, boolean defaultUt)
		throws Exception {

	UserTransaction ut = mock(UserTransaction.class);
	TransactionManager tm = mock(TransactionManager.class);
	if (defaultUt) {
		given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}
	else {
		given(tm.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
	}

	JtaTransactionManager ptm = new JtaTransactionManager();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	if (defaultUt) {
		jndiTemplate.addObject("java:comp/UserTransaction", ut);
	}
	jndiTemplate.addObject(tmName, tm);
	ptm.setJndiTemplate(jndiTemplate);
	ptm.afterPropertiesSet();

	if (tmFound) {
		assertEquals(tm, ptm.getTransactionManager());
	}
	else {
		assertNull(ptm.getTransactionManager());
	}

	if (defaultUt) {
		assertEquals(ut, ptm.getUserTransaction());
	}
	else {
		assertTrue(ptm.getUserTransaction() instanceof UserTransactionAdapter);
		UserTransactionAdapter uta = (UserTransactionAdapter) ptm.getUserTransaction();
		assertEquals(tm, uta.getTransactionManager());
	}

	TransactionTemplate tt = new TransactionTemplate(ptm);
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			// something transactional
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
		}
	});
	assertTrue(!TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());


	if (defaultUt) {
		verify(ut).begin();
		verify(ut).commit();
	}
	else {
		verify(tm).begin();
		verify(tm).commit();
	}

}
 
Example #6
Source File: ConfigurableJtaPlatform.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, UserTransaction ut, TransactionSynchronizationRegistry tsr) {
	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}
 
Example #7
Source File: ConfigurableJtaPlatform.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, UserTransaction ut, TransactionSynchronizationRegistry tsr) {
	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}
 
Example #8
Source File: ConfigurableJtaPlatform.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, UserTransaction ut, TransactionSynchronizationRegistry tsr) {
	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}
 
Example #9
Source File: ConfigurableJtaPlatform.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Create a new ConfigurableJtaPlatform instance with the given
 * JTA TransactionManager and optionally a given UserTransaction.
 * @param tm the JTA TransactionManager reference (required)
 * @param ut the JTA UserTransaction reference (optional)
 * @param tsr the JTA 1.1 TransactionSynchronizationRegistry (optional)
 */
public ConfigurableJtaPlatform(TransactionManager tm, UserTransaction ut, TransactionSynchronizationRegistry tsr) {
	Assert.notNull(tm, "TransactionManager reference must not be null");
	this.transactionManager = tm;
	this.userTransaction = (ut != null ? ut : new UserTransactionAdapter(tm));
	this.transactionSynchronizationRegistry = tsr;
}