org.springframework.transaction.annotation.Isolation类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.8k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中org.springframework.transaction.annotation.Isolation类的一些代码示例,展示了Isolation类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Isolation类的具体详情如下:
包路径:org.springframework.transaction.annotation.Isolation
类名称:Isolation

Isolation介绍

[英]Enumeration that represents transaction isolation levels for use with the Transactional annotation, corresponding to the TransactionDefinition interface.
[中]枚举,表示与TransactionDefinition接口对应的事务性注释一起使用的事务隔离级别。

代码示例

代码示例来源:origin: spring-projects/spring-framework

protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
  RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
  Propagation propagation = attributes.getEnum("propagation");
  rbta.setPropagationBehavior(propagation.value());
  Isolation isolation = attributes.getEnum("isolation");
  rbta.setIsolationLevel(isolation.value());
  rbta.setTimeout(attributes.getNumber("timeout").intValue());
  rbta.setReadOnly(attributes.getBoolean("readOnly"));
  rbta.setQualifier(attributes.getString("value"));
  List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
  for (Class<?> rbRule : attributes.getClassArray("rollbackFor")) {
    rollbackRules.add(new RollbackRuleAttribute(rbRule));
  }
  for (String rbRule : attributes.getStringArray("rollbackForClassName")) {
    rollbackRules.add(new RollbackRuleAttribute(rbRule));
  }
  for (Class<?> rbRule : attributes.getClassArray("noRollbackFor")) {
    rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
  }
  for (String rbRule : attributes.getStringArray("noRollbackForClassName")) {
    rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
  }
  rbta.setRollbackRules(rollbackRules);
  return rbta;
}

代码示例来源:origin: pentaho/pentaho-platform

.get( IDBDatasourceService.DEFAULT_TRANSACTION_ISOLATION ) ) ) {
Isolation isolationLevel =
  Isolation.valueOf( attributes.get( IDBDatasourceService.DEFAULT_TRANSACTION_ISOLATION ) );
 pcf.setDefaultTransactionIsolation( isolationLevel.value() );

代码示例来源:origin: top.wboost/datasource-spring-boot-starter

RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
String propagation = methodEle.propagation().toString();
String isolation = methodEle.isolation().toString();
String timeout = String.valueOf(methodEle.timeout());
String readOnly = String.valueOf(methodEle.readOnly());

代码示例来源:origin: spring-projects/spring-batch

/**
 * Getter for the {@link TransactionAttribute} for subclasses only.
 * @return the transactionAttribute
 */
@SuppressWarnings("serial")
protected TransactionAttribute getTransactionAttribute() {
  DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
  attribute.setPropagationBehavior(propagation.value());
  attribute.setIsolationLevel(isolation.value());
  attribute.setTimeout(transactionTimeout);
  return new DefaultTransactionAttribute(attribute) {
    /**
     * Ignore the default behaviour and rollback on all exceptions that bubble up to the tasklet level. The
     * tasklet has to deal with the rollback rules internally.
     */
    @Override
    public boolean rollbackOn(Throwable ex) {
      return true;
    }
  };
}

代码示例来源:origin: org.springframework/spring-tx

protected TransactionAttribute parseTransactionAnnotation(AnnotationAttributes attributes) {
  RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
  Propagation propagation = attributes.getEnum("propagation");
  rbta.setPropagationBehavior(propagation.value());
  Isolation isolation = attributes.getEnum("isolation");
  rbta.setIsolationLevel(isolation.value());
  rbta.setTimeout(attributes.getNumber("timeout").intValue());
  rbta.setReadOnly(attributes.getBoolean("readOnly"));
  rbta.setQualifier(attributes.getString("value"));
  List<RollbackRuleAttribute> rollbackRules = new ArrayList<>();
  for (Class<?> rbRule : attributes.getClassArray("rollbackFor")) {
    rollbackRules.add(new RollbackRuleAttribute(rbRule));
  }
  for (String rbRule : attributes.getStringArray("rollbackForClassName")) {
    rollbackRules.add(new RollbackRuleAttribute(rbRule));
  }
  for (Class<?> rbRule : attributes.getClassArray("noRollbackFor")) {
    rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
  }
  for (String rbRule : attributes.getStringArray("noRollbackForClassName")) {
    rollbackRules.add(new NoRollbackRuleAttribute(rbRule));
  }
  rbta.setRollbackRules(rollbackRules);
  return rbta;
}

代码示例来源:origin: spring-projects/spring-batch

attribute.setIsolationLevel(isolation.value());

代码示例来源:origin: spring-projects/spring-integration

public TransactionInterceptorBuilder isolation(Isolation isolation) {
  Assert.notNull(isolation, "'isolation' must not be null.");
  this.transactionAttribute.setIsolationLevel(isolation.value());
  return this;
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void test() throws InterruptedException {
  int maxMessages = 10;
  int maxWaitTime = 30000;
  final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
  transactionTemplate.setIsolationLevel(Isolation.READ_COMMITTED.value());
  transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  for (int i = 1; i <= maxMessages; ++i) {
    final String message = "TEST MESSAGE " + i;
    log.info("Sending message: " + message);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
      @Override
      protected void doInTransactionWithoutResult(TransactionStatus status) {
        inputChannel.send(MessageBuilder.withPayload(message).build());
      }
    });
    log.info(String.format("Done sending message %s of %s: %s", i, maxMessages, message));
  }
  log.info("Done sending " + maxMessages + " messages.");
  Assert.assertTrue(String.format("Countdown latch did not count down from " +
      "%s to 0 in %sms.", maxMessages, maxWaitTime), testService.await(maxWaitTime));
  for (int i = 0; i < maxMessages; i++) {
    Message<?> afterTxMessage = this.afterTxChannel.receive(10000);
    assertNotNull(afterTxMessage);
  }
  Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(jdbcChannelMessageStore.getSizeOfIdCache()));
  Assert.assertEquals(Integer.valueOf(maxMessages), Integer.valueOf(testService.getSeenMessages().size()));
  Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(testService.getDuplicateMessagesCount()));
}

