neo4j 1.0.0.beta.9 → 1.0.0.beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/README.rdoc +5 -1971
  2. data/lib/neo4j/mapping/class_methods/relationship.rb +2 -2
  3. data/lib/neo4j/mapping/decl_relationship_dsl.rb +6 -1
  4. data/lib/neo4j/mapping/has_n.rb +17 -1
  5. data/lib/neo4j/node_traverser.rb +14 -1
  6. data/lib/neo4j/rails/model.rb +127 -31
  7. data/lib/neo4j/rails/tx_methods.rb +11 -0
  8. data/lib/neo4j/rails/value.rb +44 -1
  9. data/lib/neo4j/version.rb +1 -1
  10. data/lib/neo4j.rb +1 -0
  11. metadata +4 -59
  12. data/lib/neo4j.old/batch_inserter.rb +0 -144
  13. data/lib/neo4j.old/config.rb +0 -138
  14. data/lib/neo4j.old/event_handler.rb +0 -73
  15. data/lib/neo4j.old/extensions/activemodel.rb +0 -158
  16. data/lib/neo4j.old/extensions/aggregate/aggregate_enum.rb +0 -40
  17. data/lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb +0 -69
  18. data/lib/neo4j.old/extensions/aggregate/node_aggregate.rb +0 -8
  19. data/lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb +0 -331
  20. data/lib/neo4j.old/extensions/aggregate/node_aggregator.rb +0 -216
  21. data/lib/neo4j.old/extensions/aggregate/node_group.rb +0 -43
  22. data/lib/neo4j.old/extensions/aggregate/prop_group.rb +0 -30
  23. data/lib/neo4j.old/extensions/aggregate/property_enum.rb +0 -24
  24. data/lib/neo4j.old/extensions/aggregate/props_aggregate.rb +0 -8
  25. data/lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb +0 -31
  26. data/lib/neo4j.old/extensions/aggregate/props_aggregator.rb +0 -80
  27. data/lib/neo4j.old/extensions/aggregate.rb +0 -12
  28. data/lib/neo4j.old/extensions/find_path.rb +0 -117
  29. data/lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb +0 -133
  30. data/lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar +0 -0
  31. data/lib/neo4j.old/extensions/graph_algo.rb +0 -1
  32. data/lib/neo4j.old/extensions/reindexer.rb +0 -104
  33. data/lib/neo4j.old/extensions/rest/rest.rb +0 -336
  34. data/lib/neo4j.old/extensions/rest/rest_mixin.rb +0 -193
  35. data/lib/neo4j.old/extensions/rest/server.rb +0 -50
  36. data/lib/neo4j.old/extensions/rest/stubs.rb +0 -141
  37. data/lib/neo4j.old/extensions/rest.rb +0 -21
  38. data/lib/neo4j.old/extensions/rest_master.rb +0 -34
  39. data/lib/neo4j.old/extensions/rest_slave.rb +0 -31
  40. data/lib/neo4j.old/extensions/tx_tracker.rb +0 -392
  41. data/lib/neo4j.old/indexer.rb +0 -187
  42. data/lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  43. data/lib/neo4j.old/jars/neo4j-kernel-1.0.jar +0 -0
  44. data/lib/neo4j.old/jars.rb +0 -6
  45. data/lib/neo4j.old/mixins/java_list_mixin.rb +0 -139
  46. data/lib/neo4j.old/mixins/java_node_mixin.rb +0 -205
  47. data/lib/neo4j.old/mixins/java_property_mixin.rb +0 -169
  48. data/lib/neo4j.old/mixins/java_relationship_mixin.rb +0 -60
  49. data/lib/neo4j.old/mixins/migration_mixin.rb +0 -157
  50. data/lib/neo4j.old/mixins/node_mixin.rb +0 -249
  51. data/lib/neo4j.old/mixins/property_class_methods.rb +0 -265
  52. data/lib/neo4j.old/mixins/rel_class_methods.rb +0 -167
  53. data/lib/neo4j.old/mixins/relationship_mixin.rb +0 -103
  54. data/lib/neo4j.old/neo.rb +0 -247
  55. data/lib/neo4j.old/node.rb +0 -49
  56. data/lib/neo4j.old/reference_node.rb +0 -15
  57. data/lib/neo4j.old/relationship.rb +0 -85
  58. data/lib/neo4j.old/relationships/decl_relationship_dsl.rb +0 -164
  59. data/lib/neo4j.old/relationships/has_list.rb +0 -101
  60. data/lib/neo4j.old/relationships/has_n.rb +0 -129
  61. data/lib/neo4j.old/relationships/node_traverser.rb +0 -138
  62. data/lib/neo4j.old/relationships/relationship_dsl.rb +0 -149
  63. data/lib/neo4j.old/relationships/traversal_position.rb +0 -50
  64. data/lib/neo4j.old/relationships/wrappers.rb +0 -51
  65. data/lib/neo4j.old/search_result.rb +0 -72
  66. data/lib/neo4j.old/transaction.rb +0 -254
  67. data/lib/neo4j.old/version.rb +0 -3
