cassandra-driver 1.0.0.beta.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +4 -0
  3. data/README.md +125 -0
  4. data/lib/cassandra/auth/providers/password.rb +73 -0
  5. data/lib/cassandra/auth/providers.rb +16 -0
  6. data/lib/cassandra/auth.rb +97 -0
  7. data/lib/cassandra/client/batch.rb +212 -0
  8. data/lib/cassandra/client/client.rb +591 -0
  9. data/lib/cassandra/client/column_metadata.rb +54 -0
  10. data/lib/cassandra/client/connection_manager.rb +72 -0
  11. data/lib/cassandra/client/connector.rb +277 -0
  12. data/lib/cassandra/client/execute_options_decoder.rb +59 -0
  13. data/lib/cassandra/client/null_logger.rb +37 -0
  14. data/lib/cassandra/client/peer_discovery.rb +50 -0
  15. data/lib/cassandra/client/prepared_statement.rb +314 -0
  16. data/lib/cassandra/client/query_result.rb +230 -0
  17. data/lib/cassandra/client/request_runner.rb +71 -0
  18. data/lib/cassandra/client/result_metadata.rb +48 -0
  19. data/lib/cassandra/client/void_result.rb +78 -0
  20. data/lib/cassandra/client.rb +144 -0
  21. data/lib/cassandra/cluster/client.rb +768 -0
  22. data/lib/cassandra/cluster/connector.rb +244 -0
  23. data/lib/cassandra/cluster/control_connection.rb +425 -0
  24. data/lib/cassandra/cluster/metadata.rb +124 -0
  25. data/lib/cassandra/cluster/options.rb +42 -0
  26. data/lib/cassandra/cluster/registry.rb +198 -0
  27. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -0
  28. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
  29. data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
  30. data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
  31. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -0
  32. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
  33. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
  34. data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
  35. data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
  36. data/lib/cassandra/cluster/schema.rb +340 -0
  37. data/lib/cassandra/cluster.rb +215 -0
  38. data/lib/cassandra/column.rb +92 -0
  39. data/lib/cassandra/compression/compressors/lz4.rb +72 -0
  40. data/lib/cassandra/compression/compressors/snappy.rb +66 -0
  41. data/lib/cassandra/compression.rb +66 -0
  42. data/lib/cassandra/driver.rb +111 -0
  43. data/lib/cassandra/errors.rb +79 -0
  44. data/lib/cassandra/execution/info.rb +51 -0
  45. data/lib/cassandra/execution/options.rb +80 -0
  46. data/lib/cassandra/execution/trace.rb +152 -0
  47. data/lib/cassandra/future.rb +675 -0
  48. data/lib/cassandra/host.rb +79 -0
  49. data/lib/cassandra/keyspace.rb +133 -0
  50. data/lib/cassandra/listener.rb +87 -0
  51. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
  52. data/lib/cassandra/load_balancing/policies/round_robin.rb +132 -0
  53. data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
  54. data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
  55. data/lib/cassandra/load_balancing/policies.rb +19 -0
  56. data/lib/cassandra/load_balancing.rb +113 -0
  57. data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
  58. data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
  59. data/lib/cassandra/protocol/frame_decoder.rb +128 -0
  60. data/lib/cassandra/protocol/frame_encoder.rb +48 -0
  61. data/lib/cassandra/protocol/request.rb +38 -0
  62. data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
  63. data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
  64. data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
  65. data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
  66. data/lib/cassandra/protocol/requests/options_request.rb +39 -0
  67. data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
  68. data/lib/cassandra/protocol/requests/query_request.rb +153 -0
  69. data/lib/cassandra/protocol/requests/register_request.rb +38 -0
  70. data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
  71. data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
  72. data/lib/cassandra/protocol/response.rb +38 -0
  73. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
  74. data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
  75. data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
  76. data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
  77. data/lib/cassandra/protocol/responses/error_response.rb +50 -0
  78. data/lib/cassandra/protocol/responses/event_response.rb +39 -0
  79. data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
  80. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
  81. data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
  82. data/lib/cassandra/protocol/responses/result_response.rb +48 -0
  83. data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
  84. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
  85. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
  86. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
  87. data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
  88. data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
  89. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
  90. data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
  91. data/lib/cassandra/protocol/type_converter.rb +384 -0
  92. data/lib/cassandra/protocol.rb +93 -0
  93. data/lib/cassandra/reconnection/policies/constant.rb +48 -0
  94. data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
  95. data/lib/cassandra/reconnection/policies.rb +20 -0
  96. data/lib/cassandra/reconnection.rb +49 -0
  97. data/lib/cassandra/result.rb +215 -0
  98. data/lib/cassandra/retry/policies/default.rb +47 -0
  99. data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
  100. data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
  101. data/lib/cassandra/retry/policies.rb +21 -0
  102. data/lib/cassandra/retry.rb +142 -0
  103. data/lib/cassandra/session.rb +202 -0
  104. data/lib/cassandra/statement.rb +22 -0
  105. data/lib/cassandra/statements/batch.rb +95 -0
  106. data/lib/cassandra/statements/bound.rb +48 -0
  107. data/lib/cassandra/statements/prepared.rb +81 -0
  108. data/lib/cassandra/statements/simple.rb +58 -0
  109. data/lib/cassandra/statements/void.rb +33 -0
  110. data/lib/cassandra/statements.rb +23 -0
  111. data/lib/cassandra/table.rb +299 -0
  112. data/lib/cassandra/time_uuid.rb +142 -0
  113. data/lib/cassandra/util.rb +167 -0
  114. data/lib/cassandra/uuid.rb +104 -0
  115. data/lib/cassandra/version.rb +21 -0
  116. data/lib/cassandra.rb +428 -0
  117. data/lib/cassandra_murmur3.jar +0 -0
  118. metadata +211 -0
