Esempio n. 1
0
        public IAsyncResult BeginExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata,
                                              AsyncCallback callback, object state, object owner,
                                              bool isTracing, QueryProtocolOptions queryProtocolOptions, ConsistencyLevel?consistency = null)
        {
            AsyncResult <IOutput> jar = SetupJob(streamId, callback, state, owner, "EXECUTE");

            BeginJob(jar, SetupKeyspace(jar, SetupPreparedQuery(jar, id, cql, () =>
            {
                Evaluate(new ExecuteRequest(jar.StreamId, id, metadata, isTracing, queryProtocolOptions, consistency), jar.StreamId,
                         frame2 =>
                {
                    AbstractResponse response = FrameParser.Parse(frame2);
                    if (response is ResultResponse)
                    {
                        JobFinished(jar, (response as ResultResponse).Output);
                    }
                    else
                    {
                        _protocolErrorHandlerAction(new ErrorActionParam
                        {
                            AbstractResponse = response,
                            Jar = jar
                        });
                    }
                });
            })));

            return(jar);
        }
Esempio n. 2
0
        internal override IQueryRequest CreateBatchRequest(int protocolVersion)
        {
            //Uses the default query options as the individual options of the query will be ignored
            var options = QueryProtocolOptions.CreateFromQuery(this, new QueryOptions());

            return(new ExecuteRequest(protocolVersion, PreparedStatement.Id, PreparedStatement.Metadata, IsTracing, options));
        }
Esempio n. 3
0
        public ExecuteRequest(int protocolVersion, byte[] id, RowSetMetadata metadata, bool tracingEnabled, QueryProtocolOptions queryOptions)
        {
            ProtocolVersion = protocolVersion;
            if (metadata != null && queryOptions.Values.Length != metadata.Columns.Length)
            {
                throw new ArgumentException("Number of values does not match with number of prepared statement markers(?).", "values");
            }
            _id = id;
            _metadata = metadata;
            _queryOptions = queryOptions;
            if (tracingEnabled)
            {
                _flags = 0x02;
            }

            if (Consistency.IsSerialConsistencyLevel())
            {
                throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
            }
            if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
            {
                throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
            }
            if (queryOptions.Timestamp != null && protocolVersion < 3)
            {
                throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 or above.");
            }
        }
