Exemplo n.º 1
0
        public async Task <T> RunAsync <T>(IQueryConverter queryConverter, IScalarQuery <T> queryObject, CancellationToken cancellationToken)
        {
            var query = new Spec.Query();

            query.token = GetNextToken();
            query.type  = Spec.Query.QueryType.START;
            query.query = queryObject.GenerateTerm(queryConverter);

            var response = await InternalRunQuery(query, cancellationToken);

            switch (response.type)
            {
            case Response.ResponseType.SUCCESS_SEQUENCE:
            case Response.ResponseType.SUCCESS_ATOM:
                if (response.response.Count != 1)
                {
                    throw new RethinkDbRuntimeException(String.Format("Expected 1 object, received {0}", response.response.Count));
                }
                return(queryConverter.Get <T>().ConvertDatum(response.response[0]));

            case Response.ResponseType.CLIENT_ERROR:
            case Response.ResponseType.COMPILE_ERROR:
                throw new RethinkDbInternalErrorException("Client error: " + response.response[0].r_str);

            case Response.ResponseType.RUNTIME_ERROR:
                throw new RethinkDbRuntimeException("Runtime error: " + response.response[0].r_str);

            default:
                throw new RethinkDbInternalErrorException("Unhandled response type: " + response.type);
            }
        }
Exemplo n.º 2
0
 public Task <T> RunAsync <T>(IQueryConverter queryConverter, IScalarQuery <T> queryObject, CancellationToken cancellationToken)
 {
     if (this.disposed)
     {
         throw new ObjectDisposedException("PooledConnectionWrapper");
     }
     return(this.innerConnection.RunAsync <T>(queryConverter, queryObject, cancellationToken));
 }
Exemplo n.º 3
0
 public static Task <T> RunAsync <T>(this IConnection connection, IScalarQuery <T> queryObject, IQueryConverter queryConverter = null, CancellationToken?cancellationToken = null)
 {
     if (queryConverter == null)
     {
         queryConverter = connection.QueryConverter;
     }
     if (!cancellationToken.HasValue)
     {
         cancellationToken = new CancellationTokenSource(connection.QueryTimeout).Token;
     }
     return(connection.RunAsync <T>(queryConverter, queryObject, cancellationToken.Value));
 }
Exemplo n.º 4
0
 public static Task <T> RunAsync <T>(this IConnection connection, IScalarQuery <T> queryObject, IDatumConverterFactory datumConverterFactory = null, CancellationToken?cancellationToken = null)
 {
     if (datumConverterFactory == null)
     {
         datumConverterFactory = connection.DatumConverterFactory;
     }
     if (!cancellationToken.HasValue)
     {
         cancellationToken = new CancellationTokenSource(connection.QueryTimeout).Token;
     }
     return(connection.RunAsync <T>(datumConverterFactory, queryObject, cancellationToken.Value));
 }
 public Task <T> RunAsync <T>(IQueryConverter queryConverter, IScalarQuery <T> queryObject, CancellationToken cancellationToken)
 {
     return(RetryRunAsync(() => this.innerConnection.RunAsync <T>(queryConverter, queryObject, cancellationToken)));
 }
 public static T Run <T>(this IConnection connection, IScalarQuery <T> queryObject, IQueryConverter queryConverter = null, CancellationToken?cancellationToken = null)
 {
     return(TaskUtilities.ExecuteSynchronously(() => connection.RunAsync <T>(queryObject, queryConverter, cancellationToken)));
 }
 public Task <T> RunAsync <T>(IDatumConverterFactory datumConverterFactory, IScalarQuery <T> queryObject, CancellationToken cancellationToken)
 {
     return(RetryRunAsync(() => this.innerConnection.RunAsync <T>(datumConverterFactory, queryObject, cancellationToken)));
 }