Nodes are used to represent entities stored in base.

Apart from properties and relationships (edges), nodes can also be labeled with zero or more labels.

A label is a String that is used to group nodes into sets. All nodes labeled with the same label belongs to the same set. A node may be labeled with any number of labels, including none, making labels an optional addition to the graph.

Creating new nodes:

var client = new Neo4jClient("http://neo4j:7474")

var andres = new NeoNode
andres.labels.add "Person"
andres["name"] = "Andres"
andres["age"] = 22
client.save_node(andres)
assert andres.is_linked

Get nodes from Neo4j:

var url = andres.url.to_s
var node = client.load_node(url)
assert node["name"] == "Andres"
assert node["age"].to_s.to_i    == 22

Introduced properties

init from_json(t: Text)

neo4j :: NeoNode :: from_json

Retrieve the node from the specified JSON value.
init from_json_object(o: JsonObject)

neo4j :: NeoNode :: from_json_object

Retrieve the node from the specified JSON value.
fun in_edges: List[NeoEdge]

neo4j :: NeoNode :: in_edges

Get the list of NeoEdge pointing to self
fun in_nodes(rel_type: String): Array[NeoNode]

neo4j :: NeoNode :: in_nodes

Get nodes pointing to self following a rel_type edge
fun labels: Array[String]

neo4j :: NeoNode :: labels

A label is a String that is used to group nodes into sets.
fun out_edges: List[NeoEdge]

neo4j :: NeoNode :: out_edges

Get the list of NeoEdge pointing from self
fun out_nodes(rel_type: String): Array[NeoNode]

neo4j :: NeoNode :: out_nodes

Get nodes pointed by self following a rel_type edge

Redefined properties

redef type SELF: NeoNode

neo4j $ NeoNode :: SELF

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

neo4j :: json_graph_store $ NeoNode :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
redef fun append_json_for(graph: NeoGraph, v: JsonSerializer)

neo4j :: json_graph_store $ NeoNode :: append_json_for

Append the JSON representation of the node to the specified buffer.
redef init init

neo4j $ NeoNode :: init

redef fun to_s: String

neo4j :: json_graph_store $ NeoNode :: to_s

User readable representation of self.
redef fun to_s: String

neo4j $ NeoNode :: to_s

User readable representation of self.

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
protected fun accept_json_serializer(v: JsonSerializer)

serialization :: Serializable :: accept_json_serializer

Refinable service to customize the serialization of this class to JSON
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)

serialization :: Serializable :: accept_msgpack_attribute_counter

Hook to customize the behavior of the AttributeCounter
protected fun accept_msgpack_serializer(v: MsgPackSerializer)

serialization :: Serializable :: accept_msgpack_serializer

Hook to customize the serialization of this class to MessagePack
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)

serialization :: Serializable :: add_to_bundle

Called by []= to dynamically choose the appropriate method according
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.
fun core_serialize_to(serializer: Serializer)

serialization :: Serializable :: core_serialize_to

Actual serialization of self to serializer
init from_deserializer(deserializer: Deserializer)

serialization :: Serializable :: from_deserializer

Create an instance of this class from the deserializer
init from_json(t: Text)

neo4j :: NeoNode :: from_json

Retrieve the node from the specified JSON value.
init from_json_object(o: JsonObject)

neo4j :: NeoNode :: from_json_object

Retrieve the node from the specified JSON value.
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
fun in_edges: List[NeoEdge]

neo4j :: NeoNode :: in_edges

Get the list of NeoEdge pointing to self
fun in_nodes(rel_type: String): Array[NeoNode]

neo4j :: NeoNode :: in_nodes

Get nodes pointing to self following a rel_type edge
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.
fun labels: Array[String]

neo4j :: NeoNode :: labels

A label is a String that is used to group nodes into sets.
protected fun msgpack_extra_array_items: Int

serialization :: Serializable :: msgpack_extra_array_items

Hook to request a larger than usual metadata array
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun out_edges: List[NeoEdge]

neo4j :: NeoNode :: out_edges

Get the list of NeoEdge pointing from self
fun out_nodes(rel_type: String): Array[NeoNode]

neo4j :: NeoNode :: out_nodes

Get nodes pointed by self following a rel_type edge
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 serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun serialize_msgpack(plain: nullable Bool): Bytes

serialization :: Serializable :: serialize_msgpack

Serialize self to MessagePack bytes
fun serialize_to(serializer: Serializer)

serialization :: Serializable :: serialize_to

Serialize self to serializer
fun serialize_to_json(plain: nullable Bool, pretty: nullable Bool): String

serialization :: Serializable :: serialize_to_json

Serialize self to JSON
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to_json: String

serialization :: Serializable :: to_json

Serialize self to plain JSON
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_pretty_json: String

serialization :: Serializable :: to_pretty_json

Serialize self to plain pretty JSON
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::NeoNode NeoNode neo4j::NeoEntity NeoEntity neo4j::NeoNode->neo4j::NeoEntity serialization::Serializable Serializable neo4j::NeoNode->serialization::Serializable core::Object Object neo4j::NeoEntity->core::Object serialization::Serializable->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.
interface Serializable

serialization :: Serializable

Instances of this class can be passed to Serializer::serialize

Class definitions

