class Neo4j::SessionManager

Public Class Methods

adaptor_class(type, options) click to toggle source
   # File lib/neo4j/session_manager.rb
18 def adaptor_class(type, options)
19   options[:adaptor_class] || adaptor_class_by_type(type.to_sym)
20 end
open_neo4j_session(type, url_or_path, wait_for_connection = false, options = {}) click to toggle source
   # File lib/neo4j/session_manager.rb
 7 def open_neo4j_session(type, url_or_path, wait_for_connection = false, options = {})
 8   enable_unlimited_strength_crypto! if java_platform? && session_type_is_embedded?(type)
 9 
10   verbose_query_logs = Neo4j::Config.fetch(:verbose_query_logs, false)
11   adaptor = cypher_session_adaptor(type, url_or_path, options.merge(wrap_level: :proc,
12                                                                     verbose_query_logs: verbose_query_logs))
13   session = Neo4j::Core::CypherSession.new(adaptor)
14   wait_and_retry(session) if wait_for_connection
15   session
16 end

Protected Class Methods

cypher_session_adaptor(type, path_or_url, options = {}) click to toggle source
   # File lib/neo4j/session_manager.rb
36 def cypher_session_adaptor(type, path_or_url, options = {})
37   adaptor_class(type, options).new(path_or_url, options)
38 end
enable_unlimited_strength_crypto!() click to toggle source
   # File lib/neo4j/session_manager.rb
28 def enable_unlimited_strength_crypto!
29   # See https://github.com/jruby/jruby/wiki/UnlimitedStrengthCrypto
30   security_class = java.lang.Class.for_name('javax.crypto.JceSecurity')
31   restricted_field = security_class.get_declared_field('isRestricted')
32   restricted_field.accessible = true
33   restricted_field.set nil, false
34 end
java_platform?() click to toggle source
   # File lib/neo4j/session_manager.rb
40 def java_platform?
41   RUBY_PLATFORM =~ /java/
42 end
session_type_is_embedded?(session_type) click to toggle source
   # File lib/neo4j/session_manager.rb
24 def session_type_is_embedded?(session_type)
25   [:embedded_db, :embedded].include?(session_type)
26 end
wait_and_retry(session) click to toggle source
   # File lib/neo4j/session_manager.rb
44 def wait_and_retry(session)
45   Timeout.timeout(60) do
46     begin
47       session.constraints
48     rescue Neo4j::Core::CypherSession::ConnectionFailedError
49       sleep(1)
50       retry
51     end
52   end
53 rescue Timeout::Error
54   raise Timeout::Error, 'Timeout while waiting for connection to neo4j database'
55 end

Private Class Methods

adaptor_class_by_type(type) click to toggle source
   # File lib/neo4j/session_manager.rb
59 def adaptor_class_by_type(type)
60   ActiveSupport::Deprecation.warn('`embedded_db` session type is deprecated, please use `embedded`') if type == :embedded_db
61   case type
62   when :embedded_db, :embedded
63     require 'neo4j/core/cypher_session/adaptors/embedded'
64     Neo4j::Core::CypherSession::Adaptors::Embedded
65   when :http
66     require 'neo4j/core/cypher_session/adaptors/http'
67     Neo4j::Core::CypherSession::Adaptors::HTTP
68   when :bolt
69     require 'neo4j/core/cypher_session/adaptors/bolt'
70     Neo4j::Core::CypherSession::Adaptors::Bolt
71   else
72     extra = ' (`server_db` has been replaced by `http` or `bolt`)'
73     fail ArgumentError, "Invalid session type: #{type.inspect} (expected one of [:http, :bolt, :embedded])#{extra if type == :server_db}"
74   end
75 end