neo4j-core 2.0.1-java → 2.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,18 +2,18 @@ source :gemcutter
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'neo4j-advanced', :require => false
6
- gem 'neo4j-enterprise', :require => false
5
+ gem 'neo4j-advanced', '>= 1.8.M05', '< 1.9', :require => false
6
+ gem 'neo4j-enterprise', '>= 1.8.M05', '< 1.9', :require => false
7
7
 
8
8
  group 'development' do
9
- gem 'guard'
10
- gem 'rcov', '0.9.11'
11
- gem 'ruby_gntp', :require => false # GrowlNotify for Mac
12
- gem 'rb-inotify', :require => false
13
- gem 'rb-fsevent', :require => false
14
- gem 'rb-fchange', :require => false
15
- gem "guard-rspec"
16
- gem "horo", ">= 1.0.2" # TODO: Why horo, YARD seems to be much better option?
9
+ gem 'pry'
10
+ # gem 'guard'
11
+ # gem 'rcov', '0.9.11'
12
+ # gem 'ruby_gntp', :require => false # GrowlNotify for Mac
13
+ # gem 'rb-inotify', :require => false
14
+ # gem 'rb-fsevent', :require => false
15
+ # gem 'rb-fchange', :require => false
16
+ # gem "guard-rspec"
17
17
  #gem 'ruby-debug-base19' if RUBY_VERSION.include? "1.9"
18
18
  #gem 'ruby-debug-base' if RUBY_VERSION.include? "1.8"
19
19
  #gem "ruby-debug-ide"
data/lib/neo4j/neo4j.rb CHANGED
@@ -236,6 +236,12 @@ module Neo4j
236
236
  this_db.management(jmx_clazz)
237
237
  end
238
238
 
239
+ # Only available using the neo4j-enterprise gem.
240
+ # @return [Boolean] true if the Neo4j database is the HA master
241
+ def ha_master?
242
+ Neo4j.management(Java::OrgNeo4jManagement::HighAvailability).isMaster
243
+ end
244
+
239
245
  # @return [Enumerable] all nodes in the database
240
246
  def all_nodes(this_db = self.started_db)
241
247
  Enumerator.new(this_db, :each_node)
@@ -10,6 +10,7 @@ module Neo4j
10
10
  #
11
11
  # @private
12
12
  class Database
13
+ include org.neo4j.kernel.GraphDatabaseAPI
13
14
 
14
15
  # The Java graph database
15
16
  # @see http://components.neo4j.org/neo4j/1.6.1/apidocs/org/neo4j/graphdb/GraphDatabaseService.html
@@ -41,6 +42,11 @@ module Neo4j
41
42
  @default_embedded_db = db
42
43
  end
43
44
 
45
+ def self.ha_enabled?
46
+ Neo4j::Config['ha.db']
47
+ end
48
+
49
+
44
50
  # Private start method, use Neo4j.start instead
45
51
  # @see Neo4j#start
46
52
  def start
@@ -51,7 +57,7 @@ module Neo4j
51
57
  begin
52
58
  if self.class.locked?
53
59
  start_readonly_graph_db
54
- elsif Neo4j::Config['ha.db']
60
+ elsif self.class.ha_enabled?
55
61
  start_ha_graph_db
56
62
  Neo4j.migrate! if Neo4j.respond_to?(:migrate!)
57
63
  else
@@ -103,6 +109,11 @@ module Neo4j
103
109
  @lucene = nil
104
110
  @running = false
105
111
  @neo4j_manager = nil
112
+ if self.class.ha_enabled?
113
+ Neo4j.logger.info "Neo4j (HA mode) has been shutdown, machine id: #{Neo4j.config['ha.server_id']} at #{Neo4j.config['ha.server']} db #{@storage_path}"
114
+ else
115
+ Neo4j.logger.info "Neo4j has been shutdown using storage_path: #{@storage_path}"
116
+ end
106
117
  end
107
118
  end
108
119
 
@@ -165,15 +176,6 @@ module Neo4j
165
176
  @event_handler.neo4j_started(self)
166
177
  end