@@ -35,7 +35,7 @@ module Neo4j::Mapping
35
35
  Neo4j::Mapping::HasN.new(self, dsl).rels
36
36
  end}, __FILE__, __LINE__)
37
37
 
38
- _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
38
+ _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, false, params)
39
39
  end
40
40
 
41
41
 
@@ -84,7 +84,7 @@ module Neo4j::Mapping
84
84
  [*r][0]
85
85
  end}, __FILE__, __LINE__)
86
86
 
87
- _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, params)
87
+ _decl_rels[rel_type.to_sym] = Neo4j::Mapping::DeclRelationshipDsl.new(rel_type, true, params)
88
88
  end
89
89
 
90
90
  end
@@ -35,15 +35,20 @@ module Neo4j::Mapping
35
35
  attr_reader :to_type, :to_class, :cascade_delete_prop_name, :counter, :rel_id, :direction
36
36
  CASCADE_DELETE_PROP_NAMES = {:outgoing => :_cascade_delete_outgoing, :incoming => :_cascade_delete_incoming}
37
37
 
38
- def initialize(rel_id, params)
38
+ def initialize(rel_id, has_one, params)
39
39
  @direction = :outgoing
40
40
  @rel_id = rel_id
41
41
  @to_type = rel_id
42
+ @has_one = has_one
42
43
  @namespace_type = rel_id
43
44
  @cascade_delete_prop_name = CASCADE_DELETE_PROP_NAMES[params[:cascade_delete]]
44
45
  @counter = params[:counter] == true
45
46
  end
46
47
 
48
+ def has_one?
49
+ @has_one
50
+ end
51
+
47
52
  # If a counter was specified in the dsl for counting number of nodes in this relationship.
48
53
  #
49
54
  def counter?
@@ -24,6 +24,22 @@ module Neo4j
24
24
  @traverser = Neo4j::NodeTraverser.new(node._java_node, @dsl.namespace_type, @direction)
25
25
  end
26
26
 
27
+ def size
28
+ [*self].size
29
+ end
30
+
31
+ alias_method :length, :size
32
+
33
+ def [](index)
34
+ each_with_index {|node,i| break node if index == i}
35
+ end
36
+
37
+ # Pretend we are an array - this is neccessarly for Rails actionpack/actionview/formhelper to work with this
38
+ def is_a?(type)
39
+ # ActionView requires this for nested attributes to work
40
+ return true if Array == type
41
+ super
42
+ end
27
43
 
28
44
  # Returns the relationships instead of the nodes.
29
45
  #
@@ -43,7 +59,7 @@ module Neo4j
43
59
  # morpheus.friends.depth(3).each { ... }
44
60
  #
45
61
  # ==== Arguments
46
- # d<Fixnum,Symbol>:: the depth or :all if traversing to the end of the network.
62
+ # d:: the depth or :all if traversing to the end of the network (symbol or fixnum)
47
63
  # ==== Return
48
64
  # self
49
65
  #
@@ -51,6 +51,9 @@ module Neo4j
51
51
  end
52
52
 
53
53
 
