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

Entities can have two states:

  • linked: the NeoEntity references an existing node or edge in Neo4j
  • unlinked: the NeoEntity is not yet created in Neo4j

If the entity is initialized unlinked from neo4j:

var andres = new NeoNode
andres["name"] = "Andres"
# At this point, the node is not linked
assert not andres.is_linked

Then we can link the entity to the base:

var client = new Neo4jClient("http://neo4j:7474")
client.save_node(andres)
# The node is now linked
assert andres.is_linked

Entities can also be loaded from Neo4j:

var url = andres.url.to_s
var node = client.load_node(url)
assert node.is_linked

When working in connected mode, all reading operations are executed lazily on the base:

assert node["name"] == "Andres"

Introduced properties

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.
fun has_key(key: String): Bool

neo4j :: NeoEntity :: has_key

Is the property key set?
fun id: nullable Int

neo4j :: NeoEntity :: id

Get the entity id if connected to base
fun is_linked: Bool

neo4j :: NeoEntity :: is_linked

Is the entity linked to a Neo4j database?
fun properties: JsonObject

neo4j :: NeoEntity :: properties

In Neo4j, both nodes and relationships can contain properties.
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

Redefined properties

redef type SELF: NeoEntity

neo4j $ NeoEntity :: SELF

Type of this instance, automatically specialized in every class
redef init init

neo4j $ NeoEntity :: init

Create a empty (and not-connected) entity

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.
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 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.
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::NeoEntity NeoEntity core::Object Object neo4j::NeoEntity->core::Object neo4j::NeoNode NeoNode neo4j::NeoNode->neo4j::NeoEntity neo4j::NeoEdge NeoEdge neo4j::NeoEdge->neo4j::NeoEntity

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class NeoEdge

neo4j :: NeoEdge

A relationship between two nodes.
class NeoNode

neo4j :: NeoNode

Nodes are used to represent entities stored in base.

Class definitions

neo4j $ NeoEntity
# The fundamental units that form a graph are nodes and relationships.
#
# Entities can have two states:
#
# * linked: the NeoEntity references an existing node or edge in Neo4j
# * unlinked: the NeoEntity is not yet created in Neo4j
#
# If the entity is initialized unlinked from neo4j:
#
#     # Create a disconnected node
#     var andres = new NeoNode
#     andres["name"] = "Andres"
#     # At this point, the node is not linked
#     assert not andres.is_linked
#
# Then we can link the entity to the base:
#
#     # Init client
#     var client = new Neo4jClient("http://neo4j:7474")
#     client.save_node(andres)
#     # The node is now linked
#     assert andres.is_linked
#
# Entities can also be loaded from Neo4j:
#
#     # Get a node from Neo4j
#     var url = andres.url.to_s
#     var node = client.load_node(url)
#     assert node.is_linked
#
# When working in connected mode, all reading operations are executed lazily on the base:
#
#     # Get the node `name` property
#     assert node["name"] == "Andres"	# loaded lazily from base
abstract class NeoEntity
	# Neo4j client connector
	private var neo: Neo4jClient is noinit

	# Entity unique URL in Neo4j REST API
	var url: nullable String = null

	# Temp id used in batch mode to update the entity
	private var batch_id: nullable Int = null

	# Load the entity from base
	private init from_neo(neo: Neo4jClient, url: String) is nosuper do
		self.neo = neo
		self.url = url
	end

	# Init entity from JSON representation
	private init from_json(neo: Neo4jClient, obj: JsonObject) is nosuper do
		self.neo = neo
		self.url = obj["self"].to_s
		self.internal_properties = obj["data"].as(JsonObject)
	end

	# Create a empty (and not-connected) entity
	init do
		self.internal_properties = new JsonObject
	end

	# Is the entity linked to a Neo4j database?
	fun is_linked: Bool do return url != null

	# In Neo4j, both nodes and relationships can contain properties.
	# Properties are key-value pairs where the key is a string.
	# Property values are JSON formatted.
	#
	# Properties are loaded lazily
	fun properties: JsonObject do return internal_properties or else load_properties

	private var internal_properties: nullable JsonObject = null

	private fun load_properties: JsonObject do
		var obj = neo.get(url.to_s / "properties").as(JsonObject)
		internal_properties = obj
		return obj
	end

	# Get the entity `id` if connected to base
	fun id: nullable Int do
		if url == null then return null
		return url.split("/").last.to_i
	end

	# Get the entity property at `key`
	fun [](key: String): nullable Serializable do
		if not properties.has_key(key) then return null
		return properties[key]
	end

	# Set the entity property `value` at `key`
	fun []=(key: String, value: nullable Serializable) do properties[key] = value

	# Is the property `key` set?
	fun has_key(key: String): Bool do return properties.has_key(key)
end
lib/neo4j/neo4j.nit:455,1--552,3

neo4j :: json_graph_store $ NeoEntity
redef class NeoEntity

	# Append the JSON representation of the entity to the specified buffer.
	fun append_json_for(graph: NeoGraph, v: JsonSerializer) is abstract
end
lib/neo4j/graph/json_graph_store.nit:223,1--227,3