cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.1

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.
Files changed (131) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +90 -38
  3. data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
  4. data/lib/cassandra.rb +327 -130
  5. data/lib/cassandra/address_resolution.rb +1 -1
  6. data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
  7. data/lib/cassandra/address_resolution/policies/none.rb +1 -1
  8. data/lib/cassandra/aggregate.rb +21 -7
  9. data/lib/cassandra/argument.rb +2 -2
  10. data/lib/cassandra/auth.rb +4 -4
  11. data/lib/cassandra/auth/providers.rb +1 -1
  12. data/lib/cassandra/auth/providers/password.rb +9 -5
  13. data/lib/cassandra/cassandra_logger.rb +80 -0
  14. data/lib/cassandra/cluster.rb +38 -9
  15. data/lib/cassandra/cluster/client.rb +801 -205
  16. data/lib/cassandra/cluster/connection_pool.rb +2 -2
  17. data/lib/cassandra/cluster/connector.rb +74 -25
  18. data/lib/cassandra/cluster/control_connection.rb +217 -82
  19. data/lib/cassandra/cluster/failed_connection.rb +1 -1
  20. data/lib/cassandra/cluster/metadata.rb +12 -4
  21. data/lib/cassandra/cluster/options.rb +60 -11
  22. data/lib/cassandra/cluster/registry.rb +69 -16
  23. data/lib/cassandra/cluster/schema.rb +25 -7
  24. data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
  25. data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
  26. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
  27. data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
  28. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
  29. data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
  30. data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
  31. data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
  32. data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
  33. data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
  34. data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
  35. data/lib/cassandra/column.rb +3 -3
  36. data/lib/cassandra/compression.rb +1 -1
  37. data/lib/cassandra/compression/compressors/lz4.rb +4 -3
  38. data/lib/cassandra/compression/compressors/snappy.rb +4 -3
  39. data/lib/cassandra/driver.rb +103 -41
  40. data/lib/cassandra/errors.rb +265 -30
  41. data/lib/cassandra/execution/info.rb +16 -5
  42. data/lib/cassandra/execution/options.rb +99 -54
  43. data/lib/cassandra/execution/trace.rb +16 -9
  44. data/lib/cassandra/executors.rb +1 -1
  45. data/lib/cassandra/function.rb +19 -13
  46. data/lib/cassandra/function_collection.rb +85 -0
  47. data/lib/cassandra/future.rb +106 -48
  48. data/lib/cassandra/host.rb +10 -4
  49. data/lib/cassandra/keyspace.rb +90 -33
  50. data/lib/cassandra/listener.rb +1 -1
  51. data/lib/cassandra/load_balancing.rb +2 -2
  52. data/lib/cassandra/load_balancing/policies.rb +1 -1
  53. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +18 -18
  54. data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
  55. data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
  56. data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
  57. data/lib/cassandra/null_logger.rb +27 -6
  58. data/lib/cassandra/protocol.rb +1 -1
  59. data/lib/cassandra/protocol/coder.rb +78 -39
  60. data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
  61. data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
  62. data/lib/cassandra/protocol/request.rb +2 -2
  63. data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
  64. data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
  65. data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
  66. data/lib/cassandra/protocol/requests/execute_request.rb +41 -20
  67. data/lib/cassandra/protocol/requests/options_request.rb +1 -1
  68. data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
  69. data/lib/cassandra/protocol/requests/query_request.rb +27 -22
  70. data/lib/cassandra/protocol/requests/register_request.rb +2 -2
  71. data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
  72. data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
  73. data/lib/cassandra/protocol/response.rb +2 -2
  74. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
  75. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
  76. data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
  77. data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
  78. data/lib/cassandra/protocol/responses/error_response.rb +101 -13
  79. data/lib/cassandra/protocol/responses/event_response.rb +1 -1
  80. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
  81. data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
  82. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
  83. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
  84. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
  85. data/lib/cassandra/protocol/responses/ready_response.rb +3 -3
  86. data/lib/cassandra/protocol/responses/result_response.rb +4 -2
  87. data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
  88. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
  89. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
  90. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
  91. data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
  92. data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
  93. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
  94. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
  95. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
  96. data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
  97. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
  98. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
  99. data/lib/cassandra/protocol/v1.rb +101 -36
  100. data/lib/cassandra/protocol/v3.rb +124 -51
  101. data/lib/cassandra/protocol/v4.rb +172 -68
  102. data/lib/cassandra/reconnection.rb +1 -1
  103. data/lib/cassandra/reconnection/policies.rb +1 -1
  104. data/lib/cassandra/reconnection/policies/constant.rb +2 -4
  105. data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
  106. data/lib/cassandra/result.rb +53 -19
  107. data/lib/cassandra/retry.rb +8 -8
  108. data/lib/cassandra/retry/policies.rb +1 -1
  109. data/lib/cassandra/retry/policies/default.rb +1 -1
  110. data/lib/cassandra/retry/policies/downgrading_consistency.rb +7 -3
  111. data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
  112. data/lib/cassandra/session.rb +22 -16
  113. data/lib/cassandra/statement.rb +1 -1
  114. data/lib/cassandra/statements.rb +1 -1
  115. data/lib/cassandra/statements/batch.rb +16 -10
  116. data/lib/cassandra/statements/bound.rb +10 -3
  117. data/lib/cassandra/statements/prepared.rb +59 -15
  118. data/lib/cassandra/statements/simple.rb +23 -10
  119. data/lib/cassandra/statements/void.rb +1 -1
  120. data/lib/cassandra/table.rb +79 -30
  121. data/lib/cassandra/time.rb +11 -6
  122. data/lib/cassandra/time_uuid.rb +7 -7
  123. data/lib/cassandra/tuple.rb +16 -8
  124. data/lib/cassandra/types.rb +20 -9
  125. data/lib/cassandra/udt.rb +32 -36
  126. data/lib/cassandra/util.rb +20 -13
  127. data/lib/cassandra/uuid.rb +22 -15
  128. data/lib/cassandra/uuid/generator.rb +7 -5
  129. data/lib/cassandra/version.rb +2 -2
  130. data/lib/datastax/cassandra.rb +1 -1
  131. metadata +5 -3
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -46,7 +46,9 @@ module Cassandra
46
46
  # @private
47
47
  class Error < Future
48
48
  def initialize(error)
49
- raise ::ArgumentError, "error must be an exception, #{error.inspect} given" unless error.is_a?(::Exception)
49
+ unless error.is_a?(::Exception)
50
+ raise ::ArgumentError, "error must be an exception, #{error.inspect} given"
51
+ end
50
52
 
51
53
  @error = error
52
54
  end
@@ -55,41 +57,53 @@ module Cassandra
55
57
  raise(@error, @error.message, @error.backtrace)
56
58
  end
57
59
 
58
- alias :join :get
60
+ alias join get
59
61
 
60
62
  def on_success
61
- raise ::ArgumentError, "no block given" unless block_given?
63
+ raise ::ArgumentError, 'no block given' unless block_given?
62
64
  self
63
65
  end
64
66
 
65
67
  def on_failure
66
- raise ::ArgumentError, "no block given" unless block_given?
67
- yield(@error) rescue nil
68
+ raise ::ArgumentError, 'no block given' unless block_given?
69
+ begin
70
+ yield(@error)
71
+ rescue
72
+ nil
73
+ end
68
74
  self
69
75
  end
70
76
 
71
77
  def on_complete
72
- raise ::ArgumentError, "no block given" unless block_given?
73
- yield(nil, @error) rescue nil
78
+ raise ::ArgumentError, 'no block given' unless block_given?
79
+ begin
80
+ yield(nil, @error)
81
+ rescue
82
+ nil
83
+ end
74
84
  self
75
85
  end
76
86
 
77
87
  def add_listener(listener)
78
- unless (listener.respond_to?(:success) && listener.respond_to?(:failure))
79
- raise ::ArgumentError, "listener must respond to both #success and #failure"
88
+ unless listener.respond_to?(:success) && listener.respond_to?(:failure)
89
+ raise ::ArgumentError, 'listener must respond to both #success and #failure'
80
90
  end
81
91
 