Esempio n. 4
0
 public QueryRequest(int protocolVersion, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryOptions)
 {
     //TODO: Replace constructor parameters with IStatement
     ProtocolVersion = protocolVersion;
     _cqlQuery       = cqlQuery;
     _queryOptions   = queryOptions;
     if (tracingEnabled)
     {
         _headerFlags = 0x02;
     }
     if (queryOptions == null)
     {
         throw new ArgumentNullException("queryOptions");
     }
     if (Consistency.IsSerialConsistencyLevel())
     {
         throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
     }
     if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
     {
         throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
     }
     if (protocolVersion < 3)
     {
         //Features supported in protocol v3 and above
         if (queryOptions.Timestamp != null)
         {
             throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 and above.");
         }
         if (queryOptions.ValueNames != null && queryOptions.ValueNames.Count > 0)
         {
             throw new NotSupportedException("Query parameter names feature is supported in Cassandra 2.1 and above.");
         }
     }
 }
 public QueryRequest(int protocolVersion, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryOptions)
 {
     //TODO: Replace constructor parameters with IStatement
     ProtocolVersion = protocolVersion;
     _cqlQuery = cqlQuery;
     _queryOptions = queryOptions;
     if (tracingEnabled)
     {
         _headerFlags = FrameHeader.HeaderFlag.Tracing;
     }
     if (queryOptions == null)
     {
         throw new ArgumentNullException("queryOptions");
     }
     if (Consistency.IsSerialConsistencyLevel())
     {
         throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
     }
     if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
     {
         throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
     }
     if (protocolVersion < 3)
     {
         //Features supported in protocol v3 and above
         if (queryOptions.Timestamp != null)
         {
             throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 and above.");
         }
         if (queryOptions.ValueNames != null && queryOptions.ValueNames.Count > 0)
         {
             throw new NotSupportedException("Query parameter names feature is supported in Cassandra 2.1 and above.");
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Gets the Request to send to a cassandra node based on the statement type
        /// </summary>
        internal IRequest GetRequest(IStatement statement)
        {
            var defaultConsistency = Configuration.QueryOptions.GetConsistencyLevel();

            if (statement is RegularStatement)
            {
                var s       = (RegularStatement)statement;
                var options = QueryProtocolOptions.CreateFromQuery(s, defaultConsistency);
                options.ValueNames = s.QueryValueNames;
                return(new QueryRequest(BinaryProtocolVersion, s.QueryString, s.IsTracing, options));
            }
            if (statement is BoundStatement)
            {
                var s       = (BoundStatement)statement;
                var options = QueryProtocolOptions.CreateFromQuery(s, defaultConsistency);
                return(new ExecuteRequest(BinaryProtocolVersion, s.PreparedStatement.Id, null, s.IsTracing, options));
            }
            if (statement is BatchStatement)
            {
                var s           = (BatchStatement)statement;
                var consistency = defaultConsistency;
                if (s.ConsistencyLevel != null)
                {
                    consistency = s.ConsistencyLevel.Value;
                }
                return(new BatchRequest(BinaryProtocolVersion, s, consistency));
            }
            throw new NotSupportedException("Statement of type " + statement.GetType().FullName + " not supported");
        }
Esempio n. 7
0
        public ExecuteRequest(int protocolVersion, byte[] id, RowSetMetadata metadata, bool tracingEnabled, QueryProtocolOptions queryOptions)
        {
            ProtocolVersion = protocolVersion;
            if (metadata != null && queryOptions.Values.Length != metadata.Columns.Length)
            {
                throw new ArgumentException("Number of values does not match with number of prepared statement markers(?).", "values");
            }
            _id           = id;
            _metadata     = metadata;
            _queryOptions = queryOptions;
            if (tracingEnabled)
            {
                _headerFlags = FrameHeader.HeaderFlag.Tracing;
            }

            if (Consistency.IsSerialConsistencyLevel())
            {
                throw new RequestInvalidException("Serial consistency specified as a non-serial one.");
            }
            if (queryOptions.SerialConsistency != ConsistencyLevel.Any && queryOptions.SerialConsistency.IsSerialConsistencyLevel() == false)
            {
                throw new RequestInvalidException("Non-serial consistency specified as a serial one.");
            }
            if (queryOptions.Timestamp != null && protocolVersion < 3)
            {
                throw new NotSupportedException("Timestamp for query is supported in Cassandra 2.1 or above.");
            }
        }
Esempio n. 8
0
        internal override IQueryRequest CreateBatchRequest(ISerializer serializer)
        {
            // Use the default query options as the individual options of the query will be ignored
            var options = QueryProtocolOptions.CreateForBatchItem(this);

            return(new QueryRequest(serializer, QueryString, options, IsTracing, null));
        }
        internal override IQueryRequest CreateBatchRequest(ProtocolVersion protocolVersion)
        {
            // Use the default query options as the individual options of the query will be ignored
            var options = QueryProtocolOptions.CreateForBatchItem(this);

            return(new QueryRequest(protocolVersion, QueryString, IsTracing, options));
        }
Esempio n. 10
0
        internal override IQueryRequest CreateBatchRequest(int protocolVersion)
        {
            //The consistency of each query will be not used.
            var options = QueryProtocolOptions.CreateFromQuery(this, Cassandra.ConsistencyLevel.Any);

            return(new ExecuteRequest(protocolVersion, PreparedStatement.Id, PreparedStatement.Metadata, IsTracing, options));
        }
Esempio n. 11
0
 /// <inheritdoc />
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
     _pagingState = queryProtocolOptions.PagingState;
     _values = queryProtocolOptions.Values;
     _consistency = queryProtocolOptions.Consistency;
     _pageSize = queryProtocolOptions.PageSize;
     _serialConsistency = queryProtocolOptions.SerialConsistency;
 }
Esempio n. 12
0
        internal override IQueryRequest CreateBatchRequest(ProtocolVersion protocolVersion)
        {
            // Use the default query options as the individual options of the query will be ignored
            var options = QueryProtocolOptions.CreateForBatchItem(this);

            return(new ExecuteRequest(protocolVersion, PreparedStatement.Id, PreparedStatement.Metadata,
                                      PreparedStatement.ResultMetadataId, IsTracing, options));
        }
Esempio n. 13
0
 internal SimpleStatement(string query, QueryProtocolOptions queryProtocolOptions)
     : base(queryProtocolOptions)
 {
     _query = query;
     SetConsistencyLevel(queryProtocolOptions.Consistency);
     SetSerialConsistencyLevel(queryProtocolOptions.SerialConsistency);
     SetPageSize(queryProtocolOptions.PageSize);
 }
Esempio n. 14
0
 /// <inheritdoc />
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
     _pagingState       = queryProtocolOptions.PagingState;
     _values            = queryProtocolOptions.Values;
     _consistency       = queryProtocolOptions.Consistency;
     _pageSize          = queryProtocolOptions.PageSize;
     _serialConsistency = queryProtocolOptions.SerialConsistency;
 }
Esempio n. 15
0
 internal SimpleStatement(string query, QueryProtocolOptions queryProtocolOptions)
     : base(queryProtocolOptions)
 {
     _query = query;
     SetConsistencyLevel(queryProtocolOptions.Consistency);
     SetSerialConsistencyLevel(queryProtocolOptions.SerialConsistency);
     SetPageSize(queryProtocolOptions.PageSize);
 }
Esempio n. 16
0
        internal override IQueryRequest CreateBatchRequest(ISerializer serializer)
        {
            // Use the default query options as the individual options of the query will be ignored
            var options = QueryProtocolOptions.CreateForBatchItem(this);

            return(new ExecuteRequest(
                       serializer,
                       PreparedStatement.Id,
                       PreparedStatement.Variables,
                       PreparedStatement.ResultMetadata,
                       options,
                       IsTracing,
                       null));
        }
Esempio n. 17
0
        internal static QueryProtocolOptions CreateFromQuery(Statement query, ConsistencyLevel defaultConsistencyLevel)
        {
            if (query == null)
            {
                return(Default);
            }
            var options = new QueryProtocolOptions(
                query.ConsistencyLevel.HasValue ? query.ConsistencyLevel.Value : defaultConsistencyLevel,
                query.QueryValues,
                query.SkipMetadata, query.PageSize, query.PagingState, query.SerialConsistencyLevel)
            {
                Timestamp = query.Timestamp
            };

            return(options);
        }
Esempio n. 18
0
        internal IAsyncResult BeginQuery(RegularStatement query, AsyncCallback callback, object state, object tag = null)
        {
            var options      = QueryProtocolOptions.CreateFromQuery(query, Cluster.Configuration.QueryOptions.GetConsistencyLevel());
            var longActionAc = new AsyncResult <RowSet>(-1, callback, state, this, "SessionQuery", query, tag);
            var handler      = new QueryRequestHandler()
            {
                Consistency          = options.Consistency,
                CqlQuery             = query.QueryString,
                Statement            = query,
                QueryProtocolOptions = options,
                LongActionAc         = longActionAc,
                IsTracing            = query.IsTracing
            };

            ExecConn(handler, false);

            return(longActionAc);
        }
Esempio n. 19
0
        public ExecuteRequest(int streamId, byte[] id, RowSetMetadata metadata, bool tracingEnabled, QueryProtocolOptions queryProtocolOptions,
                              ConsistencyLevel?consistency = null)
        {
            if (queryProtocolOptions.Values.Length != metadata.Columns.Length)
            {
                throw new ArgumentException("Number of values does not match with number of prepared statement markers(?).", "values");
            }

            _consistency          = consistency;
            _streamId             = streamId;
            _id                   = id;
            _metadata             = metadata;
            _queryProtocolOptions = queryProtocolOptions;
            if (tracingEnabled)
            {
                _flags = 0x02;
            }
        }
Esempio n. 20
0
        internal IAsyncResult BeginExecuteQuery(BoundStatement statement, AsyncCallback callback, object state, object tag = null)
        {
            var options = QueryProtocolOptions.CreateFromQuery(statement, Cluster.Configuration.QueryOptions.GetConsistencyLevel());
            var queryId = statement.PreparedStatement.Id;

            var longActionAc = new AsyncResult <RowSet>(-1, callback, state, this, "SessionExecuteQuery", statement, tag);
            var handler      = new ExecuteQueryRequestHandler()
            {
                Consistency          = options.Consistency,
                Id                   = queryId,
                CqlQuery             = GetPreparedQuery(queryId),
                Metadata             = statement.PreparedStatement.Metadata,
                QueryProtocolOptions = options,
                Statement            = statement,
                LongActionAc         = longActionAc,
                IsTracing            = statement.IsTracing
            };

            ExecConn(handler, false);
            return(longActionAc);
        }
Esempio n. 21
0
        internal static QueryProtocolOptions CreateFromQuery(Statement query, QueryOptions queryOptions)
        {
            if (query == null)
            {
                return(Default);
            }
            var consistency = query.ConsistencyLevel ?? queryOptions.GetConsistencyLevel();
            var pageSize    = query.PageSize != 0 ? query.PageSize : queryOptions.GetPageSize();
            var options     = new QueryProtocolOptions(
                consistency,
                query.QueryValues,
                query.SkipMetadata,
                pageSize,
                query.PagingState,
                query.SerialConsistencyLevel)
            {
                Timestamp = query.Timestamp
            };

            return(options);
        }
Esempio n. 22
0
        public IAsyncResult BeginQuery(int streamId, string cqlQuery, AsyncCallback callback, object state, object owner, bool tracingEnabled,
                                       QueryProtocolOptions queryPrtclOptions, ConsistencyLevel?consistency = null)
        {
            AsyncResult <IOutput> jar = SetupJob(streamId, callback, state, owner, "QUERY");

            BeginJob(jar, SetupKeyspace(jar, () =>
            {
                Evaluate(new QueryRequest(jar.StreamId, cqlQuery, tracingEnabled, queryPrtclOptions, consistency), jar.StreamId, frame2 =>
                {
                    AbstractResponse response = FrameParser.Parse(frame2);
                    if (response is ResultResponse)
                    {
                        JobFinished(jar, (response as ResultResponse).Output);
                    }
                    else
                    {
                        _protocolErrorHandlerAction(new ErrorActionParam {
                            AbstractResponse = response, Jar = jar
                        });
                    }
                });
            }));
            return(jar);
        }
Esempio n. 23
0
 // ReSharper disable once UnusedParameter.Local
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
     //the unused parameter is maintained for backward compatibility
 }
 internal static QueryProtocolOptions CreateFromQuery(Statement query, ConsistencyLevel defaultConsistencyLevel)
 {
     if (query == null)
     {
         return Default;
     }
     var options = new QueryProtocolOptions(
         query.ConsistencyLevel.HasValue ? query.ConsistencyLevel.Value : defaultConsistencyLevel,
         query.QueryValues,
         query.SkipMetadata, query.PageSize, query.PagingState, query.SerialConsistencyLevel)
     {
         Timestamp = query.Timestamp
     };
     return options;
 }
