Module: Neo4j
- Defined in:
- lib/neo4j/neo4j.rb,
lib/neo4j-core.rb,
lib/neo4j/algo.rb,
lib/neo4j/node.rb,
lib/neo4j/config.rb,
lib/neo4j/cypher.rb,
lib/neo4j/transaction.rb,
lib/neo4j-core/to_java.rb,
lib/neo4j-core/version.rb,
lib/neo4j/relationship.rb,
lib/neo4j-core/database.rb,
lib/neo4j-core/lazy_map.rb,
lib/neo4j-core/node/node.rb,
lib/neo4j-core/rels/rels.rb,
lib/neo4j-core/equal/equal.rb,
lib/neo4j-core/index/index.rb,
lib/neo4j-core/cypher/cypher.rb,
lib/neo4j-core/event_handler.rb,
lib/neo4j-core/index/indexer.rb,
lib/neo4j-core/property/java.rb,
lib/neo4j-core/rels/traverser.rb,
lib/neo4j-core/wrapper/wrapper.rb,
lib/neo4j-core/relationship_set.rb,
lib/neo4j-core/property/property.rb,
lib/neo4j-core/index/index_config.rb,
lib/neo4j-core/index/lucene_query.rb,
lib/neo4j-core/node/class_methods.rb,
lib/neo4j-core/index/class_methods.rb,
lib/neo4j-core/traversal/evaluator.rb,
lib/neo4j-core/traversal/traversal.rb,
lib/neo4j-core/traversal/traverser.rb,
lib/neo4j-core/index/unique_factory.rb,
lib/neo4j-core/cypher/result_wrapper.rb,
lib/neo4j-core/wrapper/class_methods.rb,
lib/neo4j-core/index/indexer_registry.rb,
lib/neo4j-core/traversal/rel_expander.rb,
lib/neo4j-core/relationship/relationship.rb,
lib/neo4j-core/traversal/prune_evaluator.rb,
lib/neo4j-core/relationship/class_methods.rb,
lib/neo4j-core/traversal/filter_predicate.rb,
lib/neo4j-core/hash_with_indifferent_access.rb
Overview
Neo4j
The Neo4j modules is used to interact with an Neo4j Database instance. You can for example start and stop an instance and list all the nodes that exist in the database.
Notice - Starting and Stopping Neo4j
You don’t normally need to start the Neo4j database since it will be automatically started when needed. Before the database is started you should configure where the database is stored, see Config].
Defined Under Namespace
Modules: Core Classes: Algo, Config, Cypher, Node, Relationship, Transaction
Constant Summary collapse
- Enumerator =
Enumerator has been moved to top level in Ruby 1.9.2, make it compatible with Ruby 1.8.7
Enumerable::Enumerator
- NEO_VERSION =
Returns The version of the Neo4j jar files.
Neo4j::Community::VERSION
Class Method Summary collapse
-
._all_nodes(this_db = self.started_db) ⇒ Enumerable
All nodes in the database but not wrapped in ruby classes.
-
._query(q) ⇒ Object
Performs a cypher query with given string.
-
.all_nodes(this_db = self.started_db) ⇒ Enumerable
All nodes in the database.
-
.config ⇒ Neo4j::Config
Same as typing; Neo4j::Config.
-
.db ⇒ Neo4j::Database
Returns the database holding references to both the Neo4j Graph Database and the Lucene Database.
-
.db=(my_db) ⇒ Object
Sets which Neo4j::Database instance to use.
-
.default_logger ⇒ Object
The default Ruby logger.
-
.default_ref_node(this_db = self.started_db) ⇒ Object
The default reference node, which is a “starting point” in the node space.
-
.event_handler(this_db = db) ⇒ Neo4j::Core::EventHandler
The event handler.
-
.ha_master? ⇒ Boolean
Only available using the neo4j-enterprise gem.
-
.logger ⇒ Object
Returns the logger used by neo4j.
-
.logger=(logger) ⇒ Object
Sets which logger should be used.
-
.management(jmx_clazz = Java::OrgNeo4jJmx::Primitives, this_db = self.started_db) ⇒ Object
Returns a Management JMX Bean.
-
.query(*params, &query_dsl) ⇒ Neo4j::Core::Cypher::ResultWrapper
Executes a Cypher Query Check the neo4j Returns an enumerable of hash values.
-
.read_only? ⇒ true, false
Checks read only mode of the database.
-
.ref_node(this_db = self.started_db) ⇒ Object
Usually, a client attaches relationships to this node that leads into various parts of the node space.
-
.running? ⇒ true, false
If the database is running.
-
.shutdown(this_db = @db) ⇒ Object
Stops this database There are Ruby hooks that will do this automatically for you.
-
.start(config_file = nil, external_db = $NEO4J_SERVER) ⇒ Object
Start Neo4j using the default database.
-
.started_db ⇒ Neo4j::Database
Returns a started db instance.
-
.storage_path ⇒ String
If the database is not running it returns Neo4j::Config.storage_path otherwise it asks the database.
-
.threadlocal_ref_node=(reference_node) ⇒ Object
Changes the reference node on a threadlocal basis.
-
.unstarted_db ⇒ Neo4j::Database
Returns an unstarted db instance.
Class Method Details
._all_nodes(this_db = self.started_db) ⇒ Enumerable
Returns all nodes in the database but not wrapped in ruby classes.
251 252 253 |
# File 'lib/neo4j/neo4j.rb', line 251 def _all_nodes(this_db = self.started_db) Enumerator.new(this_db, :_each_node) end |
._query(q) ⇒ Object
Performs a cypher query with given string
124 125 126 127 128 |
# File 'lib/neo4j/neo4j.rb', line 124 def _query(q) engine = Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(db) result = engine.execute(q) Neo4j::Core::Cypher::ResultWrapper.new(result) end |
.all_nodes(this_db = self.started_db) ⇒ Enumerable
Returns all nodes in the database.
246 247 248 |
# File 'lib/neo4j/neo4j.rb', line 246 def all_nodes(this_db = self.started_db) Enumerator.new(this_db, :each_node) end |
.config ⇒ Neo4j::Config
Same as typing; Neo4j::Config
84 85 86 |
# File 'lib/neo4j/neo4j.rb', line 84 def config Neo4j::Config end |
.db ⇒ Neo4j::Database
Returns the database holding references to both the Neo4j Graph Database and the Lucene Database. Creates a new one if it does not exist, but does not start it.
56 57 58 |
# File 'lib/neo4j/neo4j.rb', line 56 def db @db ||= Neo4j::Core::Database.new end |
.db=(my_db) ⇒ Object
Sets which Neo4j::Database instance to use. It wraps both the Neo4j Database and Lucene Database.
48 49 50 |
# File 'lib/neo4j/neo4j.rb', line 48 def db=(my_db) @db = my_db end |
.default_logger ⇒ Object
Returns the default Ruby logger.
156 157 158 159 160 161 |
# File 'lib/neo4j/neo4j.rb', line 156 def default_logger #:nodoc: require 'logger' logger = Logger.new(STDOUT) logger.sev_threshold = Neo4j::Config[:logger_level] || Logger::INFO logger end |
.default_ref_node(this_db = self.started_db) ⇒ Object
Returns the default reference node, which is a “starting point” in the node space.
190 191 192 |
# File 'lib/neo4j/neo4j.rb', line 190 def default_ref_node(this_db = self.started_db) this_db.graph.reference_node end |
.event_handler(this_db = db) ⇒ Neo4j::Core::EventHandler
Returns the event handler.
256 257 258 |
# File 'lib/neo4j/neo4j.rb', line 256 def event_handler(this_db = db) this_db.event_handler end |
.ha_master? ⇒ Boolean
Only available using the neo4j-enterprise gem.
241 242 243 |
# File 'lib/neo4j/neo4j.rb', line 241 def ha_master? Neo4j.management(Java::OrgNeo4jManagement::HighAvailability).isMaster end |
.logger ⇒ Object
Returns the logger used by neo4j. If not specified (with Neo4j.logger=) it will use the standard Ruby logger. You can change standard logger threshold by configuration :logger_level.
You can also specify which logger class should take care of logging with the :logger configuration.
144 145 146 |
# File 'lib/neo4j/neo4j.rb', line 144 def logger @logger ||= Neo4j::Config[:logger] || default_logger end |
.logger=(logger) ⇒ Object
Sets which logger should be used. If this this is not called then the standard Ruby logger will be used.
151 152 153 |
# File 'lib/neo4j/neo4j.rb', line 151 def logger=(logger) @logger = logger end |
.management(jmx_clazz = Java::OrgNeo4jJmx::Primitives, this_db = self.started_db) ⇒ Object
Returns a Management JMX Bean.
Notice that this information is also provided by the jconsole Java tool, check wiki.neo4j.org/content/Monitoring_and_Deployment and docs.neo4j.org/chunked/milestone/operations-monitoring.html. Some of these management features are only available when using the neo4j-advanced and neo4j-enterprise gems.
By default it returns the Primitivies JMX Bean that can be used to find number of nodes in use.
Notice you must require the neo4j-advanced gem for these stats.
235 236 237 |
# File 'lib/neo4j/neo4j.rb', line 235 def management(jmx_clazz = Java::OrgNeo4jJmx::Primitives, this_db = self.started_db) this_db.management(jmx_clazz) end |
.query(*params, &query_dsl) ⇒ Neo4j::Core::Cypher::ResultWrapper
Returns a read-once only forward iterable.
Executes a Cypher Query Check the neo4j Returns an enumerable of hash values.
116 117 118 119 |
# File 'lib/neo4j/neo4j.rb', line 116 def query(*params, &query_dsl) q = Cypher.new(*params, &query_dsl).to_s _query(q) end |
.read_only? ⇒ true, false
Checks read only mode of the database. Only one process can have write access to the database. It will always return false if the database is not started yet.
63 64 65 |
# File 'lib/neo4j/neo4j.rb', line 63 def read_only? !!(@db && @db.graph && @db.read_only?) end |
.ref_node(this_db = self.started_db) ⇒ Object
In case the ref_node has been assigned via the threadlocal_ref_node method, then that node will be returned instead.
Usually, a client attaches relationships to this node that leads into various parts of the node space. ®return the reference node, which is a “starting point” in the node space.
198 199 200 201 |
# File 'lib/neo4j/neo4j.rb', line 198 def ref_node(this_db = self.started_db) return Thread.current[:local_ref_node] if Thread.current[:local_ref_node] default_ref_node(this_db) end |
.running? ⇒ true, false
Returns if the database is running.
177 178 179 |
# File 'lib/neo4j/neo4j.rb', line 177 def running? !!(@db && @db.running?) end |
.shutdown(this_db = @db) ⇒ Object
Stops this database There are Ruby hooks that will do this automatically for you.
184 185 186 |
# File 'lib/neo4j/neo4j.rb', line 184 def shutdown(this_db = @db) this_db.shutdown if this_db end |
.start(config_file = nil, external_db = $NEO4J_SERVER) ⇒ Object
Start Neo4j using the default database. This is usually not required since the database will be started automatically when it is used. If the global variable $NEO4J_SERVER is defined then it will use that as the Java Graph DB. This can be used if you want to embed neo4j.rb and already got an instance of the Java Neo4j Database service.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/neo4j/neo4j.rb', line 33 def start(config_file=nil, external_db = $NEO4J_SERVER) return if @db && @db.running? Neo4j.config.default_file = config_file if config_file if external_db @db ||= Neo4j::Core::Database.new self.db.start_external_db(external_db) else db.start end end |
.started_db ⇒ Neo4j::Database
Returns a started db instance. Starts it’s not running. if $NEO4J_SERVER is defined then use that Java Neo4j Database service instead of creating a new one.
70 71 72 73 |
# File 'lib/neo4j/neo4j.rb', line 70 def started_db start unless db.running? db end |
.storage_path ⇒ String
If the database is not running it returns Neo4j::Config.storage_path otherwise it asks the database
77 78 79 80 |
# File 'lib/neo4j/neo4j.rb', line 77 def storage_path return Neo4j::Config.storage_path unless db.running? db.storage_path end |
.threadlocal_ref_node=(reference_node) ⇒ Object
Changes the reference node on a threadlocal basis. This can be used to achieve multitenancy. All new entities will be attached to the new ref_node, which effectively partitions the graph, and hence scopes traversals.
206 207 208 |
# File 'lib/neo4j/neo4j.rb', line 206 def threadlocal_ref_node=(reference_node) Thread.current[:local_ref_node] = reference_node.nil? ? nil : reference_node._java_node end |
.unstarted_db ⇒ Neo4j::Database
Returns an unstarted db instance
This is typically used for configuring the database, which must sometimes be done before the database is started if the database was already started an exception will be raised
170 171 172 173 174 |
# File 'lib/neo4j/neo4j.rb', line 170 def unstarted_db @db ||= Neo4j::Core::Database.new raise "database was already started" if @db.running? @db end |