Save or load a graph using an actual Neo4j database.

Introduced properties

fun batch_max_size: Int

neo4j :: Neo4jGraphStore :: batch_max_size

The maximum number of entities saved in one request.
fun batch_max_size=(batch_max_size: Int)

neo4j :: Neo4jGraphStore :: batch_max_size=

The maximum number of entities saved in one request.
fun client: Neo4jClient

neo4j :: Neo4jGraphStore :: client

The Neo4j client to use.
protected fun client=(client: Neo4jClient)

neo4j :: Neo4jGraphStore :: client=

The Neo4j client to use.
init defaultinit(graph: NeoGraph, client: Neo4jClient, node_label: String)

neo4j :: Neo4jGraphStore :: defaultinit

fun has_node_label(name: String): Bool

neo4j :: Neo4jGraphStore :: has_node_label

Is the database already contains at least one node with the specified label?
fun node_label: String

neo4j :: Neo4jGraphStore :: node_label

The label to use to retrieve the nodes.
protected fun node_label=(node_label: String)

neo4j :: Neo4jGraphStore :: node_label=

The label to use to retrieve the nodes.

Redefined properties

redef type SELF: Neo4jGraphStore

neo4j $ Neo4jGraphStore :: SELF

Type of this instance, automatically specialized in every class
redef fun isolated_save: Bool

neo4j $ Neo4jGraphStore :: isolated_save

Can we save the graph without conflict?
redef fun load

neo4j $ Neo4jGraphStore :: load

Load the graph (or a part of it).
redef fun save_part(nodes: Collection[NeoNode], edges: Collection[NeoEdge])

neo4j $ Neo4jGraphStore :: save_part

Save the specified part of the graph.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun batch_max_size: Int

neo4j :: Neo4jGraphStore :: batch_max_size

The maximum number of entities saved in one request.
fun batch_max_size=(batch_max_size: Int)

neo4j :: Neo4jGraphStore :: batch_max_size=

The maximum number of entities saved in one request.
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun client: Neo4jClient

neo4j :: Neo4jGraphStore :: client

The Neo4j client to use.
protected fun client=(client: Neo4jClient)

neo4j :: Neo4jGraphStore :: client=

The Neo4j client to use.
init defaultinit(graph: NeoGraph, client: Neo4jClient, node_label: String)

neo4j :: Neo4jGraphStore :: defaultinit

protected fun fire_done

progression :: Trackable :: fire_done

Notice the registered ProgessionListener that the operation is done.
protected fun fire_progressed(done_part: Int, total: Int)

progression :: Trackable :: fire_progressed

Notice the registered ProgessionListener that the operation progressed.
protected fun fire_started

progression :: Trackable :: fire_started

Notice the registered ProgessionListener that the operation started.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun graph: NeoGraph

neo4j :: GraphStore :: graph

The graph to save or load.
protected fun graph=(graph: NeoGraph)

neo4j :: GraphStore :: graph=

The graph to save or load.
fun has_node_label(name: String): Bool

neo4j :: Neo4jGraphStore :: has_node_label

Is the database already contains at least one node with the specified label?
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
abstract fun isolated_save: Bool

neo4j :: GraphStore :: isolated_save

Can we save the graph without conflict?
abstract fun load

neo4j :: GraphStore :: load

Load the graph (or a part of it).
fun node_label: String

neo4j :: Neo4jGraphStore :: node_label

The label to use to retrieve the nodes.
protected fun node_label=(node_label: String)

neo4j :: Neo4jGraphStore :: node_label=

The label to use to retrieve the nodes.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
protected fun progression_listeners=(progression_listeners: SimpleCollection[ProgressionListener])

progression :: Trackable :: progression_listeners=

Listen to the progression of the operation.
fun save

neo4j :: GraphStore :: save

Save the graph.
abstract fun save_part(nodes: Collection[NeoNode], edges: Collection[NeoEdge])

neo4j :: GraphStore :: save_part

Save the specified part of the graph.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram neo4j::Neo4jGraphStore Neo4jGraphStore neo4j::GraphStore GraphStore neo4j::Neo4jGraphStore->neo4j::GraphStore progression::Trackable Trackable neo4j::GraphStore->progression::Trackable ...progression::Trackable ... ...progression::Trackable->progression::Trackable

Ancestors

interface Object

core :: Object

The root of the class hierarchy.
abstract class Trackable

progression :: Trackable

An operation that is trackable using a ProgressionListener.

Parents

abstract class GraphStore

neo4j :: GraphStore

A mean to save and load a Neo4j graph.

Class definitions

neo4j $ Neo4jGraphStore
# Save or load a graph using an actual Neo4j database.
class Neo4jGraphStore
	super GraphStore

	# The maximum number of entities saved in one request.
	#
	# Also defines the granulity of the reported progression.
	#
	# TODO Also honor this limit in `load`.
	var batch_max_size = 512 is writable

	# The Neo4j client to use.
	var client: Neo4jClient

	# The label to use to retrieve the nodes.
	var node_label: String

	private var done_part = 0
	private var total = 0

	# Is the database already contains at least one node with the specified label?
	fun has_node_label(name: String): Bool do
		var query = new CypherQuery.from_string(
				"match n where \{name\} in labels(n) return count(n)")
		query.params["name"] = name
		var data = client.cypher(query).as(JsonObject)["data"]
		var result = data.as(JsonArray).first.as(JsonArray).first.as(Int)
		return result > 0
	end

	redef fun isolated_save do return not has_node_label(node_label)

	redef fun load do
		assert batch_max_size > 0
		fire_started
		var db_nodes = client.nodes_with_label(node_label)
		var nodes = graph.nodes
		var edges = graph.edges
		var i = 0

		total = nodes.length * 2
		done_part = nodes.length
		fire_progressed(done_part, total)
		for node in db_nodes do
			nodes.add(node)
			edges.add_all(node.out_edges)
			i += 1
			if i >= batch_max_size then
				done_part += batch_max_size
				fire_progressed(done_part, total)
			end
		end
		fire_done
	end

	redef fun save_part(nodes, edges) do
		assert batch_max_size > 0
		fire_started
		total = nodes.length + edges.length
		done_part = 0

		save_entities(nodes)
		save_entities(edges)
		fire_done
	end

	# Save the specified entities.
	private fun save_entities(neo_entities: Collection[NeoEntity]) do
		var batch = new NeoBatch(client)
		var batch_length = 0

		for nentity in neo_entities do
			batch.save_entity(nentity)
			batch_length += 1
			if batch_length >= batch_max_size then
				do_batch(batch)
				done_part += batch_max_size
				fire_progressed(done_part, total)
				batch = new NeoBatch(client)
				batch_length = 0
			end
		end
		do_batch(batch)
		done_part += batch_length
	end

	# Execute `batch` and check for errors.
	#
	# Abort if `batch.execute` returns errors.
	private fun do_batch(batch: NeoBatch) do
		var errors = batch.execute
		assert errors.is_empty else
			for e in errors do sys.stderr.write("{e}\n")
		end
	end
end
lib/neo4j/graph/graph.nit:183,1--278,3