167
178
 
168
- # needed by cypher
169
- def getNodeById(id) #:nodoc:
170
- Neo4j::Node.load(id)
171
- end
172
-
173
- # needed by cypher
174
- def getRelationshipById(id) #:nodoc:
175
- Neo4j::Relationship.load(id)
176
- end
177
179
 
178
180
  def start_ha_graph_db
179
181
  Neo4j.logger.info "starting Neo4j in HA mode, machine id: #{Neo4j.config['ha.server_id']} at #{Neo4j.config['ha.server']} db #{@storage_path}"
@@ -185,6 +187,24 @@ module Neo4j
185
187
  @event_handler.neo4j_started(self)
186
188
  end
187
189
 
190
+ # Implementation of org.neo4j.kernel.GraphDatabaseAPI
191
+ # For some strange reason Cypher seems to need those methods
192
+
193
+ # needed by cypher
194
+ def getNodeById(id)
195
+ Neo4j::Node.load(id)
196
+ end
197
+
198
+ # needed by cypher
199
+ def getRelationshipById(id)
200
+ Neo4j::Relationship.load(id)
201
+ end
202
+
203
+ # needed by cypher
204
+ def getNodeManager
205
+ @graph.getNodeManager
206
+ end
207
+
188
208
  end
189
209
  end
190
- end
210
+ end
@@ -4,7 +4,7 @@ module Neo4j
4
4
  # Implements the Neo4j Predicate Java interface, only used internally.
5
5
  # @private
6
6
  class FilterPredicate
7
- include Java::OrgNeo4jHelpers::Predicate
7
+ include Java::OrgNeo4jGraphdbTraversal::Evaluator
8
8
 
9
9
  def initialize
10
10
  @procs = []
@@ -14,15 +14,18 @@ module Neo4j
14
14
  @procs << proc
15
15
  end
16
16
 
17
- def include_start_node
18
- @include_start_node = true
19
- end
20
-
21
- def accept(path)
22
- return false if @include_start_node && path.length == 0
17
+ def evaluate(path)
18
+ if path.length == 0
19
+ return Java::OrgNeo4jGraphdbTraversal::Evaluation::EXCLUDE_AND_CONTINUE
20
+ end
23
21
  # find the first filter which returns false
24
22
  # if not found then we will accept this path
25
- @procs.find { |p| !p.call(path) }.nil?
23
+ if @procs.find { |p| !p.call(path) }.nil?
24
+ Java::OrgNeo4jGraphdbTraversal::Evaluation::INCLUDE_AND_CONTINUE
25
+ else
26
+ Java::OrgNeo4jGraphdbTraversal::Evaluation::EXCLUDE_AND_CONTINUE
27
+ end
28
+
26
29
  end
27
30
  end
28
31
  end
@@ -5,16 +5,21 @@ module Neo4j
5
5
  # Implements the Neo4j PruneEvaluator Java interface, only used internally.
6
6
  # @private
7
7
  class PruneEvaluator
8
- include Java::OrgNeo4jGraphdbTraversal::PruneEvaluator
8
+ include Java::OrgNeo4jGraphdbTraversal::Evaluator
9
9
 
10
10
  def initialize(proc)
11
11
  @proc = proc
12
12
  end
13
13
 
14
- def prune_after(path)
15
- @proc.call(path)
14
+ def evaluate(path)
15
+ return Java::OrgNeo4jGraphdbTraversal::Evaluation::EXCLUDE_AND_CONTINUE if path.length == 0
16
+ if @proc.call(path)
17
+ Java::OrgNeo4jGraphdbTraversal::Evaluation::INCLUDE_AND_PRUNE
18
+ else
19
+ Java::OrgNeo4jGraphdbTraversal::Evaluation::INCLUDE_AND_CONTINUE
20
+ end
16
21
  end
17
22
  end
18
23
  end
19
24
  end
20
- end
25
+ end
@@ -4,30 +4,30 @@ module Neo4j
4
4
  # Implements the Neo4j RelationshipExpander Java interface, only used internally.
5
5
  # @private
6
6
  class RelExpander
