cassandra-driver 0.1.0.alpha1 → 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +4 -0
- data/README.md +117 -0
- data/lib/cassandra.rb +320 -0
- data/lib/cassandra/auth.rb +97 -0
- data/lib/cassandra/auth/providers.rb +16 -0
- data/lib/cassandra/auth/providers/password.rb +73 -0
- data/lib/cassandra/client.rb +144 -0
- data/lib/cassandra/client/batch.rb +212 -0
- data/lib/cassandra/client/client.rb +591 -0
- data/lib/cassandra/client/column_metadata.rb +54 -0
- data/lib/cassandra/client/connection_manager.rb +72 -0
- data/lib/cassandra/client/connector.rb +272 -0
- data/lib/cassandra/client/execute_options_decoder.rb +59 -0
- data/lib/cassandra/client/null_logger.rb +37 -0
- data/lib/cassandra/client/peer_discovery.rb +50 -0
- data/lib/cassandra/client/prepared_statement.rb +314 -0
- data/lib/cassandra/client/query_result.rb +230 -0
- data/lib/cassandra/client/request_runner.rb +71 -0
- data/lib/cassandra/client/result_metadata.rb +48 -0
- data/lib/cassandra/client/void_result.rb +78 -0
- data/lib/cassandra/cluster.rb +191 -0
- data/lib/cassandra/cluster/client.rb +767 -0
- data/lib/cassandra/cluster/connector.rb +231 -0
- data/lib/cassandra/cluster/control_connection.rb +420 -0
- data/lib/cassandra/cluster/options.rb +40 -0
- data/lib/cassandra/cluster/registry.rb +181 -0
- data/lib/cassandra/cluster/schema.rb +321 -0
- data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
- data/lib/cassandra/column.rb +92 -0
- data/lib/cassandra/compression.rb +66 -0
- data/lib/cassandra/compression/compressors/lz4.rb +72 -0
- data/lib/cassandra/compression/compressors/snappy.rb +66 -0
- data/lib/cassandra/driver.rb +86 -0
- data/lib/cassandra/errors.rb +79 -0
- data/lib/cassandra/execution/info.rb +51 -0
- data/lib/cassandra/execution/options.rb +77 -0
- data/lib/cassandra/execution/trace.rb +152 -0
- data/lib/cassandra/future.rb +675 -0
- data/lib/cassandra/host.rb +75 -0
- data/lib/cassandra/keyspace.rb +120 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing.rb +112 -0
- data/lib/cassandra/load_balancing/policies.rb +18 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +95 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
- data/lib/cassandra/protocol.rb +93 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
- data/lib/cassandra/protocol/frame_decoder.rb +128 -0
- data/lib/cassandra/protocol/frame_encoder.rb +48 -0
- data/lib/cassandra/protocol/request.rb +38 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
- data/lib/cassandra/protocol/requests/query_request.rb +153 -0
- data/lib/cassandra/protocol/requests/register_request.rb +38 -0
- data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
- data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
- data/lib/cassandra/protocol/response.rb +38 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
- data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
- data/lib/cassandra/protocol/responses/error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
- data/lib/cassandra/protocol/responses/result_response.rb +48 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
- data/lib/cassandra/protocol/type_converter.rb +384 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection/policies/constant.rb +48 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/result.rb +215 -0
- data/lib/cassandra/retry.rb +142 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry/policies/default.rb +47 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/session.rb +195 -0
- data/lib/cassandra/statement.rb +22 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/statements/batch.rb +95 -0
- data/lib/cassandra/statements/bound.rb +46 -0
- data/lib/cassandra/statements/prepared.rb +59 -0
- data/lib/cassandra/statements/simple.rb +58 -0
- data/lib/cassandra/statements/void.rb +33 -0
- data/lib/cassandra/table.rb +254 -0
- data/lib/cassandra/time_uuid.rb +141 -0
- data/lib/cassandra/util.rb +169 -0
- data/lib/cassandra/uuid.rb +104 -0
- data/lib/cassandra/version.rb +17 -1
- metadata +134 -8
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
# @private
|
22
|
+
class FrameEncoder
|
23
|
+
def initialize(protocol_version=1, compressor=nil)
|
24
|
+
@protocol_version = protocol_version
|
25
|
+
@compressor = compressor
|
26
|
+
end
|
27
|
+
|
28
|
+
def encode_frame(request, stream_id=0, buffer=nil)
|
29
|
+
raise InvalidStreamIdError, 'The stream ID must be between 0 and 127' unless 0 <= stream_id && stream_id < 128
|
30
|
+
buffer ||= CqlByteBuffer.new
|
31
|
+
flags = request.trace? ? 2 : 0
|
32
|
+
body = request.write(@protocol_version, CqlByteBuffer.new)
|
33
|
+
if @compressor && request.compressable? && @compressor.compress?(body)
|
34
|
+
flags |= 1
|
35
|
+
body = @compressor.compress(body)
|
36
|
+
end
|
37
|
+
header = [@protocol_version, flags, stream_id, request.opcode, body.bytesize]
|
38
|
+
buffer << header.pack(Formats::HEADER_FORMAT)
|
39
|
+
buffer << body
|
40
|
+
buffer
|
41
|
+
end
|
42
|
+
|
43
|
+
def change_stream_id(new_stream_id, buffer, offset=0)
|
44
|
+
buffer.update(offset + 2, new_stream_id.chr)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class Request
|
22
|
+
attr_reader :opcode, :trace
|
23
|
+
|
24
|
+
def initialize(opcode, trace=false)
|
25
|
+
@opcode = opcode
|
26
|
+
@trace = trace
|
27
|
+
end
|
28
|
+
|
29
|
+
def trace?
|
30
|
+
@trace
|
31
|
+
end
|
32
|
+
|
33
|
+
def compressable?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class AuthResponseRequest < Request
|
22
|
+
attr_reader :token
|
23
|
+
|
24
|
+
def initialize(token)
|
25
|
+
super(0x0f)
|
26
|
+
@token = token
|
27
|
+
end
|
28
|
+
|
29
|
+
def write(protocol_version, buffer)
|
30
|
+
buffer.append_bytes(@token)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
%(AUTH_RESPONSE #{@token.bytesize})
|
35
|
+
end
|
36
|
+
|
37
|
+
def eql?(other)
|
38
|
+
self.token == other.token
|
39
|
+
end
|
40
|
+
alias_method :==, :eql?
|
41
|
+
|
42
|
+
def hash
|
43
|
+
@token.hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class BatchRequest < Request
|
22
|
+
LOGGED_TYPE = 0
|
23
|
+
UNLOGGED_TYPE = 1
|
24
|
+
COUNTER_TYPE = 2
|
25
|
+
|
26
|
+
attr_reader :type, :part_count
|
27
|
+
attr_accessor :consistency, :retries
|
28
|
+
|
29
|
+
def initialize(type, consistency, trace=false)
|
30
|
+
super(0x0D, trace)
|
31
|
+
@type = type
|
32
|
+
@part_count = 0
|
33
|
+
@encoded_queries = CqlByteBuffer.new
|
34
|
+
@consistency = consistency
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_query(cql, values=nil, type_hints=nil)
|
38
|
+
@encoded_queries.append(QUERY_KIND)
|
39
|
+
@encoded_queries.append_long_string(cql)
|
40
|
+
QueryRequest.encode_values(@encoded_queries, values, type_hints)
|
41
|
+
@part_count += 1
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_prepared(id, metadata, values)
|
46
|
+
@encoded_queries.append(PREPARED_KIND)
|
47
|
+
@encoded_queries.append_short_bytes(id)
|
48
|
+
ExecuteRequest.encode_values(@encoded_queries, metadata, values)
|
49
|
+
@part_count += 1
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def write(protocol_version, buffer)
|
54
|
+
buffer.append(@type.chr)
|
55
|
+
buffer.append_short(@part_count)
|
56
|
+
buffer.append(@encoded_queries)
|
57
|
+
buffer.append_consistency(@consistency)
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s
|
61
|
+
type_str = case @type
|
62
|
+
when LOGGED_TYPE then 'LOGGED'
|
63
|
+
when UNLOGGED_TYPE then 'UNLOGGED'
|
64
|
+
when COUNTER_TYPE then 'COUNTER'
|
65
|
+
end
|
66
|
+
%(BATCH #{type_str} #{@part_count} #{@consistency.to_s.upcase})
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
TYPE_CONVERTER = TypeConverter.new
|
72
|
+
QUERY_KIND = "\x00".freeze
|
73
|
+
PREPARED_KIND = "\x01".freeze
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class CredentialsRequest < Request
|
22
|
+
attr_reader :credentials
|
23
|
+
|
24
|
+
def initialize(credentials)
|
25
|
+
super(4)
|
26
|
+
@credentials = credentials.dup.freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
def write(protocol_version, buffer)
|
30
|
+
buffer.append_string_map(@credentials)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
%(CREDENTIALS #{@credentials})
|
35
|
+
end
|
36
|
+
|
37
|
+
def eql?(rq)
|
38
|
+
self.class === rq && rq.credentials.eql?(@credentials)
|
39
|
+
end
|
40
|
+
alias_method :==, :eql?
|
41
|
+
|
42
|
+
def hash
|
43
|
+
@h ||= @credentials.hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class ExecuteRequest < Request
|
22
|
+
attr_reader :metadata, :values, :request_metadata, :serial_consistency, :page_size, :paging_state
|
23
|
+
attr_accessor :consistency, :retries, :id
|
24
|
+
|
25
|
+
def initialize(id, metadata, values, request_metadata, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false)
|
26
|
+
raise ArgumentError, "Metadata for #{metadata.size} columns, but #{values.size} values given" if metadata.size != values.size
|
27
|
+
raise ArgumentError, %(No such consistency: #{consistency.inspect}) if consistency.nil? || !CONSISTENCIES.include?(consistency)
|
28
|
+
raise ArgumentError, %(No such consistency: #{serial_consistency.inspect}) unless serial_consistency.nil? || CONSISTENCIES.include?(serial_consistency)
|
29
|
+
raise ArgumentError, %(Paging state given but no page size) if paging_state && !page_size
|
30
|
+
super(10, trace)
|
31
|
+
@id = id
|
32
|
+
@metadata = metadata
|
33
|
+
@values = values
|
34
|
+
@request_metadata = request_metadata
|
35
|
+
@consistency = consistency
|
36
|
+
@serial_consistency = serial_consistency
|
37
|
+
@page_size = page_size
|
38
|
+
@paging_state = paging_state
|
39
|
+
@encoded_values = self.class.encode_values(CqlByteBuffer.new, @metadata, @values)
|
40
|
+
end
|
41
|
+
|
42
|
+
def write(protocol_version, buffer)
|
43
|
+
buffer.append_short_bytes(@id)
|
44
|
+
if protocol_version > 1
|
45
|
+
buffer.append_consistency(@consistency)
|
46
|
+
flags = 0
|
47
|
+
flags |= 0x01 if @values.size > 0
|
48
|
+
flags |= 0x02 unless @request_metadata
|
49
|
+
flags |= 0x04 if @page_size
|
50
|
+
flags |= 0x08 if @paging_state
|
51
|
+
flags |= 0x10 if @serial_consistency
|
52
|
+
buffer.append(flags.chr)
|
53
|
+
if @values.size > 0
|
54
|
+
buffer.append(@encoded_values)
|
55
|
+
end
|
56
|
+
buffer.append_int(@page_size) if @page_size
|
57
|
+
buffer.append_bytes(@paging_state) if @paging_state
|
58
|
+
buffer.append_consistency(@serial_consistency) if @serial_consistency
|
59
|
+
else
|
60
|
+
buffer.append(@encoded_values)
|
61
|
+
buffer.append_consistency(@consistency)
|
62
|
+
end
|
63
|
+
buffer
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
id = @id.each_byte.map { |x| x.to_s(16) }.join('')
|
68
|
+
%(EXECUTE #{id} #@values #{@consistency.to_s.upcase})
|
69
|
+
end
|
70
|
+
|
71
|
+
def eql?(rq)
|
72
|
+
self.class === rq && rq.id == self.id && rq.metadata == self.metadata && rq.values == self.values && rq.consistency == self.consistency && rq.serial_consistency == self.serial_consistency && rq.page_size == self.page_size && rq.paging_state == self.paging_state
|
73
|
+
end
|
74
|
+
alias_method :==, :eql?
|
75
|
+
|
76
|
+
def hash
|
77
|
+
@h ||= begin
|
78
|
+
h = 0
|
79
|
+
h = ((h & 33554431) * 31) ^ @id.hash
|
80
|
+
h = ((h & 33554431) * 31) ^ @metadata.hash
|
81
|
+
h = ((h & 33554431) * 31) ^ @values.hash
|
82
|
+
h = ((h & 33554431) * 31) ^ @consistency.hash
|
83
|
+
h = ((h & 33554431) * 31) ^ @serial_consistency.hash
|
84
|
+
h = ((h & 33554431) * 31) ^ @page_size.hash
|
85
|
+
h = ((h & 33554431) * 31) ^ @paging_state.hash
|
86
|
+
h
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.encode_values(buffer, metadata, values)
|
91
|
+
buffer.append_short(metadata.size)
|
92
|
+
metadata.each_with_index do |(_, _, _, type), index|
|
93
|
+
TYPE_CONVERTER.to_bytes(buffer, type, values[index])
|
94
|
+
end
|
95
|
+
buffer
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
TYPE_CONVERTER = TypeConverter.new
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class OptionsRequest < Request
|
22
|
+
def initialize
|
23
|
+
super(5)
|
24
|
+
end
|
25
|
+
|
26
|
+
def compressable?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
|
30
|
+
def write(protocol_version, buffer)
|
31
|
+
buffer
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
%(OPTIONS)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2014 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
module Protocol
|
21
|
+
class PrepareRequest < Request
|
22
|
+
attr_reader :cql
|
23
|
+
attr_accessor :consistency, :retries
|
24
|
+
|
25
|
+
def initialize(cql, trace=false)
|
26
|
+
raise ArgumentError, 'No CQL given!' unless cql
|
27
|
+
super(9, trace)
|
28
|
+
@cql = cql
|
29
|
+
@consistency = :one
|
30
|
+
end
|
31
|
+
|
32
|
+
def write(protocol_version, buffer)
|
33
|
+
buffer.append_long_string(@cql)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
%(PREPARE "#@cql")
|
38
|
+
end
|
39
|
+
|
40
|
+
def eql?(rq)
|
41
|
+
self.class === rq && rq.cql == self.cql
|
42
|
+
end
|
43
|
+
alias_method :==, :eql?
|
44
|
+
|
45
|
+
def hash
|
46
|
+
@h ||= @cql.hash
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|