Esempio n. 25
0
 protected RegularStatement(QueryProtocolOptions queryProtocolOptions) : base(queryProtocolOptions)
 {
 }
 internal static QueryProtocolOptions CreateFromQuery(Statement query, QueryOptions queryOptions)
 {
     if (query == null)
     {
         return Default;
     }
     var consistency = query.ConsistencyLevel ?? queryOptions.GetConsistencyLevel();
     var pageSize = query.PageSize != 0 ? query.PageSize : queryOptions.GetPageSize();
     var options = new QueryProtocolOptions(
         consistency,
         query.QueryValues,
         query.SkipMetadata, 
         pageSize, 
         query.PagingState, 
         query.SerialConsistencyLevel)
     {
         Timestamp = query.Timestamp
     };
     return options;
 }
Esempio n. 27
0
 internal override IQueryRequest CreateBatchRequest()
 {
     return(new QueryRequest(-1, QueryString, IsTracing, QueryProtocolOptions.CreateFromQuery(this, Cassandra.ConsistencyLevel.Any)));
     // this Cassandra.ConsistencyLevel.Any is not used due fact that BATCH got own CL
 }
Esempio n. 28
0
 internal override IQueryRequest CreateBatchRequest()
 {
     return(new ExecuteRequest(-1, PreparedStatement.Id, PreparedStatement.Metadata, IsTracing,
                               QueryProtocolOptions.CreateFromQuery(this, Cassandra.ConsistencyLevel.Any)));
     // this Cassandra.ConsistencyLevel.Any is not used due fact that BATCH got own CL
 }
