Class: Dse::Session
- Inherits:
-
Object
- Object
- Dse::Session
- Defined in:
- lib/dse/session.rb
Overview
A session is used to execute queries. In addition to executing standard CQL queries via the #execute and #execute_async methods, it executes graph queries via the #execute_graph_async and #execute_graph methods.
Instance Method Summary collapse
-
#execute_graph(statement, options = {}) ⇒ Cassandra::Result
Execute a graph statement synchronously.
-
#execute_graph_async(graph_statement, options = {}) ⇒ Cassandra::Future<Cassandra::Result>
Execute a graph statement asynchronously.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object (protected)
106 107 108 109 110 111 112 |
# File 'lib/dse/session.rb', line 106 def method_missing(method_name, *args, &block) # If we get here, we don't have a method of our own. Forward the request to @cassandra_session. # If it returns itself, we will coerce the result to return our *self* instead. result = @cassandra_session.send(method_name, *args, &block) (result == @cassandra_session) ? self : result end |
Instance Method Details
#execute_graph(statement, options = {}) ⇒ Cassandra::Result
Execute a graph statement synchronously.
98 99 100 |
# File 'lib/dse/session.rb', line 98 def execute_graph(statement, = {}) execute_graph_async(statement, ).get end |
#execute_graph_async(graph_statement, options = {}) ⇒ Cassandra::Future<Cassandra::Result>
Execute a graph statement asynchronously.
43 44 45 46 47 48 49 50 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 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/dse/session.rb', line 43 def execute_graph_async(graph_statement, = {}) # Make our own copy of the options. The caller might want to re-use the options they provided, and we're # about to do some destructive mutations. = .dup Cassandra::Util.assert_instance_of_one_of([String, Dse::Graph::Statement], graph_statement) arguments = nil if Cassandra::Util.assert_instance_of(::Hash, ) arguments = .delete(:arguments) end if graph_statement.is_a?(String) graph_statement = Dse::Graph::Statement.new(graph_statement, arguments, , [:idempotent]) end [:execution_profile] ||= :default_graph profile = @profile_manager.profiles[[:execution_profile]] Cassandra::Util.assert(!profile.nil?, "Profile '#{[:execution_profile]}' does not exist") Cassandra::Util.assert_instance_of(Dse::Graph::ExecutionProfile, profile) = profile..merge(graph_statement.) # The custom payload should have a 'request-timeout' that is the value of the :timeout option, if specified. # Otherwise, fall back to the timeout in the execution profile. [:payload] = .as_payload([:timeout] || profile.timeout) if .analytics? @cassandra_session.execute_async('CALL DseClientTool.getAnalyticsGraphServer()').then do |rows| row = rows.first if row.nil? || row['result'].nil? @cassandra_session.execute_async(graph_statement, ).then do |raw_result| Dse::Graph::ResultSet.new(raw_result) end else ip = row['result']['ip'] targeted_statement = Dse::Statements::HostTargeting.new(graph_statement, ip) @cassandra_session.execute_async(targeted_statement, ).then do |raw_result| Dse::Graph::ResultSet.new(raw_result) end end end else @cassandra_session.execute_async(graph_statement, ).then do |raw_result| Dse::Graph::ResultSet.new(raw_result) end end rescue => e @futures.error(e) end |