neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/CHANGELOG +12 -0
  2. data/Gemfile +0 -4
  3. data/README.rdoc +106 -62
  4. data/lib/neo4j.rb +7 -33
  5. data/lib/neo4j/performance.rb +43 -0
  6. data/lib/neo4j/rails/accept_id.rb +19 -18
  7. data/lib/neo4j/rails/attributes.rb +366 -120
  8. data/lib/neo4j/rails/finders.rb +41 -15
  9. data/lib/neo4j/rails/has_n.rb +203 -0
  10. data/lib/neo4j/rails/identity.rb +25 -0
  11. data/lib/neo4j/rails/model.rb +65 -242
  12. data/lib/neo4j/rails/nested_attributes.rb +108 -0
  13. data/lib/neo4j/rails/node_persistance.rb +56 -0
  14. data/lib/neo4j/rails/observer.rb +0 -2
  15. data/lib/neo4j/rails/persistence.rb +32 -154
  16. data/lib/neo4j/rails/rack_middleware.rb +26 -2
  17. data/lib/neo4j/rails/rails.rb +9 -6
  18. data/lib/neo4j/rails/railtie.rb +1 -2
  19. data/lib/neo4j/rails/relationship.rb +18 -125
  20. data/lib/neo4j/rails/relationship_persistence.rb +107 -0
  21. data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
  22. data/lib/neo4j/rails/relationships/relationships.rb +187 -59
  23. data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
  24. data/lib/neo4j/rails/relationships/storage.rb +19 -17
  25. data/lib/neo4j/rails/timestamps.rb +53 -51
  26. data/lib/neo4j/rails/transaction.rb +9 -1
  27. data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
  28. data/lib/neo4j/rails/versioning/versioning.rb +2 -2
  29. data/lib/neo4j/version.rb +1 -1
  30. data/lib/orm_adapter/adapters/neo4j.rb +47 -46
  31. data/neo4j.gemspec +1 -1
  32. metadata +10 -69
  33. data/lib/neo4j/algo/algo.rb +0 -294
  34. data/lib/neo4j/batch/batch.rb +0 -4
  35. data/lib/neo4j/batch/indexer.rb +0 -109
  36. data/lib/neo4j/batch/inserter.rb +0 -179
  37. data/lib/neo4j/batch/rule_inserter.rb +0 -24
  38. data/lib/neo4j/batch/rule_node.rb +0 -72
  39. data/lib/neo4j/config.rb +0 -177
  40. data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
  41. data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
  42. data/lib/neo4j/database.rb +0 -158
  43. data/lib/neo4j/equal.rb +0 -21
  44. data/lib/neo4j/event_handler.rb +0 -263
  45. data/lib/neo4j/has_list/class_methods.rb +0 -11
  46. data/lib/neo4j/has_list/has_list.rb +0 -3
  47. data/lib/neo4j/has_list/mapping.rb +0 -133
  48. data/lib/neo4j/has_n/class_methods.rb +0 -119
  49. data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
  50. data/lib/neo4j/has_n/has_n.rb +0 -3
  51. data/lib/neo4j/has_n/mapping.rb +0 -98
  52. data/lib/neo4j/identity_map.rb +0 -140
  53. data/lib/neo4j/index/class_methods.rb +0 -108
  54. data/lib/neo4j/index/index.rb +0 -39
  55. data/lib/neo4j/index/indexer.rb +0 -341
  56. data/lib/neo4j/index/indexer_registry.rb +0 -68
  57. data/lib/neo4j/index/lucene_query.rb +0 -256
  58. data/lib/neo4j/load.rb +0 -25
  59. data/lib/neo4j/migrations/class_methods.rb +0 -110
  60. data/lib/neo4j/migrations/extensions.rb +0 -58
  61. data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
  62. data/lib/neo4j/migrations/migration.rb +0 -112
  63. data/lib/neo4j/migrations/migrations.rb +0 -6
  64. data/lib/neo4j/migrations/node_mixin.rb +0 -80
  65. data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
  66. data/lib/neo4j/model.rb +0 -4
  67. data/lib/neo4j/neo4j.rb +0 -216
  68. data/lib/neo4j/node.rb +0 -270
  69. data/lib/neo4j/node_mixin/class_methods.rb +0 -51
  70. data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
  71. data/lib/neo4j/paginated.rb +0 -23
  72. data/lib/neo4j/property/class_methods.rb +0 -79
  73. data/lib/neo4j/property/property.rb +0 -111
  74. data/lib/neo4j/rails/mapping/property.rb +0 -183
  75. data/lib/neo4j/rails/rel_persistence.rb +0 -237
  76. data/lib/neo4j/relationship.rb +0 -239
  77. data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
  78. data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
  79. data/lib/neo4j/relationship_set.rb +0 -58
  80. data/lib/neo4j/rels/rels.rb +0 -110
  81. data/lib/neo4j/rels/traverser.rb +0 -102
  82. data/lib/neo4j/rule/class_methods.rb +0 -201
  83. data/lib/neo4j/rule/event_listener.rb +0 -66
  84. data/lib/neo4j/rule/functions/count.rb +0 -43
  85. data/lib/neo4j/rule/functions/function.rb +0 -74
  86. data/lib/neo4j/rule/functions/functions.rb +0 -3
  87. data/lib/neo4j/rule/functions/sum.rb +0 -29
  88. data/lib/neo4j/rule/rule.rb +0 -150
  89. data/lib/neo4j/rule/rule_node.rb +0 -217
  90. data/lib/neo4j/to_java.rb +0 -31
  91. data/lib/neo4j/transaction.rb +0 -73
  92. data/lib/neo4j/traversal/filter_predicate.rb +0 -25
  93. data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
  94. data/lib/neo4j/traversal/rel_expander.rb +0 -31
  95. data/lib/neo4j/traversal/traversal.rb +0 -141
  96. data/lib/neo4j/traversal/traverser.rb +0 -284
  97. data/lib/neo4j/type_converters/type_converters.rb +0 -288
