neo4j 1.2.6-java → 2.0.0.alpha.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/CHANGELOG +30 -0
  2. data/CONTRIBUTORS +1 -0
  3. data/Gemfile +16 -4
  4. data/README.rdoc +25 -3
  5. data/bin/neo4j-jars +15 -8
  6. data/bin/neo4j-shell +0 -1
  7. data/bin/neo4j-upgrade +72 -0
  8. data/config/neo4j/config.yml +5 -4
  9. data/lib/neo4j/algo/algo.rb +0 -1
  10. data/lib/neo4j/batch/inserter.rb +5 -0
  11. data/lib/neo4j/database.rb +18 -12
  12. data/lib/neo4j/event_handler.rb +76 -9
  13. data/lib/neo4j/has_list/class_methods.rb +1 -1
  14. data/lib/neo4j/has_list/mapping.rb +13 -33
  15. data/lib/neo4j/has_n/decl_relationship_dsl.rb +17 -13
  16. data/lib/neo4j/has_n/mapping.rb +6 -23
  17. data/lib/neo4j/identity_map.rb +0 -3
  18. data/lib/neo4j/index/class_methods.rb +9 -3
  19. data/lib/neo4j/index/index.rb +2 -1
  20. data/lib/neo4j/index/indexer.rb +3 -2
  21. data/lib/neo4j/index/indexer_registry.rb +1 -1
  22. data/lib/neo4j/index/lucene_query.rb +52 -33
  23. data/lib/neo4j/neo4j.rb +19 -0
  24. data/lib/neo4j/node.rb +42 -36
  25. data/lib/neo4j/node_mixin/node_mixin.rb +9 -5
  26. data/lib/neo4j/paginated.rb +23 -0
  27. data/lib/neo4j/rails/accept_id.rb +66 -0
  28. data/lib/neo4j/rails/attributes.rb +14 -9
  29. data/lib/neo4j/rails/compositions.rb +9 -1
  30. data/lib/neo4j/rails/finders.rb +5 -1
  31. data/lib/neo4j/rails/mapping/property.rb +41 -28
  32. data/lib/neo4j/rails/model.rb +2 -0
  33. data/lib/neo4j/rails/observer.rb +61 -2
  34. data/lib/neo4j/rails/persistence.rb +57 -57
  35. data/lib/neo4j/rails/rails.rb +1 -0
  36. data/lib/neo4j/rails/railtie.rb +4 -1
  37. data/lib/neo4j/rails/rel_persistence.rb +11 -12
  38. data/lib/neo4j/rails/relationship.rb +9 -4
  39. data/lib/neo4j/rails/relationships/node_dsl.rb +15 -5
  40. data/lib/neo4j/rails/relationships/relationships.rb +42 -2
  41. data/lib/neo4j/rails/relationships/rels_dsl.rb +60 -3
  42. data/lib/neo4j/rails/relationships/storage.rb +43 -5
  43. data/lib/neo4j/rails/validations/uniqueness.rb +1 -0
  44. data/lib/neo4j/rails/versioning/versioning.rb +64 -9
  45. data/lib/neo4j/relationship.rb +79 -73
  46. data/lib/neo4j/rule/event_listener.rb +7 -1
  47. data/lib/neo4j/rule/functions/count.rb +6 -0
  48. data/lib/neo4j/rule/rule.rb +20 -5
  49. data/lib/neo4j/rule/rule_node.rb +33 -20
  50. data/lib/neo4j/to_java.rb +5 -0
  51. data/lib/neo4j/traversal/traverser.rb +38 -1
  52. data/lib/neo4j/type_converters/type_converters.rb +56 -5
  53. data/lib/neo4j/version.rb +1 -1
  54. data/lib/neo4j.rb +3 -49
  55. data/neo4j.gemspec +2 -2
  56. metadata +191 -216
  57. data/bin/neo4j-shell~ +0 -108
  58. data/lib/Gemfile~ +0 -3
  59. data/lib/config2.yml~ +0 -86
  60. data/lib/neo4j/jars/core/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  61. data/lib/neo4j/jars/core/lucene-core-3.1.0.jar +0 -0
  62. data/lib/neo4j/jars/core/neo4j-backup-1.4.1.jar +0 -0
  63. data/lib/neo4j/jars/core/neo4j-graph-algo-1.4.1.jar +0 -0
  64. data/lib/neo4j/jars/core/neo4j-index-1.3-1.3.M01.jar +0 -0
  65. data/lib/neo4j/jars/core/neo4j-kernel-1.4.1.jar +0 -0
  66. data/lib/neo4j/jars/core/neo4j-lucene-index-1.4.1.jar +0 -0
  67. data/lib/neo4j/jars/ha/log4j-1.2.16.jar +0 -0
  68. data/lib/neo4j/jars/ha/neo4j-com-1.4.1.jar +0 -0
  69. data/lib/neo4j/jars/ha/neo4j-ha-1.4.1.jar +0 -0
  70. data/lib/neo4j/jars/ha/neo4j-jmx-1.4.1.jar +0 -0
  71. data/lib/neo4j/jars/ha/neo4j-management-1.4.1.jar +0 -0
  72. data/lib/neo4j/jars/ha/neo4j-shell-1.4.1.jar +0 -0
  73. data/lib/neo4j/jars/ha/netty-3.2.1.Final.jar +0 -0
  74. data/lib/neo4j/jars/ha/org.apache.servicemix.bundles.jline-0.9.94_1.jar +0 -0
  75. data/lib/neo4j/jars/ha/zookeeper-3.3.2.jar +0 -0
  76. data/lib/neo4j/paginate.rb +0 -25
  77. data/lib/perf.rb~ +0 -36
  78. data/lib/test.rb~ +0 -2
