Sha256: f9ab02db27503460fbbef9c1f36cf16da0ba086b5e75a91948cdb7fe926584f4

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'neo4j/core/cypher_session/transactions'

module Neo4j
  module Core
    class CypherSession
      module Transactions
        class Driver < Base
          attr_reader :driver_tx, :driver_session

          def initialize(*args)
            super
            return unless root?
            @driver_session = session.adaptor.driver.session(Neo4j::Driver::AccessMode::WRITE)
            @driver_tx = @driver_session.begin_transaction
          rescue StandardError => e
            clean_transaction_registry
            @driver_tx.close if @driver_tx
            @driver_session.close if @driver_session
            raise e
          end

          def commit
            return unless root?
            begin
              @driver_tx.success
              @driver_tx.close
            ensure
              @driver_session.close
            end
          end

          def delete
            root.driver_tx.failure
            root.driver_tx.close
            root.driver_session.close
          end

          def started?
            true
          end

          def root_tx
            root.driver_tx
          end

          private

          def clean_transaction_registry
            Neo4j::Transaction::TransactionsRegistry.transactions_by_session_id[session.object_id] = []
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neo4j-core-9.0.0 lib/neo4j/core/cypher_session/transactions/driver.rb