54
+ def to_s
55
+ "NodeTraverser [from: #{@from.neo_id} depth: #{@depth} type: #{@type} dir:#{@dir}"
56
+ end
54
57
 
55
58
  def <<(other_node)
56
59
  new(other_node)
@@ -118,10 +121,20 @@ module Neo4j
118
121
  [*self].size
119
122
  end
120
123
 
124
+ alias_method :length, :size
125
+
126
+ def [](index)
127
+ each_with_index {|node,i| break node if index == i}
128
+ end
129
+
130
+ def empty?
131
+ first == nil
132
+ end
133
+
121
134
  def each
122
135
  iter = iterator
123
136
  while (iter.hasNext) do
124
- yield Neo4j::Node.wrapper(iter.next)
137
+ yield iter.next.wrapper
125
138
  end
126
139
  end
127
140
 
@@ -7,6 +7,8 @@ class Neo4j::Model
7
7
  extend ActiveModel::Naming
8
8
  extend ActiveModel::Callbacks
9
9
  extend Neo4j::Validations::ClassMethods
10
+ extend Neo4j::TxMethods
11
+
10
12
  define_model_callbacks :create, :save, :update, :destroy
11
13
 
12
14
 
@@ -39,7 +41,7 @@ class Neo4j::Model
39
41
  # --------------------------------------
40
42
 
41
43
  def id
42
- self.neo_id
44
+ neo_id.nil? ? nil : neo_id.to_s
43
45
  end
44
46
 
45
47
  def to_param
@@ -83,7 +85,7 @@ class Neo4j::Model
83
85
 
84
86
 
85
87
  def read_attribute_for_validation(key)
86
- respond_to?(key)? send(key) : self[key]
88
+ respond_to?(key) ? send(key) : self[key]
87
89
  end
88
90
 
89
91
  def attributes=(values)
@@ -98,26 +100,63 @@ class Neo4j::Model
98
100
 
99
101
 
100
102
  # Updates this resource with all the attributes from the passed-in Hash and requests that the record be saved.
101
- # If the saving fails because of a connection or remote service error, an exception will be raised.
102
103
  # If saving fails because the resource is invalid then false will be returned.
103
104
  def update_attributes(attributes)
104
- Neo4j::Rails::Transaction.running? ? update_attributes_in_tx(attributes) : Neo4j::Rails::Transaction.run { update_attributes_in_tx(attributes) }
105
- end
106
-
107
- def update_attributes_in_tx(attributes)
108
105
  self.attributes=attributes
109
106
  save
110
107
  end
111
108
 
112
109
  def update_attributes!(attributes)
113
- Neo4j::Rails::Transaction.running? ? update_attributes_in_tx!(attributes) : Neo4j::Rails::Transaction.run { update_attributes_in_tx!(attributes) }
114
- end
115
-
116
- def update_attributes_in_tx!(attributes)
117
110
  self.attributes=attributes
118
111
  save!
119
112
  end
120
113
 
114
+ def update_nested_attributes(rel_type, clazz, has_one, attr, options)
115
+ allow_destroy,reject_if = [options[:allow_destroy], options[:reject_if]] if options
116
+
117
+ if new?
118
+ # We are updating a node that was created with the 'new' method.
119
+ # The relationship will only be kept in the Value object.
120
+ outgoing(rel_type)<<clazz.new(attr) unless reject_if?(reject_if,attr)
121
+ else
122
+ # We have a node that was created with the #create method - has real Neo4j relationships
123
+ # does it exist ?
124
+ found = if has_one
125
+ # id == nil that means we have a has_one relationship
126
+ outgoing(rel_type).first
127
+ else
128
+ # do we have an ID ?
129
+ id = attr[:id]
130
+ # this is a has_n relationship, find which one we want to update
131
+ id && outgoing(rel_type).find { |n| n.id == id }
132
+ end
133
+
134
+ # Check if we want to destroy not found nodes (e.g. {..., :_destroy => '1' } ?
135
+ destroy = attr[:_destroy]
136
+ if found
137
+ if destroy
138
+ found.destroy if allow_destroy
139
+ else
140
+ found.update_attributes_in_tx(attr) # it already exist, so update that one
141
+ end
142
+ elsif !destroy && !reject_if?(reject_if,attr)
143
+ new_node = clazz.new(attr)
144
+ saved = new_node.save
145
+ outgoing(rel_type) << new_node if saved
146
+ end
147
+ end
148
+ end
149
+
150
+ def reject_if?(proc_or_symbol, attr)
151
+ return false if proc_or_symbol.nil?
152
+ if proc_or_symbol.is_a?(Symbol)
153
+ meth = method(proc_or_symbol)
154
+ meth.arity == 0 ? meth.call : meth.call(attr)
155
+ else
156
+ proc_or_symbol.call(attr)
157
+ end
158
+ end
159
+
121
160
  def delete
