neo4j 1.0.0.beta.27-java → 1.0.0.beta.28-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/CONTRIBUTORS +1 -0
  2. data/lib/neo4j.rb +38 -72
  3. data/lib/neo4j/{algo.rb → algo/algo.rb} +5 -1
  4. data/lib/neo4j/batch/batch.rb +2 -0
  5. data/lib/neo4j/batch/indexer.rb +108 -0
  6. data/lib/neo4j/batch/inserter.rb +168 -0
  7. data/lib/neo4j/database.rb +13 -8
  8. data/lib/neo4j/{mapping/class_methods/list.rb → has_list/class_methods.rb} +2 -4
  9. data/lib/neo4j/has_list/has_list.rb +3 -0
  10. data/lib/neo4j/{mapping/has_list.rb → has_list/mapping.rb} +2 -2
  11. data/lib/neo4j/{mapping/class_methods/relationship.rb → has_n/class_methods.rb} +42 -12
  12. data/lib/neo4j/has_n/decl_relationship_dsl.rb +216 -0
  13. data/lib/neo4j/has_n/has_n.rb +3 -0
  14. data/lib/neo4j/{mapping/has_n.rb → has_n/mapping.rb} +16 -7
  15. data/lib/neo4j/index/index.rb +5 -0
  16. data/lib/neo4j/index/indexer.rb +27 -22
  17. data/lib/neo4j/index/lucene_query.rb +3 -1
  18. data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-1.3.M01.jar +0 -0
  19. data/lib/neo4j/jars/core/neo4j-index-1.3-1.3.M01.jar +0 -0
  20. data/lib/neo4j/jars/core/neo4j-kernel-1.3-1.3.M01.jar +0 -0
  21. data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-1.3.M01.jar +0 -0
  22. data/lib/neo4j/jars/ha/{neo4j-ha-0.6-SNAPSHOT.jar → neo4j-ha-0.6-1.3.M01.jar} +0 -0
  23. data/lib/neo4j/jars/ha/neo4j-management-1.3-1.3.M01.jar +0 -0
  24. data/lib/neo4j/jars/ha/neo4j-shell-1.3-1.3.M01.jar +0 -0
  25. data/lib/neo4j/migrations/class_methods.rb +102 -0
  26. data/lib/neo4j/migrations/extensions.rb +10 -9
  27. data/lib/neo4j/migrations/lazy_node_mixin.rb +50 -0
  28. data/lib/neo4j/migrations/migration.rb +84 -81
  29. data/lib/neo4j/migrations/migrations.rb +6 -100
  30. data/lib/neo4j/migrations/node_mixin.rb +80 -0
  31. data/lib/neo4j/migrations/ref_node_wrapper.rb +32 -0
  32. data/lib/neo4j/neo4j.rb +11 -0
  33. data/lib/neo4j/node.rb +55 -25
  34. data/lib/neo4j/{mapping/class_methods/init_node.rb → node_mixin/class_methods.rb} +3 -3
  35. data/lib/neo4j/{mapping → node_mixin}/node_mixin.rb +35 -18
  36. data/lib/neo4j/{mapping/class_methods/property.rb → property/class_methods.rb} +5 -4
  37. data/lib/neo4j/{property.rb → property/property.rb} +2 -0
  38. data/lib/neo4j/rails/finders.rb +21 -7
  39. data/lib/neo4j/rails/rails.rb +19 -0
  40. data/lib/neo4j/rails/timestamps.rb +1 -1
  41. data/lib/neo4j/relationship.rb +7 -0
  42. data/lib/neo4j/{mapping/class_methods/init_rel.rb → relationship_mixin/class_methods.rb} +4 -4
  43. data/lib/neo4j/{mapping → relationship_mixin}/relationship_mixin.rb +23 -5
  44. data/lib/neo4j/rels/rels.rb +85 -0
  45. data/lib/neo4j/rels/traverser.rb +102 -0
  46. data/lib/neo4j/{mapping/class_methods/rule.rb → rule/class_methods.rb} +11 -11
  47. data/lib/neo4j/rule/functions/count.rb +37 -0
  48. data/lib/neo4j/rule/functions/function.rb +74 -0
  49. data/lib/neo4j/rule/functions/functions.rb +3 -0
  50. data/lib/neo4j/rule/functions/sum.rb +29 -0
  51. data/lib/neo4j/rule/rule.rb +5 -0
  52. data/lib/neo4j/rule/rule_event_listener.rb +162 -0
  53. data/lib/neo4j/rule/rule_node.rb +182 -0
  54. data/lib/neo4j/to_java.rb +0 -14
  55. data/lib/neo4j/traversal/filter_predicate.rb +25 -0
  56. data/lib/neo4j/traversal/prune_evaluator.rb +14 -0
  57. data/lib/neo4j/traversal/rel_expander.rb +31 -0
  58. data/lib/neo4j/traversal/traversal.rb +90 -0
  59. data/lib/neo4j/traversal/traverser.rb +173 -0
  60. data/lib/neo4j/{type_converters.rb → type_converters/type_converters.rb} +0 -0
  61. data/lib/neo4j/version.rb +1 -1
  62. data/lib/test.rb~ +2 -0
  63. data/neo4j.gemspec +11 -10
  64. metadata +48 -37
  65. data/lib/neo4j/functions/count.rb +0 -33
  66. data/lib/neo4j/functions/function.rb +0 -72
  67. data/lib/neo4j/functions/sum.rb +0 -27
  68. data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-SNAPSHOT.jar +0 -0
  69. data/lib/neo4j/jars/core/neo4j-index-1.3-SNAPSHOT.jar +0 -0
  70. data/lib/neo4j/jars/core/neo4j-kernel-1.3-SNAPSHOT.jar +0 -0
  71. data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-SNAPSHOT.jar +0 -0
  72. data/lib/neo4j/jars/ha/neo4j-management-1.3-SNAPSHOT.jar +0 -0
  73. data/lib/neo4j/jars/ha/neo4j-shell-1.3-SNAPSHOT.jar +0 -0
  74. data/lib/neo4j/mapping/decl_relationship_dsl.rb +0 -214
  75. data/lib/neo4j/mapping/rule.rb +0 -158
  76. data/lib/neo4j/mapping/rule_node.rb +0 -176
  77. data/lib/neo4j/migrations.rb +0 -12
  78. data/lib/neo4j/migrations/global_migration.rb +0 -29
  79. data/lib/neo4j/migrations/lazy_migration_mixin.rb +0 -47
  80. data/lib/neo4j/migrations/migration_mixin.rb +0 -78
  81. data/lib/neo4j/node_mixin.rb +0 -4
  82. data/lib/neo4j/node_relationship.rb +0 -161
  83. data/lib/neo4j/node_traverser.rb +0 -224
  84. data/lib/neo4j/relationship_mixin.rb +0 -4
  85. data/lib/neo4j/relationship_traverser.rb +0 -92
