neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +12 -0
- data/Gemfile +0 -4
- data/README.rdoc +106 -62
- data/lib/neo4j.rb +7 -33
- data/lib/neo4j/performance.rb +43 -0
- data/lib/neo4j/rails/accept_id.rb +19 -18
- data/lib/neo4j/rails/attributes.rb +366 -120
- data/lib/neo4j/rails/finders.rb +41 -15
- data/lib/neo4j/rails/has_n.rb +203 -0
- data/lib/neo4j/rails/identity.rb +25 -0
- data/lib/neo4j/rails/model.rb +65 -242
- data/lib/neo4j/rails/nested_attributes.rb +108 -0
- data/lib/neo4j/rails/node_persistance.rb +56 -0
- data/lib/neo4j/rails/observer.rb +0 -2
- data/lib/neo4j/rails/persistence.rb +32 -154
- data/lib/neo4j/rails/rack_middleware.rb +26 -2
- data/lib/neo4j/rails/rails.rb +9 -6
- data/lib/neo4j/rails/railtie.rb +1 -2
- data/lib/neo4j/rails/relationship.rb +18 -125
- data/lib/neo4j/rails/relationship_persistence.rb +107 -0
- data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
- data/lib/neo4j/rails/relationships/relationships.rb +187 -59
- data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
- data/lib/neo4j/rails/relationships/storage.rb +19 -17
- data/lib/neo4j/rails/timestamps.rb +53 -51
- data/lib/neo4j/rails/transaction.rb +9 -1
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
- data/lib/neo4j/rails/versioning/versioning.rb +2 -2
- data/lib/neo4j/version.rb +1 -1
- data/lib/orm_adapter/adapters/neo4j.rb +47 -46
- data/neo4j.gemspec +1 -1
- metadata +10 -69
- data/lib/neo4j/algo/algo.rb +0 -294
- data/lib/neo4j/batch/batch.rb +0 -4
- data/lib/neo4j/batch/indexer.rb +0 -109
- data/lib/neo4j/batch/inserter.rb +0 -179
- data/lib/neo4j/batch/rule_inserter.rb +0 -24
- data/lib/neo4j/batch/rule_node.rb +0 -72
- data/lib/neo4j/config.rb +0 -177
- data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
- data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
- data/lib/neo4j/database.rb +0 -158
- data/lib/neo4j/equal.rb +0 -21
- data/lib/neo4j/event_handler.rb +0 -263
- data/lib/neo4j/has_list/class_methods.rb +0 -11
- data/lib/neo4j/has_list/has_list.rb +0 -3
- data/lib/neo4j/has_list/mapping.rb +0 -133
- data/lib/neo4j/has_n/class_methods.rb +0 -119
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
- data/lib/neo4j/has_n/has_n.rb +0 -3
- data/lib/neo4j/has_n/mapping.rb +0 -98
- data/lib/neo4j/identity_map.rb +0 -140
- data/lib/neo4j/index/class_methods.rb +0 -108
- data/lib/neo4j/index/index.rb +0 -39
- data/lib/neo4j/index/indexer.rb +0 -341
- data/lib/neo4j/index/indexer_registry.rb +0 -68
- data/lib/neo4j/index/lucene_query.rb +0 -256
- data/lib/neo4j/load.rb +0 -25
- data/lib/neo4j/migrations/class_methods.rb +0 -110
- data/lib/neo4j/migrations/extensions.rb +0 -58
- data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
- data/lib/neo4j/migrations/migration.rb +0 -112
- data/lib/neo4j/migrations/migrations.rb +0 -6
- data/lib/neo4j/migrations/node_mixin.rb +0 -80
- data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
- data/lib/neo4j/model.rb +0 -4
- data/lib/neo4j/neo4j.rb +0 -216
- data/lib/neo4j/node.rb +0 -270
- data/lib/neo4j/node_mixin/class_methods.rb +0 -51
- data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
- data/lib/neo4j/paginated.rb +0 -23
- data/lib/neo4j/property/class_methods.rb +0 -79
- data/lib/neo4j/property/property.rb +0 -111
- data/lib/neo4j/rails/mapping/property.rb +0 -183
- data/lib/neo4j/rails/rel_persistence.rb +0 -237
- data/lib/neo4j/relationship.rb +0 -239
- data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
- data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
- data/lib/neo4j/relationship_set.rb +0 -58
- data/lib/neo4j/rels/rels.rb +0 -110
- data/lib/neo4j/rels/traverser.rb +0 -102
- data/lib/neo4j/rule/class_methods.rb +0 -201
- data/lib/neo4j/rule/event_listener.rb +0 -66
- data/lib/neo4j/rule/functions/count.rb +0 -43
- data/lib/neo4j/rule/functions/function.rb +0 -74
- data/lib/neo4j/rule/functions/functions.rb +0 -3
- data/lib/neo4j/rule/functions/sum.rb +0 -29
- data/lib/neo4j/rule/rule.rb +0 -150
- data/lib/neo4j/rule/rule_node.rb +0 -217
- data/lib/neo4j/to_java.rb +0 -31
- data/lib/neo4j/transaction.rb +0 -73
- data/lib/neo4j/traversal/filter_predicate.rb +0 -25
- data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
- data/lib/neo4j/traversal/rel_expander.rb +0 -31
- data/lib/neo4j/traversal/traversal.rb +0 -141
- data/lib/neo4j/traversal/traverser.rb +0 -284
- 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
|