class Cassandra::Keyspace
Represents a cassandra keyspace @see Cassandra::Cluster#each_keyspace
@see Cassandra::Cluster#keyspace
Attributes
@private
@return [String] this keyspace name
@private
Public Class Methods
@private
# File lib/cassandra/keyspace.rb 54 def initialize(name, 55 durable_writes, 56 replication, 57 tables, 58 types, 59 functions, 60 aggregates, 61 views) 62 @name = name 63 @durable_writes = durable_writes 64 @replication = replication 65 @tables = tables 66 @types = types 67 @functions = functions 68 @aggregates = aggregates 69 @views = views 70 71 # Set the keyspace attribute on the tables and views. 72 # Also set up the index collection on the keyspace and the view-collection on each table. 73 @indexes_hash = {} 74 @tables.each_value do |t| 75 t.set_keyspace(self) 76 t.each_index do |index| 77 @indexes_hash[index.name] = index 78 end 79 end 80 @views.each_value do |v| 81 v.set_keyspace(self) 82 table = v.base_table 83 table.add_view(v) if table 84 end 85 end
Public Instance Methods
@return [Cassandra::Aggregate, nil] an aggregate or nil @param name [String] aggregate name @param args [Array<String>] (var-args style) aggregate function argument types
# File lib/cassandra/keyspace.rb 257 def aggregate(name, *args) 258 @aggregates.get(name.downcase, args) 259 end
@private
# File lib/cassandra/keyspace.rb 429 def delete_aggregate(aggregate_name, aggregate_args) 430 aggregates = @aggregates.dup 431 aggregates.delete(aggregate_name, aggregate_args) 432 Keyspace.new(@name, 433 @durable_writes, 434 @replication, 435 @tables, 436 @types, 437 @functions, 438 aggregates, 439 @views) 440 end
@private
# File lib/cassandra/keyspace.rb 401 def delete_function(function_name, function_args) 402 functions = @functions.dup 403 functions.delete(function_name, function_args) 404 Keyspace.new(@name, 405 @durable_writes, 406 @replication, 407 @tables, 408 @types, 409 functions, 410 @aggregates, 411 @views) 412 end
@private
# File lib/cassandra/keyspace.rb 345 def delete_materialized_view(view_name) 346 views = @views.dup 347 views.delete(view_name) 348 Keyspace.new(@name, 349 @durable_writes, 350 @replication, 351 @tables, 352 @types, 353 @functions, 354 @aggregates, 355 views) 356 end
@private
# File lib/cassandra/keyspace.rb 317 def delete_table(table_name) 318 tables = @tables.dup 319 tables.delete(table_name) 320 Keyspace.new(@name, 321 @durable_writes, 322 @replication, 323 tables, 324 @types, 325 @functions, 326 @aggregates, 327 @views) 328 end
@private
# File lib/cassandra/keyspace.rb 373 def delete_type(type_name) 374 types = @types.dup 375 types.delete(type_name) 376 Keyspace.new(@name, 377 @durable_writes, 378 @replication, 379 @tables, 380 types, 381 @functions, 382 @aggregates, 383 @views) 384 end
@return [Boolean] whether durables writes are enabled for this keyspace
# File lib/cassandra/keyspace.rb 88 def durable_writes? 89 @durable_writes 90 end
Yield or enumerate each aggregate defined in this keyspace @overload each_aggregate
@yieldparam aggregate [Cassandra::Aggregate] current aggregate @return [Cassandra::Keyspace] self
@overload each_aggregate
@return [Array<Cassandra::Aggregate>] a list of aggregates
# File lib/cassandra/keyspace.rb 267 def each_aggregate(&block) 268 if block_given? 269 @aggregates.each_function(&block) 270 self 271 else 272 @aggregates.functions 273 end 274 end
Yield or enumerate each function defined in this keyspace @overload each_function
@yieldparam function [Cassandra::Function] current function @return [Cassandra::Keyspace] self
@overload each_function
@return [Array<Cassandra::Function>] a list of functions
# File lib/cassandra/keyspace.rb 236 def each_function(&block) 237 if block_given? 238 @functions.each_function(&block) 239 self 240 else 241 @functions.functions 242 end 243 end
Yield or enumerate each index defined in this keyspace @overload each_index
@yieldparam index [Cassandra::Index] current index @return [Cassandra::Keyspace] self
@overload each_index
@return [Array<Cassandra::Index>] a list of indexes
# File lib/cassandra/keyspace.rb 138 def each_index(&block) 139 if block_given? 140 @indexes_hash.each_value(&block) 141 self 142 else 143 @indexes_hash.values 144 end 145 end
Yield or enumerate each materialized view defined in this keyspace @overload each_materialized_view
@yieldparam view [Cassandra::MaterializedView] current materialized view @return [Cassandra::Keyspace] self
@overload each_materialized_view
@return [Array<Cassandra::MaterializedView>] a list of materialized views
# File lib/cassandra/keyspace.rb 168 def each_materialized_view(&block) 169 if block_given? 170 @views.each_value do |v| 171 yield(v) if v.base_table 172 end 173 self 174 else 175 result = [] 176 @views.each_value do |v| 177 result << v if v.base_table 178 end 179 result 180 end 181 end
Yield or enumerate each table defined in this keyspace @overload each_table
@yieldparam table [Cassandra::Table] current table @return [Cassandra::Keyspace] self
@overload each_table
@return [Array<Cassandra::Table>] a list of tables
# File lib/cassandra/keyspace.rb 110 def each_table(&block) 111 if block_given? 112 @tables.each_value(&block) 113 self 114 else 115 @tables.values 116 end 117 end
Yield or enumerate each user-defined type present in this keyspace @overload each_type
@yieldparam type [Cassandra::Types::UserDefined] current type @return [Cassandra::Keyspace] self
@overload each_type
@return [Array<Cassandra::Types::UserDefined>] a list of user-defined types
# File lib/cassandra/keyspace.rb 203 def each_type(&block) 204 if block_given? 205 @types.each_value(&block) 206 self 207 else 208 @types.values 209 end 210 end
@private
# File lib/cassandra/keyspace.rb 285 def eql?(other) 286 other.is_a?(Keyspace) && 287 @name == other.name && 288 @durable_writes == other.durable_writes && 289 @replication == other.replication && 290 @tables == other.raw_tables && 291 @types == other.raw_types && 292 @functions == other.raw_functions && 293 @aggregates == other.raw_aggregates 294 end
@return [Cassandra::Function, nil] a function or nil @param name [String] function name @param args [Array<String>] (var-args style) function argument types
# File lib/cassandra/keyspace.rb 224 def function(name, *args) 225 # The functions_hash datastructure is a hash <[func-name, args], Function>. 226 # So construct the array-key we're looking for. 227 @functions.get(name.downcase, args) 228 end
@return [Boolean] whether this keyspace has an aggregate with the given
name and arguments
@param name [String] aggregate name @param args [Array<String>] (var-args style) aggregate function argument types
# File lib/cassandra/keyspace.rb 250 def has_aggregate?(name, *args) 251 !@aggregates.get(name.downcase, args).nil? 252 end
@return [Boolean] whether this keyspace has a function with the given name and
arguments
@param name [String] function name @param args [Array<String>] (var-args style) function argument types
# File lib/cassandra/keyspace.rb 217 def has_function?(name, *args) 218 !@functions.get(name.downcase, args).nil? 219 end
@return [Boolean] whether this keyspace has an index with the given name @param name [String] index name
# File lib/cassandra/keyspace.rb 122 def has_index?(name) 123 @indexes_hash.key?(name) 124 end
@return [Boolean] whether this keyspace has a materialized view with the given name @param name [String] materialized view name
# File lib/cassandra/keyspace.rb 150 def has_materialized_view?(name) 151 # We check if the view exists *and* that its base-table is set. If base-table isn't available, 152 # it will be soon, so the user can poll on this method until we return a fully-baked materialized view. 153 @views.key?(name) && !@views[name].base_table.nil? 154 end
@return [Boolean] whether this keyspace has a table with the given name @param name [String] table name
# File lib/cassandra/keyspace.rb 94 def has_table?(name) 95 @tables.key?(name) 96 end
@return [Boolean] whether this keyspace has a user-defined type with the
given name
@param name [String] user-defined type name
# File lib/cassandra/keyspace.rb 187 def has_type?(name) 188 @types.key?(name) 189 end
@return [Cassandra::Index, nil] an index or nil @param name [String] index name
# File lib/cassandra/keyspace.rb 128 def index(name) 129 @indexes_hash[name] 130 end
@private
# File lib/cassandra/keyspace.rb 298 def inspect 299 "#<#{self.class.name}:0x#{object_id.to_s(16)} @name=#{@name}>" 300 end
@return [Cassandra::MaterializedView, nil] a materialized view or nil @param name [String] materialized view name
# File lib/cassandra/keyspace.rb 158 def materialized_view(name) 159 @views[name] if has_materialized_view?(name) 160 end
@return [Cassandra::Table, nil] a table or nil @param name [String] table name
# File lib/cassandra/keyspace.rb 100 def table(name) 101 @tables[name] 102 end
@return [String] a cql representation of this keyspace
# File lib/cassandra/keyspace.rb 278 def to_cql 279 "CREATE KEYSPACE #{Util.escape_name(@name)} " \ 280 "WITH replication = #{@replication.to_cql} AND " \ 281 "durable_writes = #{@durable_writes};" 282 end
@return [Cassandra::Types::UserDefined, nil] a type or nil @param name [String] user-defined type name
# File lib/cassandra/keyspace.rb 193 def type(name) 194 @types[name] 195 end
@private
# File lib/cassandra/keyspace.rb 415 def update_aggregate(aggregate) 416 aggregates = @aggregates.dup 417 aggregates.add_or_update(aggregate) 418 Keyspace.new(@name, 419 @durable_writes, 420 @replication, 421 @tables, 422 @types, 423 @functions, 424 aggregates, 425 @views) 426 end
@private
# File lib/cassandra/keyspace.rb 387 def update_function(function) 388 functions = @functions.dup 389 functions.add_or_update(function) 390 Keyspace.new(@name, 391 @durable_writes, 392 @replication, 393 @tables, 394 @types, 395 functions, 396 @aggregates, 397 @views) 398 end
@private
# File lib/cassandra/keyspace.rb 331 def update_materialized_view(view) 332 views = @views.dup 333 views[view.name] = view 334 Keyspace.new(@name, 335 @durable_writes, 336 @replication, 337 @tables, 338 @types, 339 @functions, 340 @aggregates, 341 views) 342 end
@private
# File lib/cassandra/keyspace.rb 303 def update_table(table) 304 tables = @tables.dup 305 tables[table.name] = table 306 Keyspace.new(@name, 307 @durable_writes, 308 @replication, 309 tables, 310 @types, 311 @functions, 312 @aggregates, 313 @views) 314 end
@private
# File lib/cassandra/keyspace.rb 359 def update_type(type) 360 types = @types.dup 361 types[type.name] = type 362 Keyspace.new(@name, 363 @durable_writes, 364 @replication, 365 @tables, 366 types, 367 @functions, 368 @aggregates, 369 @views) 370 end
Protected Instance Methods
@private
# File lib/cassandra/keyspace.rb 469 def raw_aggregates 470 @aggregates 471 end
@private
# File lib/cassandra/keyspace.rb 464 def raw_functions 465 @functions 466 end
@private
# File lib/cassandra/keyspace.rb 454 def raw_materialized_views 455 @views 456 end
@private
# File lib/cassandra/keyspace.rb 449 def raw_tables 450 @tables 451 end
@private
# File lib/cassandra/keyspace.rb 459 def raw_types 460 @types 461 end