Module: Pacer
- Defined in:
- lib/pacer-orient.rb,
lib/pacer-orient/graph.rb,
lib/pacer-orient/version.rb
Defined Under Namespace
Modules: Orient
Class Method Summary collapse
-
.orient(url = nil, args = nil) ⇒ Object
Return a graph for the given path.
Class Method Details
.orient(url = nil, args = nil) ⇒ Object
Return a graph for the given path. Will create a graph if none exists at that location.
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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pacer-orient.rb', line 23 def orient(url = nil, args = nil) if url.nil? url = "memory:#{ next_orient_name }" elsif url.is_a? String and url !~ /^(plocal|local|remote|memory):/ url = "plocal:#{ url }" end if args username = args.delete :username password = args.delete :password transactional = args.delete :transactional lightweight_edges = args.delete :lightweight_edges edge_classes = args.delete :edge_classes vertex_classes = args.delete :vertex_classes end if url.is_a? String open = proc do # TODO: can / should I cache connections? Is it essential to shut down Orient? factory = Pacer.open_graphs[[url, username]] unless factory factory = if username com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url, username, password else com.tinkerpop.blueprints.impls.orient.OrientGraphFactory.new url end Pacer.open_graphs[[url, username]] = Pacer::Orient::FactoryContainer.new(factory) end if transactional == false graph = factory.getNoTx() else graph = factory.getTx() end graph.useLightweightEdges = lightweight_edges if lightweight_edges == false graph.useClassForEdgeLabel = edge_classes if edge_classes == false graph.useClassForVertexLabel = vertex_classes if vertex_classes == false #graph.setAutoStartTx false graph end shutdown = proc do |g| factory = Pacer.open_graphs.delete [url, username] factory.shutdown if factory end Orient::Graph.new(Pacer::Orient::Encoder, open, shutdown) else # Don't register the new graph so that it won't be automatically closed. graph = url Orient::Graph.new Pacer::Orient::Encoder, proc { graph } end end |