コード例 #1
0
ファイル: CqlCommand.cs プロジェクト: priyaparul/CqlSharp
        /// <summary>
        ///   Executes the query async.
        /// </summary>
        /// <typeparam name="T"> class representing the rows returned </typeparam>
        /// <returns> </returns>
        public async Task <CqlDataReader <T> > ExecuteReaderAsync <T>() where T : class, new()
        {
            var logger = _connection.LoggerManager.GetLogger("CqlSharp.CqlCommand.ExecuteReader");

            logger.LogVerbose("Waiting on Throttle");

            //wait until allowed
            _connection.Throttle.Wait();

            try
            {
                //capture current command state
                QueryExecutionState state = CaptureState();

                logger.LogVerbose("State captured, start executing query");

                ResultFrame result = await RunWithRetry(ExecuteInternalAsync, state, logger).ConfigureAwait(false);

                if (result.ResultOpcode != ResultOpcode.Rows)
                {
                    var ex = new CqlException("Can not create a DataReader for non-select query.");
                    logger.LogError("Error executing reader: {0}", ex);
                    throw ex;
                }
                var reader = new CqlDataReader <T>(result);

                logger.LogQuery("Query {0} returned {1} results", _cql, reader.Count);

                return(reader);
            }
            finally
            {
                _connection.Throttle.Release();
            }
        }
コード例 #2
0
ファイル: CqlCommand.cs プロジェクト: priyaparul/CqlSharp
        /// <summary>
        ///   Executes the non-query async.
        /// </summary>
        /// <returns> A ICqlQueryResult of type rows, Void, SchemaChange or SetKeySpace </returns>
        /// <exception cref="CqlException">Unexpected type of result received</exception>
        public async Task <ICqlQueryResult> ExecuteNonQueryAsync()
        {
            var logger = _connection.LoggerManager.GetLogger("CqlSharp.CqlCommand.ExecuteNonQuery");

            logger.LogVerbose("Waiting on Throttle");

            //wait until allowed
            _connection.Throttle.Wait();

            try
            {
                //capture current command state
                QueryExecutionState state = CaptureState();

                logger.LogVerbose("State captured, start executing query");

                ResultFrame result = await RunWithRetry(ExecuteInternalAsync, state, logger).ConfigureAwait(false);

                switch (result.ResultOpcode)
                {
                case ResultOpcode.Rows:
                    var reader = new CqlDataReader(result);
                    logger.LogQuery("Query {0} returned {1} results", _cql, reader.Count);
                    return(reader);

                case ResultOpcode.Void:
                    logger.LogQuery("Query {0} executed succesfully", _cql);
                    return(new CqlVoid {
                        TracingId = result.TracingId
                    });

                case ResultOpcode.SchemaChange:
                    logger.LogQuery("Query {0} resulted in {1}.{2} {3}", _cql, result.Keyspace, result.Table, result.Change);
                    return(new CqlSchemaChange
                    {
                        TracingId = result.TracingId,
                        Keyspace = result.Keyspace,
                        Table = result.Table,
                        Change = result.Change
                    });

                case ResultOpcode.SetKeyspace:
                    logger.LogQuery("Query {0} resulted in keyspace set to {1}", _cql, result.Keyspace);
                    return(new CqlSetKeyspace
                    {
                        TracingId = result.TracingId,
                        Keyspace = result.Keyspace
                    });

                default:
                    throw new CqlException("Unexpected type of result received");
                }
            }
            finally
            {
                _connection.Throttle.Release();
            }
        }