当前位置: 首页>>代码示例>>Java>>正文


Java TransactionTemplate.setTimeout方法代码示例

本文整理汇总了Java中org.springframework.transaction.support.TransactionTemplate.setTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionTemplate.setTimeout方法的具体用法?Java TransactionTemplate.setTimeout怎么用?Java TransactionTemplate.setTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.transaction.support.TransactionTemplate的用法示例。


在下文中一共展示了TransactionTemplate.setTimeout方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jtaTransactionManagerWithRollbackAndSynchronizationNever

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void jtaTransactionManagerWithRollbackAndSynchronizationNever() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	ptm.setTransactionSynchronizationName("SYNCHRONIZATION_NEVER");
	tt.setTimeout(10);
	ptm.afterPropertiesSet();

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setTransactionTimeout(10);
	verify(ut).begin();
	verify(ut, atLeastOnce()).getStatus();
	verify(ut).rollback();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:JtaTransactionManagerTests.java

示例2: jtaTransactionManagerWithRollback

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void jtaTransactionManagerWithRollback() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	tt.setTimeout(10);
	tt.setName("txName");

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertNull(TransactionSynchronizationManager.getCurrentTransactionName());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			assertEquals("txName", TransactionSynchronizationManager.getCurrentTransactionName());
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertNull(TransactionSynchronizationManager.getCurrentTransactionName());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	verify(ut).setTransactionTimeout(10);
	verify(ut).begin();
	verify(ut).rollback();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:35,代码来源:JtaTransactionManagerTests.java

示例3: jtaTransactionManagerWithRollbackAndSynchronizationOnActual

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void jtaTransactionManagerWithRollbackAndSynchronizationOnActual() throws Exception {
	UserTransaction ut = mock(UserTransaction.class);
	given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE);
	final TransactionSynchronization synch = mock(TransactionSynchronization.class);

	JtaTransactionManager ptm = newJtaTransactionManager(ut);
	TransactionTemplate tt = new TransactionTemplate(ptm);
	ptm.setTransactionSynchronization(JtaTransactionManager.SYNCHRONIZATION_ON_ACTUAL_TRANSACTION);
	tt.setTimeout(10);
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			TransactionSynchronizationManager.registerSynchronization(synch);
			status.setRollbackOnly();
		}
	});
	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());

	verify(ut).setTransactionTimeout(10);
	verify(ut).begin();
	verify(ut).rollback();
	verify(synch).beforeCompletion();
	verify(synch).afterCompletion(TransactionSynchronization.STATUS_ROLLED_BACK);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:JtaTransactionManagerTests.java

示例4: testTransactionCommit

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommit() throws Exception {
	final DataSource ds = mock(DataSource.class);
	Connection con = mock(Connection.class);
	final SessionFactory sf = mock(SessionFactory.class);
	final Session session = mock(Session.class);
	Transaction tx = mock(Transaction.class);
	Query query = mock(Query.class);

	final List list = new ArrayList();
	list.add("test");
	given(con.getTransactionIsolation()).willReturn(Connection.TRANSACTION_READ_COMMITTED);
	given(sf.openSession()).willReturn(session);
	given(session.getTransaction()).willReturn(tx);
	given(session.connection()).willReturn(con);
	given(session.isOpen()).willReturn(true);
	given(session.createQuery("some query string")).willReturn(query);
	given(query.list()).willReturn(list);
	given(session.isConnected()).willReturn(true);

	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean() {
		@Override
		protected SessionFactory newSessionFactory(Configuration config) throws HibernateException {
			return sf;
		}
	};
	lsfb.afterPropertiesSet();
	final SessionFactory sfProxy = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setJdbcExceptionTranslator(new SQLStateSQLExceptionTranslator());
	tm.setSessionFactory(sfProxy);
	tm.setDataSource(ds);
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sfProxy));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	Object result = tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sfProxy));
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			HibernateTemplate ht = new HibernateTemplate(sfProxy);
			return ht.find("some query string");
		}
	});
	assertTrue("Correct result list", result == list);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sfProxy));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	verify(con).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
	verify(con).setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
	verify(tx).setTimeout(10);
	verify(tx).begin();
	verify(tx).commit();
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:65,代码来源:HibernateTransactionManagerTests.java

