org.springframework.transaction.annotation.Isolation.value()方法的使用及代码示例

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

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

Isolation.value介绍

暂无

代码示例

代码示例来源: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: 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: jkazama/sample-boot-micro

/** トランザクション分離レベルを設定します。 */
public TxTemplate isolation(Isolation isolation) {
  this.tmpl.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: 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: org.springframework.batch.core/org.motechproject.org.springframework.batch.core

/**
 * 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.batch/org.springframework.batch.core

/**
 * 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.batch/spring-batch-core

/**
 * 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: apache/servicemix-bundles

/**
 * 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: spring-projects/spring-integration-java-dsl

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

相关文章

Isolation类方法