class Neo4j::Core::CypherSession::Adaptors::Embedded
Constants
- CONSTRAINT_TYPES
Attributes
graph_db[R]
path[R]
Public Class Methods
new(path, options = {})
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 12 def initialize(path, options = {}) 13 fail 'JRuby is required for embedded mode' if RUBY_PLATFORM != 'java' 14 # TODO: Will this cause an error if a new path is specified? 15 fail ArgumentError, "Invalid path: #{path}" if File.file?(path) 16 FileUtils.mkdir_p(path) 17 18 @path = path 19 @options = options 20 end
transaction_class()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 79 def self.transaction_class 80 require 'neo4j/core/cypher_session/transactions/embedded' 81 Neo4j::Core::CypherSession::Transactions::Embedded 82 end
Public Instance Methods
connect()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 22 def connect 23 factory = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new 24 db_service = factory.newEmbeddedDatabaseBuilder(@path) 25 db_service.loadPropertiesFromFile(@options[:properties_file]) if @options[:properties_file] 26 db_service.setConfig(@options[:properties_map]) if @options[:properties_map] 27 28 @graph_db = db_service.newGraphDatabase 29 end
connected?()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 84 def connected? 85 !!@graph_db 86 end
constraints(session)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 67 def constraints(session) 68 Transaction.run(session) do 69 all_labels(session).flat_map do |label| 70 graph_db.schema.get_constraints(label).map do |definition| 71 {label: label.to_s.to_sym, 72 properties: definition.property_keys.map(&:to_sym), 73 type: CONSTRAINT_TYPES[definition.get_constraint_type.to_s]} 74 end 75 end 76 end 77 end
default_subscribe()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 94 def default_subscribe 95 subscribe_to_transaction 96 end
indexes(session, _label = nil)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 53 def indexes(session, _label = nil) 54 Transaction.run(session) do 55 graph_db = session.adaptor.graph_db 56 57 graph_db.schema.get_indexes.map do |definition| 58 {properties: definition.property_keys.map(&:to_sym), 59 label: definition.label.to_s.to_sym} 60 end 61 end 62 end
query_set(transaction, queries, options = {})
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 31 def query_set(transaction, queries, options = {}) 32 # I think that this is the best way to do a batch in embedded... 33 # Should probably do within a transaction in case of errors... 34 setup_queries!(queries, transaction, options) 35 36 self.class.instrument_transaction do 37 Responses::Embedded.new(execution_results(queries), wrap_level: options[:wrap_level] || @options[:wrap_level]).results 38 end 39 rescue Java::OrgNeo4jCypher::CypherExecutionException, Java::OrgNeo4jCypher::SyntaxException => e 40 raise CypherError.new_from(e.status.to_s, e.message) # , e.stack_track.to_a 41 end
version(_session)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 43 def version(_session) 44 if defined?(::Neo4j::Community) 45 ::Neo4j::Community::NEO_VERSION 46 elsif defined?(::Neo4j::Enterprise) 47 ::Neo4j::Enterprise::NEO_VERSION 48 else 49 fail 'Could not determine embedded version!' 50 end 51 end
Private Instance Methods
all_labels(session)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 106 def all_labels(session) 107 Java::OrgNeo4jTooling::GlobalGraphOperations.at(session.adaptor.graph_db).get_all_labels.to_a 108 end
constraint_definitions_for(graph_db, label)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 120 def constraint_definitions_for(graph_db, label); end
engine()
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 116 def engine 117 @engine ||= Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db) 118 end
execution_results(queries)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 100 def execution_results(queries) 101 queries.map do |query| 102 engine.execute(query.cypher, indifferent_params(query)) 103 end 104 end
indifferent_params(query)
click to toggle source
# File lib/neo4j/core/cypher_session/adaptors/embedded.rb 110 def indifferent_params(query) 111 params = query.parameters 112 params.each { |k, v| params[k] = HashWithIndifferentAccess.new(params[k]) if v.is_a?(Hash) && !v.respond_to?(:nested_under_indifferent_access) } 113 HashWithIndifferentAccess.new(params) 114 end