122
161
  super
123
162
  @_deleted = true
@@ -125,13 +164,10 @@ class Neo4j::Model
125
164
  end
126
165
 
127
166
  def save
128
- if valid?
167
+ valid = valid?
168
+ if valid
129
169
  # if we are trying to save a value then we should create a real node
130
- if Neo4j::Rails::Transaction.running?
131
- _run_save_callbacks { save_in_tx }
132
- else
133
- Neo4j::Rails::Transaction.run { _run_save_callbacks { save_in_tx } }
134
- end
170
+ valid = _run_save_callbacks { create_or_update_node }
135
171
  @_created_record = false
136
172
  true
137
173
  else
@@ -140,12 +176,14 @@ class Neo4j::Model
140
176
  Neo4j::Rails::Transaction.fail if Neo4j::Rails::Transaction.running? && !_java_node.kind_of?(Neo4j::Value)
141
177
  false
142
178
  end
179
+ valid
143
180
  end
144
181
 
145
- def save_in_tx
146
- # _run_save_callbacks do
182
+ def create_or_update_node
183
+ valid = true
147
184
  if _java_node.kind_of?(Neo4j::Value)
148
185
  node = Neo4j::Node.new(props)
186
+ valid = _java_node.save_nested(node)
149
187
  init_on_load(node)
150
188
  init_on_create
151
189
  end
@@ -155,6 +193,7 @@ class Neo4j::Model
155
193
  else
156
194
  _run_update_callbacks { clear_changes }
157
195
  end
196
+ valid
158
197
  end
159
198
 
160
199
  def clear_changes
@@ -178,7 +217,11 @@ class Neo4j::Model
178
217
  # Returns true if this object hasn’t been saved yet — that is, a record for the object doesn’t exist yet; otherwise, returns false.
179
218
  def new_record?()
180
219
  # it is new if the model has been created with either the new or create method
181
- _java_node.kind_of?(Neo4j::Value) || @_created_record == true
220
+ new? || @_created_record == true
221
+ end
222
+
223
+ def new?
224
+ _java_node.kind_of?(Neo4j::Value)
182
225
  end
183
226
 
184
227
  def del
@@ -187,29 +230,53 @@ class Neo4j::Model
187
230
  end
188
231
 
189
232
  def destroy
190
- Neo4j::Rails::Transaction.running? ? _run_update_callbacks { del } : Neo4j::Rails::Transaction.run { _run_update_callbacks { del } }
233
+ _run_update_callbacks { del }
191
234
  end
192
235
 
193
236
  def destroyed?()
194
237
  @_deleted
195
238
  end
196
239
 
240
+ tx_methods :destroy, :create_or_update_node, :update_attributes, :update_attributes!
197
241
 
198
242
  # --------------------------------------
199
243
  # Class Methods
200
244
  # --------------------------------------
201
245
 
202
246
  class << self
247
+ extend Neo4j::TxMethods
248
+
203
249
  # returns a value object instead of creating a new node
204
250
  def new(*args)
205
251
  value = Neo4j::Value.new
206
252
  wrapped = self.orig_new
207
253
  wrapped.init_on_load(value)
208
254
  wrapped.attributes=args[0] if args[0].respond_to?(:each_pair)
