/** * * * <pre> * `id` may be used to identify the transaction in subsequent * [Read][google.spanner.v1.Spanner.Read], * [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql], * [Commit][google.spanner.v1.Spanner.Commit], or * [Rollback][google.spanner.v1.Spanner.Rollback] calls. * Single-use read-only transactions do not have IDs, because * single-use transactions do not support multiple requests. * </pre> * * <code>bytes id = 1;</code> */ public Builder clearId() { id_ = getDefaultInstance().getId(); onChanged(); return this; }
static Map<String, AttributeValue> getTransactionAnnotations(Transaction t) { return ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(t.getId().toStringUtf8()), "Timestamp", AttributeValue.stringAttributeValue(Timestamp.fromProto(t.getReadTimestamp()).toString())); }
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.spanner.v1.Transaction)) { return super.equals(obj); } com.google.spanner.v1.Transaction other = (com.google.spanner.v1.Transaction) obj; boolean result = true; result = result && getId().equals(other.getId()); result = result && (hasReadTimestamp() == other.hasReadTimestamp()); if (hasReadTimestamp()) { result = result && getReadTimestamp().equals(other.getReadTimestamp()); } result = result && unknownFields.equals(other.unknownFields); return result; }
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + ID_FIELD_NUMBER; hash = (53 * hash) + getId().hashCode(); if (hasReadTimestamp()) { hash = (37 * hash) + READ_TIMESTAMP_FIELD_NUMBER; hash = (53 * hash) + getReadTimestamp().hashCode(); } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(com.google.spanner.v1.Transaction other) { if (other == com.google.spanner.v1.Transaction.getDefaultInstance()) return this; if (other.getId() != com.google.protobuf.ByteString.EMPTY) { setId(other.getId()); } if (other.hasReadTimestamp()) { mergeReadTimestamp(other.getReadTimestamp()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
ByteString initTransaction() { final BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setSession(session.getName()) .setOptions( TransactionOptions.newBuilder() .setPartitionedDml(TransactionOptions.PartitionedDml.getDefaultInstance())) .build(); Transaction txn = runWithRetries( new Callable<Transaction>() { @Override public Transaction call() throws Exception { return rpc.beginTransaction(request, session.options); } }); if (txn.getId().isEmpty()) { throw SpannerExceptionFactory.newSpannerException( ErrorCode.INTERNAL, "Failed to init transaction, missing transaction id\n" + session.getName()); } return txn.getId(); }
ByteString beginTransaction() { Span span = tracer.spanBuilder(BEGIN_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { final BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setSession(name) .setOptions( TransactionOptions.newBuilder() .setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance())) .build(); Transaction txn = runWithRetries( new Callable<Transaction>() { @Override public Transaction call() throws Exception { return gapicRpc.beginTransaction(request, options); } }); if (txn.getId().isEmpty()) { throw newSpannerException(ErrorCode.INTERNAL, "Missing id in transaction\n" + getName()); } span.end(); return txn.getId(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
ErrorCode.INTERNAL, "Missing expected transaction.read_timestamp metadata field"); if (transaction.getId().isEmpty()) { throw SpannerExceptionFactory.newSpannerException( ErrorCode.INTERNAL, "Missing expected transaction.id metadata field"); ErrorCode.INTERNAL, "Bad value in transaction.read_timestamp metadata field", e); transactionId = transaction.getId(); span.addAnnotation( "Transaction Creation Done", TraceUtil.getTransactionAnnotations(transaction));
static Map<String, AttributeValue> getTransactionAnnotations(Transaction t) { return ImmutableMap.of( "Id", AttributeValue.stringAttributeValue(t.getId().toStringUtf8()), "Timestamp", AttributeValue.stringAttributeValue(Timestamp.fromProto(t.getReadTimestamp()).toString())); }
ByteString initTransaction() { final BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setSession(session.getName()) .setOptions( TransactionOptions.newBuilder() .setPartitionedDml(TransactionOptions.PartitionedDml.getDefaultInstance())) .build(); Transaction txn = runWithRetries( new Callable<Transaction>() { @Override public Transaction call() throws Exception { return rpc.beginTransaction(request, session.options); } }); if (txn.getId().isEmpty()) { throw SpannerExceptionFactory.newSpannerException( ErrorCode.INTERNAL, "Failed to init transaction, missing transaction id\n" + session.getName()); } return txn.getId(); }
ErrorCode.INTERNAL, "Missing expected transaction.read_timestamp metadata field"); if (transaction.getId().isEmpty()) { throw SpannerExceptionFactory.newSpannerException( ErrorCode.INTERNAL, "Missing expected transaction.id metadata field"); ErrorCode.INTERNAL, "Bad value in transaction.read_timestamp metadata field", e); transactionId = transaction.getId(); span.addAnnotation( "Transaction Creation Done", TraceUtil.getTransactionAnnotations(transaction));
ByteString beginTransaction() { Span span = tracer.spanBuilder(BEGIN_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { final BeginTransactionRequest request = BeginTransactionRequest.newBuilder() .setSession(name) .setOptions( TransactionOptions.newBuilder() .setReadWrite(TransactionOptions.ReadWrite.getDefaultInstance())) .build(); Transaction txn = runWithRetries( new Callable<Transaction>() { @Override public Transaction call() throws Exception { return gapicRpc.beginTransaction(request, options); } }); if (txn.getId().isEmpty()) { throw newSpannerException(ErrorCode.INTERNAL, "Missing id in transaction\n" + getName()); } span.end(); return txn.getId(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }