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
@@ -1,80 +0,0 @@
1
- module Neo4j::Aggregate
2
- class PropsAggregator
3
- def initialize(root_node, agg_id)
4
- @root_node = root_node
5
- @agg_id = agg_id
6
- end
7
-
8
-
9
- def on(nodes_or_class)
10
- if (nodes_or_class.kind_of?(Class) and nodes_or_class.ancestors.include?(Neo4j::NodeMixin))
11
- Neo4j.event_handler.add(self)
12
- @filter = nodes_or_class
13
- @nodes = nodes_or_class
14
- elsif (!nodes_or_class.respond_to?(:each))
15
- @nodes = [nodes_or_class]
16
- else
17
- @nodes = nodes_or_class
18
- end
19
- self
20
- end
21
-
22
- def props(*properties)
23
- @group_by = properties
24
- self
25
- end
26
-
27
- # Unregisters this aggregate so that it will not be notified any longer
28
- # on Neo4j node events. Used when we create an aggregate that is registered
29
- # with the Neo4j even listener by including a filter in the aggregate method
30
- #
31
- # ==== Example
32
- # agg_reg = my_aggregate.aggregate_each(MyNode).group_by(:something)
33
- # # add some MyNodes that my_aggregate will aggregate into groups
34
- # MyNode.new # etc...
35
- # # we now do not want to add more nodes using the aggregate above - unregister it
36
- # agg_reg.unregister
37
- # # no more nodes will be appended /deleted /modified in the my_aggregate.
38
- #
39
- def unregister
40
- Neo4j.event_handler.remove(self)
41
- end
42
-
43
- # called from neo4j event handler
44
- # :api: private
45
- def on_property_changed(node, prop_key, old_value, new_value) # :nodoc:
46
- return if node.class != @filter
47
- return unless @group_by.include?(prop_key.to_sym)
48
-
49
- # recreate the aggregate group
50
- execute([node])
51
- end
52
-
53
-
54
- def with(prop_key, &proc)
55
- @with_proc = proc
56
- @prop_key = prop_key
57
- self
58
- end
59
-
60
- def execute(nodes = @nodes)
61
- return unless nodes
62
- nodes.each do |node|
63
- group_node = node.aggregate_groups(@agg_id)
64
- if group_node.nil?
65
- group_node = PropGroup.new
66
- group_node.group_by = @group_by.join(',')
67
- group_node.aggregate = node
68
- rel = group_node.rels.outgoing(:aggregate)[node]
69
- rel[:aggregate_group] = @agg_id
70
- @root_node.groups << group_node
71
- end
72
- if @with_proc
73
- val = group_node.inject(0) {|sum, val| next sum if val.nil?; @with_proc.call(sum, val, 0)}
74
- group_node[@prop_key.to_s] = val
75
- end
76
- end
77
- @nodes = nil # prevent it to run twice
78
- end
79
- end
80
- end
@@ -1,12 +0,0 @@
1
- require 'set'
2
- require 'neo4j/extensions/aggregate/ext/node_mixin'
3
- require 'neo4j/extensions/rule/node_rule_mixin'
4
- require 'neo4j/extensions/rule/props_rule_mixin'
5
- require 'neo4j/extensions/rule/node_rule'
6
- require 'neo4j/extensions/rule/props_rule'
7
- require 'neo4j/extensions/rule/rule_enum'
8
- require 'neo4j/extensions/rule/node_aggregator'
9
- require 'neo4j/extensions/rule/node_group'
10
- require 'neo4j/extensions/rule/prop_group'
11
- require 'neo4j/extensions/rule/property_enum'
12
- require 'neo4j/extensions/rule/props_aggregator'
@@ -1,117 +0,0 @@
1
- # Extension which finds the shortest path (in terms of number of links) between
2
- # two nodes. Use something like this:
3
- #
4
- # require 'neo4j/extensions/find_path'
5
- # node1.traverse.both(:knows).depth(:all).path_to(node2)
6
- # # => [node1, node42, node1234, node256, node2]
7
- #
8
- # This extension is still rather experimental. The algorithm is based on the one
9
- # used in the Neo4j Java IMDB example.
10
- #
11
- # Martin Kleppmann, July 2009
12
- module Neo4j
13
- module Relationships
14
- class NodeTraverser
15
-
16
- attr_accessor :predecessor_map, :other_traverser, :returnable_evaluator
17
- attr_writer :_java_node
18
-
19
- # Finds a path by starting a breadth-first traverser from each end and stopping as soon
20
- # as the two meet. Keeps a hash of current_node -> previous_node which allows us to
21
- # reconstruct the path that was taken once we meet. Returns an array with all of the
22
- # nodes constituting the path from +self+ to +other_node+ (inclusive), or +nil+ if no
23
- # path could be found.
24
- def path_to(other_node)
25
- return [] if other_node._java_node.neo_id == self._java_node.neo_id
26
- self.other_traverser = clone
27
- self.other_traverser._java_node = other_node._java_node
28
- self.other_traverser.other_traverser = self
29
- self.other_traverser.prepare_path_search
30
- self.other_traverser.swap_directions
31
- self.prepare_path_search
32
-
33
- while true # Advance the traversers in alternation
34
- break if self.search_for_path
35
- break if other_traverser.search_for_path
36
- end
37
-
38
- path = returnable_evaluator.found_path
39
- if !path && other_traverser.returnable_evaluator.found_path
40
- path = other_traverser.returnable_evaluator.found_path.reverse
41
- end
42
- path
43
- end
44
-
45
- # :nodoc:
46
- def path_traceback(end_node)
47
- # Reconstructs the chain of predecessors leading up to +end_node+. For internal use only.
48
- path = []
49
- while end_node = predecessor_map[end_node]
50
- path.unshift end_node
51
- end
52
- path
53
- end
54
-
55
- # :nodoc:
56
- def prepare_path_search
57
- self.returnable_evaluator = FindPathEvaluator.new(self, returnable_evaluator)
58
- self.predecessor_map = {Neo4j.load_node(_java_node.neo_id) => nil}
59
- end
60
-
61
- # :nodoc:
62
- def swap_directions
63
- @types_and_dirs = @types_and_dirs.map do |item|
64
- case item
65
- when org.neo4j.graphdb.Direction::INCOMING
66
- org.neo4j.graphdb.Direction::OUTGOING
67
- when org.neo4j.graphdb.Direction::OUTGOING
68
- org.neo4j.graphdb.Direction::INCOMING
69
- else
70
- item
71
- end
72
- end
73
- end
74
-
75
- # Advances this traverser's path search by one step. Returns +false+ if there is still
76
- # more to do and +true+ if finished (irrespective of whether or not a result was found).
77
- def search_for_path
78
- @path_iterator ||= iterator
79
- return true unless @path_iterator.hasNext
80
- node = @path_iterator.next
81
- !!returnable_evaluator.found_path # !! forces type to boolean
82
- end
83
- end
84
-
85
-
86
- class FindPathEvaluator
87
- include org.neo4j.graphdb.ReturnableEvaluator
88
-
89
- attr_accessor :traverser, :original_evaluator, :found_path
90
-
91
- def initialize(traverser, original_evaluator)
92
- @traverser = traverser
93
- @original_evaluator = original_evaluator
94
- end
95
-
96
- # Called at each traversal position while searching for a path. Records the current node
97
- # and its predecessor (for generating the traceback) and checks whether the two traversers
98
- # have met.
99
- def isReturnableNode(traversal_position)
100
- return false unless original_evaluator.isReturnableNode(traversal_position)
101
-
102
- current = Neo4j.load_node(traversal_position.current_node.getId)
103
- previous = Neo4j.load_node(traversal_position.previous_node.getId) unless traversal_position.previous_node.nil?
104
- traverser.predecessor_map[current] = previous
105
-
106
- if traverser.other_traverser.predecessor_map.include? current
107
- # Yay, found a path!
108
- @found_path = traverser.path_traceback(current)
109
- @found_path << current
110
- @found_path += traverser.other_traverser.path_traceback(current).reverse
111
- end
112
-
113
- true
114
- end
115
- end
116
- end
117
- end
@@ -1,133 +0,0 @@
1
- module Neo4j::GraphAlgo
2
- require 'neo4j/extensions/graph_algo/neo4j-graph-algo-0.3.jar'
3
-
4
-
5
- class ListOfAlternatingNodesAndRelationships #:nodoc:
6
- include Enumerable
7
-
8
- def initialize(list)
9
- @list = list
10
- end
11
-
12
- def each
13
- iter = @list.iterator
14
- node = true
15
- while (iter.hasNext)
16
- id = iter.next.getId
17
- if (node)
18
- yield Neo4j.load_node(id)
19
- else
20
- yield Neo4j.load_rel(id)
21
- end
22
- node = !node
23
- end
24
- end
25
- end
26
-
27
- class ListOfNodes #:nodoc:
28
- include Enumerable
29
-
30
- def initialize(list)
31
- @list = list
32
- end
33
-
34
- def size
35
- @list.size
36
- end
37
-
38
- def each
39
- iter = @list.iterator
40
- while (iter.hasNext)
41
- n = iter.next
42
- yield Neo4j.load_node(n.getId)
43
- end
44
- end
45
- end
46
-
47
- # A Wrapper for some of the neo4j graphdb algorithms
48
- #
49
- # Currently only the AllSimplePaths is wrapped in Ruby.
50
- #
51
- # === Usage
52
- #
53
- # found_nodes = GraphAlgo.all_simple_paths.from(node1).both(:knows).to(node7).depth(4).as_nodes
54
- #
55
- # === See also
56
- # * JavaDoc: http://components.neo4j.org/graph-algo/apidocs/org/neo4j/graphalgo/AllSimplePaths.html
57
- # * A complete example: http://github.com/andreasronge/neo4j/tree/master/examples/you_might_know/
58
- #
59
- class AllSimplePaths
60
- include Enumerable
61
-
62
- def initialize
63
- @types = []
64
- @direction = org.neo4j.graphdb.Direction::OUTGOING
65
- end
66
-
67
- def each
68
- if @as_nodes
69
- iter = paths.get_paths_as_nodes.iterator
70
- while (iter.has_next) do yield ListOfNodes.new(iter.next) end
71
- else
72
- iter = paths.get_paths.iterator
73
- while (iter.has_next) do yield ListOfAlternatingNodesAndRelationships.new(iter.next) end
74
- end
75
- end
76
-
77
- def as_nodes
78
- @as_nodes = true
79
- self
80
- end
81
-
82
- def size
83
- paths.get_paths_as_nodes.size
84
- end
85
-
86
- def paths
87
- @paths ||= org.neo4j.graphalgo.AllSimplePaths.new(@from._java_node, @to._java_node, @depth, @direction, @types.to_java(:"org.neo4j.graphdb.RelationshipType"))
88
- end
89
-
90
- def from(f)
91
- @from = f
92
- self
93
- end
94
-
95
- def to(t)
96
- @to = t
97
- self
98
- end
99
-
100
- def depth(d)
101
- @depth = d
102
- self
103
- end
104
-
105
- def both(*types)
106
- types.each { |type| @types << org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s) }
107
- @direction = org.neo4j.graphdb.Direction::BOTH
108
- self
109
- end
110
-
111
- def outgoing(*types)
112
- types.each { |type| @types << org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s) }
113
- @direction = org.neo4j.graphdb.Direction::OUTGOING
114
- self
115
- end
116
-
117
- def incoming(*types)
118
- types.each { |type| @types << org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s) }
119
- @direction = org.neo4j.graphdb.Direction::INCOMING
120
- self
121
- end
122
-
123
- end
124
-
125
- def self.all_simple_paths
126
- # org.neo4j.graphdb.Node node1, org.neo4j.graphdb.Node node2, int maximumTotalDepth, org.neo4j.graphdb.Direction relationshipDirection, org.neo4j.graphdb.RelationshipType... relationshipTypes)
127
- AllSimplePaths.new
128
- end
129
-
130
-
131
- end
132
-
133
-
@@ -1 +0,0 @@
1
- require 'neo4j/extensions/graph_algo/all_simple_paths'
@@ -1,104 +0,0 @@
1
- module Neo4j
2
-
3
- module PropertyClassMethods
4
- # Traverse all nodes and update the lucene index.
5
- # Can be used for example if it's' necessary to change the index on a class
6
- #
7
- def update_index
8
- all.nodes.each do |n|
9
- n.update_index
10
- end
11
- end
12
-
13
- # Returns node instances of this class.
14
- #
15
- def all
16
- index_node = IndexNode.instance
17
- index_node.rels.outgoing(self)
18
- end
19
- end
20
-
21
- module NodeMixin
22
- alias_method :ignore_incoming_cascade_delete_orig?, :ignore_incoming_cascade_delete?
23
- def ignore_incoming_cascade_delete? (relationship)
24
- # if it's an index node relationship then it should be allowed to cascade delete the node
25
- ignore_incoming_cascade_delete_orig?(relationship) || relationship.other_node(self) == IndexNode.instance
26
- end
27
-
28
- end
29
-
30
-
31
- class IndexNode
32
- include NodeMixin
33
-
34
- # Connects the given node with the reference node.
35
- # The type of the relationship will be the same as the class name of the
36
- # specified node unless the optional parameter type is specified.
37
- # This method is used internally to keep a reference to all node instances in the node space
38
- # (useful for example for reindexing all nodes by traversing the node space).
39
- #
40
- # ==== Parameters
41
- # node<Neo4j::NodeMixin>:: Connect the reference node with this node
42
- # type<String>:: Optional, the type of the relationship we want to create
43
- #
44
- # ==== Returns
45
- # nil
46
- #
47
- # :api: private
48
- def connect(node, type = node.class.root_class)
49
- rtype = org.neo4j.graphdb.DynamicRelationshipType.withName(type.to_s)
50
- @_java_node.createRelationshipTo(node._java_node, rtype)
51
- nil
52
- end
53
-
54
- def on_node_created(node)
55
- # we have to avoid connecting to our self
56
- unless self == node
57
- node.class.ancestors.grep(Class).each{|p| connect(node, p) if p.respond_to?(:all)}
58
- end
59
- end
60
-
61
- def self.on_neo_started(neo_instance)
62
- if neo_instance.ref_node.rel?(:index_node)
63
- # we already have it, put it in instance variable so we do not have to look again
64
- @index_node = neo_instance.ref_node.rels.outgoing(:index_node).nodes.first
65
- else
66
- @index_node = IndexNode.new # cache this so we do not have to look it up always
67
- neo_instance.ref_node.rels.outgoing(:index_node) << @index_node
68
- end
69
- Neo4j.event_handler.add(@index_node)
70
- end
71
-
72
- def self.on_neo_stopped(neo_instance)
73
- # unregister the instance
74
- Neo4j.event_handler.remove(@index_node)
75
- @index_node = nil
76
- end
77
-
78
- def self.instance
79
- Neo4j.start if @index_node.nil?
80
- @index_node
81
- end
82
-
83
- def self.instance?
84
- !@index_node.nil?
85
- end
86
-
87
- end
88
-
89
-
90
- # Add this so it can add it self as listener
91
- def self.load_reindexer
92
- Neo4j.event_handler.add(IndexNode)
93
- # in case we already have started
94
- Neo4j::Transaction.run { IndexNode.on_neo_started(Neo4j) } if Neo4j.running?
95
- end
96
-
97
- def self.unload_reindexer
98
- Neo4j.event_handler.remove(IndexNode)
99
- Neo4j.event_handler.remove(IndexNode.instance) if IndexNode.instance?
100
- end
101
-
102
-
103
- load_reindexer
104
- end