82
- listener.failure(@error) rescue nil
92
+ begin
93
+ listener.failure(@error)
94
+ rescue
95
+ nil
96
+ end
83
97
  self
84
98
  end
85
99
 
86
100
  def then
87
- raise ::ArgumentError, "no block given" unless block_given?
101
+ raise ::ArgumentError, 'no block given' unless block_given?
88
102
  self
89
103
  end
90
104
 
91
105
  def fallback
92
- raise ::ArgumentError, "no block given" unless block_given?
106
+ raise ::ArgumentError, 'no block given' unless block_given?
93
107
 
94
108
  begin
95
109
  result = yield(@error)
@@ -111,31 +125,43 @@ module Cassandra
111
125
  @value
112
126
  end
113
127
 
114
- alias :join :get
128
+ alias join get
115
129
 
116
130
  def on_success
117
- raise ::ArgumentError, "no block given" unless block_given?
118
- yield(@value) rescue nil
131
+ raise ::ArgumentError, 'no block given' unless block_given?
132
+ begin
133
+ yield(@value)
134
+ rescue
135
+ nil
136
+ end
119
137
  self
120
138
  end
121
139
 
122
140
  def on_failure
123
- raise ::ArgumentError, "no block given" unless block_given?
141
+ raise ::ArgumentError, 'no block given' unless block_given?
124
142
  self
125
143
  end
126
144
 
127
145
  def on_complete
128
- raise ::ArgumentError, "no block given" unless block_given?
129
- yield(@value, nil) rescue nil
146
+ raise ::ArgumentError, 'no block given' unless block_given?
147
+ begin
148
+ yield(@value, nil)
149
+ rescue
150
+ nil
151
+ end
130
152
  self
131
153
  end
132
154
 
133
155
  def add_listener(listener)
134
- unless (listener.respond_to?(:success) && listener.respond_to?(:failure))
135
- raise ::ArgumentError, "listener must respond to both #success and #failure"
156
+ unless listener.respond_to?(:success) && listener.respond_to?(:failure)
157
+ raise ::ArgumentError, 'listener must respond to both #success and #failure'
136
158
  end
137
159
 
138
- listener.success(@value) rescue nil
160
+ begin
161
+ listener.success(@value)
162
+ rescue
163
+ nil
164
+ end
139
165
  self
140
166
  end
141
167
 
@@ -144,7 +170,7 @@ module Cassandra
144
170
  end
145
171
 
146
172
  def then
147
- raise ::ArgumentError, "no block given" unless block_given?
173
+ raise ::ArgumentError, 'no block given' unless block_given?
148
174
 
149
175
  begin
150
176
  result = yield(@value)
@@ -156,7 +182,7 @@ module Cassandra
156
182
  end
157
183
 
158
184
  def fallback
159
- raise ::ArgumentError, "no block given" unless block_given?
185
+ raise ::ArgumentError, 'no block given' unless block_given?
160
186
  self
161
187
  end
162
188
  end
@@ -252,7 +278,7 @@ module Cassandra
252
278
  # @raise [ArgumentError] if no block given
253
279
  # @return [self]
254
280
  def on_success(&block)
255
- raise ::ArgumentError, "no block given" unless block_given?
281
+ raise ::ArgumentError, 'no block given' unless block_given?
256
282
  @signal.on_success(&block)
257
283
  self
258
284
  end
@@ -265,7 +291,7 @@ module Cassandra
265
291
  # @raise [ArgumentError] if no block given
266
292
  # @return [self]
267
293
  def on_failure(&block)
268
- raise ::ArgumentError, "no block given" unless block_given?
294
+ raise ::ArgumentError, 'no block given' unless block_given?
269
295
  @signal.on_failure(&block)
270
296
  self
271
297
  end
@@ -281,7 +307,7 @@ module Cassandra
281
307
  # @raise [ArgumentError] if no block given
282
308
  # @return [self]
283
309
  def on_complete(&block)
284
- raise ::ArgumentError, "no block given" unless block_given?
310
+ raise ::ArgumentError, 'no block given' unless block_given?
285
311
  @signal.on_complete(&block)
286
312
  self
287
313
  end
@@ -296,8 +322,8 @@ module Cassandra
296
322
  # `#success` and `#failure`
297
323
  # @return [self]
298
324
  def add_listener(listener)
299
- unless (listener.respond_to?(:success) && listener.respond_to?(:failure))
300
- raise ::ArgumentError, "listener must respond to both #success and #failure"
325
+ unless listener.respond_to?(:success) && listener.respond_to?(:failure)
326
+ raise ::ArgumentError, 'listener must respond to both #success and #failure'
301
327
  end
302
328
 
303
329
  @signal.add_listener(listener)
@@ -325,7 +351,7 @@ module Cassandra
325
351
  # @raise [ArgumentError] if no block given
326
352
  # @return [Cassandra::Future] a new future
327
353
  def then(&block)
328
- raise ::ArgumentError, "no block given" unless block_given?
354
+ raise ::ArgumentError, 'no block given' unless block_given?
329
355
  @signal.then(&block)
330
356
  end
331
357
 
@@ -351,7 +377,7 @@ module Cassandra
351
377
  # @raise [ArgumentError] if no block given
352
378
  # @return [Cassandra::Future] a new future
353
379
  def fallback(&block)
354
- raise ::ArgumentError, "no block given" unless block_given?
380
+ raise ::ArgumentError, 'no block given' unless block_given?
355
381
  @signal.fallback(&block)
356
382
  end
357
383
 
@@ -372,7 +398,7 @@ module Cassandra
372
398
  @signal.get(timeout)
373
399
  end
374
400
 
375
- alias :join :get
401
+ alias join get
376
402
  end
377
403
 
378
404
  # @private
@@ -507,12 +533,17 @@ module Cassandra
507
533
  @error = error
508
534
  @state = :broken
509
535
 
510
- listeners, @listeners = @listeners, nil
536
+ listeners = @listeners
537
+ @listeners = nil
511
538
  end
512
539
 
513
540
  @executor.execute do
514
541
  listeners.each do |listener|
515
- listener.failure(error) rescue nil
542
+ begin
543
+ listener.failure(error)
544
+ rescue
545
+ nil
546
+ end
516
547
  end
517
548
 
518
549
  synchronize do
@@ -534,12 +565,17 @@ module Cassandra
534
565
  @value = value
535
566
  @state = :fulfilled
536
567
 
537
- listeners, @listeners = @listeners, nil
568
+ listeners = @listeners
569
+ @listeners = nil
538
570
  end
539
571
 
540
572
  @executor.execute do
541
573
  listeners.each do |listener|
542
- listener.success(value) rescue nil
574
+ begin
575
+ listener.success(value)
576
+ rescue
577
+ nil
578
+ end
543
579
  end
544
580
 
545
581
  synchronize do
@@ -561,10 +597,12 @@ module Cassandra
561
597
  #
562
598
  # @return [Object] the value that the future has been resolved with
563
599
  def get(timeout = nil)
564
- timeout = timeout && Float(timeout)
600
+ timeout &&= Float(timeout)
565
601
 
566
602
  if timeout
567
- raise ::ArgumentError, "timeout cannot be negative, #{timeout.inspect} given" if timeout < 0
603
+ if timeout < 0
604
+ raise ::ArgumentError, "timeout cannot be negative, #{timeout.inspect} given"
605
+ end
568
606
 
569
607
  start = ::Time.now
570
608
  now = start
@@ -590,18 +628,18 @@ module Cassandra
590
628
 
591
629
  if @state == :pending
592
630
  total_wait = deadline - start
593
- raise Errors::TimeoutError, "Future did not complete within #{timeout.inspect} seconds. Wait time: #{total_wait.inspect}"
631
+ raise Errors::TimeoutError,
632
+ "Future did not complete within #{timeout.inspect} seconds. " \
633
+ "Wait time: #{total_wait.inspect}"
594
634
  end
595
635
  end
596
636
 
597
- if @state == :broken
598
- raise(@error, @error.message, @error.backtrace)
599
- end
637
+ raise(@error, @error.message, @error.backtrace) if @state == :broken
600
638
 
601
639
  @value
602
640
  end
603
641
 
604
- alias :join :get
642
+ alias join get
605
643
 
606
644
  def add_listener(listener)
607
645
  if @state == :pending
@@ -614,8 +652,16 @@ module Cassandra
614
652
  end
615
653
  end
616
654
 
617
- listener.success(@value) rescue nil if @state == :fulfilled
618
- listener.failure(@error) rescue nil if @state == :broken
655
+ begin
656
+ listener.success(@value)
657
+ rescue
658
+ nil
659
+ end if @state == :fulfilled
660
+ begin
661
+ listener.failure(@error)
662
+ rescue
663
+ nil
664
+ end if @state == :broken
619
665
 
620
666
  self
621
667
  end
@@ -630,7 +676,11 @@ module Cassandra
630
676
  end
631
677
  end
632
678
 
633
- yield(@value) rescue nil if @state == :fulfilled
679
+ begin
680
+ yield(@value)
681
+ rescue
682
+ nil
683
+ end if @state == :fulfilled
634
684
 
635
685
  self
636
686
  end
@@ -645,7 +695,11 @@ module Cassandra
645
695
  end
646
696
  end
647
697
 
648
- yield(@error) rescue nil if @state == :broken
698
+ begin
699
+ yield(@error)
700
+ rescue
701
+ nil
702
+ end if @state == :broken
649
703
 
650
704
  self
651
705
  end
@@ -660,7 +714,11 @@ module Cassandra
660
714
  end
661
715
  end
662
716
 
663
- yield(@value, @error) rescue nil
717
+ begin
718
+ yield(@value, @error)
719
+ rescue
720
+ nil
721
+ end
664
722
 
665
723
  self
666
724
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -39,7 +39,13 @@ module Cassandra
39
39
  attr_reader :status
40
40
 
41
41
  # @private
42
- def initialize(ip, id = nil, rack = nil, datacenter = nil, release_version = nil, tokens = EMPTY_LIST, status = :up)
42
+ def initialize(ip,
43
+ id = nil,
44
+ rack = nil,
45
+ datacenter = nil,
46
+ release_version = nil,
47
+ tokens = EMPTY_LIST,
48
+ status = :up)
43
49
  @ip = ip
44
50
  @id = id
45
51
  @rack = rack
@@ -72,11 +78,11 @@ module Cassandra
72
78
  def eql?(other)
73
79
  other.eql?(@ip)
74
80
  end
75
- alias :== :eql?
81
+ alias == eql?
76
82
 
77
83
  # @private
78
84
  def inspect
79
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @ip=#{@ip}>"
85
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} @ip=#{@ip}>"
80
86
  end
81
87
  end
82
88
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  #--
4
- # Copyright 2013-2015 DataStax, Inc.
4
+ # Copyright 2013-2016 DataStax, Inc.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ module Cassandra
42
42
  @klass == other.klass &&
43
43
  @options == other.options
44
44
  end
45
- alias :== :eql?
45
+ alias == eql?
46
46
  end
47
47
 
48
48
  # @return [String] this keyspace name
@@ -51,7 +51,13 @@ module Cassandra
51
51
  attr_reader :replication
52
52
 
53
53
  # @private
54
- def initialize(name, durable_writes, replication, tables, types, functions, aggregates)
54
+ def initialize(name,
55
+ durable_writes,
56
+ replication,
57
+ tables,
58
+ types,
59
+ functions,
60
+ aggregates)
55
61
  @name = name
56
62
  @durable_writes = durable_writes
57
63
  @replication = replication
@@ -69,7 +75,7 @@ module Cassandra
69
75
  # @return [Boolean] whether this keyspace has a table with the given name
70
76
  # @param name [String] table name
71
77
  def has_table?(name)
72
- @tables.has_key?(name)
78
+ @tables.key?(name)
73
79
  end
74
80
 
75
81
  # @return [Cassandra::Table, nil] a table or nil
@@ -92,13 +98,13 @@ module Cassandra
92
98
  @tables.values
93
99
  end
94
100
  end
95
- alias :tables :each_table
101
+ alias tables each_table
96
102
 
97
103
  # @return [Boolean] whether this keyspace has a user-defined type with the
98
104
  # given name
99
105
  # @param name [String] user-defined type name
100
106
  def has_type?(name)
101
- @types.has_key?(name)
107
+ @types.key?(name)
102
108
  end
103
109
 
104
110
  # @return [Cassandra::Types::UserDefined, nil] a type or nil
@@ -121,13 +127,14 @@ module Cassandra
121
127
  @types.values
122
128
  end
123
129
  end
124
- alias :types :each_type
130
+ alias types each_type
125
131
 
126
- # @return [Boolean] whether this keyspace has a function with the given name and arguments
132
+ # @return [Boolean] whether this keyspace has a function with the given name and
133
+ # arguments
127
134
  # @param name [String] function name
128
135
  # @param args [Array<String>] (var-args style) function argument types
129
136
  def has_function?(name, *args)
130
- @functions.has_key?([name.downcase, args])
137
+ !@functions.get(name.downcase, args).nil?
131
138
  end
132
139
 
133
140
  # @return [Cassandra::Function, nil] a function or nil
@@ -136,7 +143,7 @@ module Cassandra
136
143
  def function(name, *args)
137
144
  # The functions_hash datastructure is a hash <[func-name, args], Function>.
138
145
  # So construct the array-key we're looking for.
139
- @functions[[name.downcase, args]]
146
+ @functions.get(name.downcase, args)
140
147
  end
141
148
 
142
149
  # Yield or enumerate each function defined in this keyspace
@@ -147,27 +154,27 @@ module Cassandra
147
154
  # @return [Array<Cassandra::Function>] a list of functions
148
155
  def each_function(&block)
149
156
  if block_given?
150
- @functions.each_value(&block)
157
+ @functions.each_function(&block)
151
158
  self
152
159
  else
153
- @functions.values
160
+ @functions.functions
154
161
  end
155
162
  end
156
- alias :functions :each_function
163
+ alias functions each_function
157
164
 
158
165
  # @return [Boolean] whether this keyspace has an aggregate with the given
159
166
  # name and arguments
160
167
  # @param name [String] aggregate name
161
168
  # @param args [Array<String>] (var-args style) aggregate function argument types
162
169
  def has_aggregate?(name, *args)
163
- @aggregates.has_key?([name.downcase, args])
170
+ !@aggregates.get(name.downcase, args).nil?
164
171
  end
165
172
 
166
173
  # @return [Cassandra::Aggregate, nil] an aggregate or nil
167
174
  # @param name [String] aggregate name
168
175
  # @param args [Array<String>] (var-args style) aggregate function argument types
169
176
  def aggregate(name, *args)
170
- @aggregates[[name.downcase, args]]
177
+ @aggregates.get(name.downcase, args)
171
178
  end
172
179
 
173
180
  # Yield or enumerate each aggregate defined in this keyspace
@@ -178,17 +185,19 @@ module Cassandra
178
185
  # @return [Array<Cassandra::Aggregate>] a list of aggregates
179
186
  def each_aggregate(&block)
180
187
  if block_given?
181
- @aggregates.each_value(&block)
188
+ @aggregates.each_function(&block)
182
189
  self
183
190
  else
184
- @aggregates.values
191
+ @aggregates.functions
185
192
  end
186
193
  end
187
- alias :aggregates :each_aggregate
194
+ alias aggregates each_aggregate
188
195
 
189
196
  # @return [String] a cql representation of this keyspace
190
197
  def to_cql
191
- "CREATE KEYSPACE #{Util.escape_name(@name)} WITH replication = #{@replication.to_cql} AND durable_writes = #{@durable_writes};"
198
+ "CREATE KEYSPACE #{Util.escape_name(@name)} " \
199
+ "WITH replication = #{@replication.to_cql} AND " \
200
+ "durable_writes = #{@durable_writes};"
192
201
  end
193
202
 
194
203
  # @private
@@ -202,67 +211,115 @@ module Cassandra
202
211
  @functions == other.raw_functions &&
203
212
  @aggregates == other.raw_aggregates
204
213
  end
205
- alias :== :eql?
214
+ alias == eql?
206
215
 
207
216
  # @private
208
217
  def inspect
209
- "#<#{self.class.name}:0x#{self.object_id.to_s(16)} @name=#{@name}>"
218
+ "#<#{self.class.name}:0x#{object_id.to_s(16)} @name=#{@name}>"
210
219
  end