代码示例来源:origin: spring-projects/spring-integration

private void verify(TransactionInterceptor interceptor, PlatformTransactionManager txm) throws Exception {
  assertSame(txm, interceptor.getTransactionManager());
  TransactionAttribute atts = interceptor.getTransactionAttributeSource()
      .getTransactionAttribute(TransactionInterceptorBuilderTests.class.getDeclaredMethod("test"), null);
  Assert.assertThat(atts.getPropagationBehavior(), equalTo(Propagation.REQUIRES_NEW.value()));
  Assert.assertThat(atts.getIsolationLevel(), equalTo(Isolation.SERIALIZABLE.value()));
  Assert.assertThat(atts.getTimeout(), equalTo(42));
  assertTrue(atts.isReadOnly());
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testAddAndGet() throws Exception {
  final Message<String> message = MessageBuilder.withPayload("Cartman and Kenny")
      .setHeader("homeTown", "Southpark")
      .build();
  final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
  transactionTemplate.setIsolationLevel(Isolation.READ_COMMITTED.value());
  transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  transactionTemplate.execute(new TransactionCallbackWithoutResult() {
    @Override
    protected void doInTransactionWithoutResult(TransactionStatus status) {
      messageStore.addMessageToGroup(TEST_MESSAGE_GROUP, message);
    }
  });
  Message<?> messageFromDb = messageStore.pollMessageFromGroup(TEST_MESSAGE_GROUP);
  assertNotNull(messageFromDb);
  assertEquals(message.getHeaders().getId(), messageFromDb.getHeaders().getId());
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testAddAndGetCustomStatementSetter() {
  messageStore.setPreparedStatementSetter(getMessageGroupPreparedStatementSetter());
  final Message<String> message = MessageBuilder.withPayload("Cartman and Kenny").build();
  final TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
  transactionTemplate.setIsolationLevel(Isolation.READ_COMMITTED.value());
  transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  transactionTemplate.execute(new TransactionCallbackWithoutResult() {
    @Override
    protected void doInTransactionWithoutResult(TransactionStatus status) {
      messageStore.addMessageToGroup(TEST_MESSAGE_GROUP, message);
    }
  });
  Message<?> messageFromDb = messageStore.pollMessageFromGroup(TEST_MESSAGE_GROUP);
  assertNotNull(messageFromDb);
  assertEquals(message.getHeaders().getId(), messageFromDb.getHeaders().getId());
}

代码示例来源:origin: org.springframework.integration/spring-integration-core

public TransactionInterceptorBuilder isolation(Isolation isolation) {
  Assert.notNull(isolation, "'isolation' must not be null.");
  this.transactionAttribute.setIsolationLevel(isolation.value());
  return this;
}

代码示例来源:origin: org.springframework.integration/spring-integration-java-dsl

public TransactionInterceptorBuilder isolation(Isolation isolation) {
  Assert.notNull(isolation, "'isolation' must not be null.");
  this.transactionAttribute.setIsolationLevel(isolation.value());
  return this;
}

代码示例来源:origin: spring-projects/spring-integration-java-dsl

public TransactionInterceptorBuilder isolation(Isolation isolation) {
  Assert.notNull(isolation, "'isolation' must not be null.");
  this.transactionAttribute.setIsolationLevel(isolation.value());
  return this;
}

代码示例来源:origin: jkazama/sample-boot-micro

/** トランザクション分離レベルを設定します。 */
public TxTemplate isolation(Isolation isolation) {
  this.tmpl.setIsolationLevel(isolation.value());
  return this;
}

代码示例来源:origin: org.springframework.cloud.task.app/spring-cloud-starter-task-composedtaskrunner

/**
 * Using the default transaction attribute for the job will cause the
 * TaskLauncher not to see the latest state in the database but rather
 * what is in its transaction.  By setting isolation to READ_COMMITTED
 * The task launcher can see latest state of the db.  Since the changes
 * to the task execution are done by the tasks.
 * @return DefaultTransactionAttribute with isolation set to READ_COMMITTED.
 */
private TransactionAttribute getTransactionAttribute() {
  DefaultTransactionAttribute defaultTransactionAttribute =
      new DefaultTransactionAttribute();
  defaultTransactionAttribute.setIsolationLevel(
      Isolation.READ_COMMITTED.value());
  return defaultTransactionAttribute;
}

代码示例来源:origin: com.mysema.rdf/rdfbean-guice

private RDFBeanTransaction doBegin(Session session, Transactional transactional) {
  RDFBeanTransaction txn = session.beginTransaction(
      transactional.readOnly(),
      transactional.timeout(),
      transactional.isolation().value());
  session.setFlushMode(FlushMode.COMMIT);
  return txn;
}

代码示例来源:origin: com.butor/butor-web

Preconditions.checkNotNull(transactionManager,"The method is transactionnal, but no transaction manager was detected!");
TransactionTemplate trxTpl = new TransactionTemplate(transactionManager);
trxTpl.setIsolationLevel(trx.isolation().value());
trxTpl.setReadOnly(trx.readOnly());
trxTpl.setPropagationBehavior(trx.propagation().value());

代码示例来源:origin: eclipse/hawkbit

/**
 * 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);
}

代码示例来源:origin: org.eclipse.hawkbit/hawkbit-repository-jpa

/**
 * 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);
}

相关文章

Isolation类方法