当前位置: 首页>>代码示例>>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;未经允许,请勿转载。