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

x33g5p2x  于2022-01-19 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(118)

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

Entity.toPb介绍

暂无

代码示例

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

@Override
public void update(Entity... entities) {
 if (entities.length > 0) {
  List<com.google.datastore.v1.Mutation> mutationsPb = new ArrayList<>();
  Map<Key, Entity> dedupEntities = new LinkedHashMap<>();
  for (Entity entity : entities) {
   dedupEntities.put(entity.getKey(), entity);
  }
  for (Entity entity : dedupEntities.values()) {
   mutationsPb.add(
     com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build());
  }
  commitMutation(mutationsPb);
 }
}

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

com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());

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

@Test
public void testUpdate() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(ENTITY1.toPb()).build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(ENTITY2.toPb()).build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(ENTITY3.toPb()).build());
 batchWriter.update(ENTITY1, ENTITY2);
 batchWriter.update(ENTITY3);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPut() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY2.toPb()).build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY3.toPb()).build());
 List<Entity> putEntities = batchWriter.put(ENTITY1, ENTITY2);
 Entity putEntity = batchWriter.put(ENTITY3);
 assertEquals(ENTITY1, putEntities.get(0));
 assertEquals(ENTITY2, putEntities.get(1));
 assertEquals(ENTITY3, putEntity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testAddAfterDelete() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
 batchWriter.delete(KEY1);
 batchWriter.add(ENTITY1);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testUpdateAfterAdd() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.add(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPutIncompleteKey() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setUpsert(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build().toPb())
     .build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setUpsert(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build().toPb())
     .build());
 Entity putEntity = batchWriter.put(ENTITY1);
 List<Entity> putEntities = batchWriter.put(INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2);
 assertEquals(ENTITY1, putEntity);
 assertEquals(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build(), putEntities.get(0));
 assertEquals(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build(), putEntities.get(1));
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPutAfterAdd() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.add(ENTITY1);
 batchWriter.put(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testUpdateAfterUpdate() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build());
 batchWriter.update(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

lookupResponses.add(
  LookupResponse.newBuilder()
    .addFound(EntityResult.newBuilder().setEntity(ENTITY1.toPb()))
    .addFound(EntityResult.newBuilder().setEntity(entity4.toPb()))
    .addDeferred(keysPb.get(1))
    .addDeferred(keysPb.get(2))
lookupResponses.add(
  LookupResponse.newBuilder()
    .addFound(EntityResult.newBuilder().setEntity(ENTITY2.toPb()))
    .addFound(EntityResult.newBuilder().setEntity(ENTITY3.toPb()))
    .addDeferred(keysPb.get(4))
    .build());
lookupResponses.add(
  LookupResponse.newBuilder()
    .addFound(EntityResult.newBuilder().setEntity(entity5.toPb()))
    .build());
for (int i = 0; i < lookupRequests.size(); i++) {

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

@Test
public void testUpdateAfterPut() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.put(ENTITY1);
 batchWriter.update(entity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testAdd() throws Exception {
 Entity entity2 =
   Entity.newBuilder(ENTITY2).setKey(Key.newBuilder(KEY1).setName("name2").build()).build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(ENTITY1.toPb()).build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build().toPb())
     .build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build().toPb())
     .build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(entity2.toPb()).build());
 List<Entity> entities =
   batchWriter.add(ENTITY1, INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2, entity2);
 assertEquals(pbs, batchWriter.toMutationPbList());
 assertEquals(ENTITY1, entities.get(0));
 assertEquals(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build(), entities.get(1));
 assertEquals(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build(), entities.get(2));
 assertEquals(entity2, entities.get(3));
}

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

@Test
public void testPutAfterUpdate() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.update(ENTITY1);
 Entity putEntity = batchWriter.put(entity);
 assertEquals(entity, putEntity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPutAfterDelete() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 batchWriter.delete(KEY1);
 Entity putEntity = batchWriter.put(entity);
 assertEquals(entity, putEntity);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPutWithDeferredAllocation() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(INCOMPLETE_ENTITY_1.toPb())
     .build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(INCOMPLETE_ENTITY_2.toPb())
     .build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build());
 batchWriter.put(ENTITY1);
 batchWriter.putWithDeferredIdAllocation(INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testPutAfterPut() throws Exception {
 Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build();
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
 Entity putEntity1 = batchWriter.put(ENTITY1);
 Entity putEntity2 = batchWriter.put(entity);
 assertEquals(ENTITY1, putEntity1);
 assertEquals(entity, putEntity2);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

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

@Test
public void testRetryableException() throws Exception {
 LookupRequest requestPb = LookupRequest.newBuilder().addKeys(KEY1.toPb()).build();
 LookupResponse responsePb =
   LookupResponse.newBuilder()
     .addFound(EntityResult.newBuilder().setEntity(ENTITY1.toPb()))
     .build();
 EasyMock.expect(rpcMock.lookup(requestPb))
   .andThrow(new DatastoreException(14, "UNAVAILABLE", "UNAVAILABLE", null))
   .andReturn(responsePb);
 EasyMock.replay(rpcFactoryMock, rpcMock);
 Datastore datastore = rpcMockOptions.getService();
 Entity entity = datastore.get(KEY1);
 assertEquals(ENTITY1, entity);
 EasyMock.verify(rpcFactoryMock, rpcMock);
}

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

@Test
public void testAddWithDeferredAllocation() throws Exception {
 List<com.google.datastore.v1.Mutation> pbs = new LinkedList<>();
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(INCOMPLETE_ENTITY_1.toPb())
     .build());
 pbs.add(
   com.google.datastore.v1.Mutation.newBuilder()
     .setInsert(INCOMPLETE_ENTITY_2.toPb())
     .build());
 pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(ENTITY1.toPb()).build());
 batchWriter.addWithDeferredIdAllocation(ENTITY1, INCOMPLETE_ENTITY_1);
 batchWriter.addWithDeferredIdAllocation(INCOMPLETE_ENTITY_2);
 assertEquals(pbs, batchWriter.toMutationPbList());
}

代码示例来源:origin: com.google.cloud/google-cloud-datastore

@Override
public void update(Entity... entities) {
 if (entities.length > 0) {
  List<com.google.datastore.v1.Mutation> mutationsPb = new ArrayList<>();
  Map<Key, Entity> dedupEntities = new LinkedHashMap<>();
  for (Entity entity : entities) {
   dedupEntities.put(entity.getKey(), entity);
  }
  for (Entity entity : dedupEntities.values()) {
   mutationsPb.add(
     com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build());
  }
  commitMutation(mutationsPb);
 }
}

代码示例来源:origin: com.google.cloud/google-cloud-datastore

com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());

相关文章