neo4j 1.0.0.beta.9 → 1.0.0.beta.10
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/README.rdoc +5 -1971
- data/lib/neo4j/mapping/class_methods/relationship.rb +2 -2
- data/lib/neo4j/mapping/decl_relationship_dsl.rb +6 -1
- data/lib/neo4j/mapping/has_n.rb +17 -1
- data/lib/neo4j/node_traverser.rb +14 -1
- data/lib/neo4j/rails/model.rb +127 -31
- data/lib/neo4j/rails/tx_methods.rb +11 -0
- data/lib/neo4j/rails/value.rb +44 -1
- data/lib/neo4j/version.rb +1 -1
- data/lib/neo4j.rb +1 -0
- metadata +4 -59
- data/lib/neo4j.old/batch_inserter.rb +0 -144
- data/lib/neo4j.old/config.rb +0 -138
- data/lib/neo4j.old/event_handler.rb +0 -73
- data/lib/neo4j.old/extensions/activemodel.rb +0 -158
- data/lib/neo4j.old/extensions/aggregate/aggregate_enum.rb +0 -40
- data/lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb +0 -69
- data/lib/neo4j.old/extensions/aggregate/node_aggregate.rb +0 -8
- data/lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb +0 -331
- data/lib/neo4j.old/extensions/aggregate/node_aggregator.rb +0 -216
- data/lib/neo4j.old/extensions/aggregate/node_group.rb +0 -43
- data/lib/neo4j.old/extensions/aggregate/prop_group.rb +0 -30
- data/lib/neo4j.old/extensions/aggregate/property_enum.rb +0 -24
- data/lib/neo4j.old/extensions/aggregate/props_aggregate.rb +0 -8
- data/lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb +0 -31
- data/lib/neo4j.old/extensions/aggregate/props_aggregator.rb +0 -80
- data/lib/neo4j.old/extensions/aggregate.rb +0 -12
- data/lib/neo4j.old/extensions/find_path.rb +0 -117
- data/lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb +0 -133
- data/lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar +0 -0
- data/lib/neo4j.old/extensions/graph_algo.rb +0 -1
- data/lib/neo4j.old/extensions/reindexer.rb +0 -104
- data/lib/neo4j.old/extensions/rest/rest.rb +0 -336
- data/lib/neo4j.old/extensions/rest/rest_mixin.rb +0 -193
- data/lib/neo4j.old/extensions/rest/server.rb +0 -50
- data/lib/neo4j.old/extensions/rest/stubs.rb +0 -141
- data/lib/neo4j.old/extensions/rest.rb +0 -21
- data/lib/neo4j.old/extensions/rest_master.rb +0 -34
- data/lib/neo4j.old/extensions/rest_slave.rb +0 -31
- data/lib/neo4j.old/extensions/tx_tracker.rb +0 -392
- data/lib/neo4j.old/indexer.rb +0 -187
- data/lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
- data/lib/neo4j.old/jars/neo4j-kernel-1.0.jar +0 -0
- data/lib/neo4j.old/jars.rb +0 -6
- data/lib/neo4j.old/mixins/java_list_mixin.rb +0 -139
- data/lib/neo4j.old/mixins/java_node_mixin.rb +0 -205
- data/lib/neo4j.old/mixins/java_property_mixin.rb +0 -169
- data/lib/neo4j.old/mixins/java_relationship_mixin.rb +0 -60
- data/lib/neo4j.old/mixins/migration_mixin.rb +0 -157
- data/lib/neo4j.old/mixins/node_mixin.rb +0 -249
- data/lib/neo4j.old/mixins/property_class_methods.rb +0 -265
- data/lib/neo4j.old/mixins/rel_class_methods.rb +0 -167
- data/lib/neo4j.old/mixins/relationship_mixin.rb +0 -103
- data/lib/neo4j.old/neo.rb +0 -247
- data/lib/neo4j.old/node.rb +0 -49
- data/lib/neo4j.old/reference_node.rb +0 -15
- data/lib/neo4j.old/relationship.rb +0 -85
- data/lib/neo4j.old/relationships/decl_relationship_dsl.rb +0 -164
- data/lib/neo4j.old/relationships/has_list.rb +0 -101
- data/lib/neo4j.old/relationships/has_n.rb +0 -129
- data/lib/neo4j.old/relationships/node_traverser.rb +0 -138
- data/lib/neo4j.old/relationships/relationship_dsl.rb +0 -149
- data/lib/neo4j.old/relationships/traversal_position.rb +0 -50
- data/lib/neo4j.old/relationships/wrappers.rb +0 -51
- data/lib/neo4j.old/search_result.rb +0 -72
- data/lib/neo4j.old/transaction.rb +0 -254
- data/lib/neo4j.old/version.rb +0 -3
@@ -1,141 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module Rest
|
3
|
-
# A stub class that talk to a neo4j rest server.
|
4
|
-
# It behaves like a Neo4j::Node, but instead of actually performing operation
|
5
|
-
# it talks to the server over HTTP/JSON
|
6
|
-
#
|
7
|
-
module RestStubMixin
|
8
|
-
attr_accessor :json
|
9
|
-
|
10
|
-
def initialize(uri_or_json_hash)
|
11
|
-
if uri_or_json_hash.kind_of?(Hash)
|
12
|
-
@json = uri_or_json_hash
|
13
|
-
else
|
14
|
-
@json = RestHttpMethods.get_request(uri_or_json_hash)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def [](key)
|
19
|
-
@json['properties'][key.to_s]
|
20
|
-
end
|
21
|
-
|
22
|
-
def relationships
|
23
|
-
RelationshipTraverserStub.new(@json['rels'])
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
def relationship?(type, dir=:outgoing)
|
28
|
-
rels.rel?(type, dir)
|
29
|
-
end
|
30
|
-
|
31
|
-
def props
|
32
|
-
@json['properties']
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module RestHttpMethods # :nodoc:
|
37
|
-
class << self
|
38
|
-
def get_request(resource, args = {})
|
39
|
-
body = _get_request(resource, args)
|
40
|
-
JSON.parse(body)
|
41
|
-
end
|
42
|
-
|
43
|
-
def _get_request(resource, args)
|
44
|
-
_request(resource, :get, args)
|
45
|
-
end
|
46
|
-
|
47
|
-
def _request(resource, method = :get, args = {})
|
48
|
-
url = URI.parse(resource)
|
49
|
-
host = url.host
|
50
|
-
host.sub!(/0\.0\.0\.0/, 'localhost')
|
51
|
-
|
52
|
-
#if args
|
53
|
-
# url.query = args.map { |k, v| "%s=%s" % [URI.encode(k), URI.encode(v)] }.join("&")
|
54
|
-
#end
|
55
|
-
|
56
|
-
req =
|
57
|
-
case method
|
58
|
-
when :put
|
59
|
-
Net::HTTP::Put.new(url.path)
|
60
|
-
when :get
|
61
|
-
Net::HTTP::Get.new(url.path)
|
62
|
-
when :post
|
63
|
-
Net::HTTP::Post.new(url.path)
|
64
|
-
end
|
65
|
-
|
66
|
-
http = Net::HTTP.new(host, url.port)
|
67
|
-
res = http.start() { |conn| conn.request(req) }
|
68
|
-
res.body
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
class RelationshipStub # :nodoc:
|
75
|
-
include RestStubMixin
|
76
|
-
|
77
|
-
def start_node
|
78
|
-
uri = @json['start_node']['uri']
|
79
|
-
NodeStub.new(uri)
|
80
|
-
end
|
81
|
-
|
82
|
-
def end_node
|
83
|
-
uri = @json['end_node']['uri']
|
84
|
-
NodeStub.new(uri)
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class RelationshipTraverserStub
|
90
|
-
include Enumerable
|
91
|
-
|
92
|
-
def initialize(json)
|
93
|
-
@json = json
|
94
|
-
end
|
95
|
-
|
96
|
-
def outgoing(rel_type)
|
97
|
-
@rel_type = rel_type
|
98
|
-
self
|
99
|
-
end
|
100
|
-
|
101
|
-
def relationship?(type, dir=:outgoing)
|
102
|
-
!@json[type.to_s].nil?
|
103
|
-
end
|
104
|
-
|
105
|
-
def nodes
|
106
|
-
@return_nodes = true
|
107
|
-
self
|
108
|
-
end
|
109
|
-
|
110
|
-
def first
|
111
|
-
each do |x|
|
112
|
-
return x if !block_given? || yield(x)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def each
|
117
|
-
keys =
|
118
|
-
if @rel_type.nil?
|
119
|
-
@json.keys # take all keys
|
120
|
-
else
|
121
|
-
[@rel_type.to_s]
|
122
|
-
end
|
123
|
-
|
124
|
-
keys.each do |rel_type|
|
125
|
-
next unless rel?(rel_type)
|
126
|
-
if @return_nodes
|
127
|
-
@json[rel_type.to_s].each {|uri| yield RelationshipStub.new(uri).end_node}
|
128
|
-
else
|
129
|
-
@json[rel_type.to_s].each {|uri| yield RelationshipStub.new(uri)}
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
# A class that simply includes the RestStubMixin
|
136
|
-
class NodeStub
|
137
|
-
include RestStubMixin
|
138
|
-
end
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'thread'
|
3
|
-
require 'json'
|
4
|
-
require 'sinatra/base'
|
5
|
-
|
6
|
-
require 'neo4j/extensions/rest/rest'
|
7
|
-
require 'neo4j/extensions/rest/rest_mixin'
|
8
|
-
require 'neo4j/extensions/rest/stubs'
|
9
|
-
require 'neo4j/extensions/rest/server'
|
10
|
-
|
11
|
-
# Provides Neo4j::NodeMixin::ClassMethods#all
|
12
|
-
require 'neo4j/extensions/reindexer'
|
13
|
-
|
14
|
-
|
15
|
-
module Neo4j
|
16
|
-
# Make the ReferenceNode available as a REST resource
|
17
|
-
# not possible to do much without that node being exposed ...
|
18
|
-
class ReferenceNode
|
19
|
-
include Neo4j::RestMixin
|
20
|
-
end
|
21
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'neo4j'
|
2
|
-
require 'neo4j/extensions/rest'
|
3
|
-
require 'neo4j/extensions/tx_tracker'
|
4
|
-
|
5
|
-
module Neo4j
|
6
|
-
class TxNode
|
7
|
-
include Neo4j::RestMixin
|
8
|
-
end
|
9
|
-
|
10
|
-
class TxRelationshipCreatedNode
|
11
|
-
include Neo4j::RestMixin
|
12
|
-
end
|
13
|
-
|
14
|
-
class TxNodeCreated
|
15
|
-
include Neo4j::RestMixin
|
16
|
-
end
|
17
|
-
|
18
|
-
class TxNodeList
|
19
|
-
include Neo4j::RestMixin
|
20
|
-
end
|
21
|
-
|
22
|
-
class ReferenceNode
|
23
|
-
include Neo4j::RestMixin
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
# FOR TESTING PURPOSE ----
|
28
|
-
|
29
|
-
class Node
|
30
|
-
include Neo4j::RestMixin # for making it easier to test
|
31
|
-
end
|
32
|
-
|
33
|
-
Neo4j::Config[:storage_path] = 'tmp/master'
|
34
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'thread'
|
3
|
-
require 'json'
|
4
|
-
#require 'sinatra/base'
|
5
|
-
require 'neo4j/extensions/rest/stubs'
|
6
|
-
|
7
|
-
|
8
|
-
require 'neo4j/extensions/tx_tracker'
|
9
|
-
|
10
|
-
module Neo4j
|
11
|
-
|
12
|
-
module Rest #:nodoc: all
|
13
|
-
def self.base_uri
|
14
|
-
Neo4j::Config[:master_neo4j_uri]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
# TODO This is not working yet !
|
20
|
-
def self.replicate
|
21
|
-
neo_master = Neo4j::Rest::NodeStub.new(Config[:master_neo4j_uri] + "/neo")
|
22
|
-
neo_ref_node = Neo4j::Rest::NodeStub.new(neo_master[:ref_node])
|
23
|
-
tx_node_list = neo_ref_node.rels.outgoing(:tx_node_list).nodes.first
|
24
|
-
tx_node = tx_node_list.rels.outgoing(:tx_nodes).nodes.first
|
25
|
-
Neo4j::Transaction.run do
|
26
|
-
Neo4j::TxNodeList.instance.redo_tx(tx_node)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
Config[:master_neo4j_uri] = 'http://localhost:9123'
|
31
|
-
end
|
@@ -1,392 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
|
4
|
-
# The relationship class between TxNodes
|
5
|
-
class TxNodeRelationship
|
6
|
-
include Neo4j::RelationshipMixin
|
7
|
-
end
|
8
|
-
|
9
|
-
# This nodes listen for all events like node nodes created/deleted or
|
10
|
-
# if a property/relationship has changed. When a event is triggered it
|
11
|
-
#
|
12
|
-
class TxNodeList
|
13
|
-
include Neo4j::NodeMixin
|
14
|
-
|
15
|
-
has_list(:tx_nodes).relationship(TxNodeRelationship)
|
16
|
-
|
17
|
-
def on_node_created(node)
|
18
|
-
tx = TxNodeCreated.new
|
19
|
-
uuid = Neo4j.create_uuid
|
20
|
-
node[:uuid] = uuid # TODO should use a better UUID
|
21
|
-
tx[:tracked_neo_id] = node.neo_id
|
22
|
-
tx[:tracked_classname] = node.class.to_s unless node.kind_of?(org.neo4j.graphdb.Node)
|
23
|
-
tx[:created] = true
|
24
|
-
tx[:uuid] = uuid
|
25
|
-
tx_nodes << tx
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_node_deleted(node)
|
29
|
-
tx = TxNode.new
|
30
|
-
tx[:uuid] = node[:uuid]
|
31
|
-
tx[:deleted] = true
|
32
|
-
tx[:tracked_classname] = node.class.to_s unless node.kind_of?(org.neo4j.graphdb.Node)
|
33
|
-
tx_nodes << tx
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def on_tx_finished(tx)
|
38
|
-
return if self.tx_nodes.empty? # nothing yet commited
|
39
|
-
last_commited_node = self.tx_nodes.first
|
40
|
-
last_commited_node[:tx_finished] = true
|
41
|
-
end
|
42
|
-
|
43
|
-
def on_property_changed(node, key, old_value, new_value)
|
44
|
-
return if "uuid" == key.to_s # do not track uuid
|
45
|
-
tx = TxNode.new
|
46
|
-
tx[:uuid] = node[:uuid]
|
47
|
-
tx[:property_changed] = true
|
48
|
-
tx[:tracked_neo_id] = node.neo_id
|
49
|
-
tx[:key] = key
|
50
|
-
tx[:old_value] = old_value
|
51
|
-
tx[:new_value] = new_value
|
52
|
-
tx_nodes << tx
|
53
|
-
end
|
54
|
-
|
55
|
-
def on_relationship_created(relationship)
|
56
|
-
# check so that it was no this method that caused this event
|
57
|
-
return if tx_nodes.relationship_type.to_sym == relationship.relationship_type.to_sym
|
58
|
-
tx = TxRelationshipCreatedNode.new
|
59
|
-
uuid = Neo4j.create_uuid
|
60
|
-
tx[:uuid] = uuid
|
61
|
-
tx[:relationship_created] = true
|
62
|
-
tx[:tracked_neo_id] = relationship.neo_id
|
63
|
-
tx[:start_node_uuid] = relationship.start_node[:uuid]
|
64
|
-
tx[:end_node_uuid] = relationship.end_node[:uuid]
|
65
|
-
tx[:relationship_type] = relationship.relationship_type.to_s
|
66
|
-
relationship[:uuid] = uuid
|
67
|
-
tx_nodes << tx
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
def on_relationship_deleted(relationship)
|
72
|
-
# check so that it was no this method that caused this event
|
73
|
-
return if tx_nodes.relationship_type.to_sym == relationship.relationship_type.to_sym
|
74
|
-
tx = TxNode.new
|
75
|
-
uuid = Neo4j.create_uuid
|
76
|
-
tx[:uuid] = uuid
|
77
|
-
tx[:relationship_deleted] = true
|
78
|
-
tx[:tracked_neo_id] = relationship.neo_id
|
79
|
-
tx[:relationship_type] = relationship.relationship_type.to_s
|
80
|
-
tx[:start_node_uuid] = relationship.start_node[:uuid]
|
81
|
-
tx[:end_node_uuid] = relationship.end_node[:uuid]
|
82
|
-
tx_nodes << tx
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
# Return a list of TxNodes that belongs to the same transaction
|
87
|
-
# Will always include the specified from_tx_node
|
88
|
-
# It will follow the linked list of tx nodes until it founds a new transaction.
|
89
|
-
def tx_nodes_belonging_to_same_tx(from_tx_node)
|
90
|
-
nodes_in_same_tx = []
|
91
|
-
nodes_in_same_tx << from_tx_node # always include the first one
|
92
|
-
|
93
|
-
# include all other nodes until we find a new transaction marker
|
94
|
-
curr_node = from_tx_node
|
95
|
-
|
96
|
-
while (true) do
|
97
|
-
curr_node = curr_node.list(:tx_nodes).next
|
98
|
-
break if curr_node.nil?
|
99
|
-
break if curr_node[:tx_finished]
|
100
|
-
nodes_in_same_tx << curr_node
|
101
|
-
end
|
102
|
-
nodes_in_same_tx
|
103
|
-
end
|
104
|
-
|
105
|
-
def create_node(tx_node)
|
106
|
-
classname = tx_node[:tracked_classname]
|
107
|
-
node = if classname.nil?
|
108
|
-
Neo4j::Node.new
|
109
|
-
else
|
110
|
-
clazz = classname.split("::").inject(Kernel) do |container, name|
|
111
|
-
container.const_get(name.to_s)
|
112
|
-
end
|
113
|
-
clazz.new
|
114
|
-
end
|
115
|
-
|
116
|
-
uuid = tx_node[:uuid]
|
117
|
-
tx_node = find_tx(node.neo_id, :tracked_neo_id)
|
118
|
-
#tx_node = find_tx_node(uuid)
|
119
|
-
tx_node[:uuid] = uuid
|
120
|
-
tx_node[:tracked_neo_id] = node.neo_id
|
121
|
-
node[:uuid] = uuid
|
122
|
-
end
|
123
|
-
|
124
|
-
def delete_node(tx_node)
|
125
|
-
uuid = tx_node[:uuid]
|
126
|
-
node = load_node_with_uuid(uuid)
|
127
|
-
node.del
|
128
|
-
end
|
129
|
-
|
130
|
-
def undo_property_changed(tx_node)
|
131
|
-
uuid = tx_node[:uuid]
|
132
|
-
node = load_node_with_uuid(uuid)
|
133
|
-
key = tx_node[:key]
|
134
|
-
old_value = tx_node[:old_value]
|
135
|
-
node[key] = old_value
|
136
|
-
end
|
137
|
-
|
138
|
-
def redo_property_changed(tx_node)
|
139
|
-
uuid = tx_node[:uuid]
|
140
|
-
node = load_node_with_uuid(uuid)
|
141
|
-
key = tx_node[:key]
|
142
|
-
new_value = tx_node[:new_value]
|
143
|
-
node[key] = new_value
|
144
|
-
end
|
145
|
-
|
146
|
-
def create_relationship(tx_node)
|
147
|
-
# recreate deleted relationship
|
148
|
-
type = tx_node[:relationship_type]
|
149
|
-
start_node_uuid = tx_node[:start_node_uuid]
|
150
|
-
end_node_uuid = tx_node[:end_node_uuid]
|
151
|
-
start_node = load_node_with_uuid(start_node_uuid)
|
152
|
-
end_node = load_node_with_uuid(end_node_uuid)
|
153
|
-
start_node.rels.outgoing(type) << end_node
|
154
|
-
end
|
155
|
-
|
156
|
-
def delete_relationship(tx_node)
|
157
|
-
relationship = load_relationship_with_uuid(tx_node[:uuid])
|
158
|
-
relationship.del
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
def redo_tx(from_tx_node)
|
163
|
-
nodes_to_redo = tx_nodes_belonging_to_same_tx(from_tx_node)
|
164
|
-
nodes_to_redo.reverse_each do |curr_node|
|
165
|
-
if (curr_node[:created])
|
166
|
-
create_node(curr_node)
|
167
|
-
elsif (curr_node[:deleted])
|
168
|
-
delete_node(curr_node)
|
169
|
-
elsif (curr_node[:property_changed])
|
170
|
-
redo_property_changed(curr_node)
|
171
|
-
elsif (curr_node[:relationship_created])
|
172
|
-
create_relationship(curr_node)
|
173
|
-
elsif (curr_node[:relationship_deleted])
|
174
|
-
delete_relationship(curr_node)
|
175
|
-
else
|
176
|
-
raise "unknow tx #{curr_node.props.inspect}"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def undo_tx(from_tx_node = tx_nodes.first)
|
182
|
-
return if from_tx_node.nil?
|
183
|
-
|
184
|
-
nodes_to_undo = tx_nodes_belonging_to_same_tx(from_tx_node)
|
185
|
-
|
186
|
-
nodes_to_undo.each do |curr_node|
|
187
|
-
if (curr_node[:created])
|
188
|
-
delete_node(curr_node)
|
189
|
-
elsif (curr_node[:deleted])
|
190
|
-
create_node(curr_node)
|
191
|
-
elsif (curr_node[:property_changed])
|
192
|
-
undo_property_changed(curr_node)
|
193
|
-
elsif (curr_node[:relationship_created])
|
194
|
-
delete_relationship(curr_node)
|
195
|
-
elsif (curr_node[:relationship_deleted])
|
196
|
-
create_relationship(curr_node)
|
197
|
-
else
|
198
|
-
raise "unknow tx #{curr_node.props.inspect}"
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
|
204
|
-
# Load a neo4j node given a cluster wide UUID (instead of id)
|
205
|
-
# :api: public
|
206
|
-
def load_node_with_uuid(uuid)
|
207
|
-
txnode = find_tx_node(uuid)
|
208
|
-
return if txnode.nil?
|
209
|
-
# does this node exist ?
|
210
|
-
id = txnode[:tracked_neo_id]
|
211
|
-
Neo4j.load_node(id)
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
# Load a neo4j relatinship given a cluster wide UUID (instead of id)
|
216
|
-
# :api: public
|
217
|
-
def load_relationship_with_uuid(uuid)
|
218
|
-
txnode = find_tx_relationship(uuid)
|
219
|
-
return if txnode.nil?
|
220
|
-
# does this node exist ?
|
221
|
-
id = txnode[:tracked_neo_id]
|
222
|
-
Neo4j.load_rel(id)
|
223
|
-
end
|
224
|
-
|
225
|
-
|
226
|
-
# :api: private
|
227
|
-
def find_tx_node(uuid) # :nodoc:
|
228
|
-
# since lucene only updates the index after the transaction commits we
|
229
|
-
# first look in the current transaction
|
230
|
-
found = find_tx(uuid)
|
231
|
-
# if not found that find it with lucene
|
232
|
-
found ||= TxNodeCreated.find(:uuid => uuid).first
|
233
|
-
found
|
234
|
-
end
|
235
|
-
|
236
|
-
|
237
|
-
# :api: private
|
238
|
-
def find_tx_relationship(uuid) # :nodoc:
|
239
|
-
TxRelationshipCreatedNode.find(:uuid => uuid).first
|
240
|
-
end
|
241
|
-
|
242
|
-
|
243
|
-
# Find a TxNodeCreate node in the latest transaction with the given uuid
|
244
|
-
def find_tx(value, key = :uuid) # :nodoc:
|
245
|
-
tx_nodes.find {|node| node[:_classname] == TxNodeCreated.to_s && node[key] == value}
|
246
|
-
end
|
247
|
-
|
248
|
-
# Create a new a neo4j node given a cluster wide UUID (instead of id)
|
249
|
-
# :nodoc:
|
250
|
-
# :api: private
|
251
|
-
def create_node_with_uuid(uuid)
|
252
|
-
txnode = find_tx_node(uuid)
|
253
|
-
return if txnode.nil?
|
254
|
-
# does this node exist ?
|
255
|
-
id = txnode[:tracked_neo_id]
|
256
|
-
Neo4j.load_node(id)
|
257
|
-
end
|
258
|
-
|
259
|
-
#
|
260
|
-
# Class methods ------------------------------------------------------
|
261
|
-
#
|
262
|
-
|
263
|
-
def self.on_neo_started(neo_instance)
|
264
|
-
Neo4j::Transaction.run do
|
265
|
-
# has the tx_node_list already been created ?
|
266
|
-
unless neo_instance.ref_node.rel?(:tx_node_list)
|
267
|
-
# it does not exist - create it
|
268
|
-
neo_instance.ref_node.rels.outgoing(:tx_node_list) << TxNodeList.new
|
269
|
-
end
|
270
|
-
# cache this so we do not have to look it up always
|
271
|
-
@tx_node_list = neo_instance.ref_node.rels.outgoing(:tx_node_list).nodes.first
|
272
|
-
Neo4j.event_handler.add(@tx_node_list)
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
def self.on_neo_stopped(neo_instance)
|
277
|
-
# unregister the instance
|
278
|
-
Neo4j.event_handler.remove(@tx_node_list)
|
279
|
-
@tx_node_list = nil
|
280
|
-
end
|
281
|
-
|
282
|
-
|
283
|
-
def self.instance
|
284
|
-
Neo4j.start unless @tx_node_list
|
285
|
-
@tx_node_list
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
|
290
|
-
# Keeps the uuid of created relationship in a lucene index
|
291
|
-
class TxRelationshipCreatedNode
|
292
|
-
include Neo4j::NodeMixin
|
293
|
-
|
294
|
-
belongs_to_list(:tx_nodes).relationship(TxNodeRelationship)
|
295
|
-
|
296
|
-
property :uuid
|
297
|
-
index :uuid
|
298
|
-
|
299
|
-
def to_s
|
300
|
-
"TxRelationshipCreatedNode: " + props.inspect
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
|
305
|
-
# Keeps the uuid of created nodes in a lucene index
|
306
|
-
class TxNodeCreated
|
307
|
-
include Neo4j::NodeMixin
|
308
|
-
|
309
|
-
belongs_to_list(:tx_nodes).relationship(TxNodeRelationship)
|
310
|
-
|
311
|
-
property :uuid
|
312
|
-
index :uuid
|
313
|
-
|
314
|
-
def to_s
|
315
|
-
"TxNodeCreated: " + props.inspect
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
|
320
|
-
# Represent an events like property change
|
321
|
-
# Does not represend events for relationship and node creations
|
322
|
-
class TxNode
|
323
|
-
include Neo4j::NodeMixin
|
324
|
-
|
325
|
-
belongs_to_list(:tx_nodes).relationship(TxNodeRelationship)
|
326
|
-
|
327
|
-
def to_s
|
328
|
-
"TxNode: " + props.inspect
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
|
333
|
-
#-------------------------------------------------
|
334
|
-
# Neo4j Module Methods
|
335
|
-
#
|
336
|
-
#-------------------------------------------------
|
337
|
-
|
338
|
-
|
339
|
-
# Loads the tx tracker extension
|
340
|
-
def self.load_tx_tracker
|
341
|
-
Neo4j.event_handler.add_filter(TxNode)
|
342
|
-
Neo4j.event_handler.add_filter(TxNodeCreated)
|
343
|
-
Neo4j.event_handler.add_filter(TxRelationshipCreatedNode)
|
344
|
-
|
345
|
-
Neo4j.event_handler.add(TxNodeList)
|
346
|
-
Neo4j.event_handler.add(TxNodeRelationship)
|
347
|
-
# if neo is already run we have to let txnodelist have a chance to add it self
|
348
|
-
# TxNodeList.on_neo_started(Neo4j.instance) if Neo4j.running?
|
349
|
-
Neo4j::Transaction.run { TxNodeList.on_neo_started(Neo4j) } if Neo4j.running?
|
350
|
-
end
|
351
|
-
|
352
|
-
def self.unload_tx_tracker
|
353
|
-
Neo4j.event_handler.remove_filter(TxNode)
|
354
|
-
Neo4j.event_handler.remove_filter(TxNodeCreated)
|
355
|
-
Neo4j.event_handler.remove_filter(TxRelationshipCreatedNode)
|
356
|
-
|
357
|
-
Neo4j.event_handler.remove(TxNodeList)
|
358
|
-
Neo4j.event_handler.remove(TxNodeRelationship)
|
359
|
-
end
|
360
|
-
|
361
|
-
# Undo the last transaction
|
362
|
-
#
|
363
|
-
# :api: public
|
364
|
-
def self.undo_tx
|
365
|
-
TxNodeList.instance.undo_tx
|
366
|
-
end
|
367
|
-
|
368
|
-
|
369
|
-
# Loads a node with the given uuid
|
370
|
-
# Returns nil if not found other wise the Node.
|
371
|
-
# :api: public
|
372
|
-
def self.load_node_with_uuid(uuid)
|
373
|
-
TxNodeList.instance.load_node_with_uuid(uuid)
|
374
|
-
end
|
375
|
-
|
376
|
-
|
377
|
-
# Loads a relationship with the given uuid
|
378
|
-
# Returns nil if not found other wise the Node.
|
379
|
-
# :api: public
|
380
|
-
def self.load_relationship_with_uuid(uuid)
|
381
|
-
TxNodeList.instance.load_relationship_with_uuid(uuid)
|
382
|
-
end
|
383
|
-
|
384
|
-
# Generates a new unique uuid
|
385
|
-
def self.create_uuid
|
386
|
-
rand(100000000) # TODO a very bad UUID generator ...
|
387
|
-
end
|
388
|
-
|
389
|
-
Neo4j.load_tx_tracker
|
390
|
-
|
391
|
-
|
392
|
-
end
|