neo4j :: Neo4jGraphStore :: batch_max_size
The maximum number of entities saved in one request.neo4j :: Neo4jGraphStore :: batch_max_size=
The maximum number of entities saved in one request.neo4j :: Neo4jGraphStore :: client=
The Neo4j client to use.neo4j :: Neo4jGraphStore :: defaultinit
neo4j :: Neo4jGraphStore :: has_node_label
Is the database already contains at least one node with the specified label?neo4j :: Neo4jGraphStore :: node_label
The label to use to retrieve the nodes.neo4j :: Neo4jGraphStore :: node_label=
The label to use to retrieve the nodes.neo4j $ Neo4jGraphStore :: SELF
Type of this instance, automatically specialized in every classneo4j $ Neo4jGraphStore :: isolated_save
Can we save the graph without conflict?neo4j $ Neo4jGraphStore :: save_part
Save the specified part of the graph.neo4j :: Neo4jGraphStore :: batch_max_size
The maximum number of entities saved in one request.neo4j :: Neo4jGraphStore :: batch_max_size=
The maximum number of entities saved in one request.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
neo4j :: Neo4jGraphStore :: client=
The Neo4j client to use.core :: Object :: defaultinit
progression :: Trackable :: defaultinit
neo4j :: Neo4jGraphStore :: defaultinit
neo4j :: GraphStore :: defaultinit
progression :: Trackable :: fire_done
Notice the registeredProgessionListener
that the operation is done.
progression :: Trackable :: fire_progressed
Notice the registeredProgessionListener
that the operation progressed.
progression :: Trackable :: fire_started
Notice the registeredProgessionListener
that the operation started.
neo4j :: Neo4jGraphStore :: has_node_label
Is the database already contains at least one node with the specified label?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
neo4j :: GraphStore :: isolated_save
Can we save the graph without conflict?neo4j :: Neo4jGraphStore :: node_label
The label to use to retrieve the nodes.neo4j :: Neo4jGraphStore :: node_label=
The label to use to retrieve the nodes.core :: Object :: output_class_name
Display class name on stdout (debug only).progression :: Trackable :: progression_listeners
Listen to the progression of the operation.progression :: Trackable :: progression_listeners=
Listen to the progression of the operation.neo4j :: GraphStore :: save_part
Save the specified part of the graph.ProgressionListener
.
# 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