示例5: testTransactionCommitWithEarlyFlush

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithEarlyFlush() throws Exception {
	final DataSource ds = mock(DataSource.class);
	Connection con = mock(Connection.class);
	final SessionFactory sf = mock(SessionFactory.class);
	final Session session = mock(Session.class);
	Transaction tx = mock(Transaction.class);
	Query query = mock(Query.class);

	final List list = new ArrayList();
	list.add("test");
	given(con.getTransactionIsolation()).willReturn(Connection.TRANSACTION_READ_COMMITTED);
	given(sf.openSession()).willReturn(session);
	given(session.getTransaction()).willReturn(tx);
	given(session.connection()).willReturn(con);
	given(session.isOpen()).willReturn(true);
	given(session.createQuery("some query string")).willReturn(query);
	given(query.list()).willReturn(list);
	given(session.getFlushMode()).willReturn(FlushMode.AUTO);
	given(session.isConnected()).willReturn(true);

	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean() {
		@Override
		protected SessionFactory newSessionFactory(Configuration config) throws HibernateException {
			return sf;
		}
	};
	lsfb.afterPropertiesSet();
	final SessionFactory sfProxy = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setJdbcExceptionTranslator(new SQLStateSQLExceptionTranslator());
	tm.setSessionFactory(sfProxy);
	tm.setDataSource(ds);
	tm.setEarlyFlushBeforeCommit(true);
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sfProxy));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	Object result = tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sfProxy));
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
			assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			HibernateTemplate ht = new HibernateTemplate(sfProxy);
			return ht.find("some query string");
		}
	});
	assertTrue("Correct result list", result == list);

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sfProxy));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
	InOrder ordered = inOrder(con);
	ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
	ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
	verify(tx).setTimeout(10);
	verify(tx).begin();
	verify(session).flush();
	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(tx).commit();
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:69,代码来源:HibernateTransactionManagerTests.java

示例6: testTransactionCommitWithNonExistingDatabase

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithNonExistingDatabase() throws Exception {
	final DriverManagerDataSource ds = new DriverManagerDataSource();
	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
	lsfb.setDataSource(ds);
	Properties props = new Properties();
	props.setProperty("hibernate.dialect", HSQLDialect.class.getName());
	props.setProperty("hibernate.cache.provider_class", NoCacheProvider.class.getName());
	lsfb.setHibernateProperties(props);
	lsfb.afterPropertiesSet();
	final SessionFactory sf = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setSessionFactory(sf);
	tm.afterPropertiesSet();
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	try {
		tt.execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
				assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
				HibernateTemplate ht = new HibernateTemplate(sf);
				return ht.find("from java.lang.Object");
			}
		});
		fail("Should have thrown CannotCreateTransactionException");
	}
	catch (CannotCreateTransactionException ex) {
		// expected
	}

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:HibernateTransactionManagerTests.java

示例7: testTransactionCommitWithPreBoundSessionAndNonExistingDatabase

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithPreBoundSessionAndNonExistingDatabase() throws Exception {
	final DriverManagerDataSource ds = new DriverManagerDataSource();
	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
	lsfb.setDataSource(ds);
	Properties props = new Properties();
	props.setProperty("hibernate.dialect", HSQLDialect.class.getName());
	props.setProperty("hibernate.cache.provider_class", NoCacheProvider.class.getName());
	lsfb.setHibernateProperties(props);
	lsfb.afterPropertiesSet();
	final SessionFactory sf = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setSessionFactory(sf);
	tm.afterPropertiesSet();
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	Session session = sf.openSession();
	TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
	try {
		tt.execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
				assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
				HibernateTemplate ht = new HibernateTemplate(sf);
				return ht.find("from java.lang.Object");
			}
		});
		fail("Should have thrown CannotCreateTransactionException");
	}
	catch (CannotCreateTransactionException ex) {
		// expected
		SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
		assertFalse(holder.isSynchronizedWithTransaction());
	}
	finally {
		TransactionSynchronizationManager.unbindResource(sf);
		session.close();
	}

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:51,代码来源:HibernateTransactionManagerTests.java

