當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultTransactionDefinition.setReadOnly方法代碼示例

本文整理匯總了Java中org.springframework.transaction.support.DefaultTransactionDefinition.setReadOnly方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTransactionDefinition.setReadOnly方法的具體用法?Java DefaultTransactionDefinition.setReadOnly怎麽用?Java DefaultTransactionDefinition.setReadOnly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.transaction.support.DefaultTransactionDefinition的用法示例。


在下文中一共展示了DefaultTransactionDefinition.setReadOnly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: TransactionImpl

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public TransactionImpl(PlatformTransactionManager transactionManager, PersistenceImpl persistence, boolean join,
                       @Nullable TransactionParams params, String storeName) {
    this.tm = transactionManager;
    this.persistence = persistence;
    this.storeName = storeName;

    td = new DefaultTransactionDefinition();
    if (join)
        td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    else
        td.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    if (params != null) {
        if (params.getTimeout() != 0)
            td.setTimeout(params.getTimeout());
        if (params.isReadOnly())
            td.setReadOnly(true);
    }

    ts = tm.getTransaction(td);

    persistence.registerSynchronizations(storeName);
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:24,代碼來源:TransactionImpl.java

示例2: flush

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public void flush(StatsUsageType statsUsageType) {
	if (!disabled){
		statsUsageDao.flushAndClear();
		StatsUsage statsUsage = statsUsageDao.getByUsageType(statsUsageType);
		if (statsUsage==null){
			statsUsage= initCounter(statsUsageType);
		}
		TransactionStatus txStatus = null;
		DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();
		txDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
		txDefinition.setReadOnly(false);

		txStatus = transactionManager.getTransaction(txDefinition);
		statsUsage.setUsage(counterMap.get(statsUsageType.toString()));
		statsUsageDao.save(statsUsage);
		transactionManager.commit(txStatus);
	}
}
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:19,代碼來源:StatsUsageServiceImpl.java

示例3: query

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Override
public PageSet query(String databaseName, final String sql, final Map<String, ?> paramMap, final Consumer consumer) {

	final DataSource dataSource = dataSourceDef.getDataSource(databaseName);
	PlatformTransactionManager txMgr = new DataSourceTransactionManager(dataSource);
	DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
	txDef.setReadOnly(true);

	TransactionOperations txOp = new TransactionTemplate(txMgr, txDef);
	return txOp.execute(new TransactionCallback<PageSet>() {
		@Override
		public PageSet doInTransaction(TransactionStatus status) {
			try {

				long numOfItems = extractor.extract(dataSource, sql, paramMap, consumer, new NoneLimiter());
				PageSet pageSet = paginator.paginate(0L, numOfItems, (numOfItems <= 0L ? 1L : numOfItems));

				return pageSet;
			} catch (IOException ex) {
				throw new IllegalStateException(ex);
			}
		}
	});
}
 
開發者ID:agwlvssainokuni,項目名稱:sqlapp,代碼行數:25,代碼來源:ExecQueryServiceImpl.java

示例4: execute

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Override
public <T> T execute(final Function<Session, T> callback) {
    try {
        DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
        definition.setIsolationLevel(getTransactionIsolation().getTransactionIsolation());
        int timeout = getTimeout();
        if (timeout  >= 0) {
            definition.setTimeout(timeout);
        }
        definition.setReadOnly(isReadOnly());
        return connectionProvider.connection(false, connection -> {
            Session session =  newSession(connection);
            TransactionTemplate tt = new TransactionTemplate(platformTransactionManager, definition);
            return tt.execute(transactionStatus -> callback.apply(session));
        });
    } catch (final Exception e) {
        throw JdbcTemplateExceptionTranslator.doTranslate(e);
    }
}
 
開發者ID:ufoscout,項目名稱:jporm,代碼行數:20,代碼來源:JdbcTemplateTransaction.java

示例5: setTransactionManagerReadonly

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
/**
 * Zet de transaction manager.
 *
 * @param transactionManager transaction manager
 */
@Inject
public final void setTransactionManagerReadonly(final PlatformTransactionManager transactionManager) {
    final DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition();
    transactionDefinition.setReadOnly(true);
    transactionTemplate = new TransactionTemplate(transactionManager, transactionDefinition);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:AbstractBaseReadonlyController.java

示例6: doTestNewTransactionSynchronization

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void doTestNewTransactionSynchronization(int propagationBehavior, final int synchMode) {
	MockUOWManager manager = new MockUOWManager();
	WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
	ptm.setTransactionSynchronization(synchMode);
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setPropagationBehavior(propagationBehavior);
	definition.setReadOnly(true);

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
		@Override
		public String doInTransaction(TransactionStatus status) {
			if (synchMode == WebSphereUowTransactionManager.SYNCHRONIZATION_ALWAYS) {
				assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
				assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
				assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			}
			else {
				assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
				assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
				assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			}
			return "result";
		}
	}));

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals(0, manager.getUOWTimeout());
	assertEquals(UOWManager.UOW_TYPE_LOCAL_TRANSACTION, manager.getUOWType());
	assertFalse(manager.getJoined());
	assertFalse(manager.getRollbackOnly());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:39,代碼來源:WebSphereUowTransactionManagerTests.java