@@ -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
@@ -0,0 +1,153 @@
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 QueryRequest < Request
22
+ attr_reader :cql, :values, :type_hints, :serial_consistency, :page_size, :paging_state
23
+ attr_accessor :consistency, :retries
24
+
25
+ def initialize(cql, values, type_hints, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false)
26
+ raise ArgumentError, %(No CQL given!) unless cql
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, %(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
30
+ raise ArgumentError, %(Paging state given but no page size) if paging_state && !page_size
31
+ super(7, trace)
32
+ @cql = cql
33
+ @values = values || EMPTY_LIST
34
+ @type_hints = type_hints || EMPTY_LIST
35
+ @consistency = consistency
36
+ @serial_consistency = serial_consistency
37
+ @page_size = page_size
38
+ @paging_state = paging_state
39
+ end
40
+
41
+ def write(protocol_version, buffer)
42
+ if protocol_version > 1
43
+ buffer.append_long_string(@cql)
44
+ else
45
+ buffer.append_long_string(serialized_cql)
46
+ end
47
+ buffer.append_consistency(@consistency)
48
+ if protocol_version > 1
49
+ flags = 0
50
+ flags |= 0x04 if @page_size
51
+ flags |= 0x08 if @paging_state
52
+ flags |= 0x10 if @serial_consistency
53
+ if @values && @values.size > 0
54
+ flags |= 0x01
55
+ buffer.append(flags.chr)
56
+ self.class.encode_values(buffer, @values, @type_hints)
57
+ else
58
+ buffer.append(flags.chr)
59
+ end
60
+ buffer.append_int(@page_size) if @page_size
61
+ buffer.append_bytes(@paging_state) if @paging_state
62
+ buffer.append_consistency(@serial_consistency) if @serial_consistency
63
+ end
64
+ buffer
65
+ end
66
+
67
+ def to_s
68
+ %(QUERY "#@cql" #{@consistency.to_s.upcase})
69
+ end
70
+
71
+ def eql?(rq)
72
+ self.class === rq &&
73
+ rq.cql == self.cql &&
74
+ rq.values == self.values &&
75
+ rq.type_hints == self.type_hints &&
76
+ rq.consistency == self.consistency &&
77
+ rq.serial_consistency == self.serial_consistency &&
78
+ rq.page_size == self.page_size &&
79
+ rq.paging_state == self.paging_state
80
+ end
81
+ alias_method :==, :eql?
82
+
83
+ def hash
84
+ h = 0xcbf29ce484222325
85
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @cql.hash))
86
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @values.hash))
87
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @type_hints.hash))
88
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @consistency.hash))
89
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @serial_consistency.hash))
90
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @page_size.hash))
91
+ h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @paging_state.hash))
92
+ h
93
+ end
94
+
95
+ def self.encode_values(buffer, values, hints)
96
+ if values && values.size > 0
97
+ buffer.append_short(values.size)
98
+ values.each_with_index do |value, index|
99
+ type = (hints && hints[index]) || guess_type(value)
100
+ raise EncodingError, "Could not guess a suitable type for #{value.inspect}" unless type
101
+ TYPE_CONVERTER.to_bytes(buffer, type, value)
102
+ end
103
+ buffer
104
+ else
105
+ buffer.append_short(0)
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def serialized_cql
112
+ return @cql if @values.nil? || @values.empty?
113
+ i = -1
114
+ @cql.gsub('?') { Util.encode(@values[i += 1]) }
115
+ end
116
+
117
+ def self.guess_type(value)
118
+ type = TYPE_GUESSES[value.class]
119
+ if type == :map
120
+ pair = value.first
121
+ [type, guess_type(pair[0]), guess_type(pair[1])]
122
+ elsif type == :list
123
+ [type, guess_type(value.first)]
124
+ elsif type == :set
125
+ [type, guess_type(value.first)]
126
+ else
127
+ type
128
+ end
129
+ end
130
+
131
+ TYPE_GUESSES = {
132
+ String => :varchar,
133
+ Fixnum => :bigint,
134
+ Float => :double,
135
+ Bignum => :varint,
136
+ BigDecimal => :decimal,
137
+ TrueClass => :boolean,
138
+ FalseClass => :boolean,
139
+ NilClass => :bigint,
140
+ Uuid => :uuid,
141
+ TimeUuid => :uuid,
142
+ IPAddr => :inet,
143
+ Time => :timestamp,
144
+ Hash => :map,
145
+ Array => :list,
146
+ Set => :set,
147
+ }.freeze
148
+ TYPE_CONVERTER = TypeConverter.new
149
+ EMPTY_LIST = [].freeze
150
+ NO_FLAGS = "\x00".freeze
151
+ end
152
+ end
153
+ 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 RegisterRequest < Request
22
+ attr_reader :events
23
+
24
+ def initialize(*events)
25
+ super(11)
26
+ @events = events
27
+ end
28
+
29
+ def write(protocol_version, buffer)
30
+ buffer.append_string_list(@events)
31
+ end
32
+
33
+ def to_s
34
+ %(REGISTER #@events)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
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 StartupRequest < Request
22
+ attr_reader :options
23
+
24
+ def initialize(cql_version, compression=nil)
25
+ super(1)
26
+ raise ArgumentError, "Invalid CQL version: #{cql_version.inspect}" unless cql_version
27
+ @options = {CQL_VERSION => cql_version}
28
+ @options[COMPRESSION] = compression if compression
29
+ end
30
+
31
+ def compressable?
32
+ false
33
+ end
34
+
35
+ def write(protocol_version, buffer)
36
+ buffer.append_string_map(@options)
37
+ end
38
+
39
+ def to_s
40
+ %(STARTUP #@options)
41
+ end
42
+
43
+ private
44
+
45
+ CQL_VERSION = 'CQL_VERSION'.freeze
46
+ COMPRESSION = 'COMPRESSION'.freeze
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,24 @@
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 VoidQueryRequest
22
+ end
23
+ end
24
+ 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 Response
22
+ def self.decode(opcode, protocol_version, buffer, length, trace_id)
23
+ response_class = RESPONSE_TYPES[opcode]
24
+ if response_class
25
+ response_class.decode(protocol_version, buffer, length, trace_id)
26
+ else
27
+ raise UnsupportedOperationError, "The operation #{opcode} is not supported"
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ RESPONSE_TYPES = [
34
+ # populated by subclasses
35
+ ]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
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 AuthChallengeResponse < Response
22
+ attr_reader :token
23
+
24
+ def self.decode(protocol_version, buffer, length, trace_id=nil)
25
+ new(buffer.read_bytes)
26
+ end
27
+
28
+ def initialize(token)
29
+ @token = token
30
+ end
31
+
32
+ def to_s
33
+ %(AUTH_CHALLENGE #{@token.bytesize})
34
+ end
35
+
36
+ private
37
+
38
+ RESPONSE_TYPES[0x0e] = self
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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 AuthSuccessResponse < Response
22
+ attr_reader :token
23
+
24
+ def self.decode(protocol_version, buffer, length, trace_id=nil)
25
+ new(buffer.read_bytes)
26
+ end
27
+
28
+ def initialize(token)
29
+ @token = token
30
+ end
31
+
32
+ def to_s
33
+ %(AUTH_SUCCESS #{@token.bytesize})
34
+ end
35
+
36
+ private
37
+
38
+ RESPONSE_TYPES[0x10] = self
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,41 @@
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 AuthenticateResponse < Response
22
+ attr_reader :authentication_class
23
+
24
+ def self.decode(protocol_version, buffer, length, trace_id=nil)
25
+ new(buffer.read_string)
26
+ end
27
+
28
+ def initialize(authentication_class)
29
+ @authentication_class = authentication_class
30
+ end
31
+
32
+ def to_s
33
+ %(AUTHENTICATE #{authentication_class})
34
+ end
35
+
36
+ private
37
+
38
+ RESPONSE_TYPES[0x03] = self
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,60 @@
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 DetailedErrorResponse < ErrorResponse
22
+ attr_reader :details
23
+
24
+ def initialize(code, message, details)
25
+ super(code, message)
26
+ @details = details
27
+ end
28
+
29
+ def self.decode(code, message, protocol_version, buffer, length, trace_id=nil)
30
+ details = {}
31
+ case code
32
+ when 0x1000 # unavailable
33
+ details[:cl] = buffer.read_consistency
34
+ details[:required] = buffer.read_int
35
+ details[:alive] = buffer.read_int
36
+ when 0x1100 # write_timeout
37
+ details[:cl] = buffer.read_consistency
38
+ details[:received] = buffer.read_int
39
+ details[:blockfor] = buffer.read_int
40
+ details[:write_type] = buffer.read_string
41
+ when 0x1200 # read_timeout
42
+ details[:cl] = buffer.read_consistency
43
+ details[:received] = buffer.read_int
44
+ details[:blockfor] = buffer.read_int
45
+ details[:data_present] = buffer.read_byte != 0
46
+ when 0x2400 # already_exists
47
+ details[:ks] = buffer.read_string
48
+ details[:table] = buffer.read_string
49
+ when 0x2500
50
+ details[:id] = buffer.read_short_bytes
51
+ end
52
+ new(code, message, details)
53
+ end
54
+
55
+ def to_s
56
+ "#{super} #{@details}"
57
+ end
58
+ end
59
+ end
60
+ end