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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.as_java(labels) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/neo4j-embedded/embedded_label.rb', line 80

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



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

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



36
37
38
# File 'lib/neo4j-embedded/embedded_label.rb', line 36

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

#create_index(*properties) ⇒ Object



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

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



68
69
70
71
72
73
74
75
# File 'lib/neo4j-embedded/embedded_label.rb', line 68

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{|x| x.to_sym}
    index_def.drop if (properties - keys).count < properties.count
  end

end

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



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

def find_nodes(key=nil, value=nil)
   begin
    iterator = _find_nodes(key,value)
    iterator.to_a.map{|n| n.wrapper}
  ensure
    iterator && iterator.close
  end
end

#indexesObject



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

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

#to_sObject



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

def to_s
  @name
end

#uniqueness_constraintsObject



56
57
58
59
60
61
62
63
64
# File 'lib/neo4j-embedded/embedded_label.rb', line 56

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