@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); }
com.google.datastore.v1.PartitionId.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(partitionId_); partitionId_ = subBuilder.buildPartial();
com.google.datastore.v1.PartitionId.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(partitionId_); partitionId_ = subBuilder.buildPartial();
subBuilder.mergeFrom(partitionId_); partitionId_ = subBuilder.buildPartial();
com.google.datastore.v1.PartitionId.parser(), extensionRegistry); if (subBuilder != null) { subBuilder.mergeFrom(partitionId_); partitionId_ = subBuilder.buildPartial();
subBuilder.mergeFrom(partitionId_); partitionId_ = subBuilder.buildPartial();
if (namespace() != null && namespace().get() != null) { keyBuilder.setPartitionId( PartitionId.newBuilder().setProjectId("").setNamespaceId(namespace().get()));
@Override public ListenableFuture<QueryResult> executeAsync(final Query statement, final ListenableFuture<TransactionResult> txn) { final ListenableFuture<Response> httpResponse = Futures.transformAsync(txn, result -> { final String namespace = config.getNamespace(); final RunQueryRequest.Builder request = RunQueryRequest.newBuilder() .setQuery(statement.getPb(namespace != null ? namespace : "")); if (namespace != null) { request.setPartitionId(PartitionId.newBuilder().setNamespaceId(namespace)); } final ByteString transaction = result.getTransaction(); if (transaction != null) { request.setReadOptions(ReadOptions.newBuilder().setTransaction(transaction)); } final ProtoHttpContent payload = new ProtoHttpContent(request.build()); return ListenableFutureAdapter.asGuavaFuture(prepareRequest("runQuery", payload).execute()); }, MoreExecutors.directExecutor()); return Futures.transformAsync(httpResponse, response -> { if (!isSuccessful(response.getStatusCode())) { throw new DatastoreException(response.getStatusCode(), response.getResponseBody()); } final RunQueryResponse query = RunQueryResponse.parseFrom(streamResponse(response)); return Futures.immediateFuture(QueryResult.build(query)); }, MoreExecutors.directExecutor()); } }
/** * * * <pre> * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. * This partition ID is normalized with the standard default context * partition ID. * </pre> * * <code>.google.datastore.v1.PartitionId partition_id = 2;</code> */ public Builder mergePartitionId(com.google.datastore.v1.PartitionId value) { if (partitionIdBuilder_ == null) { if (partitionId_ != null) { partitionId_ = com.google.datastore.v1.PartitionId.newBuilder(partitionId_) .mergeFrom(value) .buildPartial(); } else { partitionId_ = value; } onChanged(); } else { partitionIdBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Entities are partitioned into subsets, currently identified by a project * ID and namespace ID. * Queries are scoped to a single partition. * </pre> * * <code>.google.datastore.v1.PartitionId partition_id = 1;</code> */ public Builder mergePartitionId(com.google.datastore.v1.PartitionId value) { if (partitionIdBuilder_ == null) { if (partitionId_ != null) { partitionId_ = com.google.datastore.v1.PartitionId.newBuilder(partitionId_) .mergeFrom(value) .buildPartial(); } else { partitionId_ = value; } onChanged(); } else { partitionIdBuilder_.mergeFrom(value); } return this; } /**
/** * <pre> * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. * This partition ID is normalized with the standard default context * partition ID. * </pre> * * <code>optional .google.datastore.v1.PartitionId partition_id = 2;</code> */ public Builder mergePartitionId(com.google.datastore.v1.PartitionId value) { if (partitionIdBuilder_ == null) { if (partitionId_ != null) { partitionId_ = com.google.datastore.v1.PartitionId.newBuilder(partitionId_).mergeFrom(value).buildPartial(); } else { partitionId_ = value; } onChanged(); } else { partitionIdBuilder_.mergeFrom(value); } return this; } /**
/** * Build an entity for the given ancestorKey, kind, namespace and value. * * @param largePropertySize if greater than 0, add an unindexed property of the given size. */ static Entity makeEntity( Long value, Key ancestorKey, String kind, @Nullable String namespace, int largePropertySize) { Entity.Builder entityBuilder = Entity.newBuilder(); Key.Builder keyBuilder = makeKey(ancestorKey, kind, UUID.randomUUID().toString()); // NOTE: Namespace is not inherited between keys created with DatastoreHelper.makeKey, so // we must set the namespace on keyBuilder. TODO: Once partitionId inheritance is added, // we can simplify this code. if (namespace != null) { keyBuilder.getPartitionIdBuilder().setNamespaceId(namespace); } entityBuilder.setKey(keyBuilder.build()); entityBuilder.putProperties("value", makeValue(value).build()); if (largePropertySize > 0) { entityBuilder.putProperties( "unindexed_value", makeValue(new String(new char[largePropertySize]).replace("\0", "A")) .setExcludeFromIndexes(true) .build()); } return entityBuilder.build(); }
/** * <pre> * Entities are partitioned into subsets, currently identified by a project * ID and namespace ID. * Queries are scoped to a single partition. * </pre> * * <code>optional .google.datastore.v1.PartitionId partition_id = 1;</code> */ public Builder mergePartitionId(com.google.datastore.v1.PartitionId value) { if (partitionIdBuilder_ == null) { if (partitionId_ != null) { partitionId_ = com.google.datastore.v1.PartitionId.newBuilder(partitionId_).mergeFrom(value).buildPartial(); } else { partitionId_ = value; } onChanged(); } else { partitionIdBuilder_.mergeFrom(value); } return this; } /**
/** * <pre> * Entities are partitioned into subsets, currently identified by a project * ID and namespace ID. * Queries are scoped to a single partition. * </pre> * * <code>optional .google.datastore.v1.PartitionId partition_id = 1;</code> */ public Builder setPartitionId( com.google.datastore.v1.PartitionId.Builder builderForValue) { if (partitionIdBuilder_ == null) { partitionId_ = builderForValue.build(); onChanged(); } else { partitionIdBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * <pre> * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. * This partition ID is normalized with the standard default context * partition ID. * </pre> * * <code>optional .google.datastore.v1.PartitionId partition_id = 2;</code> */ public Builder setPartitionId( com.google.datastore.v1.PartitionId.Builder builderForValue) { if (partitionIdBuilder_ == null) { partitionId_ = builderForValue.build(); onChanged(); } else { partitionIdBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * Entities are partitioned into subsets, identified by a partition ID. * Queries are scoped to a single partition. * This partition ID is normalized with the standard default context * partition ID. * </pre> * * <code>.google.datastore.v1.PartitionId partition_id = 2;</code> */ public Builder setPartitionId(com.google.datastore.v1.PartitionId.Builder builderForValue) { if (partitionIdBuilder_ == null) { partitionId_ = builderForValue.build(); onChanged(); } else { partitionIdBuilder_.setMessage(builderForValue.build()); } return this; } /**
/** * 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(); }
QueryResultsImpl( DatastoreImpl datastore, com.google.datastore.v1.ReadOptions readOptionsPb, Query<T> query) { this.datastore = datastore; this.readOptionsPb = readOptionsPb; this.query = query; queryResultType = query.getType(); com.google.datastore.v1.PartitionId.Builder pbBuilder = com.google.datastore.v1.PartitionId.newBuilder(); pbBuilder.setProjectId(datastore.getOptions().getProjectId()); if (query.getNamespace() != null) { pbBuilder.setNamespaceId(query.getNamespace()); } else if (datastore.getOptions().getNamespace() != null) { pbBuilder.setNamespaceId(datastore.getOptions().getNamespace()); } partitionIdPb = pbBuilder.build(); sendRequest(); if (runQueryResponsePb.getBatch().getSkippedResults() > 0) { cursor = runQueryResponsePb.getBatch().getSkippedCursor(); } else { cursor = mostRecentQueryPb.getStartCursor(); } }
/** * * * <pre> * Entities are partitioned into subsets, currently identified by a project * ID and namespace ID. * Queries are scoped to a single partition. * </pre> * * <code>.google.datastore.v1.PartitionId partition_id = 1;</code> */ public Builder setPartitionId(com.google.datastore.v1.PartitionId.Builder builderForValue) { if (partitionIdBuilder_ == null) { partitionId_ = builderForValue.build(); onChanged(); } else { partitionIdBuilder_.setMessage(builderForValue.build()); } return this; } /**
@java.lang.Override public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { com.google.datastore.v1.PartitionId parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.google.datastore.v1.PartitionId) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; }