@Test public void testLookupEventualConsistency() { ReadOptions readOption = ReadOptions.newBuilder().setReadConsistencyValue(ReadConsistency.EVENTUAL_VALUE).build(); com.google.datastore.v1.Key key = com.google.datastore.v1.Key.newBuilder() .setPartitionId(PartitionId.newBuilder().setProjectId(PROJECT_ID).build()) .addPath( com.google.datastore.v1.Key.PathElement.newBuilder() .setKind("kind1") .setName("name") .build()) .build(); LookupRequest lookupRequest = LookupRequest.newBuilder().setReadOptions(readOption).addKeys(key).build(); EasyMock.expect(rpcMock.lookup(lookupRequest)) .andReturn(LookupResponse.newBuilder().build()) .times(3); EasyMock.replay(rpcFactoryMock, rpcMock); Datastore datastore = rpcMockOptions.getService(); datastore.get(KEY1, ReadOption.eventualConsistency()); datastore.get(ImmutableList.of(KEY1), ReadOption.eventualConsistency()); datastore.fetch(ImmutableList.of(KEY1), ReadOption.eventualConsistency()); EasyMock.verify(rpcFactoryMock, rpcMock); }
Key.Builder key = Key.newBuilder().addPath( Key.PathElement.newBuilder() .setKind("Trivia")
key.addPath(pathElement);
key.addPath(pathElement);
.addPath( PathElement.newBuilder() .setKind(entityKind().get())
/** * Get key */ public Key getKey(String name) { Key.Builder keyBuilder = Key.newBuilder(); // Set namespace PartitionId partitionId = PartitionId.newBuilder() .setProjectId(projectId).setNamespaceId(namespace).build(); keyBuilder.setPartitionId(partitionId); // Set parent paths if (parents != null && parents.size() > 0) { for (String parentKey : parents.keySet()) { Key.PathElement.Builder parentPath = Key.PathElement.newBuilder().setKind(parentKey).setName(parents.get(parentKey)); keyBuilder.addPath(parentPath); } } // Set main kind Key.PathElement.Builder path = Key.PathElement.newBuilder().setKind(kind).setName(name); keyBuilder.addPath(path); return keyBuilder.build(); }
com.google.datastore.v1.Key toPb() { com.google.datastore.v1.Key.Builder keyPb = com.google.datastore.v1.Key.newBuilder(); com.google.datastore.v1.PartitionId.Builder partitionIdPb = com.google.datastore.v1.PartitionId.newBuilder(); partitionIdPb.setProjectId(projectId); partitionIdPb.setNamespaceId(namespace); keyPb.setPartitionId(partitionIdPb.build()); for (PathElement pathEntry : path) { keyPb.addPath(pathEntry.toPb()); } return keyPb.build(); } }
/** * Add a path element of a given kind to this key. * * @param kind the path element kind. * @return this key builder. */ public Builder path(final String kind) { key.addPath(com.google.datastore.v1.Key.PathElement.newBuilder().setKind(kind)); return this; }
/** * Add a path element of a given kind and name to this key. * * @param kind the path element kind. * @param name the path element name. * @return this key builder. */ public Builder path(final String kind, final String name) { key.addPath(com.google.datastore.v1.Key.PathElement.newBuilder().setKind(kind).setName(name)); return this; }
/** * Add a path element of a given kind and id to this key. * * @param kind the path element kind. * @param id the path element id. * @return this key builder. */ public Builder path(final String kind, final long id) { key.addPath(com.google.datastore.v1.Key.PathElement.newBuilder().setKind(kind).setId(id)); return this; }
/** * Add a path element to this key. * * @param element the path element to add. * @return this key builder. */ public Builder path(final Element element) { key.addPath(element.getPb()); return this; }
com.google.datastore.v1.Key toPb() { com.google.datastore.v1.Key.Builder keyPb = com.google.datastore.v1.Key.newBuilder(); com.google.datastore.v1.PartitionId.Builder partitionIdPb = com.google.datastore.v1.PartitionId.newBuilder(); partitionIdPb.setProjectId(projectId); partitionIdPb.setNamespaceId(namespace); keyPb.setPartitionId(partitionIdPb.build()); for (PathElement pathEntry : path) { keyPb.addPath(pathEntry.toPb()); } return keyPb.build(); } }
private Key.Builder buildPrimaryKey(String table, String key) { Key.Builder result = Key.newBuilder(); if (this.entityGroupingMode == EntityGroupingMode.MULTI_ENTITY_PER_GROUP) { // All entities are in side the same group when we are in this mode. result.addPath(Key.PathElement.newBuilder().setKind(table). setName(rootEntityName)); } return result.addPath(Key.PathElement.newBuilder().setKind(table) .setName(key)); }