Class: Cadet::BatchInserter::Session

Inherits:
Session
  • Object
show all
Defined in:
lib/cadet/batch_inserter/session.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Session

#begin_tx, current_session, #method_missing, #transaction

Constructor Details

#initialize(underlying) ⇒ Session

Returns a new instance of Session.



5
6
7
8
# File 'lib/cadet/batch_inserter/session.rb', line 5

def initialize(underlying)
  @index_provider = CadetIndex::IndexProvider.new(underlying)
  @underlying = underlying
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Cadet::Session

Class Method Details

.open(location, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/cadet/batch_inserter/session.rb', line 19

def self.open(location, &block)
  new(org.neo4j.unsafe.batchinsert.BatchInserters.inserter(location)).tap do |session|
    @@current_session = session
    if block_given?
      session.instance_exec(session, &block)
      session.close
    end
  end
end

Instance Method Details

#closeObject



14
15
16
17
# File 'lib/cadet/batch_inserter/session.rb', line 14

def close
  @index_provider.shutdown
  super
end

#constraint(label, property) ⇒ Object



29
30
31
32
33
# File 'lib/cadet/batch_inserter/session.rb', line 29

def constraint(label, property)
  @underlying.createDeferredConstraint(DynamicLabel.label(label))
    .assertPropertyIsUnique(property)
    .create()
end

#create_node(label, properties) ⇒ Object



40
41
42
# File 'lib/cadet/batch_inserter/session.rb', line 40

def create_node(label, properties)
  Node.new(@underlying.createNode(Hash[properties.map { |k,v| [k.to_java_string, v] }], DynamicLabel.label(label)))
end

#create_relationship(from, to, type, properties) ⇒ Object



52
53
54
# File 'lib/cadet/batch_inserter/session.rb', line 52

def create_relationship(from, to, type, properties)
  Relationship.new @underlying.createRelationship(from.underlying, to.underlying, DynamicRelationshipType.withName(type), properties)
end

#find_node(label, property, value) ⇒ Object



35
36
37
38
# File 'lib/cadet/batch_inserter/session.rb', line 35

def find_node(label, property, value)
  (node = @index_provider[label].get(property.to_sym, value).first) ?
    Node.new(node) : nil
end

#get_node(label, property, value) ⇒ Object



44
45
46
# File 'lib/cadet/batch_inserter/session.rb', line 44

def get_node(label, property, value)
  find_node(label, property, value) || create_node(label, {property.to_sym => value}).tap { |n| index_on(label, property, n); }
end

#get_node_properties(node) ⇒ Object



56
57
58
# File 'lib/cadet/batch_inserter/session.rb', line 56

def get_node_properties(node)
  @underlying.getNodeProperties(node.underlying)
end

#get_relationship_properties(relationship) ⇒ Object



64
65
66
# File 'lib/cadet/batch_inserter/session.rb', line 64

def get_relationship_properties(relationship)
  @underlying.getRelationshipProperties(relationship.underlying)
end

#get_transactionObject



48
49
50
# File 'lib/cadet/batch_inserter/session.rb', line 48

def get_transaction
  Transaction.new(self)
end

#index_on(label, property, node) ⇒ Object



10
11
12
# File 'lib/cadet/batch_inserter/session.rb', line 10

def index_on(label, property, node)
  @index_provider[label].add(node.underlying, property, node[property])
end

#set_node_property(node, property, value) ⇒ Object



60
61
62
# File 'lib/cadet/batch_inserter/session.rb', line 60

def set_node_property(node, property, value)
  @underlying.setNodeProperty(node.underlying, property.to_java_string, value)
end

#set_relationship_property(relationship, property, value) ⇒ Object



68
69
70
# File 'lib/cadet/batch_inserter/session.rb', line 68

def set_relationship_property(relationship, property, value)
  @underlying.setRelationshipProperty(relationship.underlying, property.to_java_string, value)
end