neo4j 1.2.6-java → 1.3.0-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 +16 -0
- data/README.rdoc +11 -0
- data/bin/neo4j-upgrade +72 -0
- data/lib/neo4j.rb +18 -19
- data/lib/neo4j/algo/algo.rb +2 -1
- data/lib/neo4j/database.rb +12 -0
- data/lib/neo4j/event_handler.rb +69 -7
- data/lib/neo4j/has_list/class_methods.rb +1 -1
- data/lib/neo4j/has_list/mapping.rb +13 -16
- data/lib/neo4j/index/class_methods.rb +9 -3
- data/lib/neo4j/index/index.rb +2 -1
- data/lib/neo4j/index/indexer.rb +3 -2
- data/lib/neo4j/index/indexer_registry.rb +1 -1
- data/lib/neo4j/jars/core/neo4j-community-1.5.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-cypher-1.5.jar +0 -0
- data/lib/neo4j/jars/core/{neo4j-graph-algo-1.4.1.jar → neo4j-graph-algo-1.5.jar} +0 -0
- data/lib/neo4j/jars/core/neo4j-graph-matching-1.5.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-jmx-1.5.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-kernel-1.5.jar +0 -0
- data/lib/neo4j/jars/core/{neo4j-lucene-index-1.4.1.jar → neo4j-lucene-index-1.5.jar} +0 -0
- data/lib/neo4j/jars/{ha/neo4j-shell-1.4.1.jar → core/neo4j-shell-1.5.jar} +0 -0
- data/lib/neo4j/jars/core/neo4j-udc-1.5.jar +0 -0
- data/lib/neo4j/jars/{ha → core}/org.apache.servicemix.bundles.jline-0.9.94_1.jar +0 -0
- data/lib/neo4j/jars/core/scala-library-2.9.0-1.jar +0 -0
- data/lib/neo4j/jars/core/server-api-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-backup-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-com-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-enterprise-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-ha-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-management-1.5.jar +0 -0
- data/lib/neo4j/jars/ha/org.apache.servicemix.bundles.netty-3.2.5.Final_1.jar +0 -0
- data/lib/neo4j/jars/ha/slf4j-api-1.6.1.jar +0 -0
- data/lib/neo4j/neo4j.rb +16 -0
- data/lib/neo4j/node_mixin/node_mixin.rb +2 -2
- data/lib/neo4j/rails/attributes.rb +9 -5
- data/lib/neo4j/rails/compositions.rb +9 -1
- data/lib/neo4j/rails/mapping/property.rb +27 -25
- data/lib/neo4j/rails/model.rb +1 -0
- data/lib/neo4j/rails/persistence.rb +56 -56
- data/lib/neo4j/rails/rel_persistence.rb +1 -1
- data/lib/neo4j/rails/relationship.rb +9 -4
- data/lib/neo4j/rails/relationships/relationships.rb +6 -2
- data/lib/neo4j/rails/relationships/rels_dsl.rb +58 -0
- data/lib/neo4j/rails/relationships/storage.rb +10 -1
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -0
- data/lib/neo4j/rails/versioning/versioning.rb +64 -9
- data/lib/neo4j/rule/event_listener.rb +7 -1
- data/lib/neo4j/rule/functions/count.rb +6 -0
- data/lib/neo4j/rule/rule.rb +20 -5
- data/lib/neo4j/rule/rule_node.rb +31 -19
- data/lib/neo4j/traversal/traverser.rb +38 -0
- data/lib/neo4j/version.rb +1 -1
- data/neo4j.gemspec +1 -1
- metadata +24 -17
- data/lib/neo4j/jars/core/neo4j-backup-1.4.1.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-index-1.3-1.3.M01.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-kernel-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-com-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-ha-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-jmx-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-management-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/netty-3.2.1.Final.jar +0 -0
data/lib/neo4j/index/index.rb
CHANGED
@@ -19,7 +19,8 @@ module Neo4j
|
|
19
19
|
# Neo4j::Index::ClassMethods::index
|
20
20
|
#
|
21
21
|
def add_index(field, value=self[field])
|
22
|
-
|
22
|
+
converted_value = Neo4j::TypeConverters.convert(value, field, self.class)
|
23
|
+
self.class.add_index(wrapped_entity, field.to_s, converted_value)
|
23
24
|
end
|
24
25
|
|
25
26
|
# Removes an index on the given property.
|
data/lib/neo4j/index/indexer.rb
CHANGED
@@ -2,6 +2,7 @@ module Neo4j
|
|
2
2
|
module Index
|
3
3
|
class Indexer
|
4
4
|
attr_reader :indexer_for, :field_types, :via_relationships, :entity_type, :parent_indexers, :via_relationships
|
5
|
+
alias_method :index_types, :field_types # public method accessible from node.index_types
|
5
6
|
|
6
7
|
def initialize(clazz, type) #:nodoc:
|
7
8
|
# part of the unique name of the index
|
@@ -155,7 +156,7 @@ module Neo4j
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def update_single_index_on(node, field, old_val, new_val) #:nodoc:
|
158
|
-
if @field_types.
|
159
|
+
if @field_types.has_key?(field)
|
159
160
|
rm_index(node, field, old_val) if old_val
|
160
161
|
add_index(node, field, new_val) if new_val
|
161
162
|
end
|
@@ -322,7 +323,7 @@ module Neo4j
|
|
322
323
|
def index_names
|
323
324
|
@index_names ||= Hash.new do |hash, index_type|
|
324
325
|
default_filename = index_prefix + @indexer_for.to_s.gsub('::', '_')
|
325
|
-
hash.fetch(index_type) {"#{default_filename}
|
326
|
+
hash.fetch(index_type) {"#{default_filename}_#{index_type}"}
|
326
327
|
end
|
327
328
|
end
|
328
329
|
|
@@ -10,7 +10,7 @@ module Neo4j
|
|
10
10
|
def create_for(this_clazz, using_other_clazz, type)
|
11
11
|
@@indexers ||= {}
|
12
12
|
index = Indexer.new(this_clazz, type)
|
13
|
-
index.inherit_fields_from(@@indexers[using_other_clazz.to_s])
|
13
|
+
index.inherit_fields_from(@@indexers[using_other_clazz.to_s]) if @@indexers[using_other_clazz.to_s]
|
14
14
|
@@indexers[this_clazz.to_s] = index
|
15
15
|
end
|
16
16
|
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/neo4j/neo4j.rb
CHANGED
@@ -71,6 +71,22 @@ module Neo4j
|
|
71
71
|
Neo4j::Config
|
72
72
|
end
|
73
73
|
|
74
|
+
# Executes a Cypher Query
|
75
|
+
# Check the neo4j http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html
|
76
|
+
# Returns an enumerable of hash values.
|
77
|
+
#
|
78
|
+
# === Usage
|
79
|
+
#
|
80
|
+
# q = Neo4j.query("START n=node({node}) RETURN n", 'node' => @node.neo_id)
|
81
|
+
# q.first['n'] #=> the @node
|
82
|
+
# q.columns.first => 'n'
|
83
|
+
#
|
84
|
+
def query(query, params = {})
|
85
|
+
engine = org.neo4j.cypher.javacompat.ExecutionEngine.new(db)
|
86
|
+
engine.execute(query, params)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
74
90
|
# Returns the logger used by neo4j.
|
75
91
|
# If not specified (with Neo4j.logger=) it will use the standard Ruby logger.
|
76
92
|
# You can change standard logger threshold by configuration :logger_level.
|
@@ -80,7 +80,7 @@ module Neo4j
|
|
80
80
|
def _java_entity
|
81
81
|
@_java_node
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
# Trigger rules.
|
85
85
|
# You don't normally need to call this method (except in Migration) since
|
86
86
|
# it will be triggered automatically by the Neo4j::Rule::Rule
|
@@ -131,7 +131,7 @@ module Neo4j
|
|
131
131
|
super
|
132
132
|
end
|
133
133
|
|
134
|
-
c.node_indexer c
|
134
|
+
c.node_indexer c unless c == Neo4j::Rails::Model
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
@@ -201,8 +201,8 @@ module Neo4j
|
|
201
201
|
# Known properties are either in the @properties, the declared
|
202
202
|
# properties or the property keys for the persisted node
|
203
203
|
def property?(name)
|
204
|
-
@properties.
|
205
|
-
self.class._decl_props.
|
204
|
+
@properties.has_key?(name) ||
|
205
|
+
self.class._decl_props.has_key?(name) ||
|
206
206
|
begin
|
207
207
|
persisted? && super
|
208
208
|
rescue org.neo4j.graphdb.NotFoundException
|
@@ -216,9 +216,13 @@ module Neo4j
|
|
216
216
|
def attribute?(name)
|
217
217
|
name[0] != ?_ && property?(name)
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def _classname
|
221
|
-
self
|
221
|
+
self.class.to_s
|
222
|
+
end
|
223
|
+
|
224
|
+
def _classname=(value)
|
225
|
+
write_local_property_without_type_conversion("_classname",value)
|
222
226
|
end
|
223
227
|
|
224
228
|
# To get ActiveModel::Dirty to work, we need to be able to call undeclared
|
@@ -248,7 +252,7 @@ module Neo4j
|
|
248
252
|
|
249
253
|
# Wrap the setter in a conversion from Ruby to Java
|
250
254
|
def write_local_property_with_type_conversion(property, value)
|
251
|
-
|
255
|
+
@properties_before_type_cast[property.to_sym]=value if self.class._decl_props.has_key? property.to_sym
|
252
256
|
write_local_property_without_type_conversion(property, Neo4j::TypeConverters.to_java(self.class, property, value))
|
253
257
|
end
|
254
258
|
end
|
@@ -206,6 +206,14 @@ module Neo4j
|
|
206
206
|
# :constructor => Proc.new { |ip| IPAddr.new(ip, Socket::AF_INET) },
|
207
207
|
# :converter => Proc.new { |ip| ip.is_a?(Integer) ? IPAddr.new(ip, Socket::AF_INET) : IPAddr.new(ip.to_s) }
|
208
208
|
#
|
209
|
+
def is_composed_property?(property)
|
210
|
+
composed_properties.contains(property)
|
211
|
+
end
|
212
|
+
|
213
|
+
def composed_properties
|
214
|
+
@composed_properties ||= java.util.HashSet.new
|
215
|
+
end
|
216
|
+
|
209
217
|
def composed_of(part_id, options = {})
|
210
218
|
options.assert_valid_keys(:class_name, :mapping, :allow_nil, :constructor, :converter)
|
211
219
|
|
@@ -216,7 +224,7 @@ module Neo4j
|
|
216
224
|
allow_nil = options[:allow_nil] || false
|
217
225
|
constructor = options[:constructor] || :new
|
218
226
|
converter = options[:converter]
|
219
|
-
|
227
|
+
composed_properties.add(name.to_sym)
|
220
228
|
reader_method(name, class_name, mapping, allow_nil, constructor)
|
221
229
|
writer_method(name, class_name, mapping, allow_nil, converter)
|
222
230
|
end
|
@@ -106,10 +106,10 @@ module Neo4j
|
|
106
106
|
|
107
107
|
# Handles options for the property
|
108
108
|
#
|
109
|
-
# Set the property type
|
110
|
-
# Set a default
|
111
|
-
# Property must be there
|
112
|
-
# Property has a length limit
|
109
|
+
# Set the property type :type => Time
|
110
|
+
# Set a default :default => "default"
|
111
|
+
# Property must be there :null => false
|
112
|
+
# Property has a length limit :limit => 128
|
113
113
|
def property(*args)
|
114
114
|
options = args.extract_options!
|
115
115
|
args.each do |property_sym|
|
@@ -132,39 +132,41 @@ module Neo4j
|
|
132
132
|
validates(property, :non_nil => true, :on => :create)
|
133
133
|
validates(property, :non_nil => true, :on => :update)
|
134
134
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
135
|
+
validates(property, :length => { :maximum => options[:limit] }) if options[:limit]
|
136
|
+
end
|
137
|
+
|
138
|
+
def define_property_methods_for(property, options)
|
139
|
+
unless method_defined?(property)
|
140
|
+
class_eval <<-RUBY, __FILE__, __LINE__
|
141
|
+
def #{property}
|
142
|
+
send(:[], "#{property}")
|
143
|
+
end
|
144
144
|
RUBY
|
145
145
|
end
|
146
146
|
|
147
147
|
unless method_defined?("#{property}=".to_sym)
|
148
148
|
class_eval <<-RUBY, __FILE__, __LINE__
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
def #{property}=(value)
|
150
|
+
send(:[]=, "#{property}", value)
|
151
|
+
end
|
152
|
+
RUBY
|
153
|
+
end
|
154
|
+
end
|
155
155
|
|
156
156
|
def define_property_before_type_cast_methods_for(property, options)
|
157
157
|
property_before_type_cast = "#{property}_before_type_cast"
|
158
158
|
class_eval <<-RUBY, __FILE__, __LINE__
|
159
|
-
|
159
|
+
def #{property_before_type_cast}=(value)
|
160
|
+
@properties_before_type_cast[:#{property}]=value
|
161
|
+
end
|
160
162
|
|
161
163
|
def #{property_before_type_cast}
|
162
|
-
|
164
|
+
@properties_before_type_cast.has_key?(:#{property}) ? @properties_before_type_cast[:#{property}] : self.#{property}
|
163
165
|
end
|
164
166
|
RUBY
|
165
167
|
end
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
170
172
|
end
|
data/lib/neo4j/rails/model.rb
CHANGED
@@ -48,6 +48,7 @@ module Neo4j
|
|
48
48
|
|
49
49
|
# Initialize a Node with a set of properties (or empty if nothing is passed)
|
50
50
|
def initialize(attributes = {})
|
51
|
+
@properties_before_type_cast=java.util.HashMap.new
|
51
52
|
reset_attributes
|
52
53
|
clear_relationships
|
53
54
|
self.attributes = attributes if attributes.is_a?(Hash)
|
@@ -1,62 +1,62 @@
|
|
1
1
|
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
module Rails
|
3
|
+
module Persistence
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
extend TxMethods
|
8
|
+
tx_methods :destroy, :create, :update, :update_nested_attributes, :delete, :update_attributes, :update_attributes!
|
9
|
+
end
|
10
|
+
|
11
|
+
# Persist the object to the database. Validations and Callbacks are included
|
12
|
+
# by default but validation can be disabled by passing :validate => false
|
13
|
+
# to #save.
|
14
14
|
def save(*)
|
15
|
-
|
15
|
+
create_or_update
|
16
16
|
end
|
17
17
|
|
18
18
|
# Persist the object to the database. Validations and Callbacks are included
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# by default but validation can be disabled by passing :validate => false
|
20
|
+
# to #save!.
|
21
|
+
#
|
22
|
+
# Raises a RecordInvalidError if there is a problem during save.
|
23
23
|
def save!(*args)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
24
|
+
unless save(*args)
|
25
|
+
raise RecordInvalidError.new(self)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Updates a single attribute and saves the record.
|
30
|
+
# This is especially useful for boolean flags on existing records. Also note that
|
31
|
+
#
|
32
|
+
# * Validation is skipped.
|
33
|
+
# * Callbacks are invoked.
|
34
|
+
# * Updates all the attributes that are dirty in this object.
|
35
|
+
#
|
36
|
+
def update_attribute(name, value)
|
37
|
+
respond_to?("#{name}=") ? send("#{name}=", value) : self[name] = value
|
38
|
+
save(:validate => false)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Removes the node from Neo4j and freezes the object.
|
42
|
+
def destroy
|
43
|
+
delete
|
44
|
+
freeze
|
45
|
+
end
|
46
|
+
|
47
|
+
# Same as #destroy but doesn't run destroy callbacks and doesn't freeze
|
48
|
+
# the object
|
49
|
+
def delete
|
50
|
+
del unless new_record?
|
51
|
+
set_deleted_properties
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns true if the object was destroyed.
|
55
|
+
def destroyed?()
|
56
56
|
@_deleted || Neo4j::Node._load(id).nil?
|
57
57
|
end
|
58
58
|
|
59
|
-
|
59
|
+
# Updates this resource with all the attributes from the passed-in Hash and requests that the record be saved.
|
60
60
|
# If saving fails because the resource is invalid then false will be returned.
|
61
61
|
def update_attributes(attributes)
|
62
62
|
self.attributes = attributes
|
@@ -95,9 +95,9 @@ module Neo4j
|
|
95
95
|
alias :new? :new_record?
|
96
96
|
|
97
97
|
# Freeze the properties hash.
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
def freeze
|
99
|
+
@properties.freeze; self
|
100
|
+
end
|
101
101
|
|
102
102
|
# Returns +true+ if the properties hash has been frozen.
|
103
103
|
def frozen?
|
@@ -162,7 +162,7 @@ module Neo4j
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def init_on_create(*)
|
165
|
-
self
|
165
|
+
self._classname = self.class.to_s
|
166
166
|
write_default_attributes
|
167
167
|
write_changed_attributes
|
168
168
|
write_changed_relationships
|
@@ -262,7 +262,7 @@ module Neo4j
|
|
262
262
|
super(@record.errors.full_messages.join(", "))
|
263
263
|
end
|
264
264
|
end
|
265
|
-
|
266
|
-
|
265
|
+
end
|
266
|
+
end
|
267
267
|
end
|
268
268
|
|
@@ -21,7 +21,8 @@ module Neo4j
|
|
21
21
|
|
22
22
|
# Initialize a Node with a set of properties (or empty if nothing is passed)
|
23
23
|
def initialize(*args)
|
24
|
-
@
|
24
|
+
@properties_before_type_cast=java.util.HashMap.new
|
25
|
+
@type = args[0].to_s
|
25
26
|
self.start_node = args[1]
|
26
27
|
self.end_node = args[2]
|
27
28
|
attributes = args[3]
|
@@ -39,11 +40,15 @@ module Neo4j
|
|
39
40
|
|
40
41
|
|
41
42
|
alias_method :get_other_node, :other_node # so it looks like the java version
|
42
|
-
|
43
|
+
|
44
|
+
def rel_type
|
45
|
+
persisted? ? _java_entity.rel_type : @type
|
46
|
+
end
|
47
|
+
|
43
48
|
def to_s
|
44
49
|
"id: #{self.object_id} start_node: #{start_node.id} end_node: #{end_node.id} type:#{@type}"
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
def id
|
48
53
|
_java_rel.nil? || neo_id.nil? ? nil : neo_id.to_s
|
49
54
|
end
|
@@ -111,7 +116,7 @@ module Neo4j
|
|
111
116
|
def _all
|
112
117
|
_indexer.find(:_classname => self)
|
113
118
|
end
|
114
|
-
|
119
|
+
|
115
120
|
def load(*ids) # TODO Copied from finders.rb
|
116
121
|
result = ids.map { |id| entity_load(id) }
|
117
122
|
if ids.length == 1
|