neo4j $ NeoNode
# Nodes are used to represent entities stored in base.
# Apart from properties and relationships (edges),
# nodes can also be labeled with zero or more labels.
#
# A label is a `String` that is used to group nodes into sets.
# All nodes labeled with the same label belongs to the same set.
# A node may be labeled with any number of labels, including none,
# making labels an optional addition to the graph.
#
# Creating new nodes:
#
#     var client = new Neo4jClient("http://neo4j:7474")
#
#     var andres = new NeoNode
#     andres.labels.add "Person"
#     andres["name"] = "Andres"
#     andres["age"] = 22
#     client.save_node(andres)
#     assert andres.is_linked
#
# Get nodes from Neo4j:
#
#     var url = andres.url.to_s
#     var node = client.load_node(url)
#     assert node["name"] == "Andres"
#     assert node["age"].to_s.to_i	== 22
class NeoNode
	super NeoEntity

	private var internal_labels: nullable Array[String] = null
	private var internal_in_edges: nullable List[NeoEdge] = null
	private var internal_out_edges: nullable List[NeoEdge] = null

	init do
		super
		self.internal_labels = new Array[String]
		self.internal_in_edges = new List[NeoEdge]
		self.internal_out_edges = new List[NeoEdge]
	end

	redef fun to_s do
		var tpl = new FlatBuffer
		tpl.append "\{"
		tpl.append "labels: [{labels.join(", ")}],"
		tpl.append "data: {properties.to_json}"
		tpl.append "\}"
		return tpl.write_to_string
	end

	# A label is a `String` that is used to group nodes into sets.
	# A node may be labeled with any number of labels, including none.
	# All nodes labeled with the same label belongs to the same set.
	#
	# Many database queries can work with these sets instead of the whole graph,
	# making queries easier to write and more efficient.
	#
	# Labels are loaded lazily
	fun labels: Array[String] do return internal_labels or else load_labels

	private fun load_labels: Array[String] do
		var labels = new Array[String]
		var res = neo.get(url.to_s / "labels")
		if res isa JsonArray then
			for val in res do labels.add val.to_s
		end
		internal_labels = labels
		return labels
	end

	# Get the list of `NeoEdge` pointing to `self`
	#
	# Edges are loaded lazily
	fun in_edges: List[NeoEdge] do return internal_in_edges or else load_in_edges

	private fun load_in_edges: List[NeoEdge] do
		var edges = new List[NeoEdge]
		var res = neo.get(url.to_s / "relationships/in").as(JsonArray)
		for obj in res do
			edges.add(new NeoEdge.from_json(neo, obj.as(JsonObject)))
		end
		internal_in_edges = edges
		return edges
	end

	# Get the list of `NeoEdge` pointing from `self`
	#
	# Edges are loaded lazily
	fun out_edges: List[NeoEdge] do return internal_out_edges or else load_out_edges

	private fun load_out_edges: List[NeoEdge] do
		var edges = new List[NeoEdge]
		var res = neo.get(url.to_s / "relationships/out")
		for obj in res.as(JsonArray) do
			edges.add(new NeoEdge.from_json(neo, obj.as(JsonObject)))
		end
		internal_out_edges = edges
		return edges
	end

	# Get nodes pointed by `self` following a `rel_type` edge
	fun out_nodes(rel_type: String): Array[NeoNode] do
		var res = new Array[NeoNode]
		for edge in out_edges do
			if edge.rel_type == rel_type then res.add edge.to
		end
		return res
	end

	# Get nodes pointing to `self` following a `rel_type` edge
	fun in_nodes(rel_type: String): Array[NeoNode] do
		var res = new Array[NeoNode]
		for edge in in_edges do
			if edge.rel_type == rel_type then res.add edge.from
		end
		return res
	end
end
lib/neo4j/neo4j.nit:554,1--670,3

neo4j :: json_graph_store $ NeoNode
# Make `NeoNode` `Serializable`.
redef class NeoNode
	super Serializable

	# Retrieve the node from the specified JSON value.
	#
	# Note: Here, the `"id"` is optional and ignored.
	#
	# SEE: `JsonGraph`
	#
	#     var node = new NeoNode.from_json("""
	#     {
	#	"labels": ["foo", "Bar"],
	#	"properties": {
	#		"baz": 42
	#	}
	#     }
	#     """)
	#     assert ["foo", "Bar"] == node.labels
	#     assert 42 == node["baz"]
	init from_json(t: Text) do
		from_json_object(t.parse_json.as(JsonObject))
	end

	# Retrieve the node from the specified JSON value.
	#
	# Note: Here, the `"id"` is optional and ignored.
	#
	# SEE: `JsonGraph`
	init from_json_object(o: JsonObject) do
		init
		var labels = o["labels"].as(JsonArray)
		for lab in labels do self.labels.add(lab.as(String))
		var json_properties = o["properties"].as(JsonObject)
		properties.add_all(json_properties)
	end

	redef fun accept_json_serializer(v) do
		v.stream.write "\{\"labels\":["
		var i = labels.iterator
		if i.is_ok then
			i.item.serialize_to v
			i.next
			for lab in i do
				v.stream.write ","
				lab.serialize_to v
			end
		end
		v.stream.write "],\"properties\":"
		properties.serialize_to v
		v.stream.write "}"
	end

	redef fun to_s do return to_json

	# Append the JSON representation of the node to the specified buffer.
	redef fun append_json_for(graph, v) do
		accept_json_serializer v
	end
end
lib/neo4j/graph/json_graph_store.nit:229,1--288,3