@@ -1,6 +1,7 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
3
- module Property
1
+ module Neo4j
2
+ module Property
3
+
4
+ module ClassMethods
4
5
 
5
6
  # Generates accessor method and sets configuration for Neo4j node properties.
6
7
  # The generated accessor is a simple wrapper around the #[] and
@@ -80,4 +81,4 @@ module Neo4j::Mapping
80
81
  end
81
82
  end
82
83
  end
83
- end
84
+ end
@@ -1,3 +1,5 @@
1
+ require 'neo4j/property/class_methods'
2
+
1
3
  module Neo4j
2
4
  module Property
3
5
 
@@ -4,7 +4,7 @@ module Neo4j
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- rule(:_all, :functions => Neo4j::Functions::Count.new)
7
+ rule(:_all, :functions => Neo4j::Rule::Functions::Count.new)
8
8
  end
9
9
 
10
10
  module ClassMethods
@@ -59,8 +59,14 @@ module Neo4j
59
59
  when :all, :first
60
60
  kind = args.shift
61
61
  send(kind, *args)
62
+ when "0", 0
63
+ nil
62
64
  else
63
- find_with_ids(*args) or first(*args)
65
+ if ((args.first.is_a?(Integer) || args.first.is_a?(String)) && args.first.to_i > 0)
66
+ find_with_ids(*args)
67
+ else
68
+ first(*args)
69
+ end
64
70
  end
