commitRequest.setMode(Mode.NON_TRANSACTIONAL); commitRequest.addMutationsBuilder().setDelete(datastoreKey); commitRequest.addMutationsBuilder().setUpsert(entity); } else if (mutationType == MutationType.UPDATE){ commitRequest.addMutationsBuilder().setUpdate(entity); } else { throw new RuntimeException("Impossible MutationType, code bug."); datastore.commit(commitRequest.build()); logger.debug("successfully committed.");
if (!other.getProjectId().isEmpty()) { projectId_ = other.projectId_; onChanged(); setModeValue(other.getModeValue()); bitField0_ = (bitField0_ & ~0x00000008); } else { ensureMutationsIsMutable(); mutations_.addAll(other.mutations_); onChanged(); mutationsBuilder_ = com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? getMutationsFieldBuilder() : null; } else { case TRANSACTION: setTransaction(other.getTransaction()); break; this.mergeUnknownFields(other.unknownFields); onChanged(); return this;
@Override public Transaction.Response commit() { validateActive(); List<com.google.datastore.v1.Mutation> mutationsPb = toMutationPbList(); com.google.datastore.v1.CommitRequest.Builder requestPb = com.google.datastore.v1.CommitRequest.newBuilder(); requestPb.setMode(com.google.datastore.v1.CommitRequest.Mode.TRANSACTIONAL); requestPb.setTransaction(transactionId); requestPb.addAllMutations(mutationsPb); com.google.datastore.v1.CommitResponse responsePb = datastore.commit(requestPb.build()); deactivate(); return new ResponseImpl(responsePb, toAddAutoId().size()); }
creq.setTransaction(tx); Entity entity; if (lresp.getFoundCount() > 0) { creq.addMutationsBuilder().setInsert(entity); datastore.commit(creq.build());
commitRequest.addAllMutations(mutations); commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL); long startTime = System.currentTimeMillis(), endTime; datastore.commit(commitRequest.build()); endTime = System.currentTimeMillis();
if (!other.getProjectId().isEmpty()) { projectId_ = other.projectId_; onChanged(); setModeValue(other.getModeValue()); bitField0_ = (bitField0_ & ~0x00000008); } else { ensureMutationsIsMutable(); mutations_.addAll(other.mutations_); onChanged(); mutationsBuilder_ = com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? getMutationsFieldBuilder() : null; } else { case TRANSACTION: setTransaction(other.getTransaction()); break; this.mergeUnknownFields(other.unknownFields); onChanged(); return this;
if (!other.getProjectId().isEmpty()) { projectId_ = other.projectId_; onChanged(); setModeValue(other.getModeValue()); bitField0_ = (bitField0_ & ~0x00000008); } else { ensureMutationsIsMutable(); mutations_.addAll(other.mutations_); onChanged(); mutationsBuilder_ = com.google.protobuf.GeneratedMessageV3.alwaysUseFieldBuilders ? getMutationsFieldBuilder() : null; } else { mutationsBuilder_.addAllMessages(other.mutations_); setTransaction(other.getTransaction()); break; onChanged(); return this;
throw new NullPointerException(); ensureMutationsIsMutable(); mutations_.add(value); onChanged(); } else { mutationsBuilder_.addMessage(value);
throw new NullPointerException(); ensureMutationsIsMutable(); mutations_.add(index, value); onChanged(); } else { mutationsBuilder_.addMessage(index, value);
throw new NullPointerException(); ensureMutationsIsMutable(); mutations_.set(index, value); onChanged(); } else { mutationsBuilder_.setMessage(index, value);
throw new NullPointerException(); ensureMutationsIsMutable(); mutations_.add(index, value); onChanged(); } else { mutationsBuilder_.addMessage(index, value);
CommitRequest.Builder commitRequest = CommitRequest.newBuilder(); for (Entity entity : entities) { commitRequest.addMutations(mutationBuilder.apply(entity)); commitRequest.setMode(CommitRequest.Mode.NON_TRANSACTIONAL); datastore.commit(commitRequest.build());
/** * * * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder addAllMutations( java.lang.Iterable<? extends com.google.datastore.v1.Mutation> values) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); com.google.protobuf.AbstractMessageLite.Builder.addAll(values, mutations_); onChanged(); } else { mutationsBuilder_.addAllMessages(values); } return this; } /**
/** * * * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder setMutations( int index, com.google.datastore.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.set(index, builderForValue.build()); onChanged(); } else { mutationsBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
throw new NullPointerException(); ensureMutationsIsMutable(); mutations_.set(index, value); onChanged(); } else { mutationsBuilder_.setMessage(index, value);
/** * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder addAllMutations( java.lang.Iterable<? extends com.google.datastore.v1.Mutation> values) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); com.google.protobuf.AbstractMessageLite.Builder.addAll( values, mutations_); onChanged(); } else { mutationsBuilder_.addAllMessages(values); } return this; } /**
// Create an RPC request to begin a new transaction. BeginTransactionRequest.Builder treq = BeginTransactionRequest.newBuilder(); // Execute the RPC synchronously. BeginTransactionResponse tres = datastore.beginTransaction(treq.build()); // Get the transaction handle from the response. ByteString tx = tres.getTransaction(); // Create an RPC request to get entities by key. LookupRequest.Builder lreq = LookupRequest.newBuilder(); // Set the entity key with only one `path_element`: no parent. Key.Builder key = Key.newBuilder().addPathElement( Key.PathElement.newBuilder() .setKind("Trivia") .setName("hgtg")); // Add one key to the lookup request. lreq.addKey(key); // Set the transaction, so we get a consistent snapshot of the // entity at the time the transaction started. lreq.getReadOptionsBuilder().setTransaction(tx); // Execute the RPC and get the response. LookupResponse lresp = datastore.lookup(lreq.build()); // Create an RPC request to commit the transaction. CommitRequest.Builder creq = CommitRequest.newBuilder(); // Set the transaction to commit. creq.setTransaction(tx); Entity entity; if (lresp.getFoundCount() > 0) { entity = lresp.getFound(0).getEntity(); }
/** * * * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder addMutations( int index, com.google.datastore.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.add(index, builderForValue.build()); onChanged(); } else { mutationsBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder addMutations(com.google.datastore.v1.Mutation value) { if (mutationsBuilder_ == null) { if (value == null) { throw new NullPointerException(); } ensureMutationsIsMutable(); mutations_.add(value); onChanged(); } else { mutationsBuilder_.addMessage(value); } return this; } /**
/** * * * <pre> * The mutations to perform. * When mode is `TRANSACTIONAL`, mutations affecting a single entity are * applied in order. The following sequences of mutations affecting a single * entity are not permitted in a single `Commit` request: * - `insert` followed by `insert` * - `update` followed by `insert` * - `upsert` followed by `insert` * - `delete` followed by `update` * When mode is `NON_TRANSACTIONAL`, no two mutations may affect a single * entity. * </pre> * * <code>repeated .google.datastore.v1.Mutation mutations = 6;</code> */ public Builder addMutations(com.google.datastore.v1.Mutation.Builder builderForValue) { if (mutationsBuilder_ == null) { ensureMutationsIsMutable(); mutations_.add(builderForValue.build()); onChanged(); } else { mutationsBuilder_.addMessage(builderForValue.build()); } return this; } /**