Sha256: 1c288eb7f595b8f03c06c87a87487c90d0469f3696f3e7e63a039fb3409d0516

Contents?: true

Size: 1.21 KB

Versions: 18

Compression:

Stored size: 1.21 KB

Contents

module Neo4j
  class Transaction
    def self.new(current = Session.current)
      current.begin_tx
    end


    class << self

      def run(run_in_tx=true)
        raise ArgumentError.new("Expected a block to run in Transaction.run") unless block_given?

        return yield(nil) unless run_in_tx

        begin
          tx = Neo4j::Transaction.new
          ret = yield tx
          tx.success
        rescue Exception => e
          if e.respond_to?(:cause) && e.cause
            puts "Java Exception in a transaction, cause: #{e.cause}"
            e.cause.print_stack_trace
          end
          tx.failure unless tx.nil?
          raise
        ensure
          tx.finish unless tx.nil?
        end
        ret
      end

      def current
        Thread.current[:neo4j_curr_tx]
      end

      def unregister(tx)
        Thread.current[:neo4j_curr_tx] = nil if tx == Thread.current[:neo4j_curr_tx]
      end

      def register(tx)
        # we don't support running more then one transaction per thread
        raise "Already running a transaction" if current
        Thread.current[:neo4j_curr_tx] = tx
      end

      def unregister_current
        Thread.current[:neo4j_curr_tx] = nil
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
neo4j-core-3.0.0.alpha.18 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.17 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.16 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.15 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.14 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.13 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.12 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.11 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.10 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.9 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.8 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.7 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.6 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.5 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.4 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.3 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.2 lib/neo4j/transaction.rb
neo4j-core-3.0.0.alpha.1 lib/neo4j/transaction.rb