Module: Pacer

Defined in:
lib/pacer-neo4j.rb,
lib/pacer-neo4j/algo.rb,
lib/pacer-neo4j/graph.rb,
lib/pacer-neo4j/version.rb,
lib/pacer-neo4j/algo/wrapping.rb,
lib/pacer-neo4j/lucene_filter.rb,
lib/pacer-neo4j/algo/path_pipe.rb,
lib/pacer-neo4j/tx_data_wrapper.rb,
lib/pacer-neo4j/blueprints_graph.rb,
lib/pacer-neo4j/algo/path_wrapper.rb,
lib/pacer-neo4j/algo/cypher_transform.rb,
lib/pacer-neo4j/algo/block_path_expander.rb,
lib/pacer-neo4j/raw_vertex_wrapping_pipe.rb,
lib/pacer-neo4j/algo/block_cost_evaluator.rb,
lib/pacer-neo4j/transaction_event_handler.rb,
lib/pacer-neo4j/algo/block_estimate_evaluator.rb,
lib/pacer-neo4j/algo/traversal_branch_wrapper.rb

Defined Under Namespace

Modules: Core, Filter, Neo4j, Transform

Class Method Summary collapse

Class Method Details

.neo4j(path_or_graph, args = nil) ⇒ Object

Return a graph for the given path. Will create a graph if none exists at that location. (The graph is only created if data is actually added to it).

If the graph is opened from a path, it will be registered to be closed by Ruby’s at_exit callback, but if an already open graph is given, it will not.

Please note that Pacer turns on Neo4j’s checkElementsInTransaction feature by default. For some sort of performance improvement at the expense of an odd consistency model within transactions that require considerable more complexity in client code, you can use ‘graph.setCheckElementsInTransaction(false)` to disable the feature.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pacer-neo4j.rb', line 49

def neo4j(path_or_graph, args = nil)
  if path_or_graph.is_a? String
    path = File.expand_path(path_or_graph)
    open = proc do
      raw_graph = Pacer.open_graphs[path]
      if raw_graph
        graph = neo4j_class(args).new(raw_graph)
      else
        FileUtils.mkdir_p path
        if args
          graph = neo4j_class(args).new(path, args.to_hash_map)
        else
          graph = neo4j_class({}).new(path)
        end
        graph.allow_auto_tx = false
        Pacer.open_graphs[path] = graph.raw_graph
        graph.setCheckElementsInTransaction true
      end
      graph
    end
    shutdown = proc do |g|
      g.blueprints_graph.shutdown
      Pacer.open_graphs.delete path
    end
    Neo4j::Graph.new(Pacer::YamlEncoder, open, shutdown)
  else
    # Don't register the new graph so that it won't be automatically closed.
    Neo4j::Graph.new Pacer::YamlEncoder, proc { neo4j_class(args || {}).new(path_or_graph) }
  end
end

.neo4j_class(args) ⇒ Object



32
33
34
# File 'lib/pacer-neo4j.rb', line 32

def neo4j_class(args)
  Pacer::Neo4j::BlueprintsGraph
end

.neo_batch(path) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/pacer-neo4j.rb', line 80

def neo_batch(path)
  bp_neo_class = com.tinkerpop.blueprints.impls.neo4jbatch.Neo4jBatchGraph
  path = File.expand_path(path)
  open = proc do
    graph = bp_neo_class.new(path)
    Pacer.open_graphs[path] = :open_batch_graph
    graph
  end
  shutdown = proc do |g|
    g.blueprints_graph.shutdown
    Pacer.open_graphs.delete path
  end
  g = PacerGraph.new(Pacer::YamlEncoder, open, shutdown)
  g.disable_transactions = true
  g
end