65
71
  end
66
72
 
@@ -116,16 +122,24 @@ module Neo4j
116
122
 
117
123
  # does it contain an empty conditions param ?
118
124
  hash = args.find { |a| a.is_a?(Hash) }
119
- return false if hash.include?(:conditions) && hash[:conditions].empty?
125
+ if hash
126
+ return false if hash.include?(:conditions) && hash[:conditions].empty?
120
127
 
121
- # does it contain only paging or sorting params ?
122
- !hash.except(:sort, :page, :per_page).empty?
128
+ # does it contain only paging or sorting params ?
129
+ !hash.except(:sort, :page, :per_page).empty?
130
+ else
131
+ return false
132
+ end
123
133
  end
124
134
 
125
135
  def find_with_ids(*args)
126
- if ((args.first.is_a?(String) || args.first.is_a?(Integer)) && args.first.to_i > 0)
127
- load(*args.map { |p| p.to_i })
136
+ result = load(*args.map { |p| p.to_i })
137
+ if result.is_a?(Array)
138
+ result = result.select { |r| r.is_a? self }
139
+ else
140
+ result = nil unless result.is_a? self
128
141
  end
142
+ result
129
143
  end
130
144
 
131
145
  def find_with_indexer(*args)
@@ -0,0 +1,19 @@
1
+ # rails
2
+ require 'neo4j/rails/tx_methods'
3
+ require 'neo4j/rails/transaction'
4
+ require 'neo4j/rails/railtie'
5
+ require 'neo4j/rails/validations/uniqueness'
6
+ require 'neo4j/rails/validations/non_nil'
7
+ require 'neo4j/rails/finders'
8
+ require 'neo4j/rails/mapping/property'
9
+ require 'neo4j/rails/validations'
10
+ require 'neo4j/rails/callbacks'
11
+ require 'neo4j/rails/timestamps'
12
+ require 'neo4j/rails/serialization'
13
+ require 'neo4j/rails/attributes'
14
+ require 'neo4j/rails/persistence'
15
+ require 'neo4j/rails/relationships/mapper'
16
+ require 'neo4j/rails/relationships/relationship'
17
+ require 'neo4j/rails/relationships/relationships'
18
+ require 'neo4j/rails/model'
19
+ require 'neo4j/rails/lucene_connection_closer'
@@ -1,6 +1,6 @@
1
- # Handle all the created_at, updated_at, created_on, updated_on type stuff.
2
1
  module Neo4j
3
2
  module Rails
3
+ # Handle all the created_at, updated_at, created_on, updated_on type stuff.
4
4
  module Timestamps
5
5
  extend ActiveSupport::Concern
6
6
 
@@ -1,3 +1,10 @@
1
+ # external neo4j dependencies
2
+ require 'neo4j/property/property'
3
+ require 'neo4j/index/index'
4
+ require 'neo4j/equal'
5
+ require 'neo4j/load'
6
+ require 'neo4j/to_java'
7
+
1
8
  module Neo4j
2
9
 
3
10
  org.neo4j.kernel.impl.core.RelationshipProxy.class_eval do
@@ -1,6 +1,6 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
3
- module InitRel
1
+ module Neo4j
2
+ module RelationshipMixin
3
+ module ClassMethods
4
4
  def load_wrapper(rel)
5
5
  wrapped_rel = self.orig_new
6
6
  wrapped_rel.init_on_load(rel)
@@ -21,7 +21,7 @@ module Neo4j::Mapping
21
21
  # props:: optional hash of properties to initialize the create relationship with
22
22
  #
