Class: Neo4j::Core::CypherSession::Adaptors::Base

Inherits:
Object
  • Object
show all
Includes:
Instrumentable
Defined in:
lib/neo4j/core/cypher_session/adaptors.rb

Direct Known Subclasses

Bolt, Driver, Embedded, HTTP

Defined Under Namespace

Classes: Query, QueryBuilder

Constant Summary collapse

USER_AGENT_STRING =
"#{gem_name}-gem/#{version} (https://github.com/neo4jrb/#{gem_name})"
EMPTY =
''
NEWLINE_W_SPACES =
"\n  "

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Instrumentable

included

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



71
72
73
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 71

def options
  @options
end

#wrap_levelObject

Returns the value of attribute wrap_level.



70
71
72
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 70

def wrap_level
  @wrap_level
end

Class Method Details

.transaction_classObject



200
201
202
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 200

def transaction_class
  fail '.transaction_class method not implemented on adaptor!'
end

Instance Method Details

#closeObject



193
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 193

def close; end

#connect(*_args) ⇒ Object



66
67
68
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 66

def connect(*_args)
  fail '#connect not implemented!'
end

#default_subscribeObject



189
190
191
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 189

def default_subscribe
  subscribe_to_request
end

#loggerObject



154
155
156
157
158
159
160
161
162
163
164
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 154

def logger
  return @logger if @logger

  @logger = if @options[:logger]
              @options[:logger]
            else
              Logger.new(logger_location).tap do |logger|
                logger.level = logger_level
              end
            end
end

#queries(session, options = {}, &block) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 113

def queries(session, options = {}, &block)
  query_builder = QueryBuilder.new

  query_builder.instance_eval(&block)

  new_or_current_transaction(session, options[:transaction]) do |tx|
    query_set(tx, query_builder.queries, {commit: !options[:transaction]}.merge(options))
  end
end

#query(session, *args) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 102

def query(session, *args)
  options = case args.size
            when 3
              args.pop
            when 2
              args.pop if args[0].is_a?(::Neo4j::Core::Query)
            end || {}

  queries(session, options) { append(*args) }[0]
end

#setup_queries!(queries, transaction, options = {}) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 166

def setup_queries!(queries, transaction, options = {})
  validate_connection!(transaction)

  return if options[:skip_instrumentation]
  queries.each do |query|
    self.class.instrument_query(query, self) {}
  end
end

#supports_metadata?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 195

def supports_metadata?
  true
end

#transaction(session) ⇒ Object

If called without a block, returns a Transaction object which can be used to call query/queries/mark_failed/commit If called with a block, the Transaction object is yielded to the block and ‘commit` is ensured. Any uncaught exceptions will mark the transaction as failed first



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 138

def transaction(session)
  return self.class.transaction_class.new(session) if !block_given?

  begin
    tx = transaction(session)

    yield tx
  rescue => e
    tx.mark_failed if tx

    raise e
  ensure
    tx.close if tx
  end
end