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.
- data/CONTRIBUTORS +1 -0
- data/lib/neo4j.rb +38 -72
- data/lib/neo4j/{algo.rb → algo/algo.rb} +5 -1
- data/lib/neo4j/batch/batch.rb +2 -0
- data/lib/neo4j/batch/indexer.rb +108 -0
- data/lib/neo4j/batch/inserter.rb +168 -0
- data/lib/neo4j/database.rb +13 -8
- data/lib/neo4j/{mapping/class_methods/list.rb → has_list/class_methods.rb} +2 -4
- data/lib/neo4j/has_list/has_list.rb +3 -0
- data/lib/neo4j/{mapping/has_list.rb → has_list/mapping.rb} +2 -2
- data/lib/neo4j/{mapping/class_methods/relationship.rb → has_n/class_methods.rb} +42 -12
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +216 -0
- data/lib/neo4j/has_n/has_n.rb +3 -0
- data/lib/neo4j/{mapping/has_n.rb → has_n/mapping.rb} +16 -7
- data/lib/neo4j/index/index.rb +5 -0
- data/lib/neo4j/index/indexer.rb +27 -22
- data/lib/neo4j/index/lucene_query.rb +3 -1
- data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-1.3.M01.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.3-1.3.M01.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-1.3.M01.jar +0 -0
- data/lib/neo4j/jars/ha/{neo4j-ha-0.6-SNAPSHOT.jar → neo4j-ha-0.6-1.3.M01.jar} +0 -0
- data/lib/neo4j/jars/ha/neo4j-management-1.3-1.3.M01.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-shell-1.3-1.3.M01.jar +0 -0
- data/lib/neo4j/migrations/class_methods.rb +102 -0
- data/lib/neo4j/migrations/extensions.rb +10 -9
- data/lib/neo4j/migrations/lazy_node_mixin.rb +50 -0
- data/lib/neo4j/migrations/migration.rb +84 -81
- data/lib/neo4j/migrations/migrations.rb +6 -100
- data/lib/neo4j/migrations/node_mixin.rb +80 -0
- data/lib/neo4j/migrations/ref_node_wrapper.rb +32 -0
- data/lib/neo4j/neo4j.rb +11 -0
- data/lib/neo4j/node.rb +55 -25
- data/lib/neo4j/{mapping/class_methods/init_node.rb → node_mixin/class_methods.rb} +3 -3
- data/lib/neo4j/{mapping → node_mixin}/node_mixin.rb +35 -18
- data/lib/neo4j/{mapping/class_methods/property.rb → property/class_methods.rb} +5 -4
- data/lib/neo4j/{property.rb → property/property.rb} +2 -0
- data/lib/neo4j/rails/finders.rb +21 -7
- data/lib/neo4j/rails/rails.rb +19 -0
- data/lib/neo4j/rails/timestamps.rb +1 -1
- data/lib/neo4j/relationship.rb +7 -0
- data/lib/neo4j/{mapping/class_methods/init_rel.rb → relationship_mixin/class_methods.rb} +4 -4
- data/lib/neo4j/{mapping → relationship_mixin}/relationship_mixin.rb +23 -5
- data/lib/neo4j/rels/rels.rb +85 -0
- data/lib/neo4j/rels/traverser.rb +102 -0
- data/lib/neo4j/{mapping/class_methods/rule.rb → rule/class_methods.rb} +11 -11
- data/lib/neo4j/rule/functions/count.rb +37 -0
- data/lib/neo4j/rule/functions/function.rb +74 -0
- data/lib/neo4j/rule/functions/functions.rb +3 -0
- data/lib/neo4j/rule/functions/sum.rb +29 -0
- data/lib/neo4j/rule/rule.rb +5 -0
- data/lib/neo4j/rule/rule_event_listener.rb +162 -0
- data/lib/neo4j/rule/rule_node.rb +182 -0
- data/lib/neo4j/to_java.rb +0 -14
- data/lib/neo4j/traversal/filter_predicate.rb +25 -0
- data/lib/neo4j/traversal/prune_evaluator.rb +14 -0
- data/lib/neo4j/traversal/rel_expander.rb +31 -0
- data/lib/neo4j/traversal/traversal.rb +90 -0
- data/lib/neo4j/traversal/traverser.rb +173 -0
- data/lib/neo4j/{type_converters.rb → type_converters/type_converters.rb} +0 -0
- data/lib/neo4j/version.rb +1 -1
- data/lib/test.rb~ +2 -0
- data/neo4j.gemspec +11 -10
- metadata +48 -37
- data/lib/neo4j/functions/count.rb +0 -33
- data/lib/neo4j/functions/function.rb +0 -72
- data/lib/neo4j/functions/sum.rb +0 -27
- data/lib/neo4j/jars/core/neo4j-graph-algo-0.8-SNAPSHOT.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-index-1.3-SNAPSHOT.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-kernel-1.3-SNAPSHOT.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-lucene-index-0.5-SNAPSHOT.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-management-1.3-SNAPSHOT.jar +0 -0
- data/lib/neo4j/jars/ha/neo4j-shell-1.3-SNAPSHOT.jar +0 -0
- data/lib/neo4j/mapping/decl_relationship_dsl.rb +0 -214
- data/lib/neo4j/mapping/rule.rb +0 -158
- data/lib/neo4j/mapping/rule_node.rb +0 -176
- data/lib/neo4j/migrations.rb +0 -12
- data/lib/neo4j/migrations/global_migration.rb +0 -29
- data/lib/neo4j/migrations/lazy_migration_mixin.rb +0 -47
- data/lib/neo4j/migrations/migration_mixin.rb +0 -78
- data/lib/neo4j/node_mixin.rb +0 -4
- data/lib/neo4j/node_relationship.rb +0 -161
- data/lib/neo4j/node_traverser.rb +0 -224
- data/lib/neo4j/relationship_mixin.rb +0 -4
- data/lib/neo4j/relationship_traverser.rb +0 -92
data/lib/neo4j/index/index.rb
CHANGED
data/lib/neo4j/index/indexer.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
module Neo4j
|
2
2
|
module Index
|
3
|
-
class Indexer
|
4
|
-
attr_reader :indexer_for, :field_types, :via_relationships
|
3
|
+
class Indexer
|
4
|
+
attr_reader :indexer_for, :field_types, :via_relationships, :entity_type, :parent_indexers, :via_relationships
|
5
5
|
|
6
6
|
def initialize(clazz, type) #:nodoc:
|
7
7
|
# part of the unique name of the index
|
8
8
|
@indexer_for = clazz
|
9
9
|
|
10
10
|
# do we want to index nodes or relationships ?
|
11
|
-
@
|
11
|
+
@entity_type = type
|
12
12
|
|
13
13
|
@indexes = {} # key = type, value = java neo4j index
|
14
14
|
@field_types = {} # key = field, value = type (e.g. :exact or :fulltext)
|
@@ -83,9 +83,9 @@ module Neo4j
|
|
83
83
|
rel_dsl = @indexer_for._decl_rels[conf[:via]]
|
84
84
|
raise "No relationship defined for '#{conf[:via]}'. Check class '#{@indexer_for}': index :#{field}, via=>:#{conf[:via]} <-- error. Define it with a has_one or has_n" unless rel_dsl
|
85
85
|
raise "Only incoming relationship are possible to define index on. Check class '#{@indexer_for}': index :#{field}, via=>:#{conf[:via]}" unless rel_dsl.incoming?
|
86
|
-
via_indexer
|
86
|
+
via_indexer = rel_dsl.target_class._indexer
|
87
87
|
|
88
|
-
field
|
88
|
+
field = field.to_s
|
89
89
|
@via_relationships[field] = rel_dsl
|
90
90
|
conf.delete :via # avoid endless recursion
|
91
91
|
via_indexer.index(field, conf)
|
@@ -128,7 +128,7 @@ module Neo4j
|
|
128
128
|
start_node = relationship._start_node
|
129
129
|
|
130
130
|
# find the indexer to use
|
131
|
-
indexer
|
131
|
+
indexer = dsl.target_class._indexer
|
132
132
|
|
133
133
|
# is the relationship created or deleted ?
|
134
134
|
if is_created
|
@@ -141,7 +141,7 @@ module Neo4j
|
|
141
141
|
|
142
142
|
def update_index_on(node, field, old_val, new_val) #:nodoc:
|
143
143
|
if @via_relationships.include?(field)
|
144
|
-
dsl
|
144
|
+
dsl = @via_relationships[field]
|
145
145
|
target_class = dsl.target_class
|
146
146
|
|
147
147
|
dsl._all_relationships(node).each do |rel|
|
@@ -182,22 +182,25 @@ module Neo4j
|
|
182
182
|
# the lucene index in sync. See #index
|
183
183
|
#
|
184
184
|
def add_index(entity, field, value)
|
185
|
-
|
185
|
+
return false unless @field_types.has_key?(field)
|
186
|
+
value = indexed_value_for(field, value)
|
187
|
+
index = index_for_field(field.to_s)
|
188
|
+
index.add(entity, field, value)
|
189
|
+
@parent_indexers.each { |i| i.add_index(entity, field, value) }
|
190
|
+
end
|
186
191
|
|
192
|
+
def indexed_value_for(field, value)
|
187
193
|
# we might need to know what type the properties are when indexing and querying
|
188
194
|
@decl_props ||= @indexer_for.respond_to?(:_decl_props) && @indexer_for._decl_props
|
189
195
|
|
190
|
-
type
|
191
|
-
|
192
|
-
value = if String != type
|
193
|
-
org.neo4j.index.impl.lucene.ValueContext.new(value).indexNumeric
|
194
|
-
else
|
195
|
-
org.neo4j.index.impl.lucene.ValueContext.new(value)
|
196
|
-
end
|
197
|
-
end
|
196
|
+
type = @decl_props && @decl_props[field.to_sym] && @decl_props[field.to_sym][:type]
|
197
|
+
return value unless type
|
198
198
|
|
199
|
-
|
200
|
-
|
199
|
+
if String != type
|
200
|
+
org.neo4j.index.impl.lucene.ValueContext.new(value).indexNumeric
|
201
|
+
else
|
202
|
+
org.neo4j.index.impl.lucene.ValueContext.new(value)
|
203
|
+
end
|
201
204
|
end
|
202
205
|
|
203
206
|
# Removes an index on the given entity
|
@@ -236,7 +239,7 @@ module Neo4j
|
|
236
239
|
# we might need to know what type the properties are when indexing and querying
|
237
240
|
@decl_props ||= @indexer_for.respond_to?(:_decl_props) && @indexer_for._decl_props
|
238
241
|
|
239
|
-
index
|
242
|
+
index = index_for_type(params[:type] || :exact)
|
240
243
|
if query.is_a?(Hash) && (query.include?(:conditions) || query.include?(:sort))
|
241
244
|
params.merge! query.except(:conditions)
|
242
245
|
query.delete(:sort)
|
@@ -285,7 +288,7 @@ module Neo4j
|
|
285
288
|
end
|
286
289
|
|
287
290
|
def index_for_field(field) #:nodoc:
|
288
|
-
type
|
291
|
+
type = @field_types[field]
|
289
292
|
@indexes[type] ||= create_index_with(type)
|
290
293
|
end
|
291
294
|
|
@@ -300,15 +303,17 @@ module Neo4j
|
|
300
303
|
end
|
301
304
|
|
302
305
|
def create_index_with(type) #:nodoc:
|
303
|
-
db=Neo4j.started_db
|
306
|
+
db = Neo4j.started_db
|
304
307
|
index_config = lucene_config(type)
|
305
|
-
if @
|
308
|
+
if @entity_type == :node
|
306
309
|
db.lucene.for_nodes("#{@indexer_for}-#{type}", index_config)
|
307
310
|
else
|
308
311
|
db.lucene.for_relationships("#{@indexer_for}-#{type}", index_config)
|
309
312
|
end
|
310
313
|
end
|
311
314
|
|
315
|
+
|
316
|
+
|
312
317
|
end
|
313
318
|
|
314
319
|
end
|
@@ -88,6 +88,7 @@ module Neo4j
|
|
88
88
|
# This must be done according to the Neo4j Java Documentation:
|
89
89
|
def close
|
90
90
|
@hits.close if @hits
|
91
|
+
@hits = nil
|
91
92
|
end
|
92
93
|
|
93
94
|
# True if there is no search hits.
|
@@ -110,7 +111,8 @@ module Neo4j
|
|
110
111
|
end
|
111
112
|
|
112
113
|
def hits #:nodoc:
|
113
|
-
|
114
|
+
close
|
115
|
+
@hits = perform_query
|
114
116
|
end
|
115
117
|
|
116
118
|
# Performs a range query
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Migrations
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
# Sets the the version we request to migrate to
|
6
|
+
# If not set will migrate to the highest possible migration
|
7
|
+
def migrate_to=(version)
|
8
|
+
@migrate_to = version
|
9
|
+
end
|
10
|
+
|
11
|
+
def migrate_to
|
12
|
+
@migrate_to
|
13
|
+
end
|
14
|
+
|
15
|
+
def latest_migration
|
16
|
+
migrations.keys.sort.reverse[0]
|
17
|
+
end
|
18
|
+
|
19
|
+
# contains all the migrations defined with the #migration DSL method
|
20
|
+
def migrations
|
21
|
+
@migrations ||= {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specifies a migration to be performed.
|
25
|
+
# Updates the migrate_to variable so that it will migrate to the latest migration.
|
26
|
+
#
|
27
|
+
# === Example
|
28
|
+
#
|
29
|
+
# In the following example the up and down method will be evaluated in the context of a Person node.
|
30
|
+
#
|
31
|
+
# Person.migration 1, :my_first_migration do
|
32
|
+
# up { ... }
|
33
|
+
# down { ... }
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# See the Neo4j::Migrations::Migration which the DSL is evaluated in.
|
37
|
+
#
|
38
|
+
def migration(version, name, &block)
|
39
|
+
migration = Migration.new(version, name)
|
40
|
+
migration.instance_eval(&block)
|
41
|
+
migrations[version] = migration
|
42
|
+
self.migrate_to = latest_migration
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def _migrate!(context, meta_node, version=nil) #:nodoc:
|
47
|
+
# set the version we want to migrate to if provided
|
48
|
+
self.migrate_to = version if version
|
49
|
+
|
50
|
+
# requested to migrate to a version ?
|
51
|
+
return if self.migrate_to.nil?
|
52
|
+
|
53
|
+
# which version are we on now ?
|
54
|
+
current_version = meta_node[:_db_version] || 0
|
55
|
+
|
56
|
+
# do we need to migrate ?
|
57
|
+
return if current_version == self.migrate_to
|
58
|
+
|
59
|
+
# ok, so we are running some migrations
|
60
|
+
if Neo4j::Config['migration_thread']
|
61
|
+
Thread.new { _upgrade_or_downgrade(current_version, context, meta_node) }
|
62
|
+
else
|
63
|
+
_upgrade_or_downgrade(current_version, context, meta_node)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def _upgrade_or_downgrade(current_version, context, meta_node) #:nodoc:
|
68
|
+
if (current_version < self.migrate_to)
|
69
|
+
upgrade((current_version+1).upto(self.migrate_to).collect { |ver| migrations[ver] }, context, meta_node)
|
70
|
+
else
|
71
|
+
downgrade(current_version.downto(self.migrate_to+1).collect { |ver| migrations[ver] }, context, meta_node)
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Running the up method on the given migrations.
|
78
|
+
#
|
79
|
+
# === Parameters
|
80
|
+
# migrations :: an enumerable of Migration objects
|
81
|
+
def upgrade(migrations, context, meta_node)
|
82
|
+
migrations.each do |m|
|
83
|
+
Neo4j.logger.info "Running upgrade: #{m}"
|
84
|
+
m.execute_up(context, meta_node)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Running the down method on the given migrations.
|
89
|
+
#
|
90
|
+
# === Parameters
|
91
|
+
# migrations:: an enumerable of Migration objects
|
92
|
+
def downgrade(migrations, context, meta_node)
|
93
|
+
migrations.each do |m|
|
94
|
+
Neo4j.logger.info "Running downgrade: #{m}"
|
95
|
+
m.execute_down(context, meta_node)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -9,16 +9,17 @@ module Neo4j
|
|
9
9
|
# The version is stored on the reference node, with property 'db_version'
|
10
10
|
# (It Delegates to the Reference Node)
|
11
11
|
#
|
12
|
-
#
|
13
|
-
# Neo4j::
|
12
|
+
# ==== See Also
|
13
|
+
# Neo4j::Migrations::RefNodeWrapper#db_version
|
14
14
|
#
|
15
15
|
# :singleton-method: db_version
|
16
16
|
|
17
17
|
##
|
18
18
|
# Force Neo4j.rb to perform migrations
|
19
19
|
#
|
20
|
-
#
|
21
|
-
#
|
20
|
+
# ==== See Also
|
21
|
+
#
|
22
|
+
# Neo4j::Migrations::RefNodeWrapper#migrate!
|
22
23
|
#
|
23
24
|
# :singleton-method: migrate!
|
24
25
|
|
@@ -37,21 +38,21 @@ module Neo4j
|
|
37
38
|
# end
|
38
39
|
# end
|
39
40
|
#
|
40
|
-
#
|
41
|
-
# Neo4j::
|
41
|
+
# ==== See Also
|
42
|
+
# Neo4j::Migrations::ClassMethods#migration
|
42
43
|
#
|
43
44
|
# :singleton-method: migration
|
44
45
|
|
45
46
|
##
|
46
47
|
# Returns all migrations that has been defined.
|
47
48
|
#
|
48
|
-
#
|
49
|
-
# Neo4j::
|
49
|
+
# ==== See Also
|
50
|
+
# Neo4j::Migrations::ClassMethods#migrations
|
50
51
|
#
|
51
52
|
# :singleton-method: migrations
|
52
53
|
|
53
54
|
|
54
|
-
def_delegators :'Neo4j::
|
55
|
+
def_delegators :'Neo4j::Migrations::RefNodeWrapper', :db_version, :migrate!, :migrations, :migration
|
55
56
|
|
56
57
|
end
|
57
58
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Neo4j
|
2
|
+
|
3
|
+
module Migrations
|
4
|
+
|
5
|
+
# Overrides the init_on_load method so that it will check if any migration is needed.
|
6
|
+
# The init_on_create method is also overridden so that it sets the version to the latest migration number
|
7
|
+
# when a new node is created.
|
8
|
+
#
|
9
|
+
# Migration will take place if needed when the node is loaded.
|
10
|
+
#
|
11
|
+
module LazyNodeMixin
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
extend Neo4j::Migrations::ClassMethods
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
# Remote all migration and set migrate_to = nil
|
20
|
+
# Does not change the version of nodes.
|
21
|
+
def reset_migrations!
|
22
|
+
@migrations = nil
|
23
|
+
@migrate_to = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def migrate!
|
28
|
+
self.class._migrate!(self._java_node, self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def init_on_create(*)
|
32
|
+
super
|
33
|
+
# set the db version to the current
|
34
|
+
self[:_db_version] = self.class.migrate_to
|
35
|
+
end
|
36
|
+
|
37
|
+
def init_on_load(*) # :nodoc:
|
38
|
+
super
|
39
|
+
migrate!
|
40
|
+
# this if for Neo4j::Rails::Model which keeps the properties in this variable
|
41
|
+
@properties.clear if instance_variable_defined? :@properties
|
42
|
+
end
|
43
|
+
|
44
|
+
def db_version
|
45
|
+
self[:_db_version]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -1,109 +1,112 @@
|
|
1
1
|
module Neo4j
|
2
2
|
|
3
|
-
|
4
|
-
# This class is also responsible for running the migrations.
|
5
|
-
class Migration
|
6
|
-
attr_reader :up_block, :down_block, :up_migrator, :down_migrator, :version, :name
|
7
|
-
|
8
|
-
def initialize(version, name)
|
9
|
-
@auto_transaction = true
|
10
|
-
@version = version
|
11
|
-
@name = name
|
12
|
-
end
|
3
|
+
module Migrations
|
13
4
|
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
end
|
5
|
+
# This is the context in which the Migrations DSL are evaluated in.
|
6
|
+
# This class is also responsible for running the migrations.
|
7
|
+
class Migration
|
8
|
+
attr_reader :up_block, :down_block, :up_migrator, :down_migrator, :version, :name
|
19
9
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
def initialize(version, name)
|
11
|
+
@auto_transaction = true
|
12
|
+
@version = version
|
13
|
+
@name = name
|
14
|
+
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
# Specifies a code block which is run when the migration is upgraded.
|
17
|
+
#
|
18
|
+
def up(&block)
|
19
|
+
@up_block = block
|
20
|
+
end
|
30
21
|
|
22
|
+
# Specifies a code block which is run when the migration is upgraded.
|
23
|
+
#
|
24
|
+
def down(&block)
|
25
|
+
@down_block = block
|
26
|
+
end
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# Specifies if transaction should automatically be created (default)
|
29
|
+
def auto_transaction(run_with_auto_tx)
|
30
|
+
@auto_transaction = run_with_auto_tx
|
31
|
+
end
|
36
32
|
|
37
|
-
# Specifies which fields indexed should be removed
|
38
|
-
def rm_index(*fields)
|
39
|
-
@rm_indexed_field = fields
|
40
|
-
end
|
41
33
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
34
|
+
# Specifies which fields should be indexed
|
35
|
+
def add_index(*fields)
|
36
|
+
@add_indexed_field = fields
|
37
|
+
end
|
38
|
+
|
39
|
+
# Specifies which fields indexed should be removed
|
40
|
+
def rm_index(*fields)
|
41
|
+
@rm_indexed_field = fields
|
42
|
+
end
|
43
|
+
|
44
|
+
# Runs the up migration. If successful it will set the property
|
45
|
+
# ':_db_version' on the given context.
|
46
|
+
#
|
47
|
+
# === Parameters
|
48
|
+
# context:: the context on which the block is evaluated in
|
49
|
+
# meta_node:: the node on which to set the 'db_version' property
|
50
|
+
#
|
51
|
+
def execute_up(context, meta_node)
|
52
|
+
|
53
|
+
if @auto_transaction
|
54
|
+
Neo4j::Transaction.run do
|
55
|
+
context.instance_eval &@up_block if @up_block
|
56
|
+
add_index_on(context, @add_indexed_field) if @add_indexed_field
|
57
|
+
rm_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
58
|
+
meta_node._java_node[:_db_version] = version # use the raw java node since Neo4j::Rails::Mode wraps it
|
59
|
+
end
|
60
|
+
else
|
53
61
|
context.instance_eval &@up_block if @up_block
|
54
62
|
add_index_on(context, @add_indexed_field) if @add_indexed_field
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
context.instance_eval &@up_block if @up_block
|
60
|
-
add_index_on(context, @add_indexed_field) if @add_indexed_field
|
61
|
-
Neo4j::Transaction.run do
|
62
|
-
rm_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
63
|
-
meta_node._java_node[:_db_version] = version # use the raw java node since Neo4j::Rails::Mode wraps it
|
63
|
+
Neo4j::Transaction.run do
|
64
|
+
rm_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
65
|
+
meta_node._java_node[:_db_version] = version # use the raw java node since Neo4j::Rails::Mode wraps it
|
66
|
+
end
|
64
67
|
end
|
65
68
|
end
|
66
|
-
end
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
# Same as #execute_up but executes the down_block instead
|
71
|
+
def execute_down(context, meta_node)
|
72
|
+
if @auto_transaction
|
73
|
+
Neo4j::Transaction.run do
|
74
|
+
context.instance_eval &@down_block if @down_block
|
75
|
+
add_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
76
|
+
rm_index_on(context, @add_indexed_field) if @add_indexed_field
|
77
|
+
meta_node._java_node[:_db_version] = version - 1
|
78
|
+
end
|
79
|
+
else
|
72
80
|
context.instance_eval &@down_block if @down_block
|
73
81
|
add_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
context.instance_eval &@down_block if @down_block
|
79
|
-
add_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
80
|
-
Neo4j::Transaction.run do
|
81
|
-
rm_index_on(context, @add_indexed_field) if @add_indexed_field
|
82
|
-
meta_node._java_node[:_db_version] = version - 1
|
82
|
+
Neo4j::Transaction.run do
|
83
|
+
rm_index_on(context, @add_indexed_field) if @add_indexed_field
|
84
|
+
meta_node._java_node[:_db_version] = version - 1
|
85
|
+
end
|
83
86
|
end
|
84
87
|
end
|
85
|
-
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
def add_index_on(context, fields) #:nodoc:
|
90
|
+
context.all.each do |node|
|
91
|
+
fields.each do |field|
|
92
|
+
node.add_index(field)
|
93
|
+
end
|
91
94
|
end
|
92
95
|
end
|
93
|
-
end
|
94
96
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
def rm_index_on(context, fields) #:nodoc:
|
98
|
+
context.all.each do |node|
|
99
|
+
fields.each do |field|
|
100
|
+
node.rm_index(field)
|
101
|
+
end
|
99
102
|
end
|
100
103
|
end
|
101
|
-
end
|
102
104
|
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
+
def to_s
|
107
|
+
"Migration version: #{version}, name: #{name}"
|
108
|
+
end
|
106
109
|
end
|
107
|
-
end
|
108
110
|
|
109
|
-
end
|
111
|
+
end
|
112
|
+
end
|