Class: Neo4j::Embedded::EmbeddedLabel

Inherits:
Label
  • Object
show all
Extended by:
Core::TxMethods
Defined in:
lib/neo4j-embedded/embedded_label.rb

Constant Summary collapse

JAVA_CLASS =
Java::OrgNeo4jGraphdb::DynamicLabel

Constants included from Core::CypherTranslator

Core::CypherTranslator::EMPTY_PROPS, Core::CypherTranslator::SANITIZE_ESCAPED_REGEXP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::TxMethods

tx_methods

Methods inherited from Label

create, #create_constraint, #drop_constraint, find_all_nodes, find_nodes

Methods included from Core::CypherTranslator

#create_escape_value, #cypher_prop_list, #cypher_string, #escape_quotes, #escape_value, #label_string, #prop_identifier, #sanitize_escape_sequences, sanitized_column_names, translate_response

Constructor Details

#initialize(session, name) ⇒ EmbeddedLabel

Returns a new instance of EmbeddedLabel.



8
9
10
11
# File 'lib/neo4j-embedded/embedded_label.rb', line 8

def initialize(session, name)
  @name = name.to_sym
  @session = session
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/neo4j-embedded/embedded_label.rb', line 5

def name
  @name
end

Class Method Details

.as_java(labels) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/neo4j-embedded/embedded_label.rb', line 75

def as_java(labels)
  if labels.is_a?(Array)
    return nil if labels.empty?
    labels.inject([]) { |result, label| result << JAVA_CLASS.label(label.to_s) }.to_java(JAVA_CLASS)
  else
    JAVA_CLASS.label(labels.to_s)
  end
end

Instance Method Details

#_find_nodes(key = nil, value = nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/neo4j-embedded/embedded_label.rb', line 25

def _find_nodes(key = nil, value = nil)
  if key
    @session.graph_db.find_nodes_by_label_and_property(as_java, key, value).iterator
  else
    ggo = Java::OrgNeo4jTooling::GlobalGraphOperations.at(@session.graph_db)
    ggo.getAllNodesWithLabel(as_java).iterator
  end
end

#as_javaObject



34
35
36
# File 'lib/neo4j-embedded/embedded_label.rb', line 34

def as_java
  self.class.as_java(@name.to_s)
end

#create_index(*properties) ⇒ Object



38
39
40
41
42
# File 'lib/neo4j-embedded/embedded_label.rb', line 38

def create_index(*properties)
  index_creator = @session.graph_db.schema.index_for(as_java)
  # we can also use the PropertyConstraintCreator here
  properties.inject(index_creator) { |creator, key| creator.on(key.to_s) }.create
end

#drop_index(*properties) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/neo4j-embedded/embedded_label.rb', line 65

def drop_index(*properties)
  @session.graph_db.schema.indexes(as_java).each do |index_def|
    # at least one match, TODO
    keys = index_def.property_keys.map(&:to_sym)
    index_def.drop if (properties - keys).count < properties.count
  end
end

#find_nodes(key = nil, value = nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/neo4j-embedded/embedded_label.rb', line 17

def find_nodes(key = nil, value = nil)
  iterator = _find_nodes(key, value)
  iterator.to_a.map(&:wrapper)
ensure
  iterator && iterator.close
end

#indexesObject



45
46
47
48
49
50
51
# File 'lib/neo4j-embedded/embedded_label.rb', line 45

def indexes
  {
    property_keys: @session.graph_db.schema.indexes(as_java).map do |index_def|
      index_def.property_keys.map(&:to_sym)
    end
  }
end

#to_sObject



13
14
15
# File 'lib/neo4j-embedded/embedded_label.rb', line 13

def to_s
  @name
end

#uniqueness_constraintsObject



54
55
56
57
58
59
60
61
# File 'lib/neo4j-embedded/embedded_label.rb', line 54

def uniqueness_constraints
  definitions = @session.graph_db.schema.constraints(as_java).select do |index_def|
    index_def.is_a?(Java::OrgNeo4jKernelImplCoreapiSchema::PropertyUniqueConstraintDefinition)
  end
  {
    property_keys: definitions.map { |index_def| index_def.property_keys.map(&:to_sym) }
  }
end