本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
});
}
示例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);
}
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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();
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}