Class: Dse::Graph::Statement
- Inherits:
-
Object
- Object
- Dse::Graph::Statement
- Extended by:
- Forwardable
- Includes:
- Cassandra::Statement
- Defined in:
- lib/dse/graph/statement.rb
Overview
Encapsulates a graph statement, parameters, options, and idempotency. This is primarily useful for re-issuing the same statement multiple times the same way.
Instance Attribute Summary collapse
-
#parameters ⇒ Hash<String, String>
readonly
Parameters to the statement.
-
#statement ⇒ String
readonly
Graph statement string.
Instance Method Summary collapse
-
#graph_language ⇒ String
Language used in the graph statement (default "gremlin-groovy").
-
#graph_name ⇒ String
Name of the targeted graph; required unless the statement is a system query.
-
#graph_read_consistency ⇒ Cassandra::CONSISTENCIES
Read consistency level for graph statement.
-
#graph_source ⇒ String
Graph traversal source (default "g").
-
#graph_write_consistency ⇒ Cassandra::CONSISTENCIES
Write consistency level for graph statement.
-
#initialize(statement, parameters = nil, options = nil, idempotent = false) ⇒ Statement
constructor
A new instance of Statement.
Constructor Details
#initialize(statement, parameters = nil, options = nil, idempotent = false) ⇒ Statement
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dse/graph/statement.rb', line 51 def initialize(statement, parameters = nil, = nil, idempotent = false) # Save off statement and idempotent; easy stuff. @statement = statement.freeze @idempotent = idempotent.freeze @parameters = parameters.freeze # Convert the parameters into a one-element array with JSON; that's what we need to # send to DSE over the wire. But if we have no params, nil is fine. unless parameters.nil? ::Cassandra::Util.assert_instance_of(::Hash, parameters, 'Graph parameters must be a hash') # Some of our parameters may be geo-type values. Convert them to their wkt representation. tweaked_params = {} parameters.each do |name, value| value = value.wkt if value.respond_to?(:wkt) tweaked_params[name] = value end parameters = [tweaked_params.to_json] end # Create a Graph::Options object only if we have non-nil options. unless .nil? || .empty? Cassandra::Util.assert_instance_of(::Hash, ) @options = Dse::Graph::Options.new() end @simple_statement = Cassandra::Statements::Simple.new(@statement, parameters, parameters.nil? ? nil : [Cassandra::Types.varchar], @idempotent) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (protected)
121 122 123 124 |
# File 'lib/dse/graph/statement.rb', line 121 def method_missing(method, *args, &block) # Delegate unrecognized method calls to our embedded statement. @simple_statement.send(method, *args, &block) end |
Instance Attribute Details
#parameters ⇒ Hash<String, String> (readonly)
41 42 43 |
# File 'lib/dse/graph/statement.rb', line 41 def parameters @parameters end |
#statement ⇒ String (readonly)
39 40 41 |
# File 'lib/dse/graph/statement.rb', line 39 def statement @statement end |
Instance Method Details
#graph_language ⇒ String
35 36 |
# File 'lib/dse/graph/statement.rb', line 35 def_delegators :@options, :graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency |
#graph_name ⇒ String
35 36 |
# File 'lib/dse/graph/statement.rb', line 35 def_delegators :@options, :graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency |
#graph_read_consistency ⇒ Cassandra::CONSISTENCIES
35 36 |
# File 'lib/dse/graph/statement.rb', line 35 def_delegators :@options, :graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency |
#graph_source ⇒ String
35 36 |
# File 'lib/dse/graph/statement.rb', line 35 def_delegators :@options, :graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency |
#graph_write_consistency ⇒ Cassandra::CONSISTENCIES
35 36 |
# File 'lib/dse/graph/statement.rb', line 35 def_delegators :@options, :graph_name, :graph_source, :graph_language, :graph_read_consistency, :graph_write_consistency |