23
23
  def new(*args)
24
- type, from_node, to_node, props = args
24
+ type, from_node, to_node = args
25
25
  rel = Neo4j::Relationship.create(type, from_node, to_node)
26
26
  wrapped_rel = super()
27
27
  wrapped_rel.init_on_load(rel)
@@ -1,5 +1,23 @@
1
- module Neo4j::Mapping
2
-
1
+ # external neo4j dependencies
2
+ require 'neo4j/index/index'
3
+ require 'neo4j/property/property'
4
+
5
+ # internal dependencies
6
+ require 'neo4j/relationship_mixin/class_methods'
7
+
8
+
9
+ module Neo4j
10
+
11
+ # Use this mixin to wrap Neo4j Relationship Java object.
12
+ # This mixin is similar to Neo4j::NodeMixin which wraps Neo4j::Node Java objects.
13
+ #
14
+ # ==== Instance Methods, Mixins
15
+ # * Neo4j::Index :: relationships can also be indexed just like nodes
16
+ # *
17
+ # ==== Class Methods, Mixins
18
+ # * Neo4j::Index::ClassMethods :: for declaration for keeping lucene index and neo4j property in sync
19
+ # * Neo4j::Property::ClassMethods :: for declaration of convenience accessors of property
20
+ #
3
21
  module RelationshipMixin
4
22
  extend Forwardable
5
23
  include Neo4j::Index
@@ -103,9 +121,9 @@ module Neo4j::Mapping
103
121
 
104
122
  c.class_inheritable_hash :_decl_props
105
123
  c._decl_props ||= {}
106
-
107
- c.extend ClassMethods::Property
108
- c.extend ClassMethods::InitRel
124
+
125
+ c.extend ClassMethods
126
+ c.extend Neo4j::Property::ClassMethods
109
127
  c.extend Neo4j::Index::ClassMethods
110
128
 
111
129
  def c.inherited(subclass)
