当前位置: 首页>>代码示例>>Java>>正文


Java Mutation类代码示例

本文整理汇总了Java中com.google.datastore.v1.Mutation的典型用法代码示例。如果您正苦于以下问题:Java Mutation类的具体用法?Java Mutation怎么用?Java Mutation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Mutation类属于com.google.datastore.v1包,在下文中一共展示了Mutation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: datastoreWriterFnTest

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
private void datastoreWriterFnTest(int numMutations) throws Exception {
  // Create the requested number of mutations.
  List<Mutation> mutations = new ArrayList<>(numMutations);
  for (int i = 0; i < numMutations; ++i) {
    mutations.add(
        makeUpsert(Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).build()).build());
  }

  DatastoreWriterFn datastoreWriter = new DatastoreWriterFn(StaticValueProvider.of(PROJECT_ID),
      null, mockDatastoreFactory, new FakeWriteBatcher());
  DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter);
  doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
  doFnTester.processBundle(mutations);

  int start = 0;
  while (start < numMutations) {
    int end = Math.min(numMutations, start + DATASTORE_BATCH_UPDATE_ENTITIES_START);
    CommitRequest.Builder commitRequest = CommitRequest.newBuilder();
    commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);
    commitRequest.addAllMutations(mutations.subList(start, end));
    // Verify all the batch requests were made with the expected mutations.
    verify(mockDatastore, times(1)).commit(commitRequest.build());
    start = end;
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:DatastoreV1Test.java

示例2: testDatatoreWriterFnRetriesErrors

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
/** Tests {@link DatastoreWriterFn} with a failed request which is retried. */
@Test
public void testDatatoreWriterFnRetriesErrors() throws Exception {
  List<Mutation> mutations = new ArrayList<>();
  int numRpcs = 2;
  for (int i = 0; i < DATASTORE_BATCH_UPDATE_ENTITIES_START * numRpcs; ++i) {
    mutations.add(
        makeUpsert(Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).build()).build());
  }

  CommitResponse successfulCommit = CommitResponse.getDefaultInstance();
  when(mockDatastore.commit(any(CommitRequest.class))).thenReturn(successfulCommit)
    .thenThrow(
        new DatastoreException("commit", Code.DEADLINE_EXCEEDED, "", null))
    .thenReturn(successfulCommit);

  DatastoreWriterFn datastoreWriter = new DatastoreWriterFn(StaticValueProvider.of(PROJECT_ID),
      null, mockDatastoreFactory, new FakeWriteBatcher());
  DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter);
  doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
  doFnTester.processBundle(mutations);
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:DatastoreV1Test.java

示例3: executeAsyncMutations

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
private ListenableFuture<MutationResult> executeAsyncMutations(final List<Mutation> mutations, final ListenableFuture<TransactionResult> txn) {
  final ListenableFuture<Response> httpResponse = Futures.transformAsync(txn, result -> {
    final CommitRequest.Builder request = CommitRequest.newBuilder();
    if (mutations != null) {
      request.addAllMutations(mutations);
    }

    final ByteString transaction = result.getTransaction();
    if (transaction != null) {
      request.setTransaction(transaction);
    } else {
      request.setMode(CommitRequest.Mode.NON_TRANSACTIONAL);
    }
    final ProtoHttpContent payload = new ProtoHttpContent(request.build());
    return ListenableFutureAdapter.asGuavaFuture(prepareRequest("commit", payload).execute());
  });
  return Futures.transformAsync(httpResponse, response -> {
    if (!isSuccessful(response.getStatusCode())) {
      throw new DatastoreException(response.getStatusCode(), response.getResponseBody());
    }
    final CommitResponse commit = CommitResponse.parseFrom(streamResponse(response));
    return Futures.immediateFuture(MutationResult.build(commit));
  });
}
 
开发者ID:spotify,项目名称:async-datastore-client,代码行数:25,代码来源:DatastoreImpl.java

示例4: Mutate

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
/**
 * Note that {@code projectId} is only {@code @Nullable} as a matter of build order, but if
 * it is {@code null} at instantiation time, an error will be thrown.
 */
Mutate(@Nullable ValueProvider<String> projectId, @Nullable String localhost,
    SimpleFunction<T, Mutation> mutationFn) {
  this.projectId = projectId;
  this.localhost = localhost;
  this.mutationFn = checkNotNull(mutationFn);
}
 
开发者ID:apache,项目名称:beam,代码行数:11,代码来源:DatastoreV1.java

