Class: Dse::Graph::Statement

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = 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 options.nil? || options.empty?
    Cassandra::Util.assert_instance_of(::Hash, options)
    @options = Dse::Graph::Options.new(options)
  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

#parametersHash<String, String> (readonly)



41
42
43
# File 'lib/dse/graph/statement.rb', line 41

def parameters
  @parameters
end

#statementString (readonly)



39
40
41
# File 'lib/dse/graph/statement.rb', line 39

def statement
  @statement
end

Instance Method Details

#graph_languageString



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_nameString



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_consistencyCassandra::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_sourceString



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_consistencyCassandra::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