data/lib/neo4j/to_java.rb CHANGED
@@ -22,5 +22,10 @@ module Neo4j
22
22
  else raise "unknown direction '#{dir}', expects :outgoing, :incoming or :both"
23
23
  end
24
24
  end
25
+
26
+ def ensure_valid_props(hash)
27
+ hash ||= {}
28
+ Hash[ hash.each_pair.map{|k,v| [k.to_s, v]} ]
29
+ end
25
30
  end
26
31
  end
@@ -31,7 +31,6 @@ module Neo4j
31
31
  class Traverser
32
32
  include Enumerable
33
33
  include ToJava
34
- include Neo4j::Paginate
35
34
 
36
35
 
37
36
  def initialize(from, type = nil, dir=nil)
@@ -46,6 +45,44 @@ module Neo4j
46
45
  end
47
46
  end
48
47
 
48
+
49
+ # Sets traversing depth first.
50
+ #
51
+ # The <tt>pre_or_post</tt> parameter parameter can have two values: :pre or :post
52
+ # * :pre - Traversing depth first, visiting each node before visiting its child nodes (default)
53
+ # * :post - Traversing depth first, visiting each node after visiting its child nodes.
54
+ #
55
+ def depth_first(pre_or_post = :pre)
56
+ case pre_or_post
57
+ when :pre then @td = @td.order(org.neo4j.kernel.Traversal.preorderDepthFirst())
58
+ when :post then @td = @td.order(org.neo4j.kernel.Traversal.postorderDepthFirst())
59
+ else raise "Unknown type #{pre_or_post}, should be :pre or :post"
60
+ end
61
+ self
62
+ end
63
+
64
+
65
+ # Sets traversing breadth first (default).
66
+ #
67
+ # This is the default ordering if none is defined.
68
+ # The <tt>pre_or_post</tt> parameter parameter can have two values: :pre or :post
69
+ # * :pre - Traversing breadth first, visiting each node before visiting its child nodes (default)
70
+ # * :post - Traversing breadth first, visiting each node after visiting its child nodes.
71
+ #
72
+ # ==== Note
73
+ # Please note that breadth first traversals have a higher memory overhead than depth first traversals.
74
+ # BranchSelectors carries state and hence needs to be uniquely instantiated for each traversal. Therefore it is supplied to the TraversalDescription through a BranchOrderingPolicy interface, which is a factory of BranchSelector instances.
75
+ #
76
+ def breadth_first(pre_or_post = :pre)
77
+ case pre_or_post
78
+ when :pre then @td = @td.order(org.neo4j.kernel.Traversal.preorderBreadthFirst())
79
+ when :post then @td = @td.order(org.neo4j.kernel.Traversal.postorderBreadthFirst())
80
+ else raise "Unknown type #{pre_or_post}, should be :pre or :post"
81
+ end
82
+ self
83
+ end
84
+
85
+
49
86
  def eval_paths(&eval_path_block)
50
87
  @td = @td.evaluator(Evaluator.new(&eval_path_block))
51
88
  self
@@ -59,28 +59,72 @@ module Neo4j
59
59
  end
60
60
 
61
61
  def to_java(value)
62
+ return nil if value.nil?
62
63
  !!value && value != '0'
63
64
  end
64
65
 
65
66
  def to_ruby(value)