Esempio n. 29
0
 // ReSharper disable once UnusedParameter.Local
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
     //the unused parameter is maintained for backward compatibility
 }
Esempio n. 30
0
 /// <inheritdoc />
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
 }
Esempio n. 31
0
 public IOutput ExecuteQuery(int streamId, byte[] id, string cql, RowSetMetadata metadata,
                             bool isTracing, QueryProtocolOptions queryPrtclOptions, ConsistencyLevel?consistency)
 {
     return(EndExecuteQuery(BeginExecuteQuery(streamId, id, cql, metadata, null, null, this, isTracing, queryPrtclOptions, consistency),
                            this));
 }
Esempio n. 32
0
 /// <inheritdoc />
 protected Statement(QueryProtocolOptions queryProtocolOptions)
 {
 }
Esempio n. 33
0
 public IOutput Query(int streamId, string cqlQuery, bool tracingEnabled, QueryProtocolOptions queryPrtclOptions,
                      ConsistencyLevel?consistency = null)
 {
     return(EndQuery(BeginQuery(streamId, cqlQuery, null, null, this, tracingEnabled, queryPrtclOptions, consistency), this));
 }
Esempio n. 34
0
 protected RegularStatement(QueryProtocolOptions queryProtocolOptions)
     : base(queryProtocolOptions)
 {
 }