255
+
256
+ wrapped.class._decl_rels.each_pair do |field, dsl|
257
+
258
+ meta = class << wrapped;
259
+ self;
260
+ end
261
+
262
+ wrapped.class._decl_rels.each_pair do |field, dsl|
263
+ meta.send(:define_method, field) do
264
+ if new?
265
+ value.outgoing(dsl.namespace_type)
266
+ else
267
+ self.outgoing(dsl.namespace_type)
268
+ end
269
+ end if dsl.direction == :outgoing
270
+
271
+ meta.send(:define_method, field) do
272
+ raise "NOT IMPLEMENTED #{field} (incoming relationship) FOR #new method, please create a new model with the create method instead"
273
+ end if dsl.direction == :incoming
274
+ end
275
+ end
276
+
209
277
  wrapped
210
278
  end
211
279
 
212
-
213
280
  # Handle Model.find(params[:id])
214
281
  def find(*args)
215
282
  if args.length == 1 && String === args[0] && args[0].to_i != 0
@@ -236,26 +303,55 @@ class Neo4j::Model
236
303
  alias_method :_orig_create, :create
237
304
 
238
305
  def create(*)
239
- Neo4j::Rails::Transaction.running? ? create_in_tx(super) : Neo4j::Rails::Transaction.run { create_in_tx(super) }
240
- end
241
-
242
- def create!(*args)
243
- Neo4j::Rails::Transaction.running? ? create_in_tx!(_orig_create(*args)) : Neo4j::Rails::Transaction.run { create_in_tx!(_orig_create(*args)) }
244
- end
245
-
246
- def create_in_tx(model)
306
+ model = super
247
307
  model.save
248
308
  model
249
309
  end
250
310
 
251
- def create_in_tx!(model)
311
+ def create!(*args)
312
+ model = _orig_create(*args)
252
313
  model.save!
253
314
  model
254
315
  end
255
316
 
317
+ tx_methods :create, :create!
318
+
319
+
256
320
  def transaction(&block)
257
321
  Neo4j::Rails::Transaction.run &block
258
322
  end
323
+
324
+ def accepts_nested_attributes_for(*attr_names)
325
+ options = attr_names.pop if attr_names[-1].is_a?(Hash)
326
+
327
+ attr_names.each do |association_name|
328
+ rel = self._decl_rels[association_name.to_sym]
329
+ raise "No relationship declared with has_n or has_one with type #{association_name}" unless rel
330
+ to_class = rel.to_class
331
+ raise "Can't use accepts_nested_attributes_for(#{association_name}) since it has not defined which class it has a relationship to, use has_n(#{association_name}).to(MyOtherClass)" unless to_class
332
+ type = rel.namespace_type
333
+ has_one = rel.has_one?
334
+
335
+ send(:define_method, "#{association_name}_attributes=") do |attributes|
336
+ if has_one
337
+ update_nested_attributes(type, to_class, true, attributes, options)
338
+ else
339
+ if attributes.is_a?(Array)
340
+ attributes.each do |attr|
341
+ update_nested_attributes(type, to_class, false, attr, options)
342
+ end
343
+ else
344
+ attributes.each_value do |attr|
345
+ update_nested_attributes(type, to_class, false, attr, options)
346
+ end
347
+ end
348
+ end
349
+ end
350
+ tx_methods("#{association_name}_attributes=")
351
+ end
352
+ end
353
+
259
354
  end
260
355
 
261
356
  end
357
+
@@ -0,0 +1,11 @@
1
+ module Neo4j::TxMethods
2
+ def tx_methods(*methods)
3
+ methods.each do |method|
4
+ tx_method = "#{method}_in_tx"
5
+ send(:alias_method, tx_method, method)
6
+ send(:define_method, method) do |*args|
7
+ Neo4j::Rails::Transaction.running? ? send(tx_method, *args) : Neo4j::Rails::Transaction.run { send(tx_method, *args) }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -10,6 +10,7 @@ module Neo4j
10
10
  if args[0].respond_to?(:each_pair)
11
11
  args[0].each_pair { |k, v| set_property(k.to_s, v) }
12
12
  end