67
+ return nil if value.nil?
66
68
  !!value && value != '0'
67
69
  end
68
70
  end
69
71
  end
70
72
 
73
+ class SymbolConverter
74
+ class << self
75
+
76
+ def convert?(class_or_symbol)
77
+ :symbol == class_or_symbol || Symbol == class_or_symbol
78
+ end
79
+
80
+ def to_java(value)
81
+ return nil if value.nil?
82
+ value.to_s
83
+ end
84
+
85
+ def to_ruby(value)
86
+ return nil if value.nil?
87
+ value.to_sym
88
+ end
89
+ end
90
+ end
91
+
92
+
93
+ class StringConverter
94
+ class << self
95
+
96
+ def convert?(class_or_symbol)
97
+ [String, :string, :text].include? class_or_symbol
98
+ end
99
+
100
+ def to_java(value)
101
+ return nil if value.nil?
102
+ value.to_s
103
+ end
104
+
105
+ def to_ruby(value)
106
+ return nil if value.nil?
107
+ value.to_s
108
+ end
109
+ end
110
+ end
111
+
112
+
71
113
 
72
114
  class FixnumConverter
73
115
  class << self
74
116
 
75
117
  def convert?(class_or_symbol)
76
- Fixnum == class_or_symbol || :fixnum == class_or_symbol
118
+ Fixnum == class_or_symbol || :fixnum == class_or_symbol || :numeric == class_or_symbol
77
119
  end
78
120
 
79
121
  def to_java(value)
122
+ return nil if value.nil?
80
123
  value.to_i
81
124
  end
82
125
 
83
126
  def to_ruby(value)
127
+ return nil if value.nil?
84
128
  value.to_i
85
129
  end
86
130
  end
@@ -94,10 +138,12 @@ module Neo4j
94
138
  end
95
139
 
96
140
  def to_java(value)
141
+ return nil if value.nil?
97
142
  value.to_f
98
143
  end
99
144
 
100
145
  def to_ruby(value)
146
+ return nil if value.nil?
101
147
  value.to_f
102
148
  end
103
149
  end
@@ -184,7 +230,10 @@ module Neo4j
184
230
  end
185
231
 
186
232
  # Always returns a converter that handles to_ruby or to_java
187
- def converter(type = nil)
233
+ # if +enforce_type+ is set to false then it will raise in case of unknown type
234
+ # otherwise it will return the DevaultConverter.
235
+ def converter(type = nil, enforce_type = true)
236
+ return DefaultConverter unless type
188
237
  @converters ||= begin
189
238
  Neo4j::TypeConverters.constants.find_all do |c|
190
239
  Neo4j::TypeConverters.const_get(c).respond_to?(:convert?)
@@ -192,14 +241,16 @@ module Neo4j
192
241
  Neo4j::TypeConverters.const_get(c)
193
242
  end
194
243
  end
195
- (type && @converters.find { |c| c.convert?(type) }) || DefaultConverter
244
+ found = @converters.find {|c| c.convert?(type) }
245
+ raise "The type #{type.inspect} is unknown. Use one of #{@converters.map{|c| c.name.demodulize.sub('Converter','') }.join(", ")} or create a custom type converter." if !found && enforce_type
246
+ found or DefaultConverter
196
247
  end
197
248
 
198
249
  # Converts the given value to a Java type by using the registered converters.
199
250
  # It just looks at the class of the given value unless an attribute name is given.
200
251
  # It will convert it if there is a converter registered (in Neo4j::Config) for this value.
201
- def convert(value, attribute = nil, klass = nil)
202
- converter(attribute_type(value, attribute, klass)).to_java(value)
252
+ def convert(value, attribute = nil, klass = nil, enforce_type = true)
253
+ converter(attribute_type(value, attribute, klass), enforce_type).to_java(value)
203
254
  end
204
255
 
205
256
  # Converts the given property (key, value) to Java if there is a type converter for given type.
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.2.6"
2
+ VERSION = "2.0.0.alpha.3"
3
3
  end
data/lib/neo4j.rb CHANGED
@@ -10,56 +10,9 @@ require 'active_support/core_ext/class/inheritable_attributes'
10
10
  require 'active_support/core_ext/hash/indifferent_access'
11
11
  require 'active_model'
12
12
 
13
- require 'will_paginate/collection'
14
- require 'will_paginate/finders/base'
15
-
16
13
  # core extensions
17
14
  require 'neo4j/core_ext/class/inheritable_attributes'
18
15
 
