Class: CassandraClient
- Inherits:
-
Object
- Object
- CassandraClient
- Defined in:
- lib/cassandra_client/ordered_hash.rb,
lib/cassandra_client/table.rb,
lib/cassandra_client/client.rb,
lib/cassandra_client/serialization.rb
Overview
Copyright © 2004-2009 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Modules: Serialization Classes: AccessError, OrderedHash, SafeClient, Table
Instance Attribute Summary collapse
-
#block_for ⇒ Object
readonly
Returns the value of attribute block_for.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#serialization ⇒ Object
readonly
Returns the value of attribute serialization.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
-
#initialize(host = '127.0.0.1', port = 9160, block_for = 1, serialization = CassandraClient::Serialization::JSON) ⇒ CassandraClient
constructor
Instantiate a new CassandraClient and open the connection.
- #inspect(full = true) ⇒ Object
-
#remove_all ⇒ Object
Remove all rows in all column families in all tables.
-
#table(table_name) ⇒ Object
Return the CassandraClient::Table instance for the table_name you request.
Constructor Details
#initialize(host = '127.0.0.1', port = 9160, block_for = 1, serialization = CassandraClient::Serialization::JSON) ⇒ CassandraClient
Instantiate a new CassandraClient and open the connection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cassandra_client/client.rb', line 7 def initialize(host = '127.0.0.1', port = 9160, block_for = 1, serialization = CassandraClient::Serialization::JSON) @host = host @port = port @serialization = serialization @block_for = block_for @transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port)) @transport.open @client = SafeClient.new( Cassandra::Client.new(Thrift::BinaryProtocol.new(@transport)), @transport) @tables = @client.getStringListProperty("tables").map do |table_name| ::CassandraClient::Table.new(table_name, self) end end |
Instance Attribute Details
#block_for ⇒ Object (readonly)
Returns the value of attribute block_for.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def block_for @block_for end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def client @client end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def port @port end |
#serialization ⇒ Object (readonly)
Returns the value of attribute serialization.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def serialization @serialization end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def tables @tables end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
2 3 4 |
# File 'lib/cassandra_client/client.rb', line 2 def transport @transport end |
Instance Method Details
#inspect(full = true) ⇒ Object
25 26 27 28 29 |
# File 'lib/cassandra_client/client.rb', line 25 def inspect(full = true) string = "#<CassandraClient:#{object_id}, @host=#{host.inspect}, @port=#{@port.inspect}" string += ", @block_for=#{block_for.inspect}, @tables=[#{tables.map {|t| t.inspect(false) }.join(', ')}]" if full string + ">" end |
#remove_all ⇒ Object
Remove all rows in all column families in all tables.
41 42 43 44 45 46 47 |
# File 'lib/cassandra_client/client.rb', line 41 def remove_all tables.each do |table| table.schema.keys.each do |column_family| table.remove_all(column_family) end end end |
#table(table_name) ⇒ Object
Return the CassandraClient::Table instance for the table_name you request. You can get an array of all available tables with the #tables method.
34 35 36 37 38 |
# File 'lib/cassandra_client/client.rb', line 34 def table(table_name) table = @tables.detect {|table| table.name == table_name } raise AccessError, "No such table #{table_name.inspect}" unless table table end |