Permalink
Browse files

Merge remote branch 'backupify/master'

  • Loading branch information...
2 parents 265d99d + 97d6c0f commit fe7d160ab871466b5012521cb7a1c46728812fbf @ryanking ryanking committed Sep 22, 2010
@@ -9,25 +9,31 @@ def login!(username, password)
client.login(@auth_request)
end
+ def inspect
+ "#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
+ schema(false).cf_defs.map {|cfdef| ":#{cfdef.name} => #{cfdef.column_type}"}.join(', ')
+ }}, @servers=#{servers.inspect}>"
+ end
+
def keyspace=(ks)
client.set_keyspace(ks) if check_keyspace(ks)
@schema = nil; @keyspace = ks
end
def keyspaces
- client.describe_keyspaces.to_a
+ client.describe_keyspaces.to_a.collect {|ksdef| ksdef.name }
end
def schema(load=true)
if !load && !@schema
- []
+ Cassandra::Keyspace.new
else
@schema ||= client.describe_keyspace(@keyspace)
end
end
def schema_agreement?
- client.check_schema_agreement().length == 1
+ client.describe_schema_versions().length == 1
end
def version
@@ -58,7 +64,7 @@ def truncate!(column_family)
# Remove all rows in the keyspace.
def clear_keyspace!
- schema.keys.each { |column_family| truncate!(column_family) }
+ schema.cf_defs.each { |cfdef| truncate!(cfdef.name) }
end
### Read
@@ -131,6 +137,30 @@ def rename_keyspace(old_name, new_name)
res
end
+ # Open a batch operation and yield self. Inserts and deletes will be queued
+ # until the block closes, and then sent atomically to the server. Supports
+ # the <tt>:consistency</tt> option, which overrides the consistency set in
+ # the individual commands.
+ def batch(options = {})
+ _, _, _, options =
+ extract_and_validate_params(schema.cf_defs.first.name, "", [options], WRITE_DEFAULTS)
+
+ @batch = []
+ yield(self)
+ compact_mutations!
+
+ @batch.each do |mutation|
+ case mutation.first
+ when :remove
+ _remove(*mutation[1])
+ else
+ _mutate(*mutation)
+ end
+ end
+ ensure
+ @batch = nil
+ end
+
protected
def client
@@ -14,6 +14,27 @@ def timestamp=(ts)
class Cassandra
# A bunch of crap, mostly related to introspecting on column types
module Columns #:nodoc:
+
+ def is_super(column_family)
+ @is_super[column_family] ||= column_family_property(column_family, 'column_type') == "Super"
+ end
+
+ def column_name_class(column_family)
+ @column_name_class[column_family] ||= column_name_class_for_key(column_family, "comparator_type")
+ end
+
+ def sub_column_name_class(column_family)
+ @sub_column_name_class[column_family] ||= column_name_class_for_key(column_family, "subcomparator_type")
+ end
+
+ def column_family_property(column_family, key)
+ cfdef = schema.cf_defs.find {|cfdef| cfdef.name == column_family }
+ unless cfdef
+ raise AccessError, "Invalid column family \"#{column_family}\""
+ end
+ cfdef.send(key)
+ end
+
private
def _standard_insert_mutation(column_family, column_name, value, timestamp, ttl = nil)
Oops, something went wrong.

0 comments on commit fe7d160

Please sign in to comment.