neo4j 1.0.0.beta.17 → 1.0.0.beta.18
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -2
- data/README.rdoc +2 -2
- data/lib/generators/neo4j.rb +65 -0
- data/lib/generators/neo4j/model/model_generator.rb +39 -0
- data/lib/generators/neo4j/model/templates/model.rb +7 -0
- data/lib/neo4j.rb +2 -2
- data/lib/neo4j/config.rb +14 -12
- data/lib/neo4j/database.rb +1 -1
- data/lib/neo4j/equal.rb +3 -0
- data/lib/neo4j/event_handler.rb +25 -14
- data/lib/neo4j/index/class_methods.rb +3 -2
- data/lib/neo4j/index/indexer.rb +121 -21
- data/lib/neo4j/index/lucene_query.rb +156 -0
- data/lib/neo4j/load.rb +3 -2
- data/lib/neo4j/mapping/class_methods/property.rb +16 -0
- data/lib/neo4j/mapping/class_methods/relationship.rb +3 -1
- data/lib/neo4j/mapping/class_methods/root.rb +3 -0
- data/lib/neo4j/mapping/class_methods/rule.rb +141 -66
- data/lib/neo4j/mapping/decl_relationship_dsl.rb +8 -8
- data/lib/neo4j/mapping/has_n.rb +11 -1
- data/lib/neo4j/mapping/node_mixin.rb +20 -0
- data/lib/neo4j/neo4j.rb +24 -5
- data/lib/neo4j/node.rb +1 -1
- data/lib/neo4j/property.rb +1 -1
- data/lib/neo4j/rails/model.rb +40 -36
- data/lib/neo4j/rails/properties.rb +29 -0
- data/lib/neo4j/rails/value.rb +8 -29
- data/lib/neo4j/transaction.rb +0 -1
- data/lib/neo4j/version.rb +1 -1
- metadata +8 -5
- data/lib/neo4j/index/wrapped_query.rb +0 -59
- data/lib/neo4j/mapping/class_methods/index.rb +0 -17
@@ -107,14 +107,14 @@ module Neo4j::Mapping
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def create_relationship_to(node, other)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
110
|
+
if incoming?
|
111
|
+
# If we are creating an incoming relationship, we need to swap incoming and outgoing nodes
|
112
|
+
dsl = incoming_dsl
|
113
|
+
from, to = other, node
|
114
|
+
else
|
115
|
+
dsl = self
|
116
|
+
from, to = node, other
|
117
|
+
end
|
118
118
|
|
119
119
|
java_type = type_to_java(dsl.namespace_type)
|
120
120
|
|
data/lib/neo4j/mapping/has_n.rb
CHANGED
@@ -2,7 +2,13 @@ module Neo4j
|
|
2
2
|
module Mapping
|
3
3
|
|
4
4
|
# Enables creating and traversal of nodes.
|
5
|
+
#
|
5
6
|
# Includes the Enumerable Mixin.
|
7
|
+
# The Neo4j::Mapping::ClassMethods::Relationship#has_n and Neo4j::Mapping::ClassMethods::Relationship#one
|
8
|
+
# methods returns an object of this type.
|
9
|
+
#
|
10
|
+
# ==== See Also
|
11
|
+
# Neo4j::Mapping::ClassMethods::Relationship
|
6
12
|
#
|
7
13
|
class HasN
|
8
14
|
include Enumerable
|
@@ -68,7 +74,11 @@ module Neo4j
|
|
68
74
|
# self
|
69
75
|
#
|
70
76
|
def <<(other)
|
71
|
-
|
77
|
+
if @direction == :incoming && @dsl.direction == :outgoing
|
78
|
+
@dsl.create_relationship_to(other, @node)
|
79
|
+
else
|
80
|
+
@dsl.create_relationship_to(@node, other)
|
81
|
+
end
|
72
82
|
self
|
73
83
|
end
|
74
84
|
end
|
@@ -1,5 +1,24 @@
|
|
1
1
|
module Neo4j::Mapping
|
2
2
|
|
3
|
+
# This Mixin is used to wrap Neo4j Java Nodes in Ruby objects.
|
4
|
+
# It includes the Neo4j::Index module and forwards a number of method to the raw Java node which
|
5
|
+
# intern includes a number of mixins, see below.
|
6
|
+
#
|
7
|
+
# === Instance Mixins
|
8
|
+
# * Neo4j::Index
|
9
|
+
# * Neo4j::Property
|
10
|
+
# * Neo4j::NodeRelationship
|
11
|
+
# * Neo4j::Equal
|
12
|
+
# * Neo4j::Index
|
13
|
+
#
|
14
|
+
# === Class Mixins
|
15
|
+
# * Neo4j::Mapping::ClassMethods::Root
|
16
|
+
# * Neo4j::Mapping::ClassMethods::Property
|
17
|
+
# * Neo4j::Mapping::ClassMethods::InitNode
|
18
|
+
# * Neo4j::Mapping::ClassMethods::Relationship
|
19
|
+
# * Neo4j::Mapping::ClassMethods::Rule
|
20
|
+
# * Neo4j::Index::ClassMethods
|
21
|
+
#
|
3
22
|
module NodeMixin
|
4
23
|
extend Forwardable
|
5
24
|
include Neo4j::Index
|
@@ -22,6 +41,7 @@ module Neo4j::Mapping
|
|
22
41
|
|
23
42
|
|
24
43
|
# Creates a new node and initialize with given properties.
|
44
|
+
# You can override this to provide your own initialization.
|
25
45
|
#
|
26
46
|
def init_on_create(*args) # :nodoc:
|
27
47
|
self[:_classname] = self.class.to_s
|
data/lib/neo4j/neo4j.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
# = Neo4j
|
2
|
+
#
|
3
|
+
# The Neo4j modules is used to interact with an Neo4j Database instance.
|
4
|
+
# You can for example start and stop an instance and list all the nodes that exist in the database.
|
5
|
+
#
|
6
|
+
# === Starting and Stopping Neo4j
|
7
|
+
# You don't normally need to start the Neo4j database since it will be automatically started when needed.
|
8
|
+
# Before the database is started you should configure where the database is stored, see Neo4j::Config.
|
9
|
+
#
|
1
10
|
module Neo4j
|
2
11
|
|
3
12
|
class << self
|
4
|
-
|
5
|
-
|
13
|
+
|
6
14
|
# Start Neo4j using the default database.
|
7
15
|
# This is usally not required since the database will be started automatically when it is used.
|
8
16
|
#
|
@@ -31,9 +39,10 @@ module Neo4j
|
|
31
39
|
|
32
40
|
|
33
41
|
# Returns an unstarted db instance
|
34
|
-
#
|
42
|
+
#
|
43
|
+
# This is typically used for configuring the database, which must sometimes
|
35
44
|
# be done before the database is started
|
36
|
-
# if the database was already started an
|
45
|
+
# if the database was already started an exception will be raised
|
37
46
|
def unstarted_db
|
38
47
|
@db ||= Database.new
|
39
48
|
raise "database was already started" if @db.running?
|
@@ -46,10 +55,18 @@ module Neo4j
|
|
46
55
|
end
|
47
56
|
|
48
57
|
|
58
|
+
# Stops this database
|
59
|
+
# There are Ruby hooks that will do this automatically for you.
|
60
|
+
#
|
49
61
|
def shutdown(this_db = @db)
|
50
62
|
this_db.shutdown if this_db
|
51
63
|
end
|
52
64
|
|
65
|
+
# Returns the reference node, which is a "starting point" in the node space.
|
66
|
+
#
|
67
|
+
# Usually, a client attaches relationships to this node that leads into various parts of the node space.
|
68
|
+
# For more information about common node space organizational patterns, see the design guide at http://wiki.neo4j.org/content/Design_Guide
|
69
|
+
#
|
53
70
|
def ref_node(this_db = self.started_db)
|
54
71
|
this_db.graph.reference_node
|
55
72
|
end
|
@@ -59,11 +76,13 @@ module Neo4j
|
|
59
76
|
Enumerator.new(this_db, :each_node)
|
60
77
|
end
|
61
78
|
|
62
|
-
# Same as #all_nodes but does not return wrapped nodes.
|
79
|
+
# Same as #all_nodes but does not return wrapped nodes but instead raw java node objects.
|
63
80
|
def _all_nodes(this_db = self.started_db)
|
64
81
|
Enumerator.new(this_db, :_each_node)
|
65
82
|
end
|
66
83
|
|
84
|
+
# Returns the Neo4j::EventHandler
|
85
|
+
#
|
67
86
|
def event_handler(this_db = default_db)
|
68
87
|
this_db.event_handler
|
69
88
|
end
|
data/lib/neo4j/node.rb
CHANGED
@@ -58,7 +58,7 @@ module Neo4j
|
|
58
58
|
# * Neo4j::Index::ClassMethods lucene index class methods, like find
|
59
59
|
# * Neo4j::Load - methods for loading a node
|
60
60
|
#
|
61
|
-
# See also the Neo4j::NodeMixin if you want to wrap a node with your own Ruby class.
|
61
|
+
# See also the Neo4j::NodeMixin (Neo4j::Mapping::NodeMixin) if you want to wrap a node with your own Ruby class.
|
62
62
|
#
|
63
63
|
class Node
|
64
64
|
extend Neo4j::Index::ClassMethods
|
data/lib/neo4j/property.rb
CHANGED
@@ -73,7 +73,7 @@ module Neo4j
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# Sets the property of this node.
|
76
|
-
# Property keys are always strings. Valid property value types are the primitives(<tt>String</tt>, <tt>Fixnum</tt>, <tt>Float</tt>, <tt>Boolean</tt>)
|
76
|
+
# Property keys are always strings. Valid property value types are the primitives(<tt>String</tt>, <tt>Fixnum</tt>, <tt>Float</tt>, <tt>Boolean</tt>).
|
77
77
|
#
|
78
78
|
def []=(key, value)
|
79
79
|
k = key.to_s
|
data/lib/neo4j/rails/model.rb
CHANGED
@@ -57,7 +57,6 @@ module Neo4j
|
|
57
57
|
persisted? ? [:id] : nil
|
58
58
|
end
|
59
59
|
|
60
|
-
|
61
60
|
# enables ActiveModel::Dirty and Validation
|
62
61
|
def method_missing(method_id, *args, &block)
|
63
62
|
if !self.class.attribute_methods_generated?
|
@@ -101,7 +100,6 @@ module Neo4j
|
|
101
100
|
end
|
102
101
|
end
|
103
102
|
|
104
|
-
|
105
103
|
# Updates this resource with all the attributes from the passed-in Hash and requests that the record be saved.
|
106
104
|
# If saving fails because the resource is invalid then false will be returned.
|
107
105
|
def update_attributes(attributes)
|
@@ -161,12 +159,6 @@ module Neo4j
|
|
161
159
|
end
|
162
160
|
end
|
163
161
|
|
164
|
-
def delete
|
165
|
-
super
|
166
|
-
@_deleted = true
|
167
|
-
@_persisted = false
|
168
|
-
end
|
169
|
-
|
170
162
|
def save
|
171
163
|
_run_save_callbacks do
|
172
164
|
if create_or_update_node
|
@@ -208,13 +200,12 @@ module Neo4j
|
|
208
200
|
@previously_changed = changes
|
209
201
|
@changed_attributes.clear
|
210
202
|
end
|
211
|
-
|
203
|
+
|
212
204
|
def reload(options = nil)
|
213
|
-
|
214
|
-
|
215
|
-
self
|
205
|
+
clear_changes
|
206
|
+
reload_from_database or set_deleted_properties and return self
|
216
207
|
end
|
217
|
-
|
208
|
+
|
218
209
|
def save!
|
219
210
|
raise RecordInvalidError.new(self) unless save
|
220
211
|
end
|
@@ -234,14 +225,19 @@ module Neo4j
|
|
234
225
|
|
235
226
|
alias :new_record? :new?
|
236
227
|
|
237
|
-
def
|
238
|
-
|
239
|
-
super
|
228
|
+
def ==(other)
|
229
|
+
new? ? self.__id__ == other.__id__ : @_java_node == (other)
|
240
230
|
end
|
241
231
|
|
242
|
-
def
|
243
|
-
|
232
|
+
def del_with_wrapper
|
233
|
+
_run_destroy_callbacks do
|
234
|
+
del_without_wrapper
|
235
|
+
set_deleted_properties
|
236
|
+
end
|
244
237
|
end
|
238
|
+
|
239
|
+
alias_method_chain :del, :wrapper
|
240
|
+
alias :destroy :del_with_wrapper
|
245
241
|
|
246
242
|
def destroyed?()
|
247
243
|
@_deleted
|
@@ -265,24 +261,24 @@ module Neo4j
|
|
265
261
|
wrapped
|
266
262
|
end
|
267
263
|
|
268
|
-
|
264
|
+
# Behave like ActiveModel
|
269
265
|
def all_with_args(*args)
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
266
|
+
if args.empty?
|
267
|
+
all_without_args
|
268
|
+
else
|
269
|
+
hits = find_without_checking_for_id(*args)
|
270
|
+
# We need to save this so that the Rack Neo4j::Rails:LuceneConnection::Closer can close it
|
271
|
+
Thread.current[:neo4j_lucene_connection] ||= []
|
272
|
+
Thread.current[:neo4j_lucene_connection] << hits
|
273
|
+
hits
|
274
|
+
end
|
279
275
|
end
|
280
|
-
|
276
|
+
|
281
277
|
alias_method_chain :all, :args
|
282
278
|
|
283
279
|
# Handle Model.find(params[:id])
|
284
280
|
def find_with_checking_for_id(*args)
|
285
|
-
|
281
|
+
if args.length == 1 && String === args[0] && args[0].to_i != 0
|
286
282
|
load(*args)
|
287
283
|
else
|
288
284
|
all_with_args(*args).first
|
@@ -300,7 +296,6 @@ module Neo4j
|
|
300
296
|
end
|
301
297
|
end
|
302
298
|
|
303
|
-
|
304
299
|
alias_method :_orig_create, :create
|
305
300
|
|
306
301
|
def create(*args)
|
@@ -308,12 +303,11 @@ module Neo4j
|
|
308
303
|
end
|
309
304
|
|
310
305
|
def create!(*args)
|
311
|
-
|
306
|
+
new(*args).tap { |o| o.save! }
|
312
307
|
end
|
313
308
|
|
314
309
|
tx_methods :create, :create!
|
315
310
|
|
316
|
-
|
317
311
|
def transaction(&block)
|
318
312
|
Neo4j::Rails::Transaction.run &block
|
319
313
|
end
|
@@ -347,10 +341,20 @@ module Neo4j
|
|
347
341
|
tx_methods("#{association_name}_attributes=")
|
348
342
|
end
|
349
343
|
end
|
350
|
-
|
351
344
|
end
|
352
|
-
|
345
|
+
|
346
|
+
private
|
347
|
+
def reload_from_database
|
348
|
+
if reloaded = self.class.load(self.id.to_s)
|
349
|
+
attributes = reloaded.attributes
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def set_deleted_properties
|
354
|
+
@_deleted = true
|
355
|
+
@_persisted = false
|
356
|
+
@_java_node = Neo4j::Rails::Value.new(self)
|
357
|
+
end
|
353
358
|
end
|
354
|
-
|
355
359
|
end
|
356
360
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Rails
|
3
|
+
# provide some properties before we have a real node or relationship
|
4
|
+
module Properties # :nodoc:
|
5
|
+
include Neo4j::Property
|
6
|
+
|
7
|
+
# override Neo4j::Property#props
|
8
|
+
def props
|
9
|
+
@props ||= {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_property?(key)
|
13
|
+
!props[key].nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def set_property(key,value)
|
17
|
+
props[key] = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_property(key)
|
21
|
+
props[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
def remove_property(key)
|
25
|
+
props.delete(key)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/neo4j/rails/value.rb
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
module Neo4j::Rails
|
2
2
|
|
3
3
|
class Value
|
4
|
-
include
|
4
|
+
include Properties
|
5
5
|
include org.neo4j.graphdb.Node
|
6
6
|
|
7
7
|
def initialize(wrapper)
|
8
8
|
@wrapper = wrapper
|
9
|
-
@props = {}
|
10
9
|
@outgoing_rels = {} # a hash of all relationship with key type
|
11
10
|
end
|
12
11
|
|
13
|
-
# override Neo4j::Property#props
|
14
|
-
def props
|
15
|
-
@props
|
16
|
-
end
|
17
|
-
|
18
12
|
def getId
|
19
13
|
nil
|
20
14
|
end
|
21
15
|
|
22
|
-
|
23
16
|
def create_relationship_to(other_java_node, java_type)
|
24
17
|
outgoing(java_type.name).new(other_java_node)
|
25
18
|
end
|
@@ -36,23 +29,6 @@ module Neo4j::Rails
|
|
36
29
|
outgoing.rels
|
37
30
|
end
|
38
31
|
|
39
|
-
# Pretend this object is a Java Node
|
40
|
-
def has_property?(key)
|
41
|
-
!@props[key].nil?
|
42
|
-
end
|
43
|
-
|
44
|
-
def set_property(key,value)
|
45
|
-
@props[key] = value
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_property(key)
|
49
|
-
@props[key]
|
50
|
-
end
|
51
|
-
|
52
|
-
def remove_property(key)
|
53
|
-
@props.delete(key)
|
54
|
-
end
|
55
|
-
|
56
32
|
def wrapper
|
57
33
|
@wrapper
|
58
34
|
end
|
@@ -64,10 +40,11 @@ module Neo4j::Rails
|
|
64
40
|
def save_nested(root_node)
|
65
41
|
valid = true
|
66
42
|
@outgoing_rels.each_pair do |type, rel|
|
67
|
-
rel.
|
68
|
-
|
43
|
+
rel.each_with_index do |new_node, i|
|
44
|
+
wrapper = new_node.respond_to?(:wrapper) ? new_node.wrapper : new_node
|
69
45
|
if wrapper.save
|
70
|
-
|
46
|
+
new_rel = Neo4j::Relationship.new(type.to_sym, root_node, wrapper)
|
47
|
+
rel.rels[i].props.each_pair { |property, value| new_rel[property] = value }
|
71
48
|
else
|
72
49
|
valid = false
|
73
50
|
end
|
@@ -82,7 +59,9 @@ module Neo4j::Rails
|
|
82
59
|
end
|
83
60
|
|
84
61
|
class Relationship
|
85
|
-
|
62
|
+
include org.neo4j.graphdb.Relationship
|
63
|
+
include Properties
|
64
|
+
|
86
65
|
attr_reader :end_node, :start_node
|
87
66
|
|
88
67
|
def initialize(from, to)
|
data/lib/neo4j/transaction.rb
CHANGED
data/lib/neo4j/version.rb
CHANGED
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 1.0.0.beta.
|
10
|
+
- 18
|
11
|
+
version: 1.0.0.beta.18
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Andreas Ronge
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-11-
|
19
|
+
date: 2010-11-04 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,9 @@ extra_rdoc_files:
|
|
59
59
|
- README.rdoc
|
60
60
|
files:
|
61
61
|
- lib/neo4j.rb
|
62
|
+
- lib/generators/neo4j.rb
|
63
|
+
- lib/generators/neo4j/model/model_generator.rb
|
64
|
+
- lib/generators/neo4j/model/templates/model.rb
|
62
65
|
- lib/neo4j/event_handler.rb
|
63
66
|
- lib/neo4j/model.rb
|
64
67
|
- lib/neo4j/node_traverser.rb
|
@@ -82,6 +85,7 @@ files:
|
|
82
85
|
- lib/neo4j/rails/lucene_connection_closer.rb
|
83
86
|
- lib/neo4j/rails/transaction.rb
|
84
87
|
- lib/neo4j/rails/tx_methods.rb
|
88
|
+
- lib/neo4j/rails/properties.rb
|
85
89
|
- lib/neo4j/rails/value.rb
|
86
90
|
- lib/neo4j/rails/validations/uniqueness.rb
|
87
91
|
- lib/neo4j/jars/lucene-core-3.0.1.jar
|
@@ -96,13 +100,12 @@ files:
|
|
96
100
|
- lib/neo4j/mapping/class_methods/rule.rb
|
97
101
|
- lib/neo4j/mapping/class_methods/init_node.rb
|
98
102
|
- lib/neo4j/mapping/class_methods/property.rb
|
99
|
-
- lib/neo4j/mapping/class_methods/index.rb
|
100
103
|
- lib/neo4j/mapping/class_methods/root.rb
|
101
104
|
- lib/neo4j/mapping/class_methods/init_rel.rb
|
102
105
|
- lib/neo4j/mapping/class_methods/relationship.rb
|
103
106
|
- lib/neo4j/index/index_registry.rb
|
104
|
-
- lib/neo4j/index/wrapped_query.rb
|
105
107
|
- lib/neo4j/index/indexer.rb
|
108
|
+
- lib/neo4j/index/lucene_query.rb
|
106
109
|
- lib/neo4j/index/class_methods.rb
|
107
110
|
- lib/neo4j/index/index.rb
|
108
111
|
- README.rdoc
|