internal static void ApplyResourcePrefixHeaderFromSession(ref CallSettings settings, string resource)
        {
            // If we haven't been given a resource name, just leave the request as it is.
            if (string.IsNullOrEmpty(resource))
            {
                return;
            }

            if (SessionName.TryParse(resource, out SessionName session))
            {
                var database = DatabaseName.FromProjectInstanceDatabase(
                    session.ProjectId, session.InstanceId, session.DatabaseId);
                settings = settings.WithHeader(ResourcePrefixHeader, database.ToString());
            }
        }
Beispiel #2
0
 private PooledSession(SessionPool.ISessionPool pool, SessionName sessionName, ByteString transactionId, ModeOneofCase transactionMode, DateTime evictionTime, long refreshTicks)
 {
     GaxPreconditions.CheckArgument(
         (transactionId == null) == (transactionMode == ModeOneofCase.None),
         nameof(transactionMode),
         "Transaction mode and ID don't match.");
     _pool           = pool;
     SessionName     = GaxPreconditions.CheckNotNull(sessionName, nameof(sessionName));
     TransactionId   = transactionId;
     TransactionMode = transactionMode;
     _session        = new Session {
         SessionName = SessionName
     };
     _evictionTime = evictionTime;
     _refreshTicks = refreshTicks;
 }
 /// <summary>
 /// Creates a <see cref="PooledSession"/> with a known name and transaction ID/mode, with the client associated
 /// with this pool, but is otherwise not part of this pool. This method does not query the server for the session state.
 /// When the returned <see cref="PooledSession"/> is released, it will not become part of this pool, and the transaction
 /// will not be rolled back.
 /// </summary>
 /// <remarks>
 /// This is typically used for partitioned queries, where the same session is used across multiple machines, so should
 /// not be reused by the pool.
 /// </remarks>
 /// <param name="sessionName">The name of the transaction. Must not be null.</param>
 /// <param name="transactionId">The ID of the transaction. Must not be null.</param>
 /// <param name="transactionMode">The mode of the transaction.</param>
 /// <returns>A <see cref="PooledSession"/> for the given session and transaction.</returns>
 public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, ModeOneofCase transactionMode)
 {
     GaxPreconditions.CheckNotNull(sessionName, nameof(sessionName));
     GaxPreconditions.CheckNotNull(transactionId, nameof(transactionId));
     return(PooledSession.FromSessionName(_detachedSessionPool, sessionName).WithTransaction(transactionId, transactionMode));
 }
Beispiel #4
0
 /// <summary>
 /// Creates a <see cref="PooledSession"/> with a known name and transaction ID/mode, with the client associated
 /// with this pool, but is otherwise not part of this pool. This method does not query the server for the session state.
 /// When the returned <see cref="PooledSession"/> is released, it will not become part of this pool, and the transaction
 /// will not be rolled back.
 /// </summary>
 /// <remarks>
 /// This is typically used for partitioned queries, where the same session is used across multiple machines, so should
 /// not be reused by the pool.
 /// </remarks>
 /// <param name="sessionName">The name of the transaction. Must not be null.</param>
 /// <param name="transactionId">The ID of the transaction. Must not be null.</param>
 /// <param name="transactionMode">The mode of the transaction.</param>
 /// <returns>A <see cref="PooledSession"/> for the given session and transaction.</returns>
 public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, ModeOneofCase transactionMode) =>
 CreateDetachedSession(sessionName, transactionId, transactionMode, readTimestamp: null);