cassandra-driver 1.0.0.beta.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +4 -0
- data/README.md +125 -0
- data/lib/cassandra/auth/providers/password.rb +73 -0
- data/lib/cassandra/auth/providers.rb +16 -0
- data/lib/cassandra/auth.rb +97 -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 +277 -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/client.rb +144 -0
- data/lib/cassandra/cluster/client.rb +768 -0
- data/lib/cassandra/cluster/connector.rb +244 -0
- data/lib/cassandra/cluster/control_connection.rb +425 -0
- data/lib/cassandra/cluster/metadata.rb +124 -0
- data/lib/cassandra/cluster/options.rb +42 -0
- data/lib/cassandra/cluster/registry.rb +198 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -0
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -0
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
- data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
- data/lib/cassandra/cluster/schema.rb +340 -0
- data/lib/cassandra/cluster.rb +215 -0
- data/lib/cassandra/column.rb +92 -0
- data/lib/cassandra/compression/compressors/lz4.rb +72 -0
- data/lib/cassandra/compression/compressors/snappy.rb +66 -0
- data/lib/cassandra/compression.rb +66 -0
- data/lib/cassandra/driver.rb +111 -0
- data/lib/cassandra/errors.rb +79 -0
- data/lib/cassandra/execution/info.rb +51 -0
- data/lib/cassandra/execution/options.rb +80 -0
- data/lib/cassandra/execution/trace.rb +152 -0
- data/lib/cassandra/future.rb +675 -0
- data/lib/cassandra/host.rb +79 -0
- data/lib/cassandra/keyspace.rb +133 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +132 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
- data/lib/cassandra/load_balancing/policies.rb +19 -0
- data/lib/cassandra/load_balancing.rb +113 -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/protocol.rb +93 -0
- data/lib/cassandra/reconnection/policies/constant.rb +48 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/result.rb +215 -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/retry/policies.rb +21 -0
- data/lib/cassandra/retry.rb +142 -0
- data/lib/cassandra/session.rb +202 -0
- data/lib/cassandra/statement.rb +22 -0
- data/lib/cassandra/statements/batch.rb +95 -0
- data/lib/cassandra/statements/bound.rb +48 -0
- data/lib/cassandra/statements/prepared.rb +81 -0
- data/lib/cassandra/statements/simple.rb +58 -0
- data/lib/cassandra/statements/void.rb +33 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/table.rb +299 -0
- data/lib/cassandra/time_uuid.rb +142 -0
- data/lib/cassandra/util.rb +167 -0
- data/lib/cassandra/uuid.rb +104 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/cassandra.rb +428 -0
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +211 -0
|
@@ -0,0 +1,78 @@
|
|
|
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 Client
|
|
21
|
+
# Many CQL queries do not return any rows, but they can still return
|
|
22
|
+
# data about the query, for example the trace ID. This class exist to make
|
|
23
|
+
# that data available.
|
|
24
|
+
#
|
|
25
|
+
# It has the exact same API as {Cassandra::Client::QueryResult} so that you don't
|
|
26
|
+
# need to check the return value of for example {Cassandra::Client::Client#execute}.
|
|
27
|
+
#
|
|
28
|
+
# @see Cassandra::Client::QueryResult
|
|
29
|
+
# @see Cassandra::Client::Client#execute
|
|
30
|
+
# @see Cassandra::Client::PreparedStatement#execute
|
|
31
|
+
class VoidResult
|
|
32
|
+
include Enumerable
|
|
33
|
+
|
|
34
|
+
INSTANCE = self.new
|
|
35
|
+
|
|
36
|
+
# @return [ResultMetadata]
|
|
37
|
+
attr_reader :metadata
|
|
38
|
+
|
|
39
|
+
# The ID of the query trace associated with the query, if any.
|
|
40
|
+
#
|
|
41
|
+
# @return [Cassandra::Uuid]
|
|
42
|
+
attr_reader :trace_id
|
|
43
|
+
|
|
44
|
+
# @private
|
|
45
|
+
def initialize(trace_id=nil)
|
|
46
|
+
@trace_id = trace_id
|
|
47
|
+
@metadata = EMPTY_METADATA
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Always returns true
|
|
51
|
+
def empty?
|
|
52
|
+
true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Always returns true
|
|
56
|
+
def last_page?
|
|
57
|
+
true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Always returns nil
|
|
61
|
+
def next_page
|
|
62
|
+
nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# No-op for API compatibility with {QueryResult}.
|
|
66
|
+
#
|
|
67
|
+
# @return [Enumerable]
|
|
68
|
+
def each(&block)
|
|
69
|
+
self
|
|
70
|
+
end
|
|
71
|
+
alias_method :each_row, :each
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
EMPTY_METADATA = ResultMetadata.new([])
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
# A CQL client manages connections to one or more Cassandra nodes and you use
|
|
21
|
+
# it run queries, insert and update data.
|
|
22
|
+
#
|
|
23
|
+
# Client instances are threadsafe.
|
|
24
|
+
#
|
|
25
|
+
# See {Cassandra::Client::Client} for the full client API, or {Cassandra::Client.connect}
|
|
26
|
+
# for the options available when connecting.
|
|
27
|
+
#
|
|
28
|
+
# @example Connecting and changing to a keyspace
|
|
29
|
+
# # create a client and connect to two Cassandra nodes
|
|
30
|
+
# client = Cassandra::Client.connect(hosts: %w[node01.cassandra.local node02.cassandra.local])
|
|
31
|
+
# # change to a keyspace
|
|
32
|
+
# client.use('stuff')
|
|
33
|
+
#
|
|
34
|
+
# @example Query for data
|
|
35
|
+
# rows = client.execute('SELECT * FROM things WHERE id = 2')
|
|
36
|
+
# rows.each do |row|
|
|
37
|
+
# p row
|
|
38
|
+
# end
|
|
39
|
+
#
|
|
40
|
+
# @example Inserting and updating data
|
|
41
|
+
# client.execute("INSERT INTO things (id, value) VALUES (4, 'foo')")
|
|
42
|
+
# client.execute("UPDATE things SET value = 'bar' WHERE id = 5")
|
|
43
|
+
#
|
|
44
|
+
# @example Prepared statements
|
|
45
|
+
# statement = client.prepare('INSERT INTO things (id, value) VALUES (?, ?)')
|
|
46
|
+
# statement.execute(9, 'qux')
|
|
47
|
+
# statement.execute(8, 'baz')
|
|
48
|
+
# @private
|
|
49
|
+
module Client
|
|
50
|
+
InvalidKeyspaceNameError = Class.new(Errors::ClientError)
|
|
51
|
+
|
|
52
|
+
# @private
|
|
53
|
+
module SynchronousBacktrace
|
|
54
|
+
def synchronous_backtrace
|
|
55
|
+
yield
|
|
56
|
+
rescue Error => e
|
|
57
|
+
new_backtrace = caller
|
|
58
|
+
if new_backtrace.first.include?(SYNCHRONOUS_BACKTRACE_METHOD_NAME)
|
|
59
|
+
new_backtrace = new_backtrace.drop(1)
|
|
60
|
+
end
|
|
61
|
+
e.set_backtrace(new_backtrace)
|
|
62
|
+
raise
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
SYNCHRONOUS_BACKTRACE_METHOD_NAME = 'synchronous_backtrace'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Create a new client and connect to Cassandra.
|
|
71
|
+
#
|
|
72
|
+
# By default the client will connect to localhost port 9042, which can be
|
|
73
|
+
# overridden with the `:hosts` and `:port` options, respectively. Once
|
|
74
|
+
# connected to the hosts given in `:hosts` the rest of the nodes in the
|
|
75
|
+
# cluster will automatically be discovered and connected to.
|
|
76
|
+
#
|
|
77
|
+
# If you have a multi data center setup the client will connect to all nodes
|
|
78
|
+
# in the data centers where the nodes you pass to `:hosts` are located. So
|
|
79
|
+
# if you only want to connect to nodes in one data center, make sure that
|
|
80
|
+
# you only specify nodes in that data center in `:hosts`.
|
|
81
|
+
#
|
|
82
|
+
# The connection will succeed if at least one node is up and accepts the
|
|
83
|
+
# connection. Nodes that don't respond within the specified timeout, or
|
|
84
|
+
# where the connection initialization fails for some reason, are ignored.
|
|
85
|
+
#
|
|
86
|
+
# @param [Hash] options
|
|
87
|
+
# @option options [Array<String>] :hosts (['localhost']) One or more
|
|
88
|
+
# hostnames used as seed nodes when connecting. Duplicates will be removed.
|
|
89
|
+
# @option options [String] :port (9042) The port to connect to, this port
|
|
90
|
+
# will be used for all nodes. Because the `system.peers` table does not
|
|
91
|
+
# contain the port that the nodes are listening on, the port must be the
|
|
92
|
+
# same for all nodes.
|
|
93
|
+
# @option options [Integer] :connection_timeout (5) Max time to wait for a
|
|
94
|
+
# connection, in seconds.
|
|
95
|
+
# @option options [String] :keyspace The keyspace to change to immediately
|
|
96
|
+
# after all connections have been established, this is optional.
|
|
97
|
+
# @option options [Hash] :credentials When using Cassandra's built in
|
|
98
|
+
# authentication you can provide your username and password through this
|
|
99
|
+
# option. Example: `:credentials => {:username => 'cassandra', :password => 'cassandra'}`
|
|
100
|
+
# @option options [Object] :auth_provider When using custom authentication
|
|
101
|
+
# use this option to specify the auth provider that will handle the
|
|
102
|
+
# authentication negotiation. See {Cassandra::Client::AuthProvider} for more info.
|
|
103
|
+
# @option options [Integer] :connections_per_node (1) The number of
|
|
104
|
+
# connections to open to each node. Each connection can have 128
|
|
105
|
+
# concurrent requests, so unless you have a need for more than that (times
|
|
106
|
+
# the number of nodes in your cluster), leave this option at its default.
|
|
107
|
+
# @option options [Integer] :default_consistency (:quorum) The consistency
|
|
108
|
+
# to use unless otherwise specified. Consistency can also be specified on
|
|
109
|
+
# a per-request basis.
|
|
110
|
+
# @option options [Cassandra::Compression::Compressor] :compressor An object that
|
|
111
|
+
# can compress and decompress frames. By specifying this option frame
|
|
112
|
+
# compression will be enabled. If the server does not support compression
|
|
113
|
+
# or the specific compression algorithm specified by the compressor,
|
|
114
|
+
# compression will not be enabled and a warning will be logged.
|
|
115
|
+
# @option options [String] :cql_version Specifies which CQL version the
|
|
116
|
+
# server should expect.
|
|
117
|
+
# @option options [Integer] :logger If you want the client to log
|
|
118
|
+
# significant events pass an object implementing the standard Ruby logger
|
|
119
|
+
# interface (e.g. quacks like `Logger` from the standard library) with
|
|
120
|
+
# this option.
|
|
121
|
+
# @raise Cassandra::Io::ConnectionError when a connection couldn't be established
|
|
122
|
+
# to any node
|
|
123
|
+
# @raise Cassandra::Errors::QueryError when the specified keyspace does not exist
|
|
124
|
+
# or when the specifed CQL version is not supported.
|
|
125
|
+
# @return [Cassandra::Client::Client]
|
|
126
|
+
def self.connect(options={})
|
|
127
|
+
SynchronousClient.new(AsynchronousClient.new(options)).connect
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
require 'cassandra/client/connection_manager'
|
|
133
|
+
require 'cassandra/client/connector'
|
|
134
|
+
require 'cassandra/client/null_logger'
|
|
135
|
+
require 'cassandra/client/column_metadata'
|
|
136
|
+
require 'cassandra/client/result_metadata'
|
|
137
|
+
require 'cassandra/client/execute_options_decoder'
|
|
138
|
+
require 'cassandra/client/client'
|
|
139
|
+
require 'cassandra/client/prepared_statement'
|
|
140
|
+
require 'cassandra/client/batch'
|
|
141
|
+
require 'cassandra/client/query_result'
|
|
142
|
+
require 'cassandra/client/void_result'
|
|
143
|
+
require 'cassandra/client/request_runner'
|
|
144
|
+
require 'cassandra/client/peer_discovery'
|