19
- # Jars
20
-
21
- require 'neo4j/jars/core/geronimo-jta_1.1_spec-1.1.1.jar'
22
- require 'neo4j/jars/core/lucene-core-3.1.0.jar'
23
- require 'neo4j/jars/core/neo4j-lucene-index-1.4.1.jar'
24
- require 'neo4j/jars/core/neo4j-kernel-1.4.1.jar'
25
- require 'neo4j/jars/ha/neo4j-management-1.4.1.jar'
26
- require 'neo4j/jars/ha/neo4j-jmx-1.4.1.jar'
27
-
28
- module Neo4j
29
-
30
- def self.load_local_jars
31
- # This is a temporary fix since the HA does not yet work with this JAR
32
- # It will be solved in a future version of the Java Neo4j library.
33
- if Neo4j.config[:online_backup_enabled]
34
- Neo4j.load_online_backup
35
- else
36
- # backup and HA does not work with this JAR FILE
37
- require 'neo4j/jars/core/neo4j-index-1.3-1.3.M01.jar'
38
- end
39
- end
40
-
41
- def self.load_shell_jars
42
- require 'neo4j/jars/ha/neo4j-shell-1.4.1.jar'
43
- end
44
-
45
- def self.load_online_backup
46
- require 'neo4j/jars/ha/neo4j-com-1.4.1.jar'
47
- require 'neo4j/jars/core/neo4j-backup-1.4.1.jar'
48
- require 'neo4j/jars/ha/netty-3.2.1.Final.jar'
49
- Neo4j.send(:const_set, :OnlineBackup, org.neo4j.backup.OnlineBackup)
50
- end
51
-
52
- def self.load_ha_jars
53
- require 'neo4j/jars/core/neo4j-backup-1.4.1.jar'
54
- require 'neo4j/jars/ha/log4j-1.2.16.jar'
55
- require 'neo4j/jars/ha/neo4j-ha-1.4.1.jar'
56
- require 'neo4j/jars/ha/neo4j-com-1.4.1.jar'
57
- require 'neo4j/jars/ha/netty-3.2.1.Final.jar'
58
- require 'neo4j/jars/ha/org.apache.servicemix.bundles.jline-0.9.94_1.jar'
59
- # require 'neo4j/jars/ha/org.apache.servicemix.bundles.lucene-3.0.1_2.jar' # TODO IS THIS NEEDED ?
60
- require 'neo4j/jars/ha/zookeeper-3.3.2.jar'
61
- end
62
- end
63
16
 
64
17
  module Neo4j
65
18
  include Java
@@ -68,9 +21,10 @@ module Neo4j
68
21
  Enumerator = Enumerable::Enumerator unless defined? Enumerator
69
22
  end
70
23
 
24
+ require 'neo4j-community'
71
25
  require 'neo4j/version'
72
26
  require 'neo4j/neo4j'
73
- require 'neo4j/paginate'
27
+ require 'neo4j/paginated'
74
28
  require 'neo4j/node'
75
29
  require 'neo4j/relationship'
76
30
  require 'neo4j/relationship_set'
@@ -105,4 +59,4 @@ require 'neo4j/batch/batch'
105
59
 
106
60
  require 'orm_adapter/adapters/neo4j'
107
61
 
108
- require 'neo4j/identity_map'
62
+ require 'neo4j/identity_map'
data/neo4j.gemspec CHANGED
@@ -24,13 +24,13 @@ It comes included with the Apache Lucene document database.
24
24
 
25
25
  s.require_path = 'lib'
26
26
  s.files = Dir.glob("{bin,lib,config}/**/*") + %w(README.rdoc CHANGELOG CONTRIBUTORS Gemfile neo4j.gemspec)
27
- s.executables = ['neo4j-shell', 'neo4j-jars']
27
+ s.executables = ['neo4j-shell', 'neo4j-jars', 'neo4j-upgrade']
28
28
  s.has_rdoc = true
29
29
  s.extra_rdoc_files = %w( README.rdoc )
30
30
  s.rdoc_options = ["--quiet", "--title", "Neo4j.rb", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
31
31
 
32
32
  s.add_dependency('orm_adapter', ">= 0.0.3")
33
33
  s.add_dependency("activemodel", ">= 3.0.0")
34
- s.add_dependency("will_paginate", ["3.0.pre4"]) # should be ~>3.0 but it's API has changed '
35
34
  s.add_dependency("railties", ">= 3.0.0")
35
+ s.add_dependency("neo4j-community", "1.6.0.alpha.6")
36
36
  end