Class: Eurydice::Pelops::Keyspace
Instance Attribute Summary collapse
Instance Method Summary
collapse
#default_cl?, #get_cl
#thrift_exception_handler, #transform_thrift_exception
Constructor Details
#initialize(name, cluster, pool_name, driver) ⇒ Keyspace
Returns a new instance of Keyspace.
11
12
13
14
15
16
17
|
# File 'lib/eurydice/pelops/keyspace.rb', line 11
def initialize(name, cluster, pool_name, driver)
@name = name
@cluster = cluster
@pool_name = pool_name
@driver = driver
@batch_key = "#{@name}-batch-#{object_id}"
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/eurydice/pelops/keyspace.rb', line 9
def name
@name
end
|
Instance Method Details
#batch(options = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/eurydice/pelops/keyspace.rb', line 79
def batch(options={})
if batch_in_progress?
check_batch_options!(options)
yield current_batch_mutator
else
start_batch(options)
begin
yield current_batch_mutator
end_batch!
ensure
clear_batch!
end
end
nil
end
|
#column_families(reload = false) ⇒ Object
48
49
50
|
# File 'lib/eurydice/pelops/keyspace.rb', line 48
def column_families(reload=false)
definition(reload)[:column_families].keys
end
|
#column_family(name, options = {}) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/eurydice/pelops/keyspace.rb', line 52
def column_family(name, options={})
create = options.fetch(:create, true)
cf = ColumnFamily.new(self, name)
cf.create! if create && !cf.exists?
cf
end
|
#column_family_manger ⇒ Object
75
76
77
|
# File 'lib/eurydice/pelops/keyspace.rb', line 75
def column_family_manger
@column_family_manger ||= @driver.create_column_family_manager(@cluster, @name)
end
|
#create!(options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/eurydice/pelops/keyspace.rb', line 31
def create!(options={})
thrift_exception_handler do
ks_properties = options.merge(:name => @name)
ks_properties[:strategy_class] = DEFAULT_STRATEGY_CLASS unless ks_properties.key?(:strategy_class)
ks_properties[:strategy_options] = DEFAULT_STRATEGY_OPTIONS if !ks_properties.key?(:strategy_options) && ks_properties[:strategy_class] == DEFAULT_STRATEGY_CLASS
ks_def = Cassandra::KsDef.from_h(ks_properties)
keyspace_manager.add_keyspace(ks_def)
@driver.add_pool(@pool_name, @cluster, @name)
end
end
|
#create_mutator ⇒ Object
59
60
61
|
# File 'lib/eurydice/pelops/keyspace.rb', line 59
def create_mutator
@driver.create_mutator(@pool_name)
end
|
#create_row_deletor ⇒ Object
67
68
69
|
# File 'lib/eurydice/pelops/keyspace.rb', line 67
def create_row_deletor
@driver.create_row_deletor(@pool_name)
end
|
#create_selector ⇒ Object
63
64
65
|
# File 'lib/eurydice/pelops/keyspace.rb', line 63
def create_selector
@driver.create_selector(@pool_name)
end
|
#definition(reload = false) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/eurydice/pelops/keyspace.rb', line 19
def definition(reload=false)
thrift_exception_handler do
@definition = nil if reload
@definition ||= keyspace_manager.get_keyspace_schema(@name).to_h
@definition
end
end
|
#drop! ⇒ Object
42
43
44
45
46
|
# File 'lib/eurydice/pelops/keyspace.rb', line 42
def drop!
keyspace_manager.drop_keyspace(@name)
rescue Exception => e
transform_thrift_exception(e)
end
|
#exists? ⇒ Boolean
27
28
29
|
# File 'lib/eurydice/pelops/keyspace.rb', line 27
def exists?
keyspace_manager.keyspace_names.map { |ks_def| ks_def.name }.include?(@name)
end
|
#keyspace_manager ⇒ Object
71
72
73
|
# File 'lib/eurydice/pelops/keyspace.rb', line 71
def keyspace_manager
@keyspace_manager ||= @driver.create_keyspace_manager(@cluster)
end
|