7
- include Java::OrgNeo4jGraphdb::RelationshipExpander
7
+ include Java::OrgNeo4jGraphdb::PathExpander
8
8
 
9
- attr_accessor :reversed
9
+ attr_accessor :reversed, :reverse
10
10
 
11
11
  def initialize(&block)
12
12
  @block = block
13
- @reverse = false
13
+ @reversed = false
14
14
  end
15
15
 
16
16
  def self.create_pair(&block)
17
17
  normal = RelExpander.new(&block)
18
18
  reversed = RelExpander.new(&block)
19
- normal.reversed = reversed
19
+ normal.reverse = reversed
20
20
  reversed.reversed = normal
21
21
  reversed.reverse!
22
22
  normal
23
23
  end
24
24
 
25
- def expand(node)
26
- @block.arity == 1 ? @block.call(node) : @block.call(node, @reverse)
25
+ def expand(node, _)
26
+ @block.arity == 1 ? @block.call(node) : @block.call(node, @reversed)
27
27
  end
28
28
 
29
29
  def reverse!
30
- @reverse = true
30
+ @reversed = true
31
31
  end
32
32
  end
33
33
  end
@@ -290,7 +290,7 @@ module Neo4j
290
290
  # a.outgoing(:friends).outgoing(:recommend).depth(:all).prune{|path| path.end_node[:name] == 'B'}
291
291
  # @see http://components.neo4j.org/neo4j/milestone/apidocs/org/neo4j/graphdb/Path.html
292
292
  def prune(&block)
293
- @td = @td.prune(PruneEvaluator.new(block))
293
+ @td = @td.evaluator(PruneEvaluator.new(block))
294
294
  self
295
295
  end
296
296
 
@@ -308,7 +308,7 @@ module Neo4j
308
308
  @filter_predicate.add(block)
309
309
 
310
310
 
311
- @td = @td.filter(@filter_predicate)
311
+ @td = @td.evaluator(@filter_predicate)
312
312
  self
313
313
  end
314
314
 
@@ -373,13 +373,9 @@ module Neo4j
373
373
  # @return the java iterator
374
374
  def iterator
375
375
  unless @include_start_node
376
- if @filter_predicate
377
- @filter_predicate.include_start_node
378
- else
379
- @td = @td.filter(Java::OrgNeo4jKernel::Traversal.return_all_but_start_node)
380
- end
376
+ @td = @td.evaluator(Java::OrgNeo4jGraphdbTraversal::Evaluators.exclude_start_position)
381
377
  end
382
- @td = @td.prune(Java::OrgNeo4jKernel::Traversal.pruneAfterDepth(@depth)) unless @depth == :all
378
+ @td = @td.evaluator(Java::OrgNeo4jGraphdbTraversal::Evaluators.toDepth(@depth)) unless @depth == :all
383
379
  if @traversal_result == :rels
384
380
  @td.traverse(@from._java_node).relationships
385
381
  elsif @traversal_result == :paths
@@ -1,5 +1,5 @@
1
1
  module Neo4j
2
2
  module Core
3
- VERSION = "2.0.1"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
data/neo4j-core.gemspec CHANGED
@@ -27,5 +27,5 @@ It comes included with the Apache Lucene document database.
27
27
  s.extra_rdoc_files = %w( README.rdoc )
