Class: Neo4j::Rails::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/neo4j/rails/transaction.rb

Overview

This method is typically used in an Rails ActionController as a filter method. It will guarantee that an transaction is create before your action is called, and that the transaction is finished after your action is called.

Example:

class MyController < ActionController::Base
    around_filter Neo4j::Rails::Transaction, :only => [:edit, :delete]
    ...
end

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) current



35
36
37
# File 'lib/neo4j/rails/transaction.rb', line 35

def current
  Thread.current[:neo4j_transaction]
end

+ (Object) fail



47
48
49
# File 'lib/neo4j/rails/transaction.rb', line 47

def fail
  Thread.current[:neo4j_transaction_fail] = true
end

+ (Boolean) fail?

Returns:

  • (Boolean)


43
44
45
# File 'lib/neo4j/rails/transaction.rb', line 43

def fail?
  Thread.current[:neo4j_transaction_fail] != nil
end

+ (Object) filter(&block)



71
72
73
# File 'lib/neo4j/rails/transaction.rb', line 71

def filter(*, &block)
  run &block
end

+ (Object) finish



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/neo4j/rails/transaction.rb', line 55

def finish
  tx = Thread.current[:neo4j_transaction]
  tx.success unless fail?
  tx.finish
  Thread.current[:neo4j_transaction] = nil
  Thread.current[:neo4j_transaction_fail] = nil
rescue Exception => e
  if Neo4j::Config[:debug_java] && e.respond_to?(:cause)
    puts "Java Exception in a transaction, cause: #{e.cause}"
    e.cause.print_stack_trace
  end
  tx.failure unless tx.nil?
  raise
end

+ (Object) run



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/neo4j/rails/transaction.rb', line 75

def run
  if running?
    yield self
  else
    begin
      new
      ret = yield self
    rescue
      fail
      raise
    ensure
      finish
    end
    ret
  end
end

+ (Boolean) running?

Returns:

  • (Boolean)


39
40
41
# File 'lib/neo4j/rails/transaction.rb', line 39

def running?
  Thread.current[:neo4j_transaction] != nil
end

+ (Object) success



51
52
53
# File 'lib/neo4j/rails/transaction.rb', line 51

def success
  Thread.current[:neo4j_transaction_fail] = nil
end

Instance Method Details

- (Java::OrgNeo4jGraphdb::Lock) acquire_read_lock(java_entity)

Acquires a read lock for entity for this transaction. The lock (returned from this method) can be released manually, but if not it's released automatically when the transaction finishes. There is no implementation for this here because it's an java method

Parameters:

  • java_entity (Neo4j::Relationship, Neo4j::Node)

    the entity to acquire a lock for. If another transaction currently hold a write lock to that entity this call will wait until it's released.

Returns:

  • (Java::OrgNeo4jGraphdb::Lock)

    a Lock which optionally can be used to release this lock earlier than when the transaction finishes. If not released (with Lock.release() it's going to be released with the transaction finishes.

See Also:



31
32
# File 'lib/neo4j/rails/transaction.rb', line 31

def acquire_read_lock(java_entity)
end

- (Java::OrgNeo4jGraphdb::Lock) acquire_write_lock(java_entity)

Acquires a write lock for entity for this transaction. The lock (returned from this method) can be released manually, but if not it's released automatically when the transaction finishes. There is no implementation for this here because it's an java method

Parameters:

  • java_entity (Neo4j::Relationship, Neo4j::Node)

    the entity to acquire a lock for. If another transaction currently holds a write lock to that entity this call will wait until it's released.

Returns:

  • (Java::OrgNeo4jGraphdb::Lock)

    a Lock which optionally can be used to release this lock earlier than when the transaction finishes. If not released (with Lock.release() it's going to be released with the transaction finishes.

See Also:



22
23
# File 'lib/neo4j/rails/transaction.rb', line 22

def acquire_write_lock(java_entity)
end