Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
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;
            }
        }