@@ -1,288 +0,0 @@
1
- module Neo4j
2
-
3
- # Responsible for converting values from and to Java Neo4j and Lucene.
4
- # You can implement your own converter by implementing the method <tt>convert?</tt>
5
- # <tt>to_java</tt> and <tt>to_ruby</tt> in this module.
6
- #
7
- # There are currently three default converters that are triggered when a Time, Date or a DateTime is read or written
8
- # if there is a type declared for the property.
9
- #
10
- # ==== Example
11
- #
12
- # Example of writing your own marshalling converter:
13
- #
14
- # class Foo
15
- # include Neo4j::NodeMixin
16
- # property :thing, :type => MyType
17
- # end
18
- #
19
- # module Neo4j::TypeConverters
20
- # class MyTypeConverter
21
- # class << self
22
- # def convert?(type)
23
- # type == MyType
24
- # end
25
- #
26
- # def to_java(val)
27
- # "silly:#{val}"
28
- # end
29
- #
30
- # def to_ruby(val)
31
- # val.sub(/silly:/, '')
32
- # end
33
- # end
34
- # end
35
- # end
36
- #
37
- module TypeConverters
38
-
39
- # The default converter to use if there isn't a specific converter for the type
40
- class DefaultConverter
41
- class << self
42
-
43
- def to_java(value)
44
- value
45
- end
46
-
47
- def to_ruby(value)
48
- value
49
- end
50
- end
51
- end
52
-
53
-
54
- class BooleanConverter
55
- class << self
56
-
57
- def convert?(class_or_symbol)
58
- :boolean == class_or_symbol
59
- end
60
-
61
- def to_java(value)
62
- return nil if value.nil?
63
- !!value && value != '0'
64
- end
65
-
66
- def to_ruby(value)
67
- return nil if value.nil?
68
- !!value && value != '0'
69
- end
70
- end
71
- end
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
-
113
-
114
- class FixnumConverter
115
- class << self
116
-
117
- def convert?(class_or_symbol)
118
- Fixnum == class_or_symbol || :fixnum == class_or_symbol || :numeric == class_or_symbol
119
- end
120
-
121
- def to_java(value)
122
- return nil if value.nil?
123
- value.to_i
124
- end
125
-
126
- def to_ruby(value)
127
- return nil if value.nil?
128
- value.to_i
129
- end
130
- end
131
- end
132
-
133
- class FloatConverter
134
- class << self
135
-
136
- def convert?(clazz_or_symbol)
137
- Float == clazz_or_symbol || :float == clazz_or_symbol
138
- end
139
-
140
- def to_java(value)
141
- return nil if value.nil?
142
- value.to_f
143
- end
144
-
145
- def to_ruby(value)
146
- return nil if value.nil?
147
- value.to_f
148
- end
149
- end
150
- end
151
-
152
- # Converts Date objects to Java long types. Must be timezone UTC.
153
- class DateConverter
154
- class << self
155
-
156
- def convert?(clazz_or_symbol)
157
- Date == clazz_or_symbol || :date == clazz_or_symbol
158
- end
159
-
160
- def to_java(value)
161
- return nil if value.nil?
162
- Time.utc(value.year, value.month, value.day).to_i
163
- end
164
-
165
- def to_ruby(value)
166
- return nil if value.nil?
167
- Time.at(value).utc.to_date
168
- end
169
- end
170
- end
171
-
172
- # Converts DateTime objects to and from Java long types. Must be timezone UTC.
173
- class DateTimeConverter
174
- class << self
175
-
176
- def convert?(clazz_or_symbol)
177
- DateTime == clazz_or_symbol || :datetime == clazz_or_symbol
178
- end
179
-
180
- # Converts the given DateTime (UTC) value to an Fixnum.
181
- # Only utc times are supported !
182
- def to_java(value)
183
- return nil if value.nil?
184
- if value.class == Date
185
- Time.utc(value.year, value.month, value.day, 0, 0, 0).to_i
186
- else
187
- Time.utc(value.year, value.month, value.day, value.hour, value.min, value.sec).to_i
188
- end
189
- end
190
-
191
- def to_ruby(value)
192
- return nil if value.nil?
193
- t = Time.at(value).utc
194
- DateTime.civil(t.year, t.month, t.day, t.hour, t.min, t.sec)
195
- end
196
- end
197
- end
198
-
199
- class TimeConverter
200
- class << self
201
-
202
- def convert?(clazz_or_symbol)
203
- Time == clazz_or_symbol || :time == clazz_or_symbol
204
- end
205
-
206
- # Converts the given DateTime (UTC) value to an Fixnum.
207
- # Only utc times are supported !
208
- def to_java(value)
209
- return nil if value.nil?
210
- if value.class == Date
211
- Time.utc(value.year, value.month, value.day, 0, 0, 0).to_i
212
- else
213
- value.utc.to_i
214
- end
215
- end
216
-
217
- def to_ruby(value)
218
- return nil if value.nil?
219
- Time.at(value).utc
220
- end
221
- end
222
- end
223
-
224
- class << self
225
-
226
- # Mostly for testing purpose, You can use this method in order to
227
- # add a converter while the neo4j has already started.
228
- def converters=(converters)
229
- @converters = converters
230
- end
231
-
232
- # Always returns a converter that handles to_ruby or to_java
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
237
- @converters ||= begin
238
- Neo4j::TypeConverters.constants.find_all do |c|
239
- Neo4j::TypeConverters.const_get(c).respond_to?(:convert?)
240
- end.map do |c|
241
- Neo4j::TypeConverters.const_get(c)
242
- end
243
- end
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
247
- end
248
-
249
- # Converts the given value to a Java type by using the registered converters.
250
- # It just looks at the class of the given value unless an attribute name is given.
251
- # It will convert it if there is a converter registered (in Neo4j::Config) for this value.
252
- def convert(value, attribute = nil, klass = nil, enforce_type = true)
253
- converter(attribute_type(value, attribute, klass), enforce_type).to_java(value)
254
- end
255
-
256
- # Converts the given property (key, value) to Java if there is a type converter for given type.
257
- # The type must also be declared using Neo4j::NodeMixin#property property_name, :type => clazz
258
- # If no Converter is defined for this value then it simply returns the given value.
259
- def to_java(clazz, key, value)
260
- type = clazz._decl_props[key.to_sym] && clazz._decl_props[key.to_sym][:type]
261
- converter(type).to_java(value)
262
- end
263
-
264
- # Converts the given property (key, value) to Ruby if there is a type converter for given type.
265
- # If no Converter is defined for this value then it simply returns the given value.
266
- def to_ruby(clazz, key, value)
267
- type = clazz._decl_props[key.to_sym] && clazz._decl_props[key.to_sym][:type]
268
- converter(type).to_ruby(value)
269
- end
270
-
271
- private
272
- def attribute_type(value, attribute = nil, klass = nil)
273
- type = (attribute && klass) ? attribute_type_from_attribute_and_klass(value, attribute, klass) : nil
274
- type || attribute_type_from_value(value)
275
- end
276
-
277
- def attribute_type_from_attribute_and_klass(value, attribute, klass)
278
- if klass.respond_to?(:_decl_props)
279
- (klass._decl_props.has_key?(attribute) && klass._decl_props[attribute][:type]) ? klass._decl_props[attribute][:type] : nil
280
- end
281
- end
282
-
283
- def attribute_type_from_value(value)
284
- value.class
285
- end
286
- end
287
- end
288
- end