211
220
 
212
221
  # @private
213
222
  def update_table(table)
214
223
  tables = @tables.dup
215
224
  tables[table.name] = table
216
- Keyspace.new(@name, @durable_writes, @replication, tables, @types, @functions, @aggregates)
225
+ Keyspace.new(@name,
226
+ @durable_writes,
227
+ @replication,
228
+ tables,
229
+ @types,
230
+ @functions,
231
+ @aggregates)
217
232
  end
218
233
 
219
234
  # @private
220
235
  def delete_table(table_name)
221
236
  tables = @tables.dup
222
237
  tables.delete(table_name)
223
- Keyspace.new(@name, @durable_writes, @replication, tables, @types, @functions, @aggregates)
238
+ Keyspace.new(@name,
239
+ @durable_writes,
240
+ @replication,
241
+ tables,
242
+ @types,
243
+ @functions,
244
+ @aggregates)
224
245
  end
225
246
 
226
247
  # @private
227
248
  def update_type(type)
228
249
  types = @types.dup
229
250
  types[type.name] = type
230
- Keyspace.new(@name, @durable_writes, @replication, @tables, types, @functions, @aggregates)
251
+ Keyspace.new(@name,
252
+ @durable_writes,
253
+ @replication,
254
+ @tables,
255
+ types,
256
+ @functions,
257
+ @aggregates)
231
258
  end
232
259
 
233
260
  # @private
234
261
  def delete_type(type_name)
235
262
  types = @types.dup
236
263
  types.delete(type_name)
237
- Keyspace.new(@name, @durable_writes, @replication, @tables, types, @functions, @aggregates)
264
+ Keyspace.new(@name,
265
+ @durable_writes,
266
+ @replication,
267
+ @tables,
268
+ types,
269
+ @functions,
270
+ @aggregates)
238
271
  end
239
272
 
240
273
  # @private
241
274
  def update_function(function)
242
275
  functions = @functions.dup
243
- functions[[function.name, function.argument_types]] = function
244
- Keyspace.new(@name, @durable_writes, @replication, @tables, @types, functions, @aggregates)
276
+ functions.add_or_update(function)
277
+ Keyspace.new(@name,
278
+ @durable_writes,
279
+ @replication,
280
+ @tables,
281
+ @types,
282
+ functions,
283
+ @aggregates)
245
284
  end
246
285
 
247
286
  # @private
248
287
  def delete_function(function_name, function_args)
249
288
  functions = @functions.dup
250
- functions.delete([function_name, function_args])
251
- Keyspace.new(@name, @durable_writes, @replication, @tables, @types, functions, @aggregates)
289
+ functions.delete(function_name, function_args)
290
+ Keyspace.new(@name,
291
+ @durable_writes,
292
+ @replication,
293
+ @tables,
294
+ @types,
295
+ functions,
296
+ @aggregates)
252
297
  end
253
298
 
254
299
  # @private
255
300
  def update_aggregate(aggregate)
256
301
  aggregates = @aggregates.dup
257
- aggregates[[aggregate.name, aggregate.argument_types]] = aggregate
258
- Keyspace.new(@name, @durable_writes, @replication, @tables, @types, @functions, aggregates)
302
+ aggregates.add_or_update(aggregate)
303
+ Keyspace.new(@name,
304
+ @durable_writes,
305
+ @replication,
306
+ @tables,
307
+ @types,
308
+ @functions,
309
+ aggregates)
259
310
  end
260
311
 
261
312
  # @private
262
313
  def delete_aggregate(aggregate_name, aggregate_args)
263
314
  aggregates = @aggregates.dup
264
- aggregates.delete([aggregate_name, aggregate_args])
265
- Keyspace.new(@name, @durable_writes, @replication, @tables, @types, @functions, aggregates)
315
+ aggregates.delete(aggregate_name, aggregate_args)
316
+ Keyspace.new(@name,
317
+ @durable_writes,
318
+ @replication,
319
+ @tables,
320
+ @types,
321
+ @functions,
322
+ aggregates)
266
323
  end
267
324
 
268
325
  # @private