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, 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

#wrap_levelObject

Returns the value of attribute wrap_level.



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

def wrap_level
  @wrap_level
end

Class Method Details

.instrument_queries(queries) ⇒ Object



184
185
186
187
188
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 184

def instrument_queries(queries)
  queries.each do |query|
    instrument_query(query) {}
  end
end

.transaction_classObject



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

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

Instance Method Details

#connect(*_args) ⇒ Object



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

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

#loggerObject



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

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



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

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



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

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



164
165
166
167
168
169
170
# File 'lib/neo4j/core/cypher_session/adaptors.rb', line 164

def setup_queries!(queries, transaction, options = {})
  fail 'Query attempted without a connection' if !connected?
  fail "Invalid transaction object: #{transaction.inspect}" if !transaction.is_a?(self.class.transaction_class)

  # context option not yet implemented
  self.class.instrument_queries(queries) unless options[:skip_instrumentation]
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



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

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