Exemple #1
0
        public BatchRequest(ProtocolVersion protocolVersion, BatchStatement statement, ConsistencyLevel consistency, IRequestOptions requestOptions)
        {
            if (!protocolVersion.SupportsBatch())
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }
            _type     = statement.BatchType;
            _requests = statement.Queries
                        .Select(q => q.CreateBatchRequest(protocolVersion))
                        .ToArray();
            Consistency = consistency;
            if (statement.IsTracing)
            {
                _headerFlags = FrameHeader.HeaderFlag.Tracing;
            }

            SerialConsistency = requestOptions.GetSerialConsistencyLevelOrDefault(statement);
            _batchFlags      |= QueryProtocolOptions.QueryFlags.WithSerialConsistency;

            _timestamp = BatchRequest.GetRequestTimestamp(protocolVersion, statement, requestOptions.TimestampGenerator);
            if (_timestamp != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }

            if (protocolVersion.SupportsKeyspaceInRequest() && statement.Keyspace != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithKeyspace;
                _keyspace    = statement.Keyspace;
            }
        }
Exemple #2
0
        private QueryFlags GetFlags(ProtocolVersion protocolVersion, bool isPrepared)
        {
            QueryFlags flags = 0;

            if (Values != null && Values.Length > 0)
            {
                flags |= QueryFlags.Values;
            }
            if (_skipMetadata)
            {
                flags |= QueryFlags.SkipMetadata;
            }
            if (PageSize != int.MaxValue && PageSize >= 0)
            {
                flags |= QueryFlags.PageSize;
            }
            if (PagingState != null)
            {
                flags |= QueryFlags.WithPagingState;
            }
            if (SerialConsistency != ConsistencyLevel.Any)
            {
                flags |= QueryFlags.WithSerialConsistency;
            }
            if (protocolVersion.SupportsTimestamp() && RawTimestamp != null)
            {
                flags |= QueryFlags.WithDefaultTimestamp;
            }
            if (ValueNames != null && ValueNames.Count > 0)
            {
                flags |= QueryFlags.WithNameForValues;
            }

            if (!isPrepared && protocolVersion.SupportsKeyspaceInRequest() && _keyspace != null)
            {
                // Providing keyspace is only useful for QUERY requests.
                // For EXECUTE requests, the keyspace will be the one from the prepared statement.
                flags |= QueryFlags.WithKeyspace;
            }

            return(flags);
        }