neo4j 2.0.1-java → 2.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/Gemfile +0 -3
- data/README.rdoc +12 -22
- data/lib/db/index/lucene-store.db +0 -0
- data/lib/db/index/lucene.log.active +0 -0
- data/lib/db/index/{lucene.log.1 → lucene.log.v0} +0 -0
- data/lib/db/messages.log +170 -162
- data/lib/db/neostore +0 -0
- data/lib/db/neostore.id +0 -0
- data/lib/db/neostore.nodestore.db +0 -0
- data/lib/db/neostore.nodestore.db.id +0 -0
- data/lib/db/neostore.propertystore.db +0 -0
- data/lib/db/neostore.propertystore.db.arrays +0 -0
- data/lib/db/neostore.propertystore.db.arrays.id +0 -0
- data/lib/db/neostore.propertystore.db.id +0 -0
- data/lib/db/neostore.propertystore.db.index +0 -0
- data/lib/db/neostore.propertystore.db.index.id +0 -0
- data/lib/db/neostore.propertystore.db.index.keys +0 -0
- data/lib/db/neostore.propertystore.db.index.keys.id +0 -0
- data/lib/db/neostore.propertystore.db.strings +0 -0
- data/lib/db/neostore.propertystore.db.strings.id +0 -0
- data/lib/db/neostore.relationshipstore.db +0 -0
- data/lib/db/neostore.relationshipstore.db.id +0 -0
- data/lib/db/neostore.relationshiptypestore.db +0 -0
- data/lib/db/neostore.relationshiptypestore.db.id +0 -0
- data/lib/db/neostore.relationshiptypestore.db.names +0 -0
- data/lib/db/neostore.relationshiptypestore.db.names.id +0 -0
- data/lib/db/nioneo_logical.log.active +0 -0
- data/lib/db/nioneo_logical.log.v0 +0 -0
- data/lib/db/tm_tx_log.1 +0 -0
- data/lib/neo4j/rails/attributes.rb +6 -3
- data/lib/neo4j/rails/column.rb +26 -0
- data/lib/neo4j/rails/finders.rb +48 -4
- data/lib/{db/lock → neo4j/rails/ha_console.rb} +0 -0
- data/lib/neo4j/rails/ha_console/ha_console.rb +68 -0
- data/lib/neo4j/rails/ha_console/railtie.rb +21 -0
- data/lib/neo4j/rails/ha_console/zookeeper/clean.sh +4 -0
- data/lib/neo4j/rails/ha_console/zookeeper/conf/server1.cfg +11 -0
- data/lib/neo4j/rails/ha_console/zookeeper/data/zookeeper1/myid +1 -0
- data/lib/neo4j/rails/ha_console/zookeeper/start_zookeeper.sh +17 -0
- data/lib/neo4j/rails/ha_console/zookeeper/zookeeper.rb +62 -0
- data/lib/neo4j/rails/has_n.rb +3 -0
- data/lib/neo4j/rails/persistence.rb +3 -1
- data/lib/neo4j/rails/rails.rb +2 -1
- data/lib/neo4j/version.rb +1 -1
- data/lib/neo4j/version.rb~ +3 -0
- data/lib/orm_adapter/adapters/neo4j.rb +52 -5
- data/neo4j.gemspec +1 -1
- metadata +311 -186
- data/bin/neo4j-shell~ +0 -108
- data/lib/Gemfile~ +0 -3
- data/lib/config2.yml~ +0 -86
- data/lib/db/nioneo_logical.log.1 +0 -0
- data/lib/perf.rb~ +0 -36
- data/lib/test.rb~ +0 -2
data/lib/db/neostore
CHANGED
Binary file
|
data/lib/db/neostore.id
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/db/tm_tx_log.1
CHANGED
Binary file
|
@@ -18,7 +18,8 @@ module Neo4j
|
|
18
18
|
included do
|
19
19
|
include ActiveModel::Dirty # track changes to attributes
|
20
20
|
include ActiveModel::MassAssignmentSecurity # handle attribute hash assignment
|
21
|
-
|
21
|
+
|
22
|
+
|
22
23
|
class << self
|
23
24
|
attr_accessor :attribute_defaults
|
24
25
|
end
|
@@ -238,10 +239,12 @@ module Neo4j
|
|
238
239
|
module ClassMethods
|
239
240
|
# Returns all defined properties
|
240
241
|
def columns
|
241
|
-
|
242
|
+
columns = []
|
243
|
+
props = Marshal.load( Marshal.dump(self._decl_props ))
|
244
|
+
props.each { |k,v| v.store(:name, k ); columns << Column.new(v) }
|
245
|
+
columns
|
242
246
|
end
|
243
247
|
|
244
|
-
|
245
248
|
# Declares a property.
|
246
249
|
# It support the following hash options:
|
247
250
|
# <tt>:default</tt>,<tt>:null</tt>,<tt>:limit</tt>,<tt>:type</tt>,<tt>:index</tt>,<tt>:converter</tt>.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# This is a way to wrap model attributes as Active Record-like column objects, providing a name and type for the column.
|
3
|
+
# This helps when using view generators, such as twitter-bootstrap-rails.
|
4
|
+
#
|
5
|
+
|
6
|
+
|
7
|
+
module Neo4j
|
8
|
+
module Rails
|
9
|
+
|
10
|
+
class Column
|
11
|
+
|
12
|
+
attr_reader :name, :type, :index, :converter
|
13
|
+
|
14
|
+
def initialize(args)
|
15
|
+
raise ArgumentError, "Column must passed a :name" if args[:name].nil?
|
16
|
+
args[:type] ||= "String" # default the type to String.
|
17
|
+
args.each do |k,v|
|
18
|
+
instance_variable_set("@#{k}", v.to_s) unless v.nil?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end #rails
|
25
|
+
end #neo4j
|
26
|
+
|
data/lib/neo4j/rails/finders.rb
CHANGED
@@ -57,7 +57,7 @@ module Neo4j
|
|
57
57
|
if self._decl_props[field.to_sym] && self._decl_props[field.to_sym][:type] == Fixnum
|
58
58
|
module_eval <<-RUBY, __FILE__, __LINE__
|
59
59
|
def self.all_by_#{field}(value)
|
60
|
-
|
60
|
+
find_with_indexer_or_traversal(:#{field} => value)
|
61
61
|
end
|
62
62
|
def self.find_by_#{field}(value)
|
63
63
|
all_by_#{field}(value).first
|
@@ -66,7 +66,7 @@ module Neo4j
|
|
66
66
|
else
|
67
67
|
module_eval <<-RUBY, __FILE__, __LINE__
|
68
68
|
def self.all_by_#{field}(value)
|
69
|
-
|
69
|
+
find_with_indexer_or_traversal("#{field}: \\"\#{value}\\"")
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.find_by_#{field}(value)
|
@@ -175,13 +175,19 @@ module Neo4j
|
|
175
175
|
if ids
|
176
176
|
[find_with_ids(ids)].flatten
|
177
177
|
else
|
178
|
-
|
178
|
+
find_with_indexer_or_traversal(*args, &block)
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
182
182
|
|
183
183
|
def first(*args, &block)
|
184
|
-
all(*args, &block).first
|
184
|
+
found = all(*args, &block).first
|
185
|
+
if found && args.first.is_a?(Hash) && args.first.include?(:id)
|
186
|
+
# if search for an id then all the other properties must match
|
187
|
+
args.first.find{|k,v| k != :id && found.send(k) != v} ? nil : found
|
188
|
+
else
|
189
|
+
found
|
190
|
+
end
|
185
191
|
end
|
186
192
|
|
187
193
|
def last(*args)
|
@@ -245,6 +251,28 @@ module Neo4j
|
|
245
251
|
entity.is_a?(self) and entity.reachable_from_ref_node?
|
246
252
|
end
|
247
253
|
|
254
|
+
|
255
|
+
def use_traversal_finder?(*args)
|
256
|
+
# Conditions for using a traversal:
|
257
|
+
# 1. the first argument is a hash
|
258
|
+
return false unless args.first.is_a?(Hash)
|
259
|
+
|
260
|
+
# 2. no support for :condition hash
|
261
|
+
return false if args.first.include?(:conditions)
|
262
|
+
|
263
|
+
# 3. there is at least one property which does not have a lucene index
|
264
|
+
args.first.keys.find{|k| !index?(k)}
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
def find_with_indexer_or_traversal(*args, &block)
|
269
|
+
if use_traversal_finder?(*args)
|
270
|
+
find_with_traversal(args.first)
|
271
|
+
else
|
272
|
+
find_with_indexer(*args, &block)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
248
276
|
def find_with_indexer(*args, &block)
|
249
277
|
hits = if args.first.is_a?(Hash) && args.first.include?(:conditions)
|
250
278
|
params = args.first.clone
|
@@ -262,6 +290,22 @@ module Neo4j
|
|
262
290
|
hits
|
263
291
|
end
|
264
292
|
|
293
|
+
def find_with_traversal(conditions)
|
294
|
+
this = self
|
295
|
+
all.query do |cypher|
|
296
|
+
conditions.each_pair do |k,v|
|
297
|
+
if this._decl_rels.keys.include?(k)
|
298
|
+
n = node(v.id)
|
299
|
+
rel_name = rel(this._decl_rels[k].rel_type)
|
300
|
+
this._decl_rels[k].dir == :outgoing ? cypher > rel_name > n : cypher < rel_name < n
|
301
|
+
else
|
302
|
+
cypher[k] == v
|
303
|
+
end
|
304
|
+
end
|
305
|
+
cypher
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
265
309
|
# Find the first object or create/initialize it.
|
266
310
|
#
|
267
311
|
# @example Find or perform an action.
|
File without changes
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'neo4j-enterprise'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
module Neo4j
|
6
|
+
|
7
|
+
module Rails
|
8
|
+
|
9
|
+
# Configures Neo4j HA and Zookeeper in order to be used from a rails console
|
10
|
+
# @see Railtie
|
11
|
+
module HaConsole
|
12
|
+
class << self
|
13
|
+
def machine_id
|
14
|
+
(defined? IRB) ? 2 : 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def proj_root
|
18
|
+
Object::Rails.root
|
19
|
+
end
|
20
|
+
|
21
|
+
def storage_path(id = machine_id)
|
22
|
+
File.expand_path("db/ha_neo_#{id}", proj_root)
|
23
|
+
end
|
24
|
+
|
25
|
+
def config_machine(id = machine_id)
|
26
|
+
puts "config_machine #{id}"
|
27
|
+
# override this default config with this machine configuration
|
28
|
+
Neo4j.config['ha.db'] = true
|
29
|
+
Neo4j.config['ha.server_id'] = id
|
30
|
+
Neo4j.config['ha.server'] = "localhost:600#{machine_id}"
|
31
|
+
Neo4j.config['ha.pull_interval'] = "2"
|
32
|
+
Neo4j.config[:storage_path] = storage_path(id)
|
33
|
+
|
34
|
+
copy_config unless File.exist?(config_dir)
|
35
|
+
require "#{config_dir}/zookeeper"
|
36
|
+
end
|
37
|
+
|
38
|
+
def config_dir
|
39
|
+
File.expand_path("neo4j_ha_console/zookeeper", Dir.tmpdir)
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_config
|
43
|
+
source_dir = File.expand_path("zookeeper", File.dirname(__FILE__))
|
44
|
+
system("mkdir -p #{File.expand_path("..", config_dir)}")
|
45
|
+
system("cp -r #{source_dir} #{config_dir}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def zookeeper_running?
|
49
|
+
Zookeeper.pid_file?
|
50
|
+
end
|
51
|
+
|
52
|
+
def start_zookeeper
|
53
|
+
Zookeeper.start unless zookeeper_running?
|
54
|
+
end
|
55
|
+
|
56
|
+
def shutdown_zookeeper
|
57
|
+
if zookeeper_running?
|
58
|
+
Zookeeper.shutdown
|
59
|
+
else
|
60
|
+
puts "Can't shutdown zookeeper - no PID file found for zookeeper process at #{Zookeeper.pid_file}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../ha_console', __FILE__)
|
2
|
+
|
3
|
+
module Neo4j
|
4
|
+
|
5
|
+
module Rails
|
6
|
+
|
7
|
+
module HaConsole
|
8
|
+
|
9
|
+
# Include this in your config/application.rb in order to run a rails console
|
10
|
+
# It avoids the Neo4j limitation of only having one process accessing the database by using HA clustering/neo4j-enterprise
|
11
|
+
class Railtie < Object::Rails::Railtie
|
12
|
+
config.before_configuration do
|
13
|
+
Neo4j::Rails::HaConsole.config_machine
|
14
|
+
Neo4j::Rails::HaConsole.start_zookeeper
|
15
|
+
config.neo4j.storage_path = Neo4j::Rails::HaConsole.storage_path
|
16
|
+
puts "HA: #{Neo4j.config['ha.db']}, server_id: #{Neo4j.config['ha.server_id']}, master: #{Neo4j.ha_master?}, storage_path=#{config.neo4j.storage_path}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# Only follow symlinks if readlink supports it
|
4
|
+
if readlink -f "$0" > /dev/null 2>&1
|
5
|
+
then
|
6
|
+
ZOOBIN=`readlink -f "$0"`
|
7
|
+
else
|
8
|
+
ZOOBIN="$0"
|
9
|
+
fi
|
10
|
+
|
11
|
+
ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain"
|
12
|
+
|
13
|
+
ZOOBINDIR=`dirname "$ZOOBIN"`
|
14
|
+
JARDIR=`cd "${ZOOBINDIR}/lib"; pwd`
|
15
|
+
|
16
|
+
CLASSPATH=$JARDIR/log4j-1.2.16.jar:$JARDIR/zookeeper-3.3.2.jar
|
17
|
+
java -cp "$CLASSPATH" $ZOOMAIN conf/server1.cfg
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Rails
|
3
|
+
module HaConsole
|
4
|
+
module Zookeeper
|
5
|
+
class << self
|
6
|
+
def shutdown
|
7
|
+
return unless pid_file?
|
8
|
+
file = File.open(pid_file, "rb")
|
9
|
+
pid = file.read.to_s.chomp
|
10
|
+
IO.popen("pkill -TERM -P #{pid}")
|
11
|
+
puts "Zookeeper: shutdown #{pid}"
|
12
|
+
system("rm -f #{pid_file}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def clean
|
16
|
+
dir = File.expand_path("data/zookeeper1/version-2", File.dirname(__FILE__))
|
17
|
+
puts "Zookeeper: clean #{dir}"
|
18
|
+
system("rm -rf #{dir}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def pid_file
|
22
|
+
File.expand_path("zookeeper.pid", File.dirname(__FILE__)).to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def pid_file?
|
26
|
+
x = File.exist?(pid_file)
|
27
|
+
puts "Zookeeper: pid file #{x} at #{pid_file}"
|
28
|
+
x
|
29
|
+
end
|
30
|
+
|
31
|
+
def lib_dir
|
32
|
+
File.expand_path("lib", File.dirname(__FILE__))
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_jars
|
36
|
+
puts "Zookeeper: Copy JARs"
|
37
|
+
files = $CLASSPATH.find_all{|x| x =~ /\.jar$/}.collect{|y| y.sub('file:', '')}
|
38
|
+
zookeeper = files.find{|f| f =~ /\/zookeeper/}
|
39
|
+
raise "zookeper JAR not found in a GEM, did you forget to include neo4j-enterprise in your Gemfile (development)" unless zookeeper
|
40
|
+
|
41
|
+
log4j = files.find{|f| f =~ /\/log4j/}
|
42
|
+
raise "log4j not found in a GEM, did you forget to include neo4j-enterprise in your Gemfile (development)" unless log4j
|
43
|
+
|
44
|
+
|
45
|
+
system("mkdir -p #{lib_dir}")
|
46
|
+
FileUtils.cp(zookeeper, lib_dir)
|
47
|
+
FileUtils.cp(log4j, lib_dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
def start
|
51
|
+
puts "Zookeeper: start, check jars?"
|
52
|
+
copy_jars unless File.exist?(lib_dir)
|
53
|
+
zookeeper_exec = File.expand_path("start_zookeeper.sh", File.dirname(__FILE__)).to_s
|
54
|
+
Dir.chdir(File.dirname(__FILE__))
|
55
|
+
pipe = IO.popen(zookeeper_exec)
|
56
|
+
File.open(pid_file, 'w') { |f| f.write(pipe.pid) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/neo4j/rails/has_n.rb
CHANGED
@@ -160,11 +160,13 @@ module Neo4j
|
|
160
160
|
else
|
161
161
|
true
|
162
162
|
end
|
163
|
+
rescue => e
|
164
|
+
Neo4j::Rails::Transaction.fail if Neo4j::Rails::Transaction.running?
|
165
|
+
raise e
|
163
166
|
ensure
|
164
167
|
@_create_or_updating = nil
|
165
168
|
end
|
166
169
|
|
167
|
-
|
168
170
|
def set_deleted_properties
|
169
171
|
@_deleted = true
|
170
172
|
end
|
data/lib/neo4j/rails/rails.rb
CHANGED
@@ -13,6 +13,7 @@ require 'neo4j/rails/observer'
|
|
13
13
|
require 'neo4j/rails/compositions'
|
14
14
|
require 'neo4j/rails/accept_id'
|
15
15
|
require 'neo4j/rails/timestamps'
|
16
|
+
require 'neo4j/rails/column'
|
16
17
|
require 'neo4j/rails/attributes'
|
17
18
|
require 'neo4j/rails/nested_attributes'
|
18
19
|
require 'neo4j/rails/serialization'
|
@@ -27,4 +28,4 @@ require 'neo4j/rails/has_n'
|
|
27
28
|
require 'neo4j/rails/rack_middleware'
|
28
29
|
require 'neo4j/rails/versioning/versioning'
|
29
30
|
require 'neo4j/rails/model'
|
30
|
-
require 'neo4j/rails/relationship'
|
31
|
+
require 'neo4j/rails/relationship'
|
data/lib/neo4j/version.rb
CHANGED