示例7: doTestNewTransactionWithCommit

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void doTestNewTransactionWithCommit(int propagationBehavior, final int synchMode) {
	MockUOWManager manager = new MockUOWManager();
	WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
	ptm.setTransactionSynchronization(synchMode);
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setPropagationBehavior(propagationBehavior);
	definition.setReadOnly(true);

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
		@Override
		public String doInTransaction(TransactionStatus status) {
			if (synchMode != WebSphereUowTransactionManager.SYNCHRONIZATION_NEVER) {
				assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
				assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
				assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			}
			else {
				assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
				assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
				assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			}
			return "result";
		}
	}));

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals(0, manager.getUOWTimeout());
	assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
	assertFalse(manager.getJoined());
	assertFalse(manager.getRollbackOnly());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:39,代碼來源:WebSphereUowTransactionManagerTests.java

示例8: newTransactionWithCommitAndTimeout

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
@Test
public void newTransactionWithCommitAndTimeout() {
	MockUOWManager manager = new MockUOWManager();
	WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager(manager);
	DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	definition.setTimeout(10);
	definition.setReadOnly(true);

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {
		@Override
		public String doInTransaction(TransactionStatus status) {
			assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
			assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
			assertTrue(TransactionSynchronizationManager.isCurrentTransactionReadOnly());
			return "result";
		}
	}));

	assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
	assertFalse(TransactionSynchronizationManager.isActualTransactionActive());
	assertFalse(TransactionSynchronizationManager.isCurrentTransactionReadOnly());

	assertEquals(10, manager.getUOWTimeout());
	assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
	assertFalse(manager.getJoined());
	assertFalse(manager.getRollbackOnly());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:32,代碼來源:WebSphereUowTransactionManagerTests.java

示例9: createTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
public static TransactionStatus createTransaction(String name, int propagationBehavior, int isolationLevel, PlatformTransactionManager transactionManager, boolean isReadOnly) {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName(name);
    def.setReadOnly(isReadOnly);
    def.setPropagationBehavior(propagationBehavior);
    def.setIsolationLevel(isolationLevel);
    return transactionManager.getTransaction(def);
}
 
開發者ID:passion1014,項目名稱:metaworks_framework,代碼行數:9,代碼來源:TransactionUtils.java

示例10: AutoAssignChecker

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
/**
 * Instantiates a new auto assign checker
 *
 * @param targetFilterQueryManagement
 *            to get all target filter queries
 * @param targetManagement
 *            to get targets
 * @param deploymentManagement
 *            to assign distribution sets to targets
 * @param transactionManager
 *            to run transactions
 */
public AutoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement,
        final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
        final PlatformTransactionManager transactionManager) {
    this.targetFilterQueryManagement = targetFilterQueryManagement;
    this.targetManagement = targetManagement;
    this.deploymentManagement = deploymentManagement;

    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("autoAssignDSToTargets");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    def.setReadOnly(false);
    def.setIsolationLevel(Isolation.READ_COMMITTED.value());
    transactionTemplate = new TransactionTemplate(transactionManager, def);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:27,代碼來源:AutoAssignChecker.java

示例11: startScheduledActionsByRolloutGroupParentInNewTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private long startScheduledActionsByRolloutGroupParentInNewTransaction(final Long rolloutId,
        final Long distributionSetId, final Long rolloutGroupParentId, final int limit) {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("startScheduledActions-" + rolloutId);
    def.setReadOnly(false);
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    return new TransactionTemplate(txManager, def).execute(status -> {
        final Page<Action> rolloutGroupActions = findActionsByRolloutAndRolloutGroupParent(rolloutId,
                rolloutGroupParentId, limit);

        if (rolloutGroupActions.getContent().isEmpty()) {
            return 0L;
        }

        final String tenant = rolloutGroupActions.getContent().get(0).getTenant();

        final List<Action> targetAssignments = rolloutGroupActions.getContent().stream()
                .map(action -> (JpaAction) action).map(this::closeActionIfSetWasAlreadyAssigned)
                .filter(Objects::nonNull).map(this::startScheduledActionIfNoCancelationHasToBeHandledFirst)
                .filter(Objects::nonNull).collect(Collectors.toList());

        if (!CollectionUtils.isEmpty(targetAssignments)) {
            afterCommit.afterCommit(() -> eventPublisher.publishEvent(new TargetAssignDistributionSetEvent(tenant,
                    distributionSetId, targetAssignments, applicationContext.getId())));
        }

        return rolloutGroupActions.getTotalElements();
    });
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:30,代碼來源:JpaDeploymentManagement.java

示例12: runInNewTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private <T> T runInNewTransaction(final String transactionName, final TransactionCallback<T> action) {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName(transactionName);
    def.setReadOnly(false);
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    return new TransactionTemplate(txManager, def).execute(action);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:8,代碼來源:JpaControllerManagement.java

示例13: runInNewTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
protected Long runInNewTransaction(final String transactionName, final TransactionCallback<Long> action) {
    final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName(transactionName);
    def.setReadOnly(false);
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
    return new TransactionTemplate(txManager, def).execute(action);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:8,代碼來源:AbstractRolloutManagement.java

示例14: startTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void startTransaction() {
txDefinition = new DefaultTransactionDefinition();
txDefinition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
txDefinition.setReadOnly(false);

txStatus = transactionManager.getTransaction(txDefinition);
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:8,代碼來源:EditZipCodeAction.java

示例15: startTransaction

import org.springframework.transaction.support.DefaultTransactionDefinition; //導入方法依賴的package包/類
private void startTransaction() {
	txDefinition = new DefaultTransactionDefinition();
	txDefinition
			.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
	txDefinition.setReadOnly(false);

	txStatus = transactionManager.getTransaction(txDefinition);
}
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:9,代碼來源:EditFeatureAction.java


注:本文中的org.springframework.transaction.support.DefaultTransactionDefinition.setReadOnly方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。