示例5: processElement

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
  Mutation write = c.element();
  int size = write.getSerializedSize();
  if (mutations.size() > 0
      && mutationsSize + size >= DatastoreV1.DATASTORE_BATCH_UPDATE_BYTES_LIMIT) {
    flushBatch();
  }
  mutations.add(c.element());
  mutationsSize += size;
  if (mutations.size() >= writeBatcher.nextBatchSize(System.currentTimeMillis())) {
    flushBatch();
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:15,代码来源:DatastoreV1.java

示例6: apply

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public Mutation apply(Entity entity) {
  // Verify that the entity to write has a complete key.
  checkArgument(isValidKey(entity.getKey()),
      "Entities to be written to the Cloud Datastore must have complete keys:\n%s", entity);

  return makeUpsert(entity).build();
}
 
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DatastoreV1.java

示例7: testAddEntities

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Test
/**
 * Test that entities with valid keys are transformed to upsert mutations.
 */
public void testAddEntities() throws Exception {
  Key key = makeKey("bird", "finch").build();
  Entity entity = Entity.newBuilder().setKey(key).build();
  UpsertFn upsertFn = new UpsertFn();

  Mutation exceptedMutation = makeUpsert(entity).build();
  assertEquals(upsertFn.apply(entity), exceptedMutation);
}
 
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:DatastoreV1Test.java

示例8: testDeleteEntities

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
/**
 * Test that entities with valid keys are transformed to delete mutations.
 */
@Test
public void testDeleteEntities() throws Exception {
  Key key = makeKey("bird", "finch").build();
  Entity entity = Entity.newBuilder().setKey(key).build();
  DeleteEntityFn deleteEntityFn = new DeleteEntityFn();

  Mutation exceptedMutation = makeDelete(entity.getKey()).build();
  assertEquals(deleteEntityFn.apply(entity), exceptedMutation);
}
 
开发者ID:apache,项目名称:beam,代码行数:13,代码来源:DatastoreV1Test.java

示例9: testDeleteKeys

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
/**
 * Test that valid keys are transformed to delete mutations.
 */
@Test
public void testDeleteKeys() throws Exception {
  Key key = makeKey("bird", "finch").build();
  DeleteKeyFn deleteKeyFn = new DeleteKeyFn();

  Mutation exceptedMutation = makeDelete(key).build();
  assertEquals(deleteKeyFn.apply(key), exceptedMutation);
}
 
开发者ID:apache,项目名称:beam,代码行数:12,代码来源:DatastoreV1Test.java

示例10: getPb

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public Mutation getPb(final String namespace) {
  final com.google.datastore.v1.Mutation.Builder mutation =
    com.google.datastore.v1.Mutation.newBuilder();

  return mutation.setInsert(entity.build().getPb(namespace)).build();
}
 
开发者ID:spotify,项目名称:async-datastore-client,代码行数:8,代码来源:Insert.java

示例11: getPb

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public Mutation getPb(final String namespace) {
  final com.google.datastore.v1.Mutation.Builder mutation =
    com.google.datastore.v1.Mutation.newBuilder();
  if (upsert) {
    mutation.setUpsert(entity.build().getPb(namespace));
  } else {
    mutation.setUpdate(entity.build().getPb(namespace));
  }
  return mutation.build();
}
 
开发者ID:spotify,项目名称:async-datastore-client,代码行数:12,代码来源:Update.java

示例12: executeAsync

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public ListenableFuture<MutationResult> executeAsync(final MutationStatement statement, final ListenableFuture<TransactionResult> txn) {
  final List<Mutation> mutations = Optional
    .ofNullable(statement)
    .flatMap(s -> Optional.of(ImmutableList.of(s.getPb(config.getNamespace()))))
    .orElse(ImmutableList.of());

  return executeAsyncMutations(mutations, txn);
}
 
开发者ID:spotify,项目名称:async-datastore-client,代码行数:10,代码来源:DatastoreImpl.java

示例13: insert

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
/**
  * Insert an entity into the datastore.
  *
  * The entity must have no ids.
  *
  * @return The key for the inserted entity.
  * @throws DatastoreException on error
  */
 private Key insert(Entity entity) throws DatastoreException {
   CommitRequest req = CommitRequest.newBuilder()
.addMutations(Mutation.newBuilder()
    .setInsert(entity))
       .setMode(CommitRequest.Mode.NON_TRANSACTIONAL)
.build();
   return datastore.commit(req).getMutationResults(0).getKey();
 }
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-datastore,代码行数:17,代码来源:Guestbook.java

示例14: apply

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public Mutation.Builder apply(Entity entity) {
  return makeUpsert(entity);
}
 
开发者ID:apache,项目名称:beam,代码行数:5,代码来源:V1TestUtil.java

示例15: getPb

import com.google.datastore.v1.Mutation; //导入依赖的package包/类
@Override
public Mutation getPb(final String namespace) {
  final com.google.datastore.v1.Key mutationKey = getKey().getPb(namespace);
  return com.google.datastore.v1.Mutation.newBuilder().setDelete(mutationKey).build();
}
 
开发者ID:spotify,项目名称:async-datastore-client,代码行数:6,代码来源:Delete.java


注:本文中的com.google.datastore.v1.Mutation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。