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


Java TransactionTemplate.setReadOnly方法代码示例

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


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

示例1: afterPropertiesSet

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
    // Our transaction template will be read-only
    readonlyTransactionTemplate = new TransactionTemplate(transactionManager);
    readonlyTransactionTemplate.setReadOnly(true);

    cachedWriters = new HashMap<Class<?>, IndexWriter>();

    statusFile = new File(indexHandler.getIndexRoot(), "status");
    status = new Properties();
    try {
        status.load(new FileReader(statusFile));
        long time = Long.parseLong(status.getProperty(LAST_OPERATION_TIME));
        lastOperationTime = new GregorianCalendar();
        lastOperationTime.setTimeInMillis(time);
        lastOperationId = Long.parseLong(status.getProperty(LAST_OPERATION_ID));
    } catch (Exception e) {
        // Ok, ignore. We'll start with empty properties
        lastOperationTime = null;
        lastOperationId = null;
    }

    // Start the thread
    thread = new Thread(this, "IndexOperationRunner");
    thread.start();
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:27,代码来源:IndexOperationRunner.java

示例2: testTransactionWithIsolationAndReadOnly

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Test
public void testTransactionWithIsolationAndReadOnly() throws Exception {
	given(con.getTransactionIsolation()).willReturn(Connection.TRANSACTION_READ_COMMITTED);
	given(con.getAutoCommit()).willReturn(true);

	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
	tt.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
	tt.setReadOnly(true);
	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	tt.execute(new TransactionCallbackWithoutResult() {
		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			// something transactional
		}
	});

	assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
	InOrder ordered = inOrder(con);
	ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
	ordered.verify(con).setAutoCommit(false);
	ordered.verify(con).commit();
	ordered.verify(con).setAutoCommit(true);
	ordered.verify(con).setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
	verify(con).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:DataSourceTransactionManagerTests.java

示例3: setTransactionManager

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
public final void setTransactionManager(PlatformTransactionManager transactionManager) {
    this.transactionManager = transactionManager;

    transactionTemplate = new TransactionTemplate(transactionManager);
    transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);

    transactionTemplateReadOnly = new TransactionTemplate(transactionManager);
    transactionTemplateReadOnly.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    transactionTemplateReadOnly.setReadOnly(true);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:JdbcAggregationRepository.java

示例4: testTransactionCommitWithReadOnly

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

	final List list = new ArrayList();
	list.add("test");
	given(sf.openSession()).willReturn(session);
	given(session.beginTransaction()).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);
	given(con.isReadOnly()).willReturn(true);

	HibernateTransactionManager tm = new HibernateTransactionManager(sf);
	TransactionTemplate tt = new TransactionTemplate(tm);
	tt.setReadOnly(true);
	assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
	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(sf));
			assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			HibernateTemplate ht = new HibernateTemplate(sf);
			return ht.find("some query string");
		}
	});
	assertTrue("Correct result list", result == list);

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

	verify(session).setFlushMode(FlushMode.MANUAL);
	verify(con).setReadOnly(true);
	verify(tx).commit();
	verify(con).setReadOnly(false);
	verify(session).close();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:47,代码来源:HibernateTransactionManagerTests.java

示例5: setTransactionManager

import org.springframework.transaction.support.TransactionTemplate; //导入方法依赖的package包/类
@Inject
public void setTransactionManager(final PlatformTransactionManager transactionManager) {
    transactionTemplate = new TransactionTemplate(transactionManager);
    transactionTemplate.setReadOnly(true);
}
 
开发者ID:mateli,项目名称:OpenCyclos,代码行数:6,代码来源:JspTransactionFilter.java


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