コード例 #1
0
 /// <summary>
 /// Creates a wrapper around an existing Spanner read-only transaction that can be used with EFCore.
 /// Read-only transactions are never aborted by Cloud Spanner and no additional retry handling is
 /// needed for this type of transaction.
 /// </summary>
 /// <param name="connection">The connection associated with the transaction</param>
 /// <param name="spannerTransaction">The underlying Spanner transaction. This transaction must be marked as read-only</param>
 public SpannerReadOnlyTransaction([NotNull] SpannerRetriableConnection connection, [NotNull] SpannerTransaction spannerTransaction)
 {
     GaxPreconditions.CheckNotNull(spannerTransaction, nameof(spannerTransaction));
     GaxPreconditions.CheckArgument(spannerTransaction.Mode == TransactionMode.ReadOnly, nameof(spannerTransaction), "Must be a read-only transaction");
     DbConnection       = GaxPreconditions.CheckNotNull(connection, nameof(connection));
     SpannerTransaction = spannerTransaction;
 }
コード例 #2
0
        /// <summary>
        /// Creates a connection to the Cloud Spanner instance that is referenced by <see cref="RelationalConnection.ConnectionString"/>.
        /// The connection is not associated with any specific database.
        /// </summary>
        public ISpannerRelationalConnection CreateMasterConnection()
        {
            var builder = new SpannerConnectionStringBuilder(ConnectionString);
            //Spanner actually has no master or admin db, so we just use a normal connection.
            var masterConn =
                new SpannerRetriableConnection(new SpannerConnection($"Data Source=projects/{builder.Project}/instances/{builder.SpannerInstance}"));
            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseSpanner(masterConn);

            return(new SpannerRelationalConnection(Dependencies.With(optionsBuilder.Options)));
        }
 internal SpannerRetriableTransaction(
     SpannerRetriableConnection connection,
     SpannerTransaction spannerTransaction,
     IClock clock,
     IScheduler scheduler,
     RetriableTransactionOptions options = null)
 {
     Connection         = connection;
     SpannerTransaction = spannerTransaction;
     _clock             = GaxPreconditions.CheckNotNull(clock, nameof(clock));
     _scheduler         = GaxPreconditions.CheckNotNull(scheduler, nameof(scheduler));
     _options           = options ?? RetriableTransactionOptions.CreateDefault();
 }
 internal SpannerRetriableCommand(SpannerRetriableConnection connection, SpannerCommand spannerCommand)
 {
     _connection     = connection;
     _spannerCommand = (SpannerCommand)GaxPreconditions.CheckNotNull(spannerCommand, nameof(spannerCommand)).Clone();
 }
コード例 #5
0
 internal SpannerRetriableBatchCommand(SpannerRetriableConnection connection)
 {
     Connection = connection;
 }