neo4j 3.0.0.alpha.6 → 3.0.0.alpha.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +9 -0
- data/Gemfile +6 -2
- data/lib/mydb2/active_tx_log +1 -0
- data/lib/mydb2/index/lucene-store.db +0 -0
- data/lib/mydb2/index/lucene.log.1 +0 -0
- data/lib/mydb2/index/lucene.log.active +0 -0
- data/lib/mydb2/index/lucene.log.v0 +0 -0
- data/lib/mydb2/lock +0 -0
- data/lib/mydb2/messages.log +618 -0
- data/lib/mydb2/neostore +0 -0
- data/lib/mydb2/neostore.id +0 -0
- data/lib/mydb2/neostore.labeltokenstore.db +0 -0
- data/lib/mydb2/neostore.labeltokenstore.db.id +0 -0
- data/lib/mydb2/neostore.labeltokenstore.db.names +0 -0
- data/lib/mydb2/neostore.labeltokenstore.db.names.id +0 -0
- data/lib/mydb2/neostore.nodestore.db +0 -0
- data/lib/mydb2/neostore.nodestore.db.id +0 -0
- data/lib/mydb2/neostore.nodestore.db.labels +0 -0
- data/lib/mydb2/neostore.nodestore.db.labels.id +0 -0
- data/lib/mydb2/neostore.propertystore.db +0 -0
- data/lib/mydb2/neostore.propertystore.db.arrays +0 -0
- data/lib/mydb2/neostore.propertystore.db.arrays.id +0 -0
- data/lib/mydb2/neostore.propertystore.db.id +0 -0
- data/lib/mydb2/neostore.propertystore.db.index +0 -0
- data/lib/mydb2/neostore.propertystore.db.index.id +0 -0
- data/lib/mydb2/neostore.propertystore.db.index.keys +0 -0
- data/lib/mydb2/neostore.propertystore.db.index.keys.id +0 -0
- data/lib/mydb2/neostore.propertystore.db.strings +0 -0
- data/lib/mydb2/neostore.propertystore.db.strings.id +0 -0
- data/lib/mydb2/neostore.relationshipstore.db +0 -0
- data/lib/mydb2/neostore.relationshipstore.db.id +0 -0
- data/lib/mydb2/neostore.relationshiptypestore.db +0 -0
- data/lib/mydb2/neostore.relationshiptypestore.db.id +0 -0
- data/lib/mydb2/neostore.relationshiptypestore.db.names +0 -0
- data/lib/mydb2/neostore.relationshiptypestore.db.names.id +0 -0
- data/lib/mydb2/neostore.schemastore.db +0 -0
- data/lib/mydb2/neostore.schemastore.db.id +0 -0
- data/lib/mydb2/nioneo_logical.log.1 +0 -0
- data/lib/mydb2/nioneo_logical.log.active +0 -0
- data/lib/mydb2/nioneo_logical.log.v0 +0 -0
- data/lib/mydb2/schema/label/lucene/segments.gen +0 -0
- data/lib/mydb2/schema/label/lucene/segments_1 +0 -0
- data/lib/mydb2/schema/label/lucene/write.lock +0 -0
- data/lib/mydb2/store_lock +0 -0
- data/lib/mydb2/tm_tx_log.1 +0 -0
- data/lib/neo4j.rb +4 -6
- data/lib/neo4j.rb~ +40 -0
- data/lib/neo4j/active_node.rb +10 -2
- data/lib/neo4j/active_node/has_n.rb +25 -3
- data/lib/neo4j/active_node/has_n/decl_rel.rb +6 -2
- data/lib/neo4j/active_node/has_n/nodes.rb +11 -2
- data/lib/neo4j/active_node/identity.rb +3 -2
- data/lib/neo4j/active_node/initialize.rb +1 -1
- data/lib/neo4j/active_node/labels.rb +69 -7
- data/lib/neo4j/active_node/orm_adapter.rb +88 -0
- data/lib/neo4j/active_node/persistence.rb +47 -5
- data/lib/neo4j/active_node/property.rb +48 -2
- data/lib/neo4j/active_node/rels.rb +2 -2
- data/lib/neo4j/active_node/validations.rb +3 -4
- data/lib/neo4j/version.rb +1 -1
- data/lib/neo4j/wrapper.rb +24 -2
- data/lib/rails/generators/neo4j/model/model_generator.rb +4 -4
- data/lib/rails/generators/neo4j/model/templates/model.erb +1 -1
- data/neo4j.gemspec +3 -3
- metadata +51 -6
data/lib/mydb2/neostore
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
Binary file
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
data/lib/neo4j.rb
CHANGED
@@ -30,9 +30,7 @@ require 'neo4j/active_node/has_n/decl_rel'
|
|
30
30
|
require 'neo4j/active_node/has_n/nodes'
|
31
31
|
require 'neo4j/active_node'
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
require 'rails/generators/neo4j_generator'
|
38
|
-
end
|
33
|
+
require 'neo4j/active_node/orm_adapter'
|
34
|
+
require 'rails/generators'
|
35
|
+
require 'rails/generators/neo4j_generator'
|
36
|
+
|
data/lib/neo4j.rb~
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'neo4j/version'
|
2
|
+
|
3
|
+
#require "delegate"
|
4
|
+
#require "time"
|
5
|
+
#require "set"
|
6
|
+
#
|
7
|
+
#require "active_support/core_ext"
|
8
|
+
#require "active_support/json"
|
9
|
+
#require "active_support/inflector"
|
10
|
+
#require "active_support/time_with_zone"
|
11
|
+
|
12
|
+
require "neo4j-core"
|
13
|
+
require "active_model"
|
14
|
+
require 'active_support/concern'
|
15
|
+
require 'active_support/core_ext/class/attribute.rb'
|
16
|
+
|
17
|
+
require 'active_attr'
|
18
|
+
require 'neo4j/wrapper'
|
19
|
+
require 'neo4j/type_converters'
|
20
|
+
require "neo4j/active_node/labels"
|
21
|
+
require 'neo4j/active_node/identity'
|
22
|
+
require 'neo4j/active_node/callbacks'
|
23
|
+
require 'neo4j/active_node/initialize'
|
24
|
+
require 'neo4j/active_node/property'
|
25
|
+
require 'neo4j/active_node/persistence'
|
26
|
+
require 'neo4j/active_node/validations'
|
27
|
+
require 'neo4j/active_node/rels'
|
28
|
+
require 'neo4j/active_node/has_n'
|
29
|
+
require 'neo4j/active_node/has_n/decl_rel'
|
30
|
+
require 'neo4j/active_node/has_n/nodes'
|
31
|
+
require 'neo4j/active_node'
|
32
|
+
|
33
|
+
require 'neo4j/active_node/orm_adapter'
|
34
|
+
|
35
|
+
if defined? Rails::Generators # defined in 'rails/generators.rb'
|
36
|
+
# TODO, not sure this is the correct way of adding rails generators
|
37
|
+
# See https://github.com/andreasronge/neo4j/blob/gh-pages/neo4j.rb
|
38
|
+
# It is required from the rails config/application file
|
39
|
+
require 'rails/generators/neo4j_generator'
|
40
|
+
end
|
data/lib/neo4j/active_node.rb
CHANGED
@@ -28,13 +28,14 @@ module Neo4j
|
|
28
28
|
include ActiveModel::Conversion
|
29
29
|
include ActiveModel::Serializers::Xml
|
30
30
|
include ActiveModel::Serializers::JSON
|
31
|
+
|
31
32
|
include Neo4j::ActiveNode::Initialize
|
32
33
|
include Neo4j::ActiveNode::Identity
|
33
34
|
include Neo4j::ActiveNode::Persistence
|
34
35
|
include Neo4j::ActiveNode::Property
|
35
36
|
include Neo4j::ActiveNode::Labels
|
36
|
-
include Neo4j::ActiveNode::Callbacks
|
37
37
|
include Neo4j::ActiveNode::Validations
|
38
|
+
include Neo4j::ActiveNode::Callbacks
|
38
39
|
include Neo4j::ActiveNode::Rels
|
39
40
|
include Neo4j::ActiveNode::HasN
|
40
41
|
|
@@ -43,7 +44,7 @@ module Neo4j
|
|
43
44
|
end
|
44
45
|
|
45
46
|
def neo4j_obj
|
46
|
-
_persisted_node || raise("Tried to access native neo4j object on a
|
47
|
+
_persisted_node || raise("Tried to access native neo4j object on a non persisted object")
|
47
48
|
end
|
48
49
|
|
49
50
|
module ClassMethods
|
@@ -61,6 +62,13 @@ module Neo4j
|
|
61
62
|
end
|
62
63
|
|
63
64
|
included do
|
65
|
+
self.include_root_in_json = true
|
66
|
+
|
67
|
+
|
68
|
+
def self.i18n_scope
|
69
|
+
:neo4j
|
70
|
+
end
|
71
|
+
|
64
72
|
def self.inherited(other)
|
65
73
|
attributes.each_pair do |k,v|
|
66
74
|
other.attributes[k] = v
|
@@ -8,6 +8,19 @@ module Neo4j::ActiveNode
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
|
11
|
+
|
12
|
+
def has_relationship?(rel_type)
|
13
|
+
!!_decl_rels[rel_type]
|
14
|
+
end
|
15
|
+
|
16
|
+
def has_one_relationship?(rel_type)
|
17
|
+
has_relationship?(rel_type) && _decl_rels[rel_type].has_one?
|
18
|
+
end
|
19
|
+
|
20
|
+
def relationship_dir(rel_type)
|
21
|
+
has_relationship?(rel_type) && _decl_rels[rel_type].dir
|
22
|
+
end
|
23
|
+
|
11
24
|
def _decl_rels
|
12
25
|
@_decl_rels ||= {}
|
13
26
|
end
|
@@ -50,7 +63,7 @@ module Neo4j::ActiveNode
|
|
50
63
|
#
|
51
64
|
# FolderNode.files #=> 'File#files' the name of the relationship
|
52
65
|
#
|
53
|
-
# @example
|
66
|
+
# @example has_one(x).from(class, has_one_name)
|
54
67
|
#
|
55
68
|
# # generate accessor method for traversing and adding relationship on incoming nodes.
|
56
69
|
# class FileNode
|
@@ -64,19 +77,28 @@ module Neo4j::ActiveNode
|
|
64
77
|
# @return [Neo4j::ActiveNode::HasN::DeclRel] a DSL object where the has_n relationship can be further specified
|
65
78
|
def has_n(rel_type)
|
66
79
|
clazz = self
|
80
|
+
module_eval(%Q{def #{rel_type}=(values)
|
81
|
+
#{rel_type}_rels.each {|rel| rel.del }
|
82
|
+
|
83
|
+
dsl = _decl_rels_for('#{rel_type}'.to_sym)
|
84
|
+
values.each do |value|
|
85
|
+
dsl.create_relationship_to(self, value)
|
86
|
+
end
|
87
|
+
end}, __FILE__, __LINE__)
|
88
|
+
|
67
89
|
module_eval(%Q{
|
68
90
|
def #{rel_type}()
|
69
91
|
dsl = _decl_rels_for('#{rel_type}'.to_sym)
|
70
92
|
Neo4j::ActiveNode::HasN::Nodes.new(self, dsl)
|
71
93
|
end}, __FILE__, __LINE__)
|
72
94
|
|
73
|
-
|
74
95
|
module_eval(%Q{
|
75
96
|
def #{rel_type}_rels
|
76
97
|
dsl = _decl_rels_for('#{rel_type}'.to_sym)
|
77
98
|
dsl.all_relationships(self)
|
78
99
|
end}, __FILE__, __LINE__)
|
79
100
|
|
101
|
+
|
80
102
|
instance_eval(%Q{
|
81
103
|
def #{rel_type}
|
82
104
|
_decl_rels[:#{rel_type}].rel_type
|
@@ -135,4 +157,4 @@ module Neo4j::ActiveNode
|
|
135
157
|
end
|
136
158
|
end
|
137
159
|
|
138
|
-
end
|
160
|
+
end
|
@@ -54,7 +54,11 @@ module Neo4j
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_s
|
57
|
-
"DeclRel #{
|
57
|
+
"DeclRel one #{has_one?}, dir: #{@dir}, rel_id: #{@method_id}, rel_type: #{@rel_type}, target_class:#{@target_name}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def inspect
|
61
|
+
to_s
|
58
62
|
end
|
59
63
|
|
60
64
|
# @return [true, false]
|
@@ -197,7 +201,7 @@ module Neo4j
|
|
197
201
|
|
198
202
|
# @private
|
199
203
|
def each_node(node, &block)
|
200
|
-
node.nodes(dir: dir, type: rel_type).each { |n| block.call(n)}
|
204
|
+
node.nodes(dir: dir, type: rel_type).each { |n| block.call(n) }
|
201
205
|
end
|
202
206
|
|
203
207
|
def all_relationships(node)
|
@@ -14,7 +14,11 @@ module Neo4j
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|
17
|
-
"
|
17
|
+
"[#{@decl_rel.dir}, from: #{@node.neo_id} type: #{@decl_rel.rel_type} has_one #{@decl_rel.has_one?}]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
to_s
|
18
22
|
end
|
19
23
|
|
20
24
|
# Traverse the relationship till the index position
|
@@ -32,6 +36,11 @@ module Neo4j
|
|
32
36
|
super
|
33
37
|
end
|
34
38
|
|
39
|
+
def ==(other)
|
40
|
+
self.to_a == other.to_a
|
41
|
+
end
|
42
|
+
alias_method :eql?, :==
|
43
|
+
|
35
44
|
# Required by the Enumerable mixin.
|
36
45
|
def each
|
37
46
|
@decl_rel.each_node(@node) { |n| yield n } # Should use yield here as passing &block through doesn't always work (why?)
|
@@ -79,4 +88,4 @@ module Neo4j
|
|
79
88
|
|
80
89
|
end
|
81
90
|
end
|
82
|
-
end
|
91
|
+
end
|
@@ -9,7 +9,7 @@ module Neo4j::ActiveNode::Initialize
|
|
9
9
|
# @param [Hash] properties of the persisted node.
|
10
10
|
def init_on_load(persisted_node, properties)
|
11
11
|
@_persisted_node = persisted_node
|
12
|
-
|
12
|
+
changed_attributes && changed_attributes.clear
|
13
13
|
@attributes = attributes.merge(properties.stringify_keys)
|
14
14
|
@attributes = convert_properties_to :ruby, @attributes
|
15
15
|
end
|
@@ -7,11 +7,27 @@ module Neo4j
|
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
WRAPPED_CLASSES = []
|
10
|
+
class InvalidQueryError < StandardError; end
|
10
11
|
|
12
|
+
# @return the labels
|
13
|
+
# @see Neo4j-core
|
11
14
|
def labels
|
12
15
|
@_persisted_node.labels
|
13
16
|
end
|
14
17
|
|
18
|
+
# adds one or more labels
|
19
|
+
# @see Neo4j-core
|
20
|
+
def add_label(*label)
|
21
|
+
@_persisted_node.add_label(*label)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Removes one or more labels
|
25
|
+
# Be careful, don't remove the label representing the Ruby class.
|
26
|
+
# @see Neo4j-core
|
27
|
+
def remove_label(*label)
|
28
|
+
@_persisted_node.remove_label(*label)
|
29
|
+
end
|
30
|
+
|
15
31
|
def self.included(klass)
|
16
32
|
add_wrapped_class(klass)
|
17
33
|
end
|
@@ -21,7 +37,6 @@ module Neo4j
|
|
21
37
|
@_wrapped_labels = nil
|
22
38
|
end
|
23
39
|
|
24
|
-
|
25
40
|
def self._wrapped_classes
|
26
41
|
Neo4j::ActiveNode::Labels::WRAPPED_CLASSES
|
27
42
|
end
|
@@ -48,7 +63,7 @@ module Neo4j
|
|
48
63
|
# @param [Hash, nil] args the search critera or nil if finding all
|
49
64
|
# @param [Neo4j::Session] session defaults to the model's session
|
50
65
|
def all(args = nil, session = self.neo4j_session)
|
51
|
-
if
|
66
|
+
if args
|
52
67
|
find_by_hash(args, session)
|
53
68
|
else
|
54
69
|
Neo4j::Label.find_all_nodes(mapped_label_name, session)
|
@@ -57,8 +72,8 @@ module Neo4j
|
|
57
72
|
|
58
73
|
# @return [Fixnum] number of nodes of this class
|
59
74
|
def count(session = self.neo4j_session)
|
60
|
-
q = session.query(
|
61
|
-
q.to_a[0]
|
75
|
+
q = session.query(label: mapped_label_name, return: "count(n) AS count", map_return: :value)
|
76
|
+
q.to_a[0]
|
62
77
|
end
|
63
78
|
|
64
79
|
# Same as #all but return only one object
|
@@ -69,7 +84,7 @@ module Neo4j
|
|
69
84
|
when Hash
|
70
85
|
find_by_hash(args, session).first
|
71
86
|
when String, Fixnum
|
72
|
-
Neo4j::Node.load(args)
|
87
|
+
Neo4j::Node.load(args.to_i)
|
73
88
|
else
|
74
89
|
raise "Unknown argument #{args.class} in find method"
|
75
90
|
end
|
@@ -94,6 +109,9 @@ module Neo4j
|
|
94
109
|
end
|
95
110
|
end
|
96
111
|
|
112
|
+
def index?(index_def)
|
113
|
+
mapped_label.indexes[:property_keys].include?(index_def)
|
114
|
+
end
|
97
115
|
|
98
116
|
# @return [Array{Symbol}] all the labels that this class has
|
99
117
|
def mapped_label_names
|
@@ -111,8 +129,52 @@ module Neo4j
|
|
111
129
|
|
112
130
|
protected
|
113
131
|
|
114
|
-
def find_by_hash(
|
115
|
-
|
132
|
+
def find_by_hash(query, session)
|
133
|
+
validate_query!(query)
|
134
|
+
|
135
|
+
extract_relationship_conditions!(query)
|
136
|
+
|
137
|
+
session.query(query.merge(label: mapped_label_name))
|
138
|
+
end
|
139
|
+
|
140
|
+
# Raises an error if query is malformed
|
141
|
+
def validate_query!(query)
|
142
|
+
invalid_query_keys = query.keys.map(&:to_sym) - [:conditions, :order, :limit, :skip]
|
143
|
+
|
144
|
+
raise InvalidQueryError, "Invalid query keys: #{invalid_query_keys.join(', ')}" if not invalid_query_keys.empty?
|
145
|
+
end
|
146
|
+
|
147
|
+
# Takes out :conditions query keys for associations and creates corresponding :conditions and :match keys
|
148
|
+
# example:
|
149
|
+
# class Person
|
150
|
+
# property :name
|
151
|
+
# has_n :friend
|
152
|
+
# end
|
153
|
+
#
|
154
|
+
# :conditions => {name: 'Fred', friend: person}
|
155
|
+
# should result in:
|
156
|
+
# :conditions => {name => 'Fred', 'id(n1)' => person.id}, :match => 'n--n1'
|
157
|
+
#
|
158
|
+
def extract_relationship_conditions!(query)
|
159
|
+
node_num = 1
|
160
|
+
if query[:conditions]
|
161
|
+
query[:conditions].dup.each do |key, value|
|
162
|
+
if has_one_relationship?(key)
|
163
|
+
neo_id = value.try(:neo_id) || value
|
164
|
+
raise InvalidQueryError, "Invalid value for '#{key}' condition" if not neo_id.is_a?(Integer)
|
165
|
+
|
166
|
+
query[:match] ||= []
|
167
|
+
n_string = "n#{node_num}"
|
168
|
+
dir = relationship_dir(key)
|
169
|
+
|
170
|
+
match = dir == :outgoing ? "n-->(#{n_string})" : "n<--(#{n_string})"
|
171
|
+
query[:match] << match
|
172
|
+
query[:conditions]["id(#{n_string})"] = neo_id.to_i
|
173
|
+
query[:conditions].delete(key)
|
174
|
+
node_num += 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
116
178
|
end
|
117
179
|
|
118
180
|
def _index(property)
|