Class: Neo4j::Embedded::EmbeddedLabel
Constant Summary
collapse
- JAVA_CLASS =
Java::OrgNeo4jGraphdb::DynamicLabel
Constants inherited
from Label
Label::CONSTRAINT_PATH, Label::INDEX_PATH
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
tx_methods
Methods inherited from Label
constraint?, constraints, create, #create_constraint, drop_all_constraints, drop_all_indexes, #drop_constraint, find_all_nodes, find_nodes, index?, indexes
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
#name ⇒ Object
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
76
77
78
79
80
81
82
83
84
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 76
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
#as_java ⇒ Object
31
32
33
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 31
def as_java
self.class.as_java(@name.to_s)
end
|
#create_index(property, options = {}, session = Neo4j::Session.current) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 35
def create_index(property, options = {}, session = Neo4j::Session.current)
validate_index_options!(options)
index_creator = session.graph_db.schema.index_for(as_java)
properties = property.is_a?(Array) ? property : [property]
properties.inject(index_creator) { |creator, key| creator.on(key.to_s) }.create
end
|
#drop_index(property, options = {}, session = Neo4j::Session.current) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 64
def drop_index(property, options = {}, session = Neo4j::Session.current)
validate_index_options!(options)
properties = property.is_a?(Array) ? property : [property]
session.graph_db.schema.indexes(as_java).each do |index_def|
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
23
24
25
26
27
28
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 17
def find_nodes(key = nil, value = nil)
iterator = 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
iterator.to_a.map(&:wrapper)
ensure
iterator && iterator.close
end
|
#indexes ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 44
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_s ⇒ Object
13
14
15
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 13
def to_s
@name
end
|
#uniqueness_constraints ⇒ Object
53
54
55
56
57
58
59
60
|
# File 'lib/neo4j-embedded/embedded_label.rb', line 53
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
|