示例8: testTransactionCommitWithNonExistingDatabaseAndLazyConnection

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithNonExistingDatabaseAndLazyConnection() throws Exception {
	DriverManagerDataSource dsTarget = new DriverManagerDataSource();
	final LazyConnectionDataSourceProxy ds = new LazyConnectionDataSourceProxy();
	ds.setTargetDataSource(dsTarget);
	ds.setDefaultAutoCommit(true);
	ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
	//ds.setDefaultTransactionIsolationName("TRANSACTION_READ_COMMITTED");

	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
	lsfb.setDataSource(ds);
	Properties props = new Properties();
	props.setProperty("hibernate.dialect", HSQLDialect.class.getName());
	props.setProperty("hibernate.cache.provider_class", NoCacheProvider.class.getName());
	props.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
	lsfb.setHibernateProperties(props);
	lsfb.afterPropertiesSet();
	final SessionFactory sf = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setSessionFactory(sf);
	tm.afterPropertiesSet();
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
			HibernateTemplate ht = new HibernateTemplate(sf);
			return ht.find("from java.lang.Object");
		}
	});

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:44,代码来源:HibernateTransactionManagerTests.java

示例9: testTransactionCommitWithNonExistingDatabase

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithNonExistingDatabase() throws Exception {
	final DriverManagerDataSource ds = new DriverManagerDataSource();
	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
	lsfb.setDataSource(ds);
	Properties props = new Properties();
	props.setProperty("hibernate.dialect", HSQLDialect.class.getName());
	lsfb.setHibernateProperties(props);
	lsfb.afterPropertiesSet();
	final SessionFactory sf = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setSessionFactory(sf);
	tm.afterPropertiesSet();
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	try {
		tt.execute(new TransactionCallback() {
			@Override
			public Object doInTransaction(TransactionStatus status) {
				assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
				assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
				Session session = ((SessionHolder) TransactionSynchronizationManager.getResource(sf)).getSession();
				return session.createQuery("from java.lang.Object").list();
			}
		});
		fail("Should have thrown CannotCreateTransactionException");
	}
	catch (CannotCreateTransactionException ex) {
		// expected
	}

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:42,代码来源:HibernateTransactionManagerTests.java

示例10: testTransactionCommitWithNonExistingDatabaseAndLazyConnection

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionCommitWithNonExistingDatabaseAndLazyConnection() throws Exception {
	DriverManagerDataSource dsTarget = new DriverManagerDataSource();
	final LazyConnectionDataSourceProxy ds = new LazyConnectionDataSourceProxy();
	ds.setTargetDataSource(dsTarget);
	ds.setDefaultAutoCommit(true);
	ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
	//ds.setDefaultTransactionIsolationName("TRANSACTION_READ_COMMITTED");

	LocalSessionFactoryBean lsfb = new LocalSessionFactoryBean();
	lsfb.setDataSource(ds);
	Properties props = new Properties();
	props.setProperty("hibernate.dialect", HSQLDialect.class.getName());
	props.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
	lsfb.setHibernateProperties(props);
	lsfb.afterPropertiesSet();
	final SessionFactory sf = lsfb.getObject();

	HibernateTransactionManager tm = new HibernateTransactionManager();
	tm.setSessionFactory(sf);
	tm.afterPropertiesSet();
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setTimeout(10);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

	tt.execute(new TransactionCallback() {
		@Override
		public Object doInTransaction(TransactionStatus status) {
			assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
			assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(ds));
			Session session = ((SessionHolder) TransactionSynchronizationManager.getResource(sf)).getSession();
			return session.createQuery("from java.lang.Object").list();
		}
	});

	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:43,代码来源:HibernateTransactionManagerTests.java


注:本文中的org.springframework.transaction.support.TransactionTemplate.setTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。