13
+ @rels = {} # a hash of all relationship with key type
13
14
  end
14
15
 
15
16
  # override Neo4j::Property#props
@@ -38,6 +39,48 @@ module Neo4j
38
39
  @props.delete(key)
39
40
  end
40
41
 
41
- end
42
+ def outgoing(type)
43
+ @rels[type.to_sym] ||= OutgoingRels.new
44
+ end
45
+
46
+ def save_nested(root_node)
47
+ valid = true
48
+ @rels.each_pair do |type, rel|
49
+ rel.each do |new_node|
50
+ if new_node.save
51
+ root_node.outgoing(type) << new_node
52
+ else
53
+ valid = false
54
+ end
55
+ end
56
+ end
57
+ valid
58
+ end
59
+
60
+ class OutgoingRels
61
+ include Enumerable
62
+ def initialize
63
+ @nodes = []
64
+ end
65
+
66
+ def <<(other)
67
+ @nodes << other
68
+ end
42
69
 
70
+ def each
71
+ @nodes.each {|n| yield n}
72
+ end
73
+
74
+ def empty?
75
+ @nodes.empty?
76
+ end
77
+
78
+ def is_a?(type)
79
+ # ActionView requires this for nested attributes to work
80
+ return true if Array == type
81
+ super
82
+ end
83
+ end
84
+
85
+ end
43
86
  end
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.0.0.beta.9"
2
+ VERSION = "1.0.0.beta.10"
3
3
  end
data/lib/neo4j.rb CHANGED
@@ -42,6 +42,7 @@ require 'neo4j/mapping/class_methods/rule'
42
42
  # rails
43
43
  require 'rails/railtie'
44
44
  require 'active_model'
45
+ require 'neo4j/rails/tx_methods'
45
46
  require 'neo4j/rails/transaction'
46
47
  require 'neo4j/rails/railtie'
47
48
  require 'neo4j/rails/validations/uniqueness'
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 9
11
- version: 1.0.0.beta.9
10
+ - 10
11
+ version: 1.0.0.beta.10
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-10-05 00:00:00 +02:00
19
+ date: 2010-10-08 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -101,62 +101,6 @@ extra_rdoc_files:
101
101
  - README.rdoc
102
102
  files:
103
103
  - lib/neo4j.rb
104
- - lib/neo4j.old/reference_node.rb
105
- - lib/neo4j.old/event_handler.rb
106
- - lib/neo4j.old/indexer.rb
107
- - lib/neo4j.old/search_result.rb
108
- - lib/neo4j.old/config.rb
109
- - lib/neo4j.old/neo.rb
110
- - lib/neo4j.old/transaction.rb
111
- - lib/neo4j.old/node.rb
112
- - lib/neo4j.old/jars.rb
113
- - lib/neo4j.old/batch_inserter.rb
114
- - lib/neo4j.old/version.rb
115
- - lib/neo4j.old/relationship.rb
116
- - lib/neo4j.old/relationships/node_traverser.rb
117
- - lib/neo4j.old/relationships/decl_relationship_dsl.rb
118
- - lib/neo4j.old/relationships/wrappers.rb
119
- - lib/neo4j.old/relationships/has_n.rb
120
- - lib/neo4j.old/relationships/relationship_dsl.rb
121
- - lib/neo4j.old/relationships/has_list.rb
122
- - lib/neo4j.old/relationships/traversal_position.rb
123
- - lib/neo4j.old/mixins/java_node_mixin.rb
124
- - lib/neo4j.old/mixins/java_relationship_mixin.rb
125
- - lib/neo4j.old/mixins/migration_mixin.rb
126
- - lib/neo4j.old/mixins/node_mixin.rb
127
- - lib/neo4j.old/mixins/java_property_mixin.rb
128
- - lib/neo4j.old/mixins/java_list_mixin.rb
129
- - lib/neo4j.old/mixins/relationship_mixin.rb
130
- - lib/neo4j.old/mixins/rel_class_methods.rb
131
- - lib/neo4j.old/mixins/property_class_methods.rb
132
- - lib/neo4j.old/jars/neo4j-kernel-1.0.jar
133
- - lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar
134
- - lib/neo4j.old/extensions/aggregate.rb
135
- - lib/neo4j.old/extensions/find_path.rb
136
- - lib/neo4j.old/extensions/reindexer.rb
137
- - lib/neo4j.old/extensions/graph_algo.rb
138
- - lib/neo4j.old/extensions/rest.rb
139
- - lib/neo4j.old/extensions/tx_tracker.rb
140
- - lib/neo4j.old/extensions/rest_slave.rb
141
- - lib/neo4j.old/extensions/activemodel.rb
142
- - lib/neo4j.old/extensions/rest_master.rb
143
- - lib/neo4j.old/extensions/rest/server.rb
144
- - lib/neo4j.old/extensions/rest/rest.rb
145
- - lib/neo4j.old/extensions/rest/rest_mixin.rb
146
- - lib/neo4j.old/extensions/rest/stubs.rb
147
- - lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar
148
- - lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb
149
- - lib/neo4j.old/extensions/aggregate/node_aggregate.rb
150
- - lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb
151
- - lib/neo4j.old/extensions/aggregate/props_aggregator.rb
152
- - lib/neo4j.old/extensions/aggregate/prop_group.rb
153
- - lib/neo4j.old/extensions/aggregate/node_aggregator.rb
154
- - lib/neo4j.old/extensions/aggregate/props_aggregate.rb
155
- - lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb
156
- - lib/neo4j.old/extensions/aggregate/property_enum.rb
157
- - lib/neo4j.old/extensions/aggregate/aggregate_enum.rb
158
- - lib/neo4j.old/extensions/aggregate/node_group.rb
159
- - lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb
160
104
  - lib/neo4j/event_handler.rb
