A relationship between two nodes.

Relationships between nodes are a key part of a graph database. They allow for finding related data. Just like nodes, relationships can have properties.

Create a relationship:

var client = new Neo4jClient("http://neo4j:7474")
# Create nodes
var andres = new NeoNode
andres["name"] = "Andres"
var kate = new NeoNode
kate["name"] = "Kate"
# Create a relationship of type `LOVES`
var loves = new NeoEdge(andres, "LOVES", kate)
client.save_edge(loves)
assert loves.is_linked

Get an edge from DB:

var url = loves.url.to_s
var edge = client.load_edge(url)
assert edge.from["name"].to_s == "Andres"
assert edge.to["name"].to_s == "Kate"

Introduced properties

init defaultinit(from: NeoNode, rel_type: String, to: NeoNode)

neo4j :: NeoEdge :: defaultinit

fun from: NeoNode

neo4j :: NeoEdge :: from

Get from node
fun rel_type: nullable String

neo4j :: NeoEdge :: rel_type

Get edge type
fun to: NeoNode

neo4j :: NeoEdge :: to

Get to node

Redefined properties

redef type SELF: NeoEdge

neo4j $ NeoEdge :: SELF

Type of this instance, automatically specialized in every class
redef fun append_json_for(graph: NeoGraph, v: JsonSerializer)

neo4j :: json_graph_store $ NeoEdge :: append_json_for

Append the JSON representation of the relationship to the specified buffer.

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 [](key: String): nullable Serializable

neo4j :: NeoEntity :: []

Get the entity property at key
fun []=(key: String, value: nullable Serializable)

neo4j :: NeoEntity :: []=

Set the entity property value at key
abstract fun append_json_for(graph: NeoGraph, v: JsonSerializer)

neo4j :: NeoEntity :: append_json_for

Append the JSON representation of the entity to the specified buffer.
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.
init defaultinit(from: NeoNode, rel_type: String, to: NeoNode)

neo4j :: NeoEdge :: defaultinit

fun from: NeoNode

neo4j :: NeoEdge :: from

Get from node
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun has_key(key: String): Bool

neo4j :: NeoEntity :: has_key

Is the property key set?
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun id: nullable Int

neo4j :: NeoEntity :: id

Get the entity id if connected to base
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".
fun is_linked: Bool

neo4j :: NeoEntity :: is_linked

Is the entity linked to a Neo4j database?
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.
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).
fun properties: JsonObject

neo4j :: NeoEntity :: properties

In Neo4j, both nodes and relationships can contain properties.
fun rel_type: nullable String

neo4j :: NeoEdge :: rel_type

Get edge type
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.
fun to: NeoNode

neo4j :: NeoEdge :: to

Get to node
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun url: nullable String

neo4j :: NeoEntity :: url

Entity unique URL in Neo4j REST API
protected fun url=(url: nullable String)

neo4j :: NeoEntity :: url=

Entity unique URL in Neo4j REST API
package_diagram neo4j::NeoEdge NeoEdge neo4j::NeoEntity NeoEntity neo4j::NeoEdge->neo4j::NeoEntity core::Object Object neo4j::NeoEntity->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class NeoEntity

neo4j :: NeoEntity

The fundamental units that form a graph are nodes and relationships.

Class definitions

neo4j $ NeoEdge
# A relationship between two nodes.
# Relationships between nodes are a key part of a graph database.
# They allow for finding related data. Just like nodes, relationships can have properties.
#
# Create a relationship:
#
#     var client = new Neo4jClient("http://neo4j:7474")
#     # Create nodes
#     var andres = new NeoNode
#     andres["name"] = "Andres"
#     var kate = new NeoNode
#     kate["name"] = "Kate"
#     # Create a relationship of type `LOVES`
#     var loves = new NeoEdge(andres, "LOVES", kate)
#     client.save_edge(loves)
#     assert loves.is_linked
#
# Get an edge from DB:
#
#     var url = loves.url.to_s
#     var edge = client.load_edge(url)
#     assert edge.from["name"].to_s == "Andres"
#     assert edge.to["name"].to_s == "Kate"
class NeoEdge
	super NeoEntity

	private var internal_from: nullable NeoNode
	private var internal_to: nullable NeoNode
	private var internal_type: nullable String
	private var internal_from_url: nullable String
	private var internal_to_url: nullable String

	init(from: NeoNode, rel_type: String, to: NeoNode) do
		self.internal_from = from
		self.internal_to = to
		self.internal_type = rel_type
	end

	redef init from_neo(neo, url) do
		super
		var obj = neo.get(url).as(JsonObject)
		self.internal_type = obj["type"].to_s
		self.internal_from_url = obj["start"].to_s
		self.internal_to_url = obj["end"].to_s
	end

	redef init from_json(neo, obj) do
		super
		self.internal_type = obj["type"].to_s
		self.internal_from_url = obj["start"].to_s
		self.internal_to_url = obj["end"].to_s
	end

	# Get `from` node
	fun from: NeoNode do return internal_from or else load_from

	private fun load_from: NeoNode do
		var node = neo.load_node(internal_from_url.to_s)
		internal_from = node
		return node
	end

	# Get `to` node
	fun to: NeoNode do return internal_to or else load_to

	private fun load_to: NeoNode do
		var node = neo.load_node(internal_to_url.to_s)
		internal_to = node
		return node
	end

	# Get edge type
	fun rel_type: nullable String do return internal_type

	# Get the JSON body of a REST request that create the relationship.
	private fun to_rest: JsonObject do
		var obj = new JsonObject
		if to.is_linked then
			obj["to"] = to.url
		else
			obj["to"] = "\{{to.batch_id.to_s}\}"
		end
		obj["type"] = rel_type
		obj["data"] = properties
		return obj
	end
end
lib/neo4j/neo4j.nit:672,1--758,3

neo4j :: json_graph_store $ NeoEdge
redef class NeoEdge

	# Append the JSON representation of the relationship to the specified buffer.
	#
	# Use the IDs specfied by `graph.nodes`.
	redef fun append_json_for(graph, v) do
		v.stream.write "\{\"type\":"
		rel_type.as(not null).serialize_to(v)
		v.stream.write ",\"properties\":"
		properties.serialize_to(v)
		v.stream.write ",\"from\":"
		graph.nodes.id_of(from).serialize_to(v)
		v.stream.write ",\"to\":"
		graph.nodes.id_of(to).serialize_to(v)
		v.stream.write "}"
	end
end
lib/neo4j/graph/json_graph_store.nit:290,1--306,3