neo4j 2.0.0.alpha.5-java → 2.0.0.alpha.6-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 -4
- data/README.rdoc +106 -62
- data/lib/neo4j.rb +7 -33
- data/lib/neo4j/performance.rb +43 -0
- data/lib/neo4j/rails/accept_id.rb +19 -18
- data/lib/neo4j/rails/attributes.rb +366 -120
- data/lib/neo4j/rails/finders.rb +41 -15
- data/lib/neo4j/rails/has_n.rb +203 -0
- data/lib/neo4j/rails/identity.rb +25 -0
- data/lib/neo4j/rails/model.rb +65 -242
- data/lib/neo4j/rails/nested_attributes.rb +108 -0
- data/lib/neo4j/rails/node_persistance.rb +56 -0
- data/lib/neo4j/rails/observer.rb +0 -2
- data/lib/neo4j/rails/persistence.rb +32 -154
- data/lib/neo4j/rails/rack_middleware.rb +26 -2
- data/lib/neo4j/rails/rails.rb +9 -6
- data/lib/neo4j/rails/railtie.rb +1 -2
- data/lib/neo4j/rails/relationship.rb +18 -125
- data/lib/neo4j/rails/relationship_persistence.rb +107 -0
- data/lib/neo4j/rails/relationships/node_dsl.rb +72 -44
- data/lib/neo4j/rails/relationships/relationships.rb +187 -59
- data/lib/neo4j/rails/relationships/rels_dsl.rb +18 -17
- data/lib/neo4j/rails/relationships/storage.rb +19 -17
- data/lib/neo4j/rails/timestamps.rb +53 -51
- data/lib/neo4j/rails/transaction.rb +9 -1
- data/lib/neo4j/rails/validations/uniqueness.rb +1 -1
- data/lib/neo4j/rails/versioning/versioning.rb +2 -2
- data/lib/neo4j/version.rb +1 -1
- data/lib/orm_adapter/adapters/neo4j.rb +47 -46
- data/neo4j.gemspec +1 -1
- metadata +10 -69
- data/lib/neo4j/algo/algo.rb +0 -294
- data/lib/neo4j/batch/batch.rb +0 -4
- data/lib/neo4j/batch/indexer.rb +0 -109
- data/lib/neo4j/batch/inserter.rb +0 -179
- data/lib/neo4j/batch/rule_inserter.rb +0 -24
- data/lib/neo4j/batch/rule_node.rb +0 -72
- data/lib/neo4j/config.rb +0 -177
- data/lib/neo4j/core_ext/class/inheritable_attributes.rb +0 -12
- data/lib/neo4j/core_ext/class/rewrite_inheritable_attributes.rb +0 -170
- data/lib/neo4j/database.rb +0 -158
- data/lib/neo4j/equal.rb +0 -21
- data/lib/neo4j/event_handler.rb +0 -263
- data/lib/neo4j/has_list/class_methods.rb +0 -11
- data/lib/neo4j/has_list/has_list.rb +0 -3
- data/lib/neo4j/has_list/mapping.rb +0 -133
- data/lib/neo4j/has_n/class_methods.rb +0 -119
- data/lib/neo4j/has_n/decl_relationship_dsl.rb +0 -246
- data/lib/neo4j/has_n/has_n.rb +0 -3
- data/lib/neo4j/has_n/mapping.rb +0 -98
- data/lib/neo4j/identity_map.rb +0 -140
- data/lib/neo4j/index/class_methods.rb +0 -108
- data/lib/neo4j/index/index.rb +0 -39
- data/lib/neo4j/index/indexer.rb +0 -341
- data/lib/neo4j/index/indexer_registry.rb +0 -68
- data/lib/neo4j/index/lucene_query.rb +0 -256
- data/lib/neo4j/load.rb +0 -25
- data/lib/neo4j/migrations/class_methods.rb +0 -110
- data/lib/neo4j/migrations/extensions.rb +0 -58
- data/lib/neo4j/migrations/lazy_node_mixin.rb +0 -41
- data/lib/neo4j/migrations/migration.rb +0 -112
- data/lib/neo4j/migrations/migrations.rb +0 -6
- data/lib/neo4j/migrations/node_mixin.rb +0 -80
- data/lib/neo4j/migrations/ref_node_wrapper.rb +0 -32
- data/lib/neo4j/model.rb +0 -4
- data/lib/neo4j/neo4j.rb +0 -216
- data/lib/neo4j/node.rb +0 -270
- data/lib/neo4j/node_mixin/class_methods.rb +0 -51
- data/lib/neo4j/node_mixin/node_mixin.rb +0 -141
- data/lib/neo4j/paginated.rb +0 -23
- data/lib/neo4j/property/class_methods.rb +0 -79
- data/lib/neo4j/property/property.rb +0 -111
- data/lib/neo4j/rails/mapping/property.rb +0 -183
- data/lib/neo4j/rails/rel_persistence.rb +0 -237
- data/lib/neo4j/relationship.rb +0 -239
- data/lib/neo4j/relationship_mixin/class_methods.rb +0 -36
- data/lib/neo4j/relationship_mixin/relationship_mixin.rb +0 -142
- data/lib/neo4j/relationship_set.rb +0 -58
- data/lib/neo4j/rels/rels.rb +0 -110
- data/lib/neo4j/rels/traverser.rb +0 -102
- data/lib/neo4j/rule/class_methods.rb +0 -201
- data/lib/neo4j/rule/event_listener.rb +0 -66
- data/lib/neo4j/rule/functions/count.rb +0 -43
- data/lib/neo4j/rule/functions/function.rb +0 -74
- data/lib/neo4j/rule/functions/functions.rb +0 -3
- data/lib/neo4j/rule/functions/sum.rb +0 -29
- data/lib/neo4j/rule/rule.rb +0 -150
- data/lib/neo4j/rule/rule_node.rb +0 -217
- data/lib/neo4j/to_java.rb +0 -31
- data/lib/neo4j/transaction.rb +0 -73
- data/lib/neo4j/traversal/filter_predicate.rb +0 -25
- data/lib/neo4j/traversal/prune_evaluator.rb +0 -14
- data/lib/neo4j/traversal/rel_expander.rb +0 -31
- data/lib/neo4j/traversal/traversal.rb +0 -141
- data/lib/neo4j/traversal/traverser.rb +0 -284
- data/lib/neo4j/type_converters/type_converters.rb +0 -288
@@ -1,58 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
class << self
|
4
|
-
extend Forwardable
|
5
|
-
|
6
|
-
##
|
7
|
-
# Returns the current version of the database.
|
8
|
-
# This version has been set by running one or more migrations.
|
9
|
-
# The version is stored on the reference node, with property 'db_version'
|
10
|
-
# (It Delegates to the Reference Node)
|
11
|
-
#
|
12
|
-
# ==== See Also
|
13
|
-
# Neo4j::Migrations::RefNodeWrapper#db_version
|
14
|
-
#
|
15
|
-
# :singleton-method: db_version
|
16
|
-
|
17
|
-
##
|
18
|
-
# Force Neo4j.rb to perform migrations
|
19
|
-
#
|
20
|
-
# ==== See Also
|
21
|
-
#
|
22
|
-
# Neo4j::Migrations::RefNodeWrapper#migrate!
|
23
|
-
#
|
24
|
-
# :singleton-method: migrate!
|
25
|
-
|
26
|
-
##
|
27
|
-
# Specifies a single migration.
|
28
|
-
# The up and down methods are automatically wrapped in a transaction.
|
29
|
-
#
|
30
|
-
# === Example
|
31
|
-
#
|
32
|
-
# Neo4j.migration 1, :create_articles do
|
33
|
-
# up do
|
34
|
-
# Neo4j.ref_node.rels.outgoing(:colours) << Neo4j.Node.new(:colour => 'red') << Neo4j.Node.new(:colour => 'blue')
|
35
|
-
# end
|
36
|
-
# down do
|
37
|
-
# Neo4j.ref_node.rels.outgoing(:colours).each {|n| n.del }
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
#
|
41
|
-
# ==== See Also
|
42
|
-
# Neo4j::Migrations::ClassMethods#migration
|
43
|
-
#
|
44
|
-
# :singleton-method: migration
|
45
|
-
|
46
|
-
##
|
47
|
-
# Returns all migrations that has been defined.
|
48
|
-
#
|
49
|
-
# ==== See Also
|
50
|
-
# Neo4j::Migrations::ClassMethods#migrations
|
51
|
-
#
|
52
|
-
# :singleton-method: migrations
|
53
|
-
|
54
|
-
|
55
|
-
def_delegators :'Neo4j::Migrations::RefNodeWrapper', :db_version, :migrate!, :migrations, :migration
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
@@ -1,41 +0,0 @@
|
|
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
|
-
def self.included(base)
|
13
|
-
base.extend Neo4j::Migrations::ClassMethods
|
14
|
-
base.property :_db_version if base.respond_to?(:property)
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def migrate!
|
19
|
-
self.class._migrate!(self._java_node, self)
|
20
|
-
end
|
21
|
-
|
22
|
-
def init_on_create(*)
|
23
|
-
super
|
24
|
-
# set the db version to the current
|
25
|
-
self[:_db_version] = self.class.migrate_to
|
26
|
-
end
|
27
|
-
|
28
|
-
def init_on_load(*) # :nodoc:
|
29
|
-
super
|
30
|
-
migrate!
|
31
|
-
# this if for Neo4j::Rails::Model which keeps the properties in this variable
|
32
|
-
@properties.clear if instance_variable_defined? :@properties
|
33
|
-
end
|
34
|
-
|
35
|
-
def db_version
|
36
|
-
self[:_db_version]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
module Migrations
|
4
|
-
|
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
|
9
|
-
|
10
|
-
def initialize(version, name)
|
11
|
-
@auto_transaction = true
|
12
|
-
@version = version
|
13
|
-
@name = name
|
14
|
-
end
|
15
|
-
|
16
|
-
# Specifies a code block which is run when the migration is upgraded.
|
17
|
-
#
|
18
|
-
def up(&block)
|
19
|
-
@up_block = block
|
20
|
-
end
|
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
|
27
|
-
|
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
|
32
|
-
|
33
|
-
|
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
|
61
|
-
context.instance_eval &@up_block if @up_block
|
62
|
-
add_index_on(context, @add_indexed_field) if @add_indexed_field
|
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
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
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
|
80
|
-
context.instance_eval &@down_block if @down_block
|
81
|
-
add_index_on(context, @rm_indexed_field) if @rm_indexed_field
|
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
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
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
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
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
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
def to_s
|
107
|
-
"Migration version: #{version}, name: #{name}"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
112
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module Migrations
|
3
|
-
|
4
|
-
|
5
|
-
# By including this mixing on a node class one can add migrations to it.
|
6
|
-
# Each class has a unique db version.
|
7
|
-
#
|
8
|
-
# ==== Example
|
9
|
-
#
|
10
|
-
# class Person
|
11
|
-
# include Neo4j::NodeMixin
|
12
|
-
# include Neo4j::Migrations::NodeMixin
|
13
|
-
# rule :all # adding the method all to make it possible to find all nodes of this class
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# Person.migration 1, :split_property do
|
17
|
-
# up do
|
18
|
-
# all.each_raw do |node|
|
19
|
-
# node[:given_name] = node[:name].split[0]
|
20
|
-
# node[:surname] = node[:name].split[1]
|
21
|
-
# node[:name] = nil
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# down do
|
26
|
-
# all.each_raw do |node|
|
27
|
-
# node[:name] = "#{node[:given_name]} #{node[:surname]}"
|
28
|
-
# node[:surename] = nil
|
29
|
-
# node[:given_name] = nil
|
30
|
-
# end
|
31
|
-
# end
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# Notice that the up and down methods are evaluated in the context of the class (where the all method is defined
|
35
|
-
# if using the rule :all).
|
36
|
-
#
|
37
|
-
module NodeMixin
|
38
|
-
extend ActiveSupport::Concern
|
39
|
-
|
40
|
-
included do
|
41
|
-
extend Neo4j::Migrations::ClassMethods
|
42
|
-
end
|
43
|
-
|
44
|
-
module ClassMethods
|
45
|
-
def migrate!(version=nil)
|
46
|
-
_migrate!(self, migration_meta_node, version)
|
47
|
-
end
|
48
|
-
|
49
|
-
# The node that holds the db version property
|
50
|
-
def migration_meta_node
|
51
|
-
Neo4j::Rule::Rule.rule_node_for(self).rule_node
|
52
|
-
end
|
53
|
-
|
54
|
-
# Remote all migration and set migrate_to = nil and set the current version to nil
|
55
|
-
def reset_migrations!
|
56
|
-
@migrations = nil
|
57
|
-
@migrate_to = nil
|
58
|
-
Neo4j::Transaction.run do
|
59
|
-
migration_meta_node[:_db_version] = nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# sets the migration db version for this class on a 'meta' node.
|
64
|
-
def db_version=(version)
|
65
|
-
Neo4j::Transaction.run do
|
66
|
-
migration_meta_node[:_db_version] = version
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# returns the current version of the database for this class.
|
71
|
-
def db_version
|
72
|
-
migration_meta_node[:_db_version]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
module Migrations
|
4
|
-
# This node stores the migrations for Neo4j.migrations
|
5
|
-
# Uses the Neo4j.ref_node for keeping the current version of the db.
|
6
|
-
# When the database starts it will check if it needs to run a migration.
|
7
|
-
class RefNodeWrapper
|
8
|
-
extend ClassMethods
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def migrate!(version=nil)
|
12
|
-
_migrate!(self, Neo4j.ref_node, version)
|
13
|
-
end
|
14
|
-
|
15
|
-
def db_version
|
16
|
-
Neo4j.ref_node[:_db_version] || 0
|
17
|
-
end
|
18
|
-
|
19
|
-
# Remote all migration and set migrate_to = nil and set the current version to nil
|
20
|
-
def reset_migrations!
|
21
|
-
@migrations = nil
|
22
|
-
@migrate_to = nil
|
23
|
-
Neo4j::Transaction.run do
|
24
|
-
Neo4j.ref_node[:_db_version] = nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
data/lib/neo4j/model.rb
DELETED
data/lib/neo4j/neo4j.rb
DELETED
@@ -1,216 +0,0 @@
|
|
1
|
-
# external neo4j dependencies
|
2
|
-
require 'neo4j/config'
|
3
|
-
require 'neo4j/database'
|
4
|
-
|
5
|
-
# = Neo4j
|
6
|
-
#
|
7
|
-
# The Neo4j modules is used to interact with an Neo4j Database instance.
|
8
|
-
# You can for example start and stop an instance and list all the nodes that exist in the database.
|
9
|
-
#
|
10
|
-
# === Starting and Stopping Neo4j
|
11
|
-
# You don't normally need to start the Neo4j database since it will be automatically started when needed.
|
12
|
-
# Before the database is started you should configure where the database is stored, see Neo4j::Config.
|
13
|
-
#
|
14
|
-
module Neo4j
|
15
|
-
|
16
|
-
# The version of the Neo4j jar files
|
17
|
-
NEO_VERSION = Neo4j::Community::VERSION
|
18
|
-
|
19
|
-
class << self
|
20
|
-
# Start Neo4j using the default database.
|
21
|
-
# This is usally not required since the database will be started automatically when it is used.
|
22
|
-
# If the global variable $NEO4J_SERVER is defined then it will use that as the Java Graph DB. This can
|
23
|
-
# be used if you want to embed neo4j.rb and already got an instance of the Java Neo4j Database service.
|
24
|
-
#
|
25
|
-
# ==== Parameters
|
26
|
-
# config_file :: (optionally) if this is nil or not given use the Neo4j::Config, otherwise setup the Neo4j::Config file using the provided YAML configuration file.
|
27
|
-
# external_db :: (optionally) use this Java Neo4j instead of creating a new neo4j database service
|
28
|
-
def start(config_file=nil, external_db = $NEO4J_SERVER)
|
29
|
-
return if @db && @db.running?
|
30
|
-
|
31
|
-
Neo4j.config.default_file = config_file if config_file
|
32
|
-
if external_db
|
33
|
-
@db ||= Database.new
|
34
|
-
self.db.start_external_db(external_db)
|
35
|
-
else
|
36
|
-
db.start
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
# Sets the Neo4j::Database instance to use
|
42
|
-
# An Neo4j::Database instance wraps both the Neo4j Database and Lucene Database.
|
43
|
-
def db=(my_db)
|
44
|
-
@db = my_db
|
45
|
-
end
|
46
|
-
|
47
|
-
# Returns the database holding references to both the Neo4j Graph Database and the Lucene Database.
|
48
|
-
# Creates a new one if it does not exist, but does not start it.
|
49
|
-
def db
|
50
|
-
@db ||= Database.new
|
51
|
-
end
|
52
|
-
|
53
|
-
def read_only?
|
54
|
-
@db && @db.graph && @db.graph.read_only?
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns a started db instance. Starts it's not running.
|
58
|
-
# if $NEO4J_SERVER is defined then use that Java Neo4j Database service instead of creating a new one.
|
59
|
-
def started_db
|
60
|
-
start unless db.running?
|
61
|
-
db
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns the current storage path of a running neo4j database.
|
65
|
-
# If the database is not running it returns nil.
|
66
|
-
def storage_path
|
67
|
-
return nil unless db.running?
|
68
|
-
db.storage_path
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns the Neo4j::Config class
|
72
|
-
# Same as typing; Neo4j::Config
|
73
|
-
def config
|
74
|
-
Neo4j::Config
|
75
|
-
end
|
76
|
-
|
77
|
-
# Executes a Cypher Query
|
78
|
-
# Check the neo4j http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html
|
79
|
-
# Returns an enumerable of hash values.
|
80
|
-
#
|
81
|
-
# === Usage
|
82
|
-
#
|
83
|
-
# q = Neo4j.query("START n=node({node}) RETURN n", 'node' => @node.neo_id)
|
84
|
-
# q.first['n'] #=> the @node
|
85
|
-
# q.columns.first => 'n'
|
86
|
-
#
|
87
|
-
def query(query, params = {})
|
88
|
-
engine = org.neo4j.cypher.javacompat.ExecutionEngine.new(db)
|
89
|
-
engine.execute(query, params)
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
# Returns the logger used by neo4j.
|
94
|
-
# If not specified (with Neo4j.logger=) it will use the standard Ruby logger.
|
95
|
-
# You can change standard logger threshold by configuration :logger_level.
|
96
|
-
#
|
97
|
-
# You can also specify which logger class should take care of logging with the
|
98
|
-
# :logger configuration.
|
99
|
-
#
|
100
|
-
# ==== Example
|
101
|
-
#
|
102
|
-
# Neo4j::Config[:logger] = Logger.new(STDOUT)
|
103
|
-
# Neo4j::Config[:logger_level] = Logger::ERROR
|
104
|
-
#
|
105
|
-
def logger
|
106
|
-
@logger ||= Neo4j::Config[:logger] || default_logger
|
107
|
-
end
|
108
|
-
|
109
|
-
# Sets which logger should be used.
|
110
|
-
# If this this is not called then the standard Ruby logger will be used.
|
111
|
-
def logger=(logger)
|
112
|
-
@logger = logger
|
113
|
-
end
|
114
|
-
|
115
|
-
def default_logger #:nodoc:
|
116
|
-
require 'logger'
|
117
|
-
logger = Logger.new(STDOUT)
|
118
|
-
logger.sev_threshold = Neo4j::Config[:logger_level] || Logger::INFO
|
119
|
-
logger
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
# Returns an unstarted db instance
|
124
|
-
#
|
125
|
-
# This is typically used for configuring the database, which must sometimes
|
126
|
-
# be done before the database is started
|
127
|
-
# if the database was already started an exception will be raised
|
128
|
-
def unstarted_db
|
129
|
-
@db ||= Database.new
|
130
|
-
raise "database was already started" if @db.running?
|
131
|
-
@db
|
132
|
-
end
|
133
|
-
|
134
|
-
# returns true if the database is running
|
135
|
-
def running?
|
136
|
-
@db && @db.running?
|
137
|
-
end
|
138
|
-
|
139
|
-
|
140
|
-
# Stops this database
|
141
|
-
# There are Ruby hooks that will do this automatically for you.
|
142
|
-
#
|
143
|
-
def shutdown(this_db = @db)
|
144
|
-
this_db.shutdown if this_db
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
# Returns the default reference node, which is a "starting point" in the node space.
|
149
|
-
#
|
150
|
-
def default_ref_node(this_db = self.started_db)
|
151
|
-
this_db.graph.reference_node
|
152
|
-
end
|
153
|
-
|
154
|
-
# Returns the reference node, which is a "starting point" in the node space.
|
155
|
-
# In case the ref_node has been assigned via the threadlocal_ref_node method, then that node will be returned instead.
|
156
|
-
#
|
157
|
-
# Usually, a client attaches relationships to this node that leads into various parts of the node space.
|
158
|
-
# For more information about common node space organizational patterns, see the design guide at http://wiki.neo4j.org/content/Design_Guide
|
159
|
-
#
|
160
|
-
def ref_node(this_db = self.started_db)
|
161
|
-
return Thread.current[:local_ref_node] if Thread.current[:local_ref_node]
|
162
|
-
default_ref_node(this_db)
|
163
|
-
end
|
164
|
-
|
165
|
-
# Changes the reference node on a threadlocal basis.
|
166
|
-
# This can be used to achieve multitenancy. All new entities will be attached to the new ref_node,
|
167
|
-
# which effectively partitions the graph, and hence scopes traversals.
|
168
|
-
def threadlocal_ref_node=(reference_node)
|
169
|
-
Thread.current[:local_ref_node] = reference_node.nil? ? nil : reference_node._java_node
|
170
|
-
end
|
171
|
-
|
172
|
-
# Returns a Management JMX Bean.
|
173
|
-
#
|
174
|
-
# Notice that this information is also provided by the jconsole Java tool, check http://wiki.neo4j.org/content/Monitoring_and_Deployment
|
175
|
-
# and http://docs.neo4j.org/chunked/milestone/operations-monitoring.html
|
176
|
-
#
|
177
|
-
# By default it returns the Primitivies JMX Bean that can be used to find number of nodes in use.
|
178
|
-
#
|
179
|
-
# ==== Example Neo4j Primititives
|
180
|
-
#
|
181
|
-
# Neo4j.management.get_number_of_node_ids_in_use
|
182
|
-
# Neo4j.management.getNumberOfPropertyIdsInUse
|
183
|
-
# Neo4j.management.getNumberOfRelationshipIdsInUse
|
184
|
-
# Neo4j.management.get_number_of_relationship_type_ids_in_use
|
185
|
-
#
|
186
|
-
# ==== Example Neo4j HA Cluster Info
|
187
|
-
#
|
188
|
-
# Neo4j.management(org.neo4j.management.HighAvailability).isMaster
|
189
|
-
#
|
190
|
-
# ==== Arguments
|
191
|
-
#
|
192
|
-
# jmx_clazz :: http://api.neo4j.org/current/org/neo4j/management/package-summary.html
|
193
|
-
# this_db :: default currently runnig instance or a newly started neo4j db instance
|
194
|
-
#
|
195
|
-
def management(jmx_clazz = org.neo4j.jmx.Primitives, this_db = self.started_db)
|
196
|
-
this_db.management(jmx_clazz)
|
197
|
-
end
|
198
|
-
|
199
|
-
# Returns an Enumerable object for all nodes in the database
|
200
|
-
def all_nodes(this_db = self.started_db)
|
201
|
-
Enumerator.new(this_db, :each_node)
|
202
|
-
end
|
203
|
-
|
204
|
-
# Same as #all_nodes but does not return wrapped nodes but instead raw java node objects.
|
205
|
-
def _all_nodes(this_db = self.started_db)
|
206
|
-
Enumerator.new(this_db, :_each_node)
|
207
|
-
end
|
208
|
-
|
209
|
-
# Returns the Neo4j::EventHandler
|
210
|
-
#
|
211
|
-
def event_handler(this_db = db)
|
212
|
-
this_db.event_handler
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
end
|