class Cql::Protocol::QueryRequest
Constants
- EMPTY_LIST
- NO_FLAGS
- TYPE_CONVERTER
- TYPE_GUESSES
Attributes
consistency[R]
cql[R]
page_size[R]
paging_state[R]
serial_consistency[R]
type_hints[R]
values[R]
Public Class Methods
encode_values(buffer, values, hints)
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 75 def self.encode_values(buffer, values, hints) if values && values.size > 0 buffer.append_short(values.size) values.each_with_index do |value, index| type = (hints && hints[index]) || guess_type(value) raise EncodingError, "Could not guess a suitable type for #{value.inspect}" unless type TYPE_CONVERTER.to_bytes(buffer, type, value) end buffer else buffer.append_short(0) end end
new(cql, values, type_hints, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false)
click to toggle source
Calls superclass method
Cql::Protocol::Request::new
# File lib/cql/protocol/requests/query_request.rb, line 8 def initialize(cql, values, type_hints, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false) raise ArgumentError, %(No CQL given!) unless cql raise ArgumentError, %(No such consistency: #{consistency.inspect}) if consistency.nil? || !CONSISTENCIES.include?(consistency) raise ArgumentError, %(No such consistency: #{serial_consistency.inspect}) unless serial_consistency.nil? || CONSISTENCIES.include?(serial_consistency) raise ArgumentError, %(Bound values and type hints must have the same number of elements (got #{values.size} values and #{type_hints.size} hints)) if values && type_hints && values.size != type_hints.size raise ArgumentError, %(Paging state given but no page size) if paging_state && !page_size super(7, trace) @cql = cql @values = values || EMPTY_LIST @type_hints = type_hints || EMPTY_LIST @encoded_values = self.class.encode_values(CqlByteBuffer.new, @values, @type_hints) @consistency = consistency @serial_consistency = serial_consistency @page_size = page_size @paging_state = paging_state end
Private Class Methods
guess_type(value)
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 91 def self.guess_type(value) type = TYPE_GUESSES[value.class] if type == :map pair = value.first [type, guess_type(pair[0]), guess_type(pair[1])] elsif type == :list [type, guess_type(value.first)] elsif type == :set [type, guess_type(value.first)] else type end end
Public Instance Methods
eql?(rq)
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 51 def eql?(rq) self.class === rq && rq.cql == self.cql && rq.values == self.values && rq.type_hints == self.type_hints && rq.consistency == self.consistency && rq.serial_consistency == self.serial_consistency && rq.page_size == self.page_size && rq.paging_state == self.paging_state end
Also aliased as: ==
hash()
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 63 def hash h = 0xcbf29ce484222325 h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @cql.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @values.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @type_hints.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @consistency.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @serial_consistency.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @page_size.hash)) h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @paging_state.hash)) h end
to_s()
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 47 def to_s %(QUERY "#@cql" #{@consistency.to_s.upcase}) end
write(protocol_version, buffer)
click to toggle source
# File lib/cql/protocol/requests/query_request.rb, line 25 def write(protocol_version, buffer) buffer.append_long_string(@cql) buffer.append_consistency(@consistency) if protocol_version > 1 flags = 0 flags |= 0x04 if @page_size flags |= 0x08 if @paging_state flags |= 0x10 if @serial_consistency if @values && @values.size > 0 flags |= 0x01 buffer.append(flags.chr) buffer.append(@encoded_values) else buffer.append(flags.chr) end buffer.append_int(@page_size) if @page_size buffer.append_bytes(@paging_state) if @paging_state buffer.append_consistency(@serial_consistency) if @serial_consistency end buffer end