當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。