28
28
  s.rdoc_options = ["--quiet", "--title", "Neo4j::Core", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
29
29
 
30
- s.add_dependency("neo4j-community", ">= 1.7.0")
30
+ s.add_dependency("neo4j-community", '>= 1.8.M05', '< 1.9')
31
31
  end
metadata CHANGED
@@ -1,122 +1,172 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: neo4j-core
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.0.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.1.0
6
6
  platform: java
7
- authors:
8
- - Andreas Ronge
9
- autorequire:
7
+ authors:
8
+ - Andreas Ronge
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-06-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: neo4j-community
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.7.0
24
- type: :runtime
25
- version_requirements: *id001
26
- description: |
27
- You can think of Neo4j as a high-performance graph engine with all the features of a mature and robust database.
28
- The programmer works with an object-oriented, flexible network structure rather than with strict and static tables
29
- yet enjoys all the benefits of a fully transactional, enterprise-strength database.
30
- It comes included with the Apache Lucene document database.
31
-
12
+ date: 2012-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: neo4j-community
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.8.M05
21
+ - - !binary |-
22
+ PA==
23
+ - !ruby/object:Gem::Version
24
+ version: '1.9'
25
+ none: false
26
+ requirement: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.8.M05
31
+ - - !binary |-
32
+ PA==
33
+ - !ruby/object:Gem::Version
34
+ version: '1.9'
35
+ none: false
36
+ prerelease: false
37
+ type: :runtime
38
+ description: ! "You can think of Neo4j as a high-performance graph engine with all\
39
+ \ the features of a mature and robust database.\nThe programmer works with an object-oriented,\
40
+ \ flexible network structure rather than with strict and static tables \nyet enjoys\
41
+ \ all the benefits of a fully transactional, enterprise-strength database.\nIt comes\
42
+ \ included with the Apache Lucene document database.\n"
32
43
  email: andreas.ronge@gmail.com
33
44
  executables: []
34
-
35
45
  extensions: []
36
-
37
- extra_rdoc_files:
38
- - README.rdoc
39
- files:
40
- - lib/neo4j-core.rb
41
- - lib/test.rb~
42
- - lib/neo4j/config.rb
43
- - lib/neo4j/algo.rb
44
- - lib/neo4j/cypher.rb
45
- - lib/neo4j/transaction.rb
46
- - lib/neo4j/neo4j.rb
47
- - lib/neo4j/neo4j.rb~
48
- - lib/neo4j/node.rb
49
- - lib/neo4j/relationship.rb
50
- - lib/neo4j-core/event_handler.rb
51
- - lib/neo4j-core/lazy_map.rb
52
- - lib/neo4j-core/hash_with_indifferent_access.rb
53
- - lib/neo4j-core/database.rb
54
- - lib/neo4j-core/relationship_set.rb
55
- - lib/neo4j-core/version.rb
56
- - lib/neo4j-core/to_java.rb
57
- - lib/neo4j-core/node/node.rb
58
- - lib/neo4j-core/node/class_methods.rb
59
- - lib/neo4j-core/property/java.rb
60
- - lib/neo4j-core/property/property.rb
61
- - lib/neo4j-core/equal/equal.rb
62
- - lib/neo4j-core/traversal/rel_expander.rb
63
- - lib/neo4j-core/traversal/filter_predicate.rb
64
- - lib/neo4j-core/traversal/prune_evaluator.rb
65
- - lib/neo4j-core/traversal/traversal.rb
66
- - lib/neo4j-core/traversal/traverser.rb
67
- - lib/neo4j-core/traversal/evaluator.rb
68
- - lib/neo4j-core/rels/traverser.rb
69
- - lib/neo4j-core/rels/rels.rb
70
- - lib/neo4j-core/wrapper/wrapper.rb
71
- - lib/neo4j-core/wrapper/class_methods.rb
72
- - lib/neo4j-core/index/index_config.rb
73
- - lib/neo4j-core/index/indexer.rb
74
- - lib/neo4j-core/index/lucene_query.rb
75
- - lib/neo4j-core/index/indexer_registry.rb
76
- - lib/neo4j-core/index/unique_factory.rb
77
- - lib/neo4j-core/index/class_methods.rb
78
- - lib/neo4j-core/index/index.rb
79
- - lib/neo4j-core/relationship/class_methods.rb
80
- - lib/neo4j-core/relationship/relationship.rb
81
- - lib/neo4j-core/cypher/cypher.rb
82
- - lib/neo4j-core/cypher/result_wrapper.rb
83
- - config/neo4j/config.yml
84
- - README.rdoc
85
- - Gemfile
86
- - neo4j-core.gemspec
46
+ extra_rdoc_files:
47
+ - README.rdoc
48
+ files:
49
+ - !binary |-
50
+ bGliL25lbzRqLWNvcmUucmI=
51
+ - !binary |-
52
+ bGliL25lbzRqL2FsZ28ucmI=
53
+ - !binary |-
54
+ bGliL25lbzRqL2NvbmZpZy5yYg==
55
+ - !binary |-
56
+ bGliL25lbzRqL2N5cGhlci5yYg==
57
+ - !binary |-
58
+ bGliL25lbzRqL25lbzRqLnJi
59
+ - !binary |-
60
+ bGliL25lbzRqL25vZGUucmI=
61
+ - !binary |-
62
+ bGliL25lbzRqL3JlbGF0aW9uc2hpcC5yYg==
63
+ - !binary |-
64
+ bGliL25lbzRqL3RyYW5zYWN0aW9uLnJi
65
+ - !binary |-
66
+ bGliL25lbzRqLWNvcmUvZGF0YWJhc2UucmI=
67
+ - !binary |-
68
+ bGliL25lbzRqLWNvcmUvZXZlbnRfaGFuZGxlci5yYg==
69
+ - !binary |-
70
+ bGliL25lbzRqLWNvcmUvaGFzaF93aXRoX2luZGlmZmVyZW50X2FjY2Vzcy5y
71
+ Yg==
72
+ - !binary |-
73
+ bGliL25lbzRqLWNvcmUvbGF6eV9tYXAucmI=
74
+ - !binary |-
75
+ bGliL25lbzRqLWNvcmUvcmVsYXRpb25zaGlwX3NldC5yYg==
76
+ - !binary |-
77
+ bGliL25lbzRqLWNvcmUvdG9famF2YS5yYg==
78
+ - !binary |-
79
+ bGliL25lbzRqLWNvcmUvdmVyc2lvbi5yYg==
80
+ - !binary |-
81
+ bGliL25lbzRqLWNvcmUvY3lwaGVyL2N5cGhlci5yYg==
82
+ - !binary |-
83
+ bGliL25lbzRqLWNvcmUvY3lwaGVyL3Jlc3VsdF93cmFwcGVyLnJi
84
+ - !binary |-
85
+ bGliL25lbzRqLWNvcmUvZXF1YWwvZXF1YWwucmI=
86
+ - !binary |-
87
+ bGliL25lbzRqLWNvcmUvaW5kZXgvY2xhc3NfbWV0aG9kcy5yYg==
88
+ - !binary |-
89
+ bGliL25lbzRqLWNvcmUvaW5kZXgvaW5kZXgucmI=
90
+ - !binary |-
91
+ bGliL25lbzRqLWNvcmUvaW5kZXgvaW5kZXhfY29uZmlnLnJi
92
+ - !binary |-
93
+ bGliL25lbzRqLWNvcmUvaW5kZXgvaW5kZXhlci5yYg==
94
+ - !binary |-
95
+ bGliL25lbzRqLWNvcmUvaW5kZXgvaW5kZXhlcl9yZWdpc3RyeS5yYg==
96
+ - !binary |-
97
+ bGliL25lbzRqLWNvcmUvaW5kZXgvbHVjZW5lX3F1ZXJ5LnJi
98
+ - !binary |-
99
+ bGliL25lbzRqLWNvcmUvaW5kZXgvdW5pcXVlX2ZhY3RvcnkucmI=
100
+ - !binary |-
101
+ bGliL25lbzRqLWNvcmUvbm9kZS9jbGFzc19tZXRob2RzLnJi
102
+ - !binary |-
103
+ bGliL25lbzRqLWNvcmUvbm9kZS9ub2RlLnJi
104
+ - !binary |-
105
+ bGliL25lbzRqLWNvcmUvcHJvcGVydHkvamF2YS5yYg==
106
+ - !binary |-
107
+ bGliL25lbzRqLWNvcmUvcHJvcGVydHkvcHJvcGVydHkucmI=
108
+ - !binary |-
109
+ bGliL25lbzRqLWNvcmUvcmVsYXRpb25zaGlwL2NsYXNzX21ldGhvZHMucmI=
110
+ - !binary |-
111
+ bGliL25lbzRqLWNvcmUvcmVsYXRpb25zaGlwL3JlbGF0aW9uc2hpcC5yYg==
112
+ - !binary |-
113
+ bGliL25lbzRqLWNvcmUvcmVscy9yZWxzLnJi
114
+ - !binary |-
115
+ bGliL25lbzRqLWNvcmUvcmVscy90cmF2ZXJzZXIucmI=
116
+ - !binary |-
117
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL2V2YWx1YXRvci5yYg==
118
+ - !binary |-
119
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL2ZpbHRlcl9wcmVkaWNhdGUucmI=
120
+ - !binary |-
121
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL3BydW5lX2V2YWx1YXRvci5yYg==
122
+ - !binary |-
123
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL3JlbF9leHBhbmRlci5yYg==
124
+ - !binary |-
125
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL3RyYXZlcnNhbC5yYg==
126
+ - !binary |-
127
+ bGliL25lbzRqLWNvcmUvdHJhdmVyc2FsL3RyYXZlcnNlci5yYg==
128
+ - !binary |-
129
+ bGliL25lbzRqLWNvcmUvd3JhcHBlci9jbGFzc19tZXRob2RzLnJi
130
+ - !binary |-
131
+ bGliL25lbzRqLWNvcmUvd3JhcHBlci93cmFwcGVyLnJi
132
+ - !binary |-
133
+ Y29uZmlnL25lbzRqL2NvbmZpZy55bWw=
134
+ - README.rdoc
135
+ - Gemfile
136
+ - neo4j-core.gemspec
87
137
  homepage: http://github.com/andreasronge/neo4j-core/tree
88
138
  licenses: []
89
-
90
- post_install_message:
91
- rdoc_options:
92
- - --quiet
93
- - --title
94
- - Neo4j::Core
95
- - --line-numbers
96
- - --main
97
- - README.rdoc
98
- - --inline-source
99
- require_paths:
100
- - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
139
+ post_install_message:
140
+ rdoc_options:
141
+ - --quiet
142
+ - --title
143
+ - Neo4j::Core
144
+ - --line-numbers
145
+ - --main
146
+ - README.rdoc
147
+ - --inline-source
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: 1.8.7
102
155
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 1.8.7
107
- required_rubygems_version: !ruby/object:Gem::Requirement
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ segments:
161
+ - 0
162
+ hash: 2
163
+ version: !binary |-
164
+ MA==
108
165
  none: false
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: "0"
113
166
  requirements: []
114
-
115
167
  rubyforge_project: neo4j-core
116
- rubygems_version: 1.8.15
117
- signing_key:
168
+ rubygems_version: 1.8.24
169
+ signing_key:
118
170
  specification_version: 3
119
171
  summary: A graph database for JRuby
120
172
  test_files: []
121
-
122
- has_rdoc: true
data/lib/neo4j/neo4j.rb~ DELETED
@@ -1,214 +0,0 @@
1
- require 'neo4j-core/database'
2
-
3
- # = Neo4j
4
- #
5
- # The Neo4j modules is used to interact with an Neo4j Database instance.
6
- # You can for example start and stop an instance and list all the nodes that exist in the database.
7
- #
8
- # === Starting and Stopping Neo4j
9
- # You don't normally need to start the Neo4j database since it will be automatically started when needed.
10
- # Before the database is started you should configure where the database is stored, see Neo4j::Config.
11
- #
12
- module Neo4j
13
-
14
- # The version of the Neo4j jar files
15
- NEO_VERSION = Neo4j::Community::VERSION
16
-
17
- class << self
18
- # Start Neo4j using the default database.
19
- # This is usally not required since the database will be started automatically when it is used.
20
- # If the global variable $NEO4J_SERVER is defined then it will use that as the Java Graph DB. This can
21
- # be used if you want to embed neo4j.rb and already got an instance of the Java Neo4j Database service.
22
- #
23
- # ==== Parameters
24
- # 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.
25
- # external_db :: (optionally) use this Java Neo4j instead of creating a new neo4j database service
26
- def start(config_file=nil, external_db = $NEO4J_SERVER)
27
- return if @db && @db.running?
28
-
29
- Neo4j.config.default_file = config_file if config_file
30
- if external_db
31
- @db ||= Database.new
32
- self.db.start_external_db(external_db)
33
- else
34
- db.start
35
- end
36
- end
37
-
38
-
39
- # Sets the Neo4j::Database instance to use
40
- # An Neo4j::Database instance wraps both the Neo4j Database and Lucene Database.
41
- def db=(my_db)
42
- @db = my_db
43
- end
44
-
45
- # Returns the database holding references to both the Neo4j Graph Database and the Lucene Database.
46
- # Creates a new one if it does not exist, but does not start it.
47
- def db
48
- @db ||= Neo4j::Core::Database.new
49
- end
50
-
51
- def read_only?
52
- @db && @db.graph && @db.graph.read_only?
53
- end
54
-
55
- # Returns a started db instance. Starts it's not running.
56
- # if $NEO4J_SERVER is defined then use that Java Neo4j Database service instead of creating a new one.
57
- def started_db
58
- start unless db.running?
59
- db
60
- end
61
-
62
- # Returns the current storage path of a running neo4j database.
63
- # If the database is not running it returns nil.
64
- def storage_path
65
- return nil unless db.running?
66
- db.storage_path
67
- end
68
-
69
- # Returns the Neo4j::Config class
70
- # Same as typing; Neo4j::Config
71
- def config
72
- Neo4j::Config
73
- end
74
-
75
- # Executes a Cypher Query
76
- # Check the neo4j http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html
77
- # Returns an enumerable of hash values.
78
- #
79
- # === Usage
80
- #
81
- # q = Neo4j.query("START n=node({node}) RETURN n", 'node' => @node.neo_id)
82
- # q.first['n'] #=> the @node
83
- # q.columns.first => 'n'
84
- #
85
- def query(query, params = {})
86
- engine = org.neo4j.cypher.javacompat.ExecutionEngine.new(db)
87
- engine.execute(query, params)
88
- end
89
-
90
-
91
- # Returns the logger used by neo4j.
92
- # If not specified (with Neo4j.logger=) it will use the standard Ruby logger.
93
- # You can change standard logger threshold by configuration :logger_level.
94
- #
95
- # You can also specify which logger class should take care of logging with the
96
- # :logger configuration.
97
- #
98
- # ==== Example
99
- #
100
- # Neo4j::Config[:logger] = Logger.new(STDOUT)
101
- # Neo4j::Config[:logger_level] = Logger::ERROR
102
- #
103
- def logger
104
- @logger ||= Neo4j::Config[:logger] || default_logger
105
- end
106
-
107
- # Sets which logger should be used.
108
- # If this this is not called then the standard Ruby logger will be used.
109
- def logger=(logger)
110
- @logger = logger
111
- end
112
-
113
- def default_logger #:nodoc:
114
- require 'logger'
115
- logger = Logger.new(STDOUT)
116
- logger.sev_threshold = Neo4j::Config[:logger_level] || Logger::INFO
117
- logger
118
- end
119
-
120
-
121
- # Returns an unstarted db instance
122
- #
123
- # This is typically used for configuring the database, which must sometimes
124
- # be done before the database is started
125
- # if the database was already started an exception will be raised
126
- def unstarted_db
127
- @db ||= Database.new
128
- raise "database was already started" if @db.running?
129
- @db
130
- end
131
-
132
- # returns true if the database is running
133
- def running?
134
- @db && @db.running?
135
- end
136
-
137
-
138
- # Stops this database
139
- # There are Ruby hooks that will do this automatically for you.
140
- #
141
- def shutdown(this_db = @db)
142
- this_db.shutdown if this_db
143
- end
144
-
145
-
146
- # Returns the default reference node, which is a "starting point" in the node space.
147
- #
148
- def default_ref_node(this_db = self.started_db)
149
- this_db.graph.reference_node
150
- end
151
-
152
- # Returns the reference node, which is a "starting point" in the node space.
153
- # In case the ref_node has been assigned via the threadlocal_ref_node method, then that node will be returned instead.
154
- #
155
- # Usually, a client attaches relationships to this node that leads into various parts of the node space.
156
- # For more information about common node space organizational patterns, see the design guide at http://wiki.neo4j.org/content/Design_Guide
157
- #
158
- def ref_node(this_db = self.started_db)
159
- return Thread.current[:local_ref_node] if Thread.current[:local_ref_node]
160
- default_ref_node(this_db)
161
- end
162
-
163
- # Changes the reference node on a threadlocal basis.
164
- # This can be used to achieve multitenancy. All new entities will be attached to the new ref_node,
165
- # which effectively partitions the graph, and hence scopes traversals.
166
- def threadlocal_ref_node=(reference_node)
167
- Thread.current[:local_ref_node] = reference_node.nil? ? nil : reference_node._java_node
168
- end
169
-
170
- # Returns a Management JMX Bean.
171
- #
172
- # Notice that this information is also provided by the jconsole Java tool, check http://wiki.neo4j.org/content/Monitoring_and_Deployment
173
- # and http://docs.neo4j.org/chunked/milestone/operations-monitoring.html
174
- #
175
- # By default it returns the Primitivies JMX Bean that can be used to find number of nodes in use.
176
- #
177
- # ==== Example Neo4j Primititives
178
- #
179
- # Neo4j.management.get_number_of_node_ids_in_use
180
- # Neo4j.management.getNumberOfPropertyIdsInUse
181
- # Neo4j.management.getNumberOfRelationshipIdsInUse
182
- # Neo4j.management.get_number_of_relationship_type_ids_in_use
183
- #
184
- # ==== Example Neo4j HA Cluster Info
185
- #
186
- # Neo4j.management(org.neo4j.management.HighAvailability).isMaster
187
- #
188
- # ==== Arguments
189
- #
190
- # jmx_clazz :: http://api.neo4j.org/current/org/neo4j/management/package-summary.html
191
- # this_db :: default currently runnig instance or a newly started neo4j db instance
192
- #
193
- def management(jmx_clazz = org.neo4j.jmx.Primitives, this_db = self.started_db)
194
- this_db.management(jmx_clazz)
195
- end
196
-
197
- # Returns an Enumerable object for all nodes in the database
198
- def all_nodes(this_db = self.started_db)
199
- Enumerator.new(this_db, :each_node)
200
- end
201
-
202
- # Same as #all_nodes but does not return wrapped nodes but instead raw java node objects.
203
- def _all_nodes(this_db = self.started_db)
204
- Enumerator.new(this_db, :_each_node)
205
- end
206
-
207
- # Returns the Neo4j::EventHandler
208
- #
209
- def event_handler(this_db = db)
210
- this_db.event_handler
211
- end
212
-
213
- end
214
- end
data/lib/test.rb~ DELETED
@@ -1,27 +0,0 @@
1
- require 'rubygems'
2
- require 'neo4j-core'
3
-
4
-
5
- def connect(d)
6
- d.each{|i| Neo4j::Relationship.new(:flies_to, i[:from], i[:to])}
7
- end
8
-
9
- puts "Using #{Neo4j::Core::VERSION}"
10
-
11
- tx = Neo4j::Transaction.new
12
- @a, @b, @c, @z = (1..4).map{Neo4j::Node.new}
13
- connect([ {:from=>@a, :to=>@b}, {:from=>@a, :to=>@c}, {:from=>@b, :to=>@c},
14
- {:from=>@b, :to=>@z}, {:from=>@c, :to=>@b}, {:from=>@c, :to=>@z}])
15
- tx.success
16
- tx.finish
17
-
18
-
19
- traversal = @a.outgoing(:flies_to).depth(:all).eval_paths { |path| :include_and_continue }
20
-
21
- # This prints out
22
- #Path (1)--[flies_to,0]-->(2)
23
- #Path (1)--[flies_to,1]-->(3)
24
- #Path (1)--[flies_to,0]-->(2)--[flies_to,3]-->(4)
25
- traversal.paths.each do |path|
26
- puts "Path #{path.to_s}"
27
- end