@@ -0,0 +1,85 @@
1
+ require 'neo4j/rels/traverser'
2
+
3
+
4
+ module Neo4j
5
+
6
+ # Contains methods for traversing relationship object of depth one from one node.
7
+ module Rels
8
+ include ToJava
9
+
10
+ # Returns an enumeration of relationship objects.
11
+ # It always returns relationship of depth one.
12
+ #
13
+ # See Neo4j::Relationship
14
+ #
15
+ # ==== Examples
16
+ # # Return both incoming and outgoing relationships
17
+ # me.rels(:friends, :work).each {|relationship|...}
18
+ #
19
+ # # Only return outgoing relationship of given type
20
+ # me.rels(:friends).outgoing.first.end_node # => my friend node
21
+ #
22
+ def rels(*type)
23
+ Traverser.new(self, type, :both)
24
+ end
25
+
26
+
27
+ # Returns the only relationship of a given type and direction that is attached to this node, or null.
28
+ # This is a convenience method that is used in the commonly occuring situation where a node has exactly zero or
29
+ # one relationships of a given type and direction to another node.
30
+ # Typically this invariant is maintained by the rest of the code: if at any time more than one such relationships
31
+ # exist, it is a fatal error that should generate an unchecked exception. This method reflects that semantics and
32
+ # returns either:
33
+ #
34
+ # * nil if there are zero relationships of the given type and direction,
35
+ # * the relationship if there's exactly one, or
36
+ # * raise an exception in all other cases.
37
+ def rel(dir, type)
38
+ result = _rel(dir, type)
39
+ result && result.wrapper
40
+ end
41
+
42
+ # Same as rel but does not return a ruby wrapped object but instead returns the Java object.
43
+ def _rel(dir, type)
44
+ get_single_relationship(type_to_java(type), dir_to_java(dir))
45
+ end
46
+
47
+ # Returns the raw java neo4j relationship object.
48
+ def _rels(dir=:both, *types)
49
+ if types.size > 1
50
+ java_types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
51
+ get_relationships(java_types)
52
+ elsif types.size == 1
53
+ get_relationships(type_to_java(types[0]), dir_to_java(dir))
54
+ elsif dir == :both
55
+ get_relationships(dir_to_java(dir))
56
+ else
57
+ raise "illegal argument, does not accept #{dir} #{types.join(',')} - only dir=:both for any relationship types"
58
+ end
59
+ end
60
+
61
+ # Check if the given relationship exists
62
+ # Returns true if there are one or more relationships from this node to other nodes
63
+ # with the given relationship.
64
+ #
65
+ # ==== Parameters
66
+ # type:: the key and value to be set, default any type
67
+ # dir:: optional default :both (either, :outgoing, :incoming, :both)
68
+ #
69
+ # ==== Returns
70
+ # true if one or more relationships exists for the given type and dir
71
+ # otherwise false
72
+ #
73
+ def rel? (type=nil, dir=:both)
74
+ if type
75
+ hasRelationship(type_to_java(type), dir_to_java(dir))
76
+ else
77
+ hasRelationship
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ end
84
+
85
+
@@ -0,0 +1,102 @@
1
+ # external neo4j dependencies
2
+ require 'neo4j/to_java'
3
+
4
+
5
+ module Neo4j
6
+ module Rels
7
+
8
+ # Traverse relationships of depth one from one node.
9
+ # This object is returned when using the Neo4j::Rels which is included in the Neo4j::Node class.
10
+ #
11
+ class Traverser
12
+ include Enumerable
13
+ include ToJava
14
+
15
+ def initialize(node, types, direction)
16
+ @node = node
17
+ if types.size > 1
18
+ @types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
19
+ elsif types.size == 1
20
+ @type = type_to_java(types[0])
21
+ end
22
+ @direction = direction
23
+ end
24
+
25
+ def to_s
26
+ if @type
27
+ "#{self.class} [type: #{@type} dir:#{@direction}]"
28
+ elsif @types
29
+ "#{self.class} [types: #{@types.join(',')} dir:#{@direction}]"
30
+ else
31
+ "#{self.class} [types: ANY dir:#{@direction}]"
32
+ end
33
+ end
34
+
35
+ def each
36
+ iter = iterator
37
+ while (iter.hasNext())
38
+ rel = iter.next
39
+ yield rel.wrapper if match_to_other?(rel)
40
+ end
41
+ end
42
+
43
+ def empty?
44
+ first == nil
45
+ end
46
+
47
+ def iterator
48
+ if @types
49
+ @node.get_relationships(@types).iterator
50
+ elsif @type
51
+ @node.get_relationships(@type, dir_to_java(@direction))
52
+ else
53
+ @node.get_relationships(dir_to_java(@direction))
54
+ end
55
+ end
56
+
57
+ def match_to_other?(rel)
58
+ if @to_other.nil?
59
+ true
60
+ elsif @direction == :outgoing
61
+ rel._end_node == @to_other
62
+ elsif @direction == :incoming
63
+ rel._start_node == @to_other
64
+ else
65
+ rel._start_node == @to_other || rel._end_node == @to_other
66
+ end
67
+ end
68
+
69
+ def to_other(to_other)
70
+ @to_other = to_other
71
+ self
72
+ end
73
+
74
+ def del
75
+ each { |rel| rel.del }
76
+ end
77
+
78
+ def size
79
+ [*self].size
80
+ end
81
+
82
+ def both
83
+ @direction = :both
84
+ self
85
+ end
86
+
87
+ def incoming
88
+ raise "Not allowed calling incoming when finding several relationships types" if @types
89
+ @direction = :incoming
90
+ self
91
+ end
92
+
93
+ def outgoing
94
+ raise "Not allowed calling outgoing when finding several relationships types" if @types
95
+ @direction = :outgoing
96
+ self
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+ end
@@ -1,5 +1,5 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
1
+ module Neo4j
2
+ module Rule
3
3
 
4
4
 
5
5
  # Allows you to group nodes by providing a rule.
@@ -72,7 +72,7 @@ module Neo4j::Mapping
72
72
  # Yes, since operations are performed in an transaction. However you may get a deadlock exception:
73
73
  # http://docs.neo4j.org/html/snapshot/#_deadlocks
74
74
  #
75
- module Rule
75
+ module ClassMethods
76
76
 
77
77
  # Creates an rule node attached to the Neo4j.ref_node
78
78
  # Can be used to rule all instances of a specific Ruby class.
@@ -102,7 +102,7 @@ module Neo4j::Mapping
102
102
 
103
103
  # define class methods
104
104
  singleton.send(:define_method, rule_name) do
105
- rule_node = Neo4j::Mapping::Rule.rule_node_for(self)
105
+ rule_node = RuleEventListener.rule_node_for(self)
106
106
  rule_node.traversal(rule_name)
107
107
  end unless respond_to?(rule_name)
108
108
 
@@ -111,11 +111,11 @@ module Neo4j::Mapping
111
111
  instance_eval &block
112
112
  end
113
113
 
114
- rule = Neo4j::Mapping::Rule.add(self, rule_name, props, &block)
114
+ rule = RuleEventListener.add(self, rule_name, props, &block)
115
115
 
116
116
  rule.functions && rule.functions.each do |func|
117
117
  singleton.send(:define_method, func.class.function_name) do |r_name, *args|
118
- rule_node = Neo4j::Mapping::Rule.rule_node_for(self)
118
+ rule_node = RuleEventListener.rule_node_for(self)
119
119
  function_id = args.empty? ? "_classname" : args[0]
120
120
  function = rule_node.find_function(r_name, func.class.function_name, function_id)
121
121
  function.value(rule_node.rule_node, r_name)
@@ -124,7 +124,7 @@ module Neo4j::Mapping
124
124
  end
125
125
 
126
126
  def inherit_rules_from(clazz)
127
- Neo4j::Mapping::Rule.inherit(clazz, self)
127
+ RuleEventListener.inherit(clazz, self)
128
128
  end
129
129
 
130
130
  # This is typically used for RSpecs to clean up rule nodes created by the #rule method.
@@ -133,7 +133,7 @@ module Neo4j::Mapping
133
133
  singelton = class << self;
134
134
  self;
135
135
  end
136
- rule_node = Neo4j::Mapping::Rule.rule_node_for(self)
136
+ rule_node = RuleEventListener.rule_node_for(self)
137
137
 
138
138
  rule_node.rule_names.each {|rule_name| singelton.send(:remove_method, rule_name)}
139
139
  rule_node.rules.clear
@@ -145,7 +145,7 @@ module Neo4j::Mapping
145
145
  # Can also be called from an migration.
146
146
  #
147
147
  def trigger_rules(node, *changes)
148
- Neo4j::Mapping::Rule.trigger_rules(node, *changes)
148
+ RuleEventListener.trigger_rules(node, *changes)
149
149
  end
150
150
 
151
151
  # Returns a proc that will call add method on the given function
@@ -167,7 +167,7 @@ module Neo4j::Mapping
167
167
  # Returns a proc that calls the given method on the given function.
168
168
  def function_for(method, rule_name, function_name_or_class, function_id = '_classname')
169
169
  function_name = function_name_or_class.is_a?(Symbol)? function_name_or_class : function_name_or_class.function_name
170
- rule_node = Neo4j::Mapping::Rule.rule_node_for(self)
170
+ rule_node = RuleEventListener.rule_node_for(self)
171
171
  rule = rule_node.find_rule(rule_name)
172
172
  rule_node_raw = rule_node.rule_node
173
173
 
@@ -179,6 +179,6 @@ module Neo4j::Mapping
179
179
  end
180
180
  end
181
181
 
182
- Neo4j.unstarted_db.event_handler.add(Neo4j::Mapping::Rule) unless Neo4j.read_only?
182
+ Neo4j.unstarted_db.event_handler.add(RuleEventListener) unless Neo4j.read_only?
183
183
  end
184
184
  end