Class: Neo4j::Core::CypherSession::Adaptors::Embedded

Inherits:
Base
  • Object
show all
Defined in:
lib/neo4j/core/cypher_session/adaptors/embedded.rb

Constant Summary

Constants inherited from Base

Base::EMPTY, Base::NEWLINE_W_SPACES

Instance Method Summary collapse

Methods inherited from Base

#indexes_for_label, instrument_queries, #queries, #query, #transaction, #uniqueness_constraints_for_label

Methods included from Instrumentable

included

Constructor Details

#initialize(path, options = {}) ⇒ Embedded

Returns a new instance of Embedded.



9
10
11
12
13
14
15
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 9

def initialize(path, options = {})
  fail 'JRuby is required for embedded mode' if RUBY_PLATFORM != 'java'
  fail ArgumentError, "Invalid path: #{path}" if !File.directory?(path)

  @path = path
  @options = options
end

Instance Method Details

#connectObject



17
18
19
20
21
22
23
24
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 17

def connect
  factory    = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new
  db_service = factory.newEmbeddedDatabaseBuilder(@path)
  db_service.loadPropertiesFromFile(@options[:properties_file]) if @options[:properties_file]
  db_service.setConfig(@options[:properties_map])               if @options[:properties_map]

  @graph_db = db_service.newGraphDatabase
end

#end_transactionObject



47
48
49
50
51
52
53
54
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 47

def end_transaction
  if @transaction.nil?
    fail 'Cannot close transaction without starting one'
  end

  @transaction.success
  @transaction.close
end

#query_set(queries) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 26

def query_set(queries)
  # I think that this is the best way to do a batch in embedded...
  # Should probably do within a transaction in case of errors...

  transaction do
    self.class.instrument_transaction do
      self.class.instrument_queries(queries)

      execution_results = queries.map do |query|
        engine.execute(query.cypher, indifferent_params(query))
      end

      Responses::Embedded.new(execution_results).results
    end
  end
end

#start_transactionObject



43
44
45
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 43

def start_transaction
  @transaction = @graph_db.begin_tx
end

#transaction_started?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 56

def transaction_started?
  !!@transaction
end

#versionObject



60
61
62
63
64
65
66
67
68
# File 'lib/neo4j/core/cypher_session/adaptors/embedded.rb', line 60

def version
  if defined?(::Neo4j::Community)
    ::Neo4j::Community::NEO_VERSION
  elsif defined?(::Neo4j::Enterprise)
    ::Neo4j::Enterprise::NEO_VERSION
  else
    fail 'Could not determine embedded version!'
  end
end