Example #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;
            }
        }
Example #2
0
        internal static QueryProtocolOptions CreateFromQuery(
            ProtocolVersion protocolVersion, Statement query, IRequestOptions requestOptions)
        {
            if (query == null)
            {
                return(Default);
            }
            var  consistency = query.ConsistencyLevel ?? requestOptions.ConsistencyLevel;
            var  pageSize    = query.PageSize != 0 ? query.PageSize : requestOptions.PageSize;
            long?timestamp   = null;

            if (query.Timestamp != null)
            {
                timestamp = TypeSerializer.SinceUnixEpoch(query.Timestamp.Value).Ticks / 10;
            }
            else if (protocolVersion.SupportsTimestamp())
            {
                timestamp = requestOptions.TimestampGenerator.Next();
                if (timestamp == long.MinValue)
                {
                    timestamp = null;
                }
            }

            return(new QueryProtocolOptions(
                       consistency,
                       query.QueryValues,
                       query.SkipMetadata,
                       pageSize,
                       query.PagingState,
                       requestOptions.GetSerialConsistencyLevelOrDefault(query),
                       timestamp,
                       query.Keyspace));
        }
Example #3
0
        public BatchRequest(
            ISerializer serializer,
            IDictionary <string, byte[]> payload,
            BatchStatement statement,
            ConsistencyLevel consistency,
            IRequestOptions requestOptions) : base(serializer, statement.IsTracing, payload)
        {
            if (!serializer.ProtocolVersion.SupportsBatch())
            {
                throw new NotSupportedException("Batch request is supported in C* >= 2.0.x");
            }

            if (statement.Timestamp != null && !serializer.ProtocolVersion.SupportsTimestamp())
            {
                throw new NotSupportedException(
                          "Timestamp for BATCH request is supported in Cassandra 2.1 or above.");
            }

            _type     = statement.BatchType;
            _requests = statement.Queries
                        .Select(q => q.CreateBatchRequest(serializer))
                        .ToArray();
            Consistency = consistency;

            if (!serializer.ProtocolVersion.SupportsBatchFlags())
            {
                // if flags are not supported, then the following additional parameters aren't either
                return;
            }

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

            if (serializer.ProtocolVersion.SupportsTimestamp())
            {
                _timestamp = BatchRequest.GetRequestTimestamp(statement, requestOptions.TimestampGenerator);
            }

            if (_timestamp != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithDefaultTimestamp;
            }

            _keyspace = statement.Keyspace;
            if (serializer.ProtocolVersion.SupportsKeyspaceInRequest() && _keyspace != null)
            {
                _batchFlags |= QueryProtocolOptions.QueryFlags.WithKeyspace;
            }
        }