neo4j 1.2.6-java → 2.0.0.alpha.3-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 +30 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +16 -4
- data/README.rdoc +25 -3
- data/bin/neo4j-jars +15 -8
- data/bin/neo4j-shell +0 -1
- data/bin/neo4j-upgrade +72 -0
- data/config/neo4j/config.yml +5 -4
- data/lib/neo4j/algo/algo.rb +0 -1
- data/lib/neo4j/batch/inserter.rb +5 -0
- data/lib/neo4j/database.rb +18 -12
- data/lib/neo4j/event_handler.rb +76 -9
- data/lib/neo4j/has_list/class_methods.rb +1 -1
- data/lib/neo4j/has_list/mapping.rb +13 -33
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +17 -13
- data/lib/neo4j/has_n/mapping.rb +6 -23
- data/lib/neo4j/identity_map.rb +0 -3
- 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/index/lucene_query.rb +52 -33
- data/lib/neo4j/neo4j.rb +19 -0
- data/lib/neo4j/node.rb +42 -36
- data/lib/neo4j/node_mixin/node_mixin.rb +9 -5
- data/lib/neo4j/paginated.rb +23 -0
- data/lib/neo4j/rails/accept_id.rb +66 -0
- data/lib/neo4j/rails/attributes.rb +14 -9
- data/lib/neo4j/rails/compositions.rb +9 -1
- data/lib/neo4j/rails/finders.rb +5 -1
- data/lib/neo4j/rails/mapping/property.rb +41 -28
- data/lib/neo4j/rails/model.rb +2 -0
- data/lib/neo4j/rails/observer.rb +61 -2
- data/lib/neo4j/rails/persistence.rb +57 -57
- data/lib/neo4j/rails/rails.rb +1 -0
- data/lib/neo4j/rails/railtie.rb +4 -1
- data/lib/neo4j/rails/rel_persistence.rb +11 -12
- data/lib/neo4j/rails/relationship.rb +9 -4
- data/lib/neo4j/rails/relationships/node_dsl.rb +15 -5
- data/lib/neo4j/rails/relationships/relationships.rb +42 -2
- data/lib/neo4j/rails/relationships/rels_dsl.rb +60 -3
- data/lib/neo4j/rails/relationships/storage.rb +43 -5
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -0
- data/lib/neo4j/rails/versioning/versioning.rb +64 -9
- data/lib/neo4j/relationship.rb +79 -73
- 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 +33 -20
- data/lib/neo4j/to_java.rb +5 -0
- data/lib/neo4j/traversal/traverser.rb +38 -1
- data/lib/neo4j/type_converters/type_converters.rb +56 -5
- data/lib/neo4j/version.rb +1 -1
- data/lib/neo4j.rb +3 -49
- data/neo4j.gemspec +2 -2
- metadata +191 -216
- data/bin/neo4j-shell~ +0 -108
- data/lib/Gemfile~ +0 -3
- data/lib/config2.yml~ +0 -86
- data/lib/neo4j/jars/core/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
- data/lib/neo4j/jars/core/lucene-core-3.1.0.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-backup-1.4.1.jar +0 -0
- data/lib/neo4j/jars/core/neo4j-graph-algo-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/core/neo4j-lucene-index-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/log4j-1.2.16.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/neo4j-shell-1.4.1.jar +0 -0
- data/lib/neo4j/jars/ha/netty-3.2.1.Final.jar +0 -0
- data/lib/neo4j/jars/ha/org.apache.servicemix.bundles.jline-0.9.94_1.jar +0 -0
- data/lib/neo4j/jars/ha/zookeeper-3.3.2.jar +0 -0
- data/lib/neo4j/paginate.rb +0 -25
- data/lib/perf.rb~ +0 -36
- data/lib/test.rb~ +0 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,33 @@
|
|
1
|
+
== 1.3.1 / 2011-12-14
|
2
|
+
* Make all relationships visible in Rails callback (rspecs #87, Dmytrii Nagirniak) [#211]
|
3
|
+
* Enable travis to build JRuby 1.9 (pull #87, Dmytrii Nagirniak) [#214]
|
4
|
+
* Support for composite lucene queries with OR and NOT (pull #89, Deepak N)
|
5
|
+
* Enforce the correct converter on a property type when the type is given (pull #86, Dmytrii Nagirniak)
|
6
|
+
* Development: make it easier to run RSpecs and guard (pull #85, Dmytrii Nagirniak)
|
7
|
+
* Added ability to disable observer (pull #84, Dmytrii Nagirniak)
|
8
|
+
* Fixing multiple assignment of has_one assocaition (pull #83 Deepak N)
|
9
|
+
* Accept association_id for has_one assocations (pull #82, Deepak N)
|
10
|
+
* Upgrade to 1.6.M01 Neo4j java jars [#209]
|
11
|
+
* Defer warning message 'Unknown outgoing relationship' (pull #81, Vivek Prahlad)
|
12
|
+
* Added string converter, e.g. property :name, :type => String (pull #80, Dmytrii Nagirniak)
|
13
|
+
* Added symbol converter e.g. property :status, :type => Symbol (pull #79, Dmytrii Nagirniak) [#205]
|
14
|
+
|
15
|
+
== 1.3.0 / 2011-12-06
|
16
|
+
* Added neo4j-upgrade script to rename lucene index files and upgrade to 1.5 [#197]
|
17
|
+
* Expose Neo4j::NodeMixin#index_types returning available indices (useful for Cypher queries) [#194]
|
18
|
+
* The to_other method is now available also in the Neo4j::Rails API [#193]
|
19
|
+
* Expose rel_type method for Neo4j::Rails::Relationship [#196]
|
20
|
+
* Support for breadth and depth first traversals [#198]
|
21
|
+
* Support for cypher query [#197]
|
22
|
+
* Fix for rule node concurrency issue (pull #78, Vivek Prahlad)
|
23
|
+
* Bugfix for the uniqueness validation for properties with quotes (pull #76, Vivek Prahlad)
|
24
|
+
* More performance tweaks (pull #75, #77, Vivek Prahlad)
|
25
|
+
* Fixing add_index for properties other than type string (pull #74, Deepak N)
|
26
|
+
* Significant performance boost for creating large numbers of models in a transaction (pull #73, Vivek Prahlad)
|
27
|
+
* Upgrade to neo4j 1.5 jars (pull #72, Vivek Prahlad)
|
28
|
+
* Fix for assigning nil values to incoming has_one relation (pull #70, Deepak N)
|
29
|
+
* Support for revert and fixes for Neo4j::Rails::Versioning (pull #71, Vivek Prahlad)
|
30
|
+
|
1
31
|
== 1.2.6 / 2011-11-02
|
2
32
|
* Generators can now generate relationships as well [#195]
|
3
33
|
* Better will_paginate support for Neo4j::Rails::Model [#194]
|
data/CONTRIBUTORS
CHANGED
data/Gemfile
CHANGED
@@ -5,14 +5,26 @@ gemspec
|
|
5
5
|
group 'test' do
|
6
6
|
gem "rake", ">= 0.8.7"
|
7
7
|
gem "rdoc", ">= 2.5.10"
|
8
|
-
gem "horo", ">= 1.0.2"
|
9
|
-
gem "rspec", "
|
8
|
+
gem "horo", ">= 1.0.2" # TODO: Why horo, YARD seems to be much better option?
|
9
|
+
gem "rspec", "~> 2.8"
|
10
|
+
gem "its" # its(:with, :arguments) { should be_possible }
|
10
11
|
|
11
|
-
|
12
|
-
gem
|
12
|
+
gem 'guard'
|
13
|
+
gem 'ruby_gntp', :require => false # GrowlNotify for Mac
|
14
|
+
gem 'rb-inotify', :require => false
|
15
|
+
gem 'rb-fsevent', :require => false
|
16
|
+
gem 'rb-fchange', :require => false
|
17
|
+
gem "guard-rspec"
|
18
|
+
|
19
|
+
gem 'shoulda-matchers', '~> 1.0'
|
13
20
|
|
14
21
|
gem "test-unit"
|
15
22
|
gem 'rcov'
|
23
|
+
|
24
|
+
gem 'pry'
|
25
|
+
|
26
|
+
gem 'neo4j-advanced', "1.6.0.alpha.5", :require => false
|
27
|
+
gem 'neo4j-enterprise', "1.6.0.alpha.5", :require => false
|
16
28
|
end
|
17
29
|
|
18
30
|
#gem 'ruby-debug-base19' if RUBY_VERSION.include? "1.9"
|
data/README.rdoc
CHANGED
@@ -12,7 +12,9 @@ It uses two powerful and mature Java libraries:
|
|
12
12
|
=== Documentation
|
13
13
|
|
14
14
|
* {Guides and API}[http://neo4j.rubyforge.org/guides/index.html]
|
15
|
+
* {RDoc}[http://neo4j.rubyforge.org]
|
15
16
|
* {Blog: Neo4j and Rails 3}[http://blog.jayway.com/2011/03/02/neo4j-rb-1-0-0-and-rails-3/]
|
17
|
+
* {Kvitter Example Application}[https://github.com/andreasronge/kvitter/]
|
16
18
|
|
17
19
|
=== Why Neo4j.rb or a Graph Database ?
|
18
20
|
|
@@ -107,6 +109,15 @@ To run it with Tomcat instead of WEBrick
|
|
107
109
|
gem install trinidad
|
108
110
|
trinidad
|
109
111
|
|
112
|
+
=== Architecture
|
113
|
+
|
114
|
+
As you seen above, neo4j.rb consists of a three layers API:
|
115
|
+
|
116
|
+
* Layer 1. For interacting with the basic building blocks of the graph database (node, properties and relationship), see Neo4j::Node and Neo4j::Relationship classes.
|
117
|
+
* Layer 2. A binding API to Ruby objects, see Neo4j::NodeMixin and Neo4j::RelationshipMixin modules.
|
118
|
+
* Layer 3. An implementation of the Rails Active Model and a subset of the Active Record API, see Neo4j::Rails::Model class.
|
119
|
+
|
120
|
+
Notice that you can always access the lower layers if you want to do some more advanced. You can even access the Java API directly.
|
110
121
|
|
111
122
|
=== Presentation Materials and other URLs
|
112
123
|
* {Presentation: RailsConf 2011}[http://andreasronge.github.com/neo4j-railsconf.pdf]
|
@@ -115,17 +126,28 @@ To run it with Tomcat instead of WEBrick
|
|
115
126
|
|
116
127
|
=== Project information
|
117
128
|
* {GitHub}[http://github.com/andreasronge/neo4j/tree/master]
|
118
|
-
* {
|
129
|
+
* {Issue Tracking}[https://github.com/andreasronge/neo4j/issues]
|
119
130
|
* {Twitter}[http://twitter.com/ronge]
|
120
|
-
* IRC - #neo4j @ irc.freenode.net
|
121
131
|
* {Mailing list, neo4jrb@googlegroups.com}[http://groups.google.com/group/neo4jrb]
|
132
|
+
* {Read only, old lighthouse issues}[http://neo4j.lighthouseapp.com]
|
133
|
+
|
134
|
+
=== Configuration
|
135
|
+
|
136
|
+
{Development configuration}[http://neo4j.rubyforge.org/guides/index.html#development-and-testing-configuration] - You can configure Neo4j through the {Neo4j::Config}[http://neo4j.rubyforge.org/Neo4j/Config.html] object.
|
137
|
+
|
138
|
+
Neo4j::Config[:storage_path] = "/var/neo4j"
|
139
|
+
|
140
|
+
{Configuring Neo4j from Rails}[http://neo4j.rubyforge.org/guides/configuration.html#config-neo4j-from-rails] - When using Neo4j.rb from rails you can use the normal rails configuration to set Neo4j configuration.
|
141
|
+
|
142
|
+
config.neo4j.storage_path = "#{config.root}/db/neo4j"
|
122
143
|
|
123
144
|
=== Contributing
|
124
145
|
|
146
|
+
{<img src="https://secure.travis-ci.org/andreasronge/neo4j.png" />}[http://travis-ci.org/andreasronge/neo4j]
|
147
|
+
|
125
148
|
Have you found a bug, need help or have a patch ?
|
126
149
|
Just clone neo4j.rb and send me a pull request or email me.
|
127
150
|
Do you need help - send me an email (andreas.ronge at gmail dot com).
|
128
|
-
Please also check/add issues at lighthouse, http://neo4j.lighthouseapp.com
|
129
151
|
|
130
152
|
=== License
|
131
153
|
* Neo4j.rb - MIT, see the LICENSE file http://github.com/andreasronge/neo4j/tree/master/LICENSE.
|
data/bin/neo4j-jars
CHANGED
@@ -5,22 +5,29 @@ require 'neo4j'
|
|
5
5
|
if ARGV.length == 0
|
6
6
|
puts <<TEXT
|
7
7
|
A tool for copying jar files needed by the application server, like trinidad
|
8
|
-
It copies
|
9
|
-
|
10
|
-
-
|
11
|
-
|
12
|
-
-local copies only the jars for running a local neo4j db
|
8
|
+
It copies all jar files which has been required (neo4j-community, neo4j-advanced or neo4j-enterprise) to the lib folder of the current directory
|
9
|
+
|
10
|
+
Usage: neo4j-jars <community|advanced|enterprise>
|
11
|
+
|
13
12
|
TEXT
|
14
13
|
exit
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
|
16
|
+
if ARGV.include?('community')
|
17
|
+
require 'neo4j-community' # not really needed
|
18
|
+
elsif ARGV.include?('advanced')
|
19
|
+
require 'neo4j-advanced' # not really needed
|
20
|
+
elsif ARGV.include?('enterprise')
|
21
|
+
require 'neo4j-enterprise' # not really needed
|
22
|
+
else
|
23
|
+
puts "Expected community, advanced, enterprise"
|
24
|
+
exit -1
|
25
|
+
end
|
19
26
|
|
20
27
|
lib_dir = File.join(Dir.pwd, 'lib')
|
21
28
|
raise "Expected a lib folder where to copy the jars file, mkdir #{lib_dir}? " unless File.exist?(lib_dir)
|
22
29
|
|
23
|
-
files = $CLASSPATH.find_all{|x| x =~
|
30
|
+
files = $CLASSPATH.find_all{|x| x =~ /\.jar$/}.collect{|y| y.sub('file:', '')}
|
24
31
|
files.each {|file| FileUtils.cp(file, lib_dir)}
|
25
32
|
|
26
33
|
puts "copied #{files.size} files to #{lib_dir}"
|
data/bin/neo4j-shell
CHANGED
data/bin/neo4j-upgrade
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'neo4j'
|
5
|
+
|
6
|
+
if ARGV.length == 0
|
7
|
+
puts <<TEXT
|
8
|
+
A tool for upgrading the neo4j database to #{Neo4j::VERSION}.
|
9
|
+
Make sure you shutdown the database cleanly before running this script.
|
10
|
+
More info: http://neo4j.rubyforge.org/guides/configuration.html#upgrade-to-a-new-neo4j-version
|
11
|
+
|
12
|
+
Usage : neo4j-upgrade <location of database>
|
13
|
+
Example : neo4j-upgrade db/neo4j-development
|
14
|
+
|
15
|
+
TEXT
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
def error(msg)
|
20
|
+
puts msg
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
def rename_index(folder, file)
|
25
|
+
new_file = File.join(folder, file.gsub(/-/, '_'))
|
26
|
+
old_file = File.join(folder, file)
|
27
|
+
puts "moved index '#{old_file}' to '#{new_file}'"
|
28
|
+
FileUtils.move(old_file, new_file)
|
29
|
+
end
|
30
|
+
|
31
|
+
def upgrade(path)
|
32
|
+
Dir.entries(path).each do |file|
|
33
|
+
rename_index(path, file) if file =~ /(-exact)|(-fulltext)$/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
root = ARGV[0]
|
38
|
+
error("Can't find database at location #{root}") unless File.exist?(root)
|
39
|
+
error("Expected location #{root} to be a folder") unless File.directory?(root)
|
40
|
+
|
41
|
+
# Upgrade
|
42
|
+
puts "upgrade database to Neo4j.rb version #{Neo4j::VERSION}, this might take a while ...."
|
43
|
+
Neo4j::Config[:storage_path] = root
|
44
|
+
Neo4j::Config[:allow_store_upgrade] = 'true'
|
45
|
+
Neo4j.start
|
46
|
+
puts "Neo4j database at #{root} upgraded to #{Neo4j::VERSION}, now shutdown"
|
47
|
+
Neo4j.shutdown
|
48
|
+
puts "Rename lucene index files"
|
49
|
+
|
50
|
+
nodes_path = File.join(root, "index", "lucene", "node")
|
51
|
+
if File.exist?(nodes_path)
|
52
|
+
upgrade(nodes_path)
|
53
|
+
else
|
54
|
+
puts("Can't find lucene index at location #{nodes_path}")
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
nodes_path = File.join(root, "index", "lucene", "node")
|
59
|
+
if File.exist?(nodes_path)
|
60
|
+
upgrade(nodes_path)
|
61
|
+
else
|
62
|
+
puts("No lucene index for nodes found at location #{nodes_path}, continue")
|
63
|
+
end
|
64
|
+
|
65
|
+
nodes_path = File.join(root, "index", "lucene", "relationship")
|
66
|
+
if File.exist?(nodes_path)
|
67
|
+
upgrade(nodes_path)
|
68
|
+
else
|
69
|
+
puts("No lucene index for relationship found at location #{nodes_path}")
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "Upgraded database done at '#{root}'"
|
data/config/neo4j/config.yml
CHANGED
@@ -28,17 +28,18 @@ lucene: { fulltext: { provider: lucene,
|
|
28
28
|
# If set to true it you can use the database while it is migrating.
|
29
29
|
migration_thread: false
|
30
30
|
|
31
|
-
# If online backup should be available, if it is the Online JAR file will be loaded
|
32
|
-
|
31
|
+
# If online backup should be available, if it is the Online JAR file will be loaded,
|
32
|
+
# Notice it must be either 'true' or 'false' as string
|
33
|
+
enable_online_backup: 'false'
|
33
34
|
|
34
35
|
#use the clustered Neo4j GraphDatabase (org.neo4j.kernel.HighlyAvailableGraphDatabase)
|
35
36
|
ha.db: false
|
36
37
|
|
37
38
|
# Example of HA Configuration, see http://wiki.neo4j.org/content/High_Availability_Cluster
|
38
39
|
# This is only used when ha.db is set to true
|
39
|
-
ha.
|
40
|
+
ha.server_id: 2
|
40
41
|
ha.server: 'localhost:6002'
|
41
|
-
ha.
|
42
|
+
ha.coordinators: 'localhost:2181,localhost:2182,localhost:2183'
|
42
43
|
|
43
44
|
# if enabled you can use the bin/neo4j-shell command to access the database
|
44
45
|
enable_remote_shell: "port=9332"
|
data/lib/neo4j/algo/algo.rb
CHANGED
data/lib/neo4j/batch/inserter.rb
CHANGED
@@ -48,6 +48,8 @@ module Neo4j
|
|
48
48
|
props = {} if clazz != Neo4j::Node && props.nil?
|
49
49
|
props['_classname'] = clazz.to_s if clazz != Neo4j::Node
|
50
50
|
|
51
|
+
props = ensure_valid_props(props)
|
52
|
+
|
51
53
|
node = @batch_inserter.create_node(props)
|
52
54
|
props && _index(node, props, clazz)
|
53
55
|
@rule_inserter.node_added(node, props)
|
@@ -68,6 +70,9 @@ module Neo4j
|
|
68
70
|
def create_rel(rel_type, from_node, to_node, props=nil, clazz=Neo4j::Relationship)
|
69
71
|
props = {} if clazz != Neo4j::Relationship && props.nil?
|
70
72
|
props['_classname'] = clazz.to_s if clazz != Neo4j::Relationship
|
73
|
+
|
74
|
+
props = ensure_valid_props(props)
|
75
|
+
|
71
76
|
rel = @batch_inserter.create_relationship(from_node, to_node, type_to_java(rel_type), props)
|
72
77
|
|
73
78
|
props && _index(rel, props, clazz)
|
data/lib/neo4j/database.rb
CHANGED
@@ -13,6 +13,8 @@ module Neo4j
|
|
13
13
|
class Database
|
14
14
|
attr_reader :graph, :lucene, :event_handler, :storage_path
|
15
15
|
|
16
|
+
alias_method :index, :lucene # needed by cypher
|
17
|
+
|
16
18
|
def initialize()
|
17
19
|
@event_handler = EventHandler.new
|
18
20
|
end
|
@@ -22,12 +24,6 @@ module Neo4j
|
|
22
24
|
@running = true
|
23
25
|
@storage_path = Config.storage_path
|
24
26
|
|
25
|
-
|
26
|
-
if Config[:enable_remote_shell]
|
27
|
-
Neo4j.logger.info("Enable remote shell at port #{Config[:enable_remote_shell]}")
|
28
|
-
Neo4j.load_shell_jars
|
29
|
-
end
|
30
|
-
|
31
27
|
begin
|
32
28
|
if self.class.locked?
|
33
29
|
start_readonly_graph_db
|
@@ -48,24 +44,34 @@ module Neo4j
|
|
48
44
|
|
49
45
|
def start_readonly_graph_db #:nodoc:
|
50
46
|
Neo4j.logger.info "Starting Neo4j in readonly mode since the #{@storage_path} is locked"
|
51
|
-
Neo4j.load_local_jars
|
52
47
|
@graph = org.neo4j.kernel.EmbeddedReadOnlyGraphDatabase.new(@storage_path, Config.to_java_map)
|
53
48
|
@lucene = @graph.index
|
54
49
|
end
|
55
50
|
|
56
51
|
def start_local_graph_db #:nodoc:
|
57
52
|
Neo4j.logger.info "Starting local Neo4j using db #{@storage_path}"
|
58
|
-
Neo4j.load_local_jars
|
59
53
|
@graph = org.neo4j.kernel.EmbeddedGraphDatabase.new(@storage_path, Config.to_java_map)
|
60
54
|
@graph.register_transaction_event_handler(@event_handler)
|
61
55
|
@lucene = @graph.index
|
62
56
|
@event_handler.neo4j_started(self)
|
63
57
|
end
|
64
58
|
|
59
|
+
# needed by cypher
|
60
|
+
def getNodeById(id) #:nodoc:
|
61
|
+
Neo4j::Node.load(id)
|
62
|
+
end
|
63
|
+
|
64
|
+
# needed by cypher
|
65
|
+
def getRelationshipById(id) #:nodoc:
|
66
|
+
Neo4j::Relationship.load(id)
|
67
|
+
end
|
68
|
+
|
65
69
|
def start_ha_graph_db
|
66
|
-
Neo4j.logger.info "starting Neo4j in HA mode, machine id: #{Neo4j.config['ha.
|
67
|
-
|
68
|
-
|
70
|
+
Neo4j.logger.info "starting Neo4j in HA mode, machine id: #{Neo4j.config['ha.server_id']} at #{Neo4j.config['ha.server']} db #{@storage_path}"
|
71
|
+
# Modify the public base classes for the HA Node and Relationships
|
72
|
+
# (instead of private org.neo4j.kernel.HighlyAvailableGraphDatabase::LookupNode)
|
73
|
+
Neo4j::Node.extend_java_class(org.neo4j.tooling.wrap.WrappedNode)
|
74
|
+
Neo4j::Relationship.extend_java_class(org.neo4j.tooling.wrap.WrappedRelationship)
|
69
75
|
@graph = org.neo4j.kernel.HighlyAvailableGraphDatabase.new(@storage_path, Neo4j.config.to_java_map)
|
70
76
|
@graph.register_transaction_event_handler(@event_handler)
|
71
77
|
@lucene = @graph.index
|
@@ -94,7 +100,7 @@ module Neo4j
|
|
94
100
|
# Returns true if the neo4j db was started in read only mode.
|
95
101
|
# This can occur if the database was locked (it was already one instance running).
|
96
102
|
def read_only?
|
97
|
-
@graph.
|
103
|
+
@graph.java_class == org.neo4j.kernel.EmbeddedGraphDatabase
|
98
104
|
end
|
99
105
|
|
100
106
|
# check if the database is locked. A neo4j database is locked when the database is running.
|
data/lib/neo4j/event_handler.rb
CHANGED
@@ -71,6 +71,9 @@ module Neo4j
|
|
71
71
|
# * <tt>old_value</tt> :: old value of the property
|
72
72
|
# * <tt>new_value</tt> :: new value of the property
|
73
73
|
#
|
74
|
+
# ==== classes_changed(class_change_map)
|
75
|
+
# * <tt>class_change_map</tt> :: a hash with class names as keys, and class changes as values. See Neo4j::ClassChanges
|
76
|
+
#
|
74
77
|
# == Usage
|
75
78
|
#
|
76
79
|
# class MyListener
|
@@ -99,30 +102,47 @@ module Neo4j
|
|
99
102
|
end
|
100
103
|
|
101
104
|
def before_commit(data)
|
102
|
-
|
103
|
-
|
105
|
+
class_change_map = java.util.HashMap.new
|
106
|
+
created_node_identity_map = iterate_created_nodes(data.created_nodes, class_change_map)
|
107
|
+
deleted_node_identity_map = deleted_node_identity_map(data.deleted_nodes)
|
104
108
|
deleted_relationship_set = relationship_set(data.deleted_relationships)
|
105
109
|
removed_node_properties_map = property_map(data.removed_node_properties)
|
106
110
|
removed_relationship_properties_map = property_map(data.removed_relationship_properties)
|
111
|
+
add_deleted_nodes(data, class_change_map, removed_node_properties_map)
|
107
112
|
empty_map = java.util.HashMap.new
|
108
|
-
data.
|
109
|
-
data.assigned_node_properties.each { |tx_data| property_changed(tx_data.entity, tx_data.key, tx_data.previously_commited_value, tx_data.value) }
|
113
|
+
data.assigned_node_properties.each { |tx_data| property_changed(tx_data.entity, tx_data.key, tx_data.previously_commited_value, tx_data.value) unless tx_data.key == '_classname'}
|
110
114
|
data.removed_node_properties.each { |tx_data| property_changed(tx_data.entity, tx_data.key, tx_data.previously_commited_value, nil) unless deleted_node_identity_map.containsKey(tx_data.entity.getId) }
|
111
115
|
data.deleted_nodes.each { |node| node_deleted(node, removed_node_properties_map.get(node.getId)||empty_map, deleted_relationship_set, deleted_node_identity_map)}
|
112
116
|
data.created_relationships.each {|rel| relationship_created(rel, created_node_identity_map)}
|
113
117
|
data.deleted_relationships.each {|rel| relationship_deleted(rel, removed_relationship_properties_map.get(rel.getId)||empty_map, deleted_relationship_set, deleted_node_identity_map)}
|
114
118
|
data.assigned_relationship_properties.each { |tx_data| rel_property_changed(tx_data.entity, tx_data.key, tx_data.previously_commited_value, tx_data.value) }
|
115
119
|
data.removed_relationship_properties.each {|tx_data| rel_property_changed(tx_data.entity, tx_data.key, tx_data.previously_commited_value, nil) unless deleted_relationship_set.contains_rel?(tx_data.entity) }
|
120
|
+
classes_changed(class_change_map)
|
121
|
+
rescue Exception => e
|
122
|
+
# since these exceptions gets swallowed
|
123
|
+
puts "ERROR in before commit hook #{e}"
|
124
|
+
puts e.backtrace.join("\n")
|
116
125
|
end
|
117
126
|
|
118
|
-
|
119
|
-
|
120
|
-
|
127
|
+
|
128
|
+
def iterate_created_nodes(nodes, class_change_map)
|
129
|
+
identity_map = java.util.HashMap.new
|
130
|
+
nodes.each do |node|
|
131
|
+
identity_map.put(node.neo_id,node) #using put due to a performance regression in JRuby 1.6.4
|
132
|
+
instance_created(node, class_change_map)
|
133
|
+
node_created(node)
|
134
|
+
end
|
135
|
+
identity_map
|
136
|
+
end
|
137
|
+
|
138
|
+
def deleted_node_identity_map(nodes)
|
139
|
+
identity_map = java.util.HashMap.new
|
140
|
+
nodes.each{|node| identity_map.put(node.neo_id,node)} #using put due to a performance regression in JRuby 1.6.4
|
121
141
|
identity_map
|
122
142
|
end
|
123
143
|
|
124
144
|
def relationship_set(relationships)
|
125
|
-
relationship_set = Neo4j::RelationshipSet.new(relationships.size)
|
145
|
+
relationship_set = Neo4j::RelationshipSet.new#(relationships.size)
|
126
146
|
relationships.each{|rel| relationship_set.add(rel)}
|
127
147
|
relationship_set
|
128
148
|
end
|
@@ -192,5 +212,52 @@ module Neo4j
|
|
192
212
|
def rel_property_changed(rel, key, old_value, new_value)
|
193
213
|
@listeners.each {|li| li.on_rel_property_changed(rel, key, old_value, new_value) if li.respond_to?(:on_rel_property_changed)}
|
194
214
|
end
|
215
|
+
|
216
|
+
def add_deleted_nodes(data, class_change_map, removed_node_properties_map)
|
217
|
+
data.deleted_nodes.each{|node| instance_deleted(node, removed_node_properties_map, class_change_map)}
|
218
|
+
end
|
219
|
+
|
220
|
+
def instance_created(node, class_change_map)
|
221
|
+
classname = node[:_classname]
|
222
|
+
class_change(classname, class_change_map).add(node) if classname
|
223
|
+
end
|
224
|
+
|
225
|
+
def instance_deleted(node, removed_node_properties_map, class_change_map)
|
226
|
+
properties = removed_node_properties_map.get(node.getId)
|
227
|
+
if properties
|
228
|
+
classname = properties.get("_classname")
|
229
|
+
class_change(classname, class_change_map).delete(node) if classname
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def class_change(classname, class_change_map)
|
234
|
+
class_change_map.put(classname, ClassChanges.new) if class_change_map.get(classname).nil?
|
235
|
+
class_change_map.get(classname)
|
236
|
+
end
|
237
|
+
|
238
|
+
def classes_changed(changed_class_map)
|
239
|
+
@listeners.each {|li| li.classes_changed(changed_class_map) if li.respond_to?(:classes_changed)}
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
class ClassChanges
|
244
|
+
attr_accessor :added, :deleted
|
245
|
+
|
246
|
+
def initialize
|
247
|
+
self.added = []
|
248
|
+
self.deleted = []
|
249
|
+
end
|
250
|
+
|
251
|
+
def add(node)
|
252
|
+
self.added << node
|
253
|
+
end
|
254
|
+
|
255
|
+
def delete(node)
|
256
|
+
self.deleted << node
|
257
|
+
end
|
258
|
+
|
259
|
+
def net_change
|
260
|
+
self.added.size - self.deleted.size
|
261
|
+
end
|
195
262
|
end
|
196
|
-
end
|
263
|
+
end
|
@@ -34,11 +34,11 @@ module Neo4j
|
|
34
34
|
class Mapping
|
35
35
|
include Enumerable
|
36
36
|
include ToJava
|
37
|
-
include WillPaginate::Finders::Base
|
38
|
-
|
39
37
|
|
40
|
-
|
41
|
-
|
38
|
+
|
39
|
+
def initialize(indexer_for, node, name)
|
40
|
+
@index = Neo4j.started_db.lucene.for_nodes("#{indexer_for.to_s.gsub('::', '_')}_#{name}-timeline", Neo4j::Config[:lucene][:exact])
|
41
|
+
@time_line = org.neo4j.index.lucene.LuceneTimeline.new(Neo4j.started_db.graph, @index)
|
42
42
|
@node = node
|
43
43
|
@name = name
|
44
44
|
self.size = 0 unless size
|
@@ -57,38 +57,38 @@ module Neo4j
|
|
57
57
|
|
58
58
|
# returns the first node with index n
|
59
59
|
def [](n)
|
60
|
-
@time_line.
|
60
|
+
@time_line.getBetween(n, n).first
|
61
61
|
end
|
62
62
|
|
63
63
|
# returns all nodes with the given index n
|
64
64
|
def all(n)
|
65
|
-
@time_line.
|
65
|
+
@time_line.getBetween(n, n)
|
66
66
|
end
|
67
67
|
|
68
68
|
# returns the first node in the list or nil
|
69
69
|
def first
|
70
|
-
@time_line.
|
70
|
+
@time_line.getFirst()
|
71
71
|
end
|
72
72
|
|
73
73
|
# returns the last node in the list or nil
|
74
74
|
def last
|
75
|
-
@time_line.
|
75
|
+
@time_line.getLast
|
76
76
|
end
|
77
77
|
|
78
78
|
# adds a node to the list with the given index n
|
79
79
|
def []=(n, other_node)
|
80
|
-
@time_line.
|
80
|
+
@time_line.add(other_node, n)
|
81
81
|
self.size = self.size + 1
|
82
82
|
end
|
83
83
|
|
84
84
|
# returns all the nodes between the given Range
|
85
85
|
def between(range)
|
86
|
-
@time_line.
|
86
|
+
@time_line.getBetween(range.first, range.end)
|
87
87
|
end
|
88
88
|
|
89
89
|
# removes one node from the list and decrases the size of the list,
|
90
90
|
def remove(node)
|
91
|
-
@
|
91
|
+
@index.remove(node, "timestamp")
|
92
92
|
self.size = self.size - 1
|
93
93
|
end
|
94
94
|
|
@@ -104,7 +104,7 @@ module Neo4j
|
|
104
104
|
# person.feeds.each {|node| node}
|
105
105
|
#
|
106
106
|
def each
|
107
|
-
@time_line.
|
107
|
+
@time_line.getBetween(java.lang.Long::MIN_VALUE,java.lang.Long::MAX_VALUE).iterator.each do |node|
|
108
108
|
if @raw then
|
109
109
|
yield node
|
110
110
|
else
|
@@ -113,41 +113,21 @@ module Neo4j
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
def wp_query(options, pager, args, &block) #:nodoc:
|
117
|
-
@raw = true
|
118
|
-
page = pager.current_page || 1
|
119
|
-
to = pager.per_page * page
|
120
|
-
from = to - pager.per_page
|
121
|
-
i = 0
|
122
|
-
res = []
|
123
|
-
each do |node|
|
124
|
-
res << node.wrapper if i >= from
|
125
|
-
i += 1
|
126
|
-
break if i >= to
|
127
|
-
end
|
128
|
-
pager.replace res
|
129
|
-
pager.total_entries ||= size
|
130
|
-
end
|
131
|
-
|
132
116
|
# If called then it will only return the raw java nodes and not the Ruby wrappers using the Neo4j::NodeMixin
|
133
117
|
def raw
|
134
118
|
@raw = true
|
135
119
|
end
|
136
120
|
|
137
121
|
def <<(other)
|
138
|
-
@time_line.
|
122
|
+
@time_line.add(other._java_node, size)
|
139
123
|
self.size = self.size + 1
|
140
124
|
self
|
141
125
|
end
|
142
126
|
|
143
|
-
|
144
127
|
private
|
145
128
|
def size=(size)
|
146
129
|
@node["_list_size_#{@name}"] = size
|
147
130
|
end
|
148
|
-
|
149
|
-
|
150
131
|
end
|
151
|
-
|
152
132
|
end
|
153
133
|
end
|