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

Returns a new instance of Statement.

Parameters:

  • statement (String)

    graph statement

  • parameters (Hash<String, String>) (defaults to: nil)

    (nil) parameters to the statement

  • options (Hash) (defaults to: nil)

    (nil) graph options

  • idempotent (Boolean) (defaults to: false)

    (false) whether or not the statement is idempotent



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)

Returns parameters to the statement.

Returns:

  • (Hash<String, String>)

    parameters to the statement



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

def parameters
  @parameters
end

#statementString (readonly)

Returns graph statement string.

Returns:

  • (String)

    graph statement string



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

def statement
  @statement
end

Instance Method Details

#graph_languageString

Returns language used in the graph statement (default "gremlin-groovy").

Returns:

  • (String)

    language used in the graph statement (default "gremlin-groovy")



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

Returns name of the targeted graph; required unless the statement is a system query.

Returns:

  • (String)

    name of the targeted graph; required unless the statement is a system query.



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

Returns read consistency level for graph statement. Overrides the standard statement consistency level. Defaults to ONE in the server, but the default may be configured differently.

Returns:

  • (Cassandra::CONSISTENCIES)

    read consistency level for graph statement. Overrides the standard statement consistency level. Defaults to ONE in the server, but the default may be configured differently.



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

Returns graph traversal source (default "g").

Returns:

  • (String)

    graph traversal source (default "g")



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

Returns write consistency level for graph statement. Overrides the standard statement consistency level. Defaults to QUORUM in the server, but the default may be configured differently.

Returns:

  • (Cassandra::CONSISTENCIES)

    write consistency level for graph statement. Overrides the standard statement consistency level. Defaults to QUORUM in the server, but the default may be configured differently.



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