161
105
  - lib/neo4j/node_traverser.rb
162
106
  - lib/neo4j/relationship_traverser.rb
@@ -179,6 +123,7 @@ files:
179
123
  - lib/neo4j/rails/railtie.rb
180
124
  - lib/neo4j/rails/lucene_connection_closer.rb
181
125
  - lib/neo4j/rails/transaction.rb
126
+ - lib/neo4j/rails/tx_methods.rb
182
127
  - lib/neo4j/rails/value.rb
183
128
  - lib/neo4j/rails/validations/uniqueness.rb
184
129
  - lib/neo4j/jars/lucene-core-3.0.1.jar
@@ -1,144 +0,0 @@
1
- module Neo4j
2
-
3
- class BatchItem # :nodoc:
4
- attr_accessor :_wrapper, :neo_id
5
-
6
- include Neo4j::JavaPropertyMixin
7
-
8
- def initialize(neo_id, inserter)
9
- @neo_id = neo_id
10
- @inserter = inserter
11
- end
12
-
13
- def getId(); neo_id end
14
-
15
- def has_property?(key)
16
- props.include?(key.to_s)
17
- end
18
-
19
- def get_property(key)
20
- props[key]
21
- end
22
-
23
- def props
24
- # not sure why I have to do it like this, Strange why I can't use the Java Hash ?
25
- # gets java.lang.UnsupportedOperationException: null, in java/util/AbstractMap.java:186:in `put'
26
- java_props = @inserter.getNodeProperties(neo_id)
27
- ruby_props = {}
28
- java_props.keySet().each{|k| ruby_props[k] = java_props[k]}
29
- ruby_props
30
- end
31
-
32
-
33
- def setProperty(key, value)
34
- ruby_props = props
35
- ruby_props[key.to_s] = value
36
- @inserter.setNodeProperties(neo_id, ruby_props)
37
-
38
- if (wrapper_class and key[0, 1] != '_') # do not want events on internal properties
39
- wrapper_class.indexer.on_property_changed(wrapper, key)
40
- end
41
- end
42
- end
43
-
44
- # Neo4j has a batch insert mode that drops support for transactions and concurrency in favor of insertion speed.
45
- # This is useful when you have a big dataset that needs to be loaded once. In our experience, the batch inserter will
46
- # typically inject data around five times faster than running in normal transactional mode.
47
- #
48
- # === Usage
49
- #
50
- # The initialize method takes a code block that will use the BatchInserter.
51
- #
52
- # Neo4j::BatchInserter.new do |b|
53
- # a = Neo4j::Node.new :name => 'a'
54
- # b = Neo4j::Node.new :name => 'b'
55
- # c = Foo.new :key1 => 'val1', :key2 => 'val2'
56
- # c[:name] = "c"
57
- # Neo4j::Relationship.new(:friend, a, b, :since => '2001-01-01')
58
- # Neo4j::Relationship.new(:friend, Neo4j.ref_node, c, :since => '2001-01-01')
59
- # end
60
- #
61
- # After the code block the normal creation for nodes and relationship will be used.
62
- # Traversals inside the batch inserter block is not possible.
63
- # The BatchInserter can be used together with Neo4j Migrations (see Neo4j#migration)
64
- #
65
- class BatchInserter
66
-
67
- # See class description for usage.
68
- #
69
- # === Parameters
70
- # storage_path:: optional, the location of the neo4j dabase on file system, default Neo4j::Config[:storage_path]
71
- # db_version:: optional, sets version number on reference node, default nil -> do not set this property
72
- def initialize(storage_path = Neo4j::Config[:storage_path], db_version=nil) # :yields: batch_inserter
73
- # create the batch inserter
74
- inserter = org.neo4j.kernel.impl.batchinsert.BatchInserterImpl.new(storage_path)
75
-
76
- # save original methods
77
- create_node_meth = Neo4j.method(:create_node)
78
- create_rel_meth = Neo4j.method(:create_rel)
79
- ref_node_meth = Neo4j.method(:ref_node)
80
- instance_meth = Neo4j.method(:instance)
81
-
82
- # replace methods
83
- neo4j_meta = (class << Neo4j; self; end)
84
- neo4j_meta.instance_eval do
85
- define_method(:create_node) do |props|
86
- props ||= {}
87
- id = inserter.createNode(props.keys.inject({}) {|hash, key| hash[key.to_s] = props[key]; hash})
88
- BatchItem.new(id, inserter)
89
- end
90
- define_method(:create_rel) do |type, from_node, to_node, props|
91
- props = Hash[*props.map{|k, v| [k.to_s, v]}.flatten] if props
92
- java_type = org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s)
93
- id = inserter.createRelationship(from_node.neo_id, to_node.neo_id, java_type, props)
94
- BatchItem.new(id, inserter)
95
- end
96
- define_method(:ref_node) do
97
- BatchItem.new(inserter.getReferenceNode, inserter)
98
- end
99
- define_method(:instance) do
100
- Neo4j::BatchInstance.new
101
- end
102
- end
103
-
104
- begin
105
- yield inserter
106
- Neo4j.ref_node[:db_version] = db_version if db_version
107
- ensure
108
- inserter.shutdown
109
- # restore old methods
110
- neo4j_meta.instance_eval do
111
- define_method(:create_node, create_node_meth)
112
- define_method(:create_rel, create_rel_meth)
113
- define_method(:ref_node, ref_node_meth)
114
- define_method(:instance, instance_meth)
115
- end
116
- end
117
- end
118
-
119
- # This method is used if the batch inserter is used from the Migration API.
120
- #
121
- # === Parameters
122
- # context:: the context on which the batch inserter code block is evaluated in, not used.
123
- # version:: optional, if given then will set the property db_version on the context
124
- def self.execute(context, version=nil, &block)
125
- # Neo4j must not be running while using batch inserter, stop it just in case ...
126
- Neo4j::Transaction.finish
127
- Neo4j.stop
128
-
129
- BatchInserter.new(Neo4j::Config[:storage_path], version, &block)
130
-
131
- Neo4j.start
132
- end
133
- end
134
-
135
- # Used instead of Neo4j.instance object - will happily accept any methods - like transaction methods.
136
- class BatchInstance # :nodoc:
137
- def method_missing(m, *args, &block)
138
- return BatchInstance.new
139
- end
140
- end
141
- end
142
-
143
-
144
-