com.google.cloud.datastore.Datastore.runInTransaction()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(168)

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

Datastore.runInTransaction介绍

[英]Invokes the callback's Datastore.TransactionCallable#run method with a DatastoreReaderWriter that is associated with a new transaction. The transaction will be committed upon successful invocation. Any thrown exception will cause the transaction to rollback and will be propagated as a DatastoreException with the original exception as its root cause.

Example of running in a transaction.

String callableResult = "my_callable_result";}; 
String result = datastore.runInTransaction(callable); 
}

[中]调用回调的数据存储。TransactionCallable#使用与新事务关联的DatastoreReaderWriter运行方法。事务将在成功调用后提交。任何抛出的异常都将导致事务回滚,并将作为DatastoreException进行传播,原始异常将作为其根本原因。
在事务中运行的示例。

String callableResult = "my_callable_result";}; 
String result = datastore.runInTransaction(callable); 
}

代码示例

代码示例来源:origin: googleapis/google-cloud-java

/** Example of running in a transaction. */
// [TARGET runInTransaction(TransactionCallable)]
// [VARIABLE "my_callable_result"]
public String runInTransaction(final String callableResult) {
 // [START runInTransaction]
 TransactionCallable<String> callable =
   new TransactionCallable<String>() {
    public String run(DatastoreReaderWriter readerWriter) {
     // use readerWriter to run in transaction
     return callableResult;
    }
   };
 String result = datastore.runInTransaction(callable);
 // [END runInTransaction]
 return result;
}

代码示例来源:origin: googleapis/google-cloud-java

int result = DATASTORE.runInTransaction(callable1);
assertEquals(result, 2);
 DATASTORE.runInTransaction(callable2);
 fail("Expecting a failure");
} catch (DatastoreException expected) {

代码示例来源:origin: googleapis/google-cloud-java

.setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance())
    .build();
Integer result = mockDatastore.runInTransaction(callable, options);
EasyMock.verify(rpcFactoryMock, rpcMock);
assertEquals(2, result.intValue());

代码示例来源:origin: googleapis/google-cloud-java

int result = DATASTORE.runInTransaction(callable1);
assertEquals(result, 2);
 DATASTORE.runInTransaction(callable2, readOnlyOptions);
 fail("Expecting a failure");
} catch (DatastoreException expected) {

代码示例来源:origin: spotify/styx

@Override
public <T> T runInTransaction(TransactionCallable<T> transactionCallable) {
 return delegate.runInTransaction(rw ->
   transactionCallable.run(InstrumentedDatastoreReaderWriter.of(stats, rw)));
}

代码示例来源:origin: spotify/styx

@Override
public <T> T runInTransaction(TransactionCallable<T> transactionCallable, TransactionOptions transactionOptions) {
 return delegate.runInTransaction(rw ->
   transactionCallable.run(InstrumentedDatastoreReaderWriter.of(stats, rw)), transactionOptions);
}

代码示例来源:origin: spring-cloud/spring-cloud-gcp

@Override
public <A> A performTransaction(Function<DatastoreOperations, A> operations) {
  if (!(getDatastoreReadWriter() instanceof Datastore)) {
    throw new DatastoreDataException(
        "This DatastoreReadWriter cannot be used to run transactions. A full Datastore service"
            + " object is required to run functions as transactions. Ensure that this method "
            + "was not called in an ongoing transaction.");
  }
  return ((Datastore) getDatastoreReadWriter())
      .runInTransaction(
      (DatastoreReaderWriter readerWriter) -> operations.apply(new DatastoreTemplate(readerWriter,
          DatastoreTemplate.this.datastoreEntityConverter,
          DatastoreTemplate.this.datastoreMappingContext,
          DatastoreTemplate.this.objectToKeyFactory)));
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-data-datastore

@Override
public <A> A performTransaction(Function<DatastoreOperations, A> operations) {
  if (!(getDatastoreReadWriter() instanceof Datastore)) {
    throw new DatastoreDataException(
        "This DatastoreReadWriter cannot be used to run transactions. A full Datastore service"
            + " object is required to run functions as transactions. Ensure that this method "
            + "was not called in an ongoing transaction.");
  }
  return ((Datastore) getDatastoreReadWriter())
      .runInTransaction(
      (DatastoreReaderWriter readerWriter) -> operations.apply(new DatastoreTemplate(readerWriter,
          DatastoreTemplate.this.datastoreEntityConverter,
          DatastoreTemplate.this.datastoreMappingContext,
          DatastoreTemplate.this.objectToKeyFactory)));
}

相关文章