Happy !

Citilab / Neo4St

Project infos

License MIT
Tags persistence neo4j database
Creation date 2013-02-13
Website

Monticello registration

About Neo4St

DESCRIPTION

Neo4St is an incomplete library providing native bindings for the Neo4j graph database, using Alien FFI and JNIPort.

Some functionalities are and might always be missing, as this is a project being coded ad-hoc to provide a persistence layer to another project, so only the necessary methods and classes have been ported.

BRIEF SNIPPET EXAMPLES

CONNECTING

N4Database 
    newWithJvmPath: '/usr/java/jre1.7.0_11/lib/i386/client/libjvm.so'
    neo4jPath: '/path/to/your/neo4j-community-1.9.M03/'

RETRIEVING A NODE BY ITS ID

N4Database singleton nodeAt: 1225

GETTING A RELATIONSHIP BY ITS ID

db relationshipAt: 1245

RETRIEVING AN INDEXED NODE

| index node |
index := N4Database singleton nodeIndexNamed: 'indexName'.
node := index getByKey: 'someKey' value: aValue

GETTING NODE PROPERTIES

node propertyAt: 'name'

GETTING RELATIONSHIP PROPERTIES

relationship propertyAt: 'date'

SETTING A NODE PROPERTY

aNode propertyAt: #name put: 'Billy'

TESTING WHETHER TWO NODES ARE RELATED

aNode isRelatedTo: anotherNode

TESTING WHETHER A NODE HAS A RELATIONSHIP WITH A GIVEN NAME

aNode hasRelationshipNamed: #friendOf

SETTING A RELATIONSHIP PROPERTY

aRelationship propertyAt: #weight put: 150

GETTING RELATED NODES

node nodesOutboundByRelationshipNamed: 'friendOf'

RELATING TWO NODES

aBoy relateTo: aGirl type: #friendOf

UNRELATING TWO NODES

aBoy unrelateTo: aGirl type: #friendOf

CREATING A NODE

db createNode

DELETING A NODE

node delete

HARD-DELETING A NODE

"deletes the node and all of its relationships, but not the related nodes"
node hardDelete

RETRIEVING ALL RELATIONSHIPS OF A NODE

node allRelationships

DELETING A RELATIONSHIP

relationship delete

WRAPPING OPERATIONS INSIDE A TRANSACTION

db transactionDo: [ "something" ]

A NOTE ON STORING VALUES IN PROPERTIES

Type conversion is a big pain, and specially so for a Smalltalker. Our approach has been to send #asJavaObjectWithJvm: to any Smalltalk object before sending it to Neo4j for storage in a key/value pair (and implement this method in all necessary classes).

The reverse operation is not automatically handled.

It is the developer's responsibility to re-convert Java objects into Smalltalk ones when retrieving them back from the Java world.

Take in account that Neo4j's setProperty() accepts only a certain set of types. That is why in some classes (like Date) the conversion needs to be handled in special ways. Please also note that storing non-homogeneous collections is not possible, as implied by the API documentation.

List of classes currently implementing #asJavaObjectWithJvm:

  • Boolean
  • Date ⚠ Converts into unix time
  • Integer
  • LargePositiveInteger
  • Float
  • String
  • Character

And SequenceableCollections (or subclasses) of:

  • Character
  • Boolean
  • String
  • Float
  • LargePositiveInteger
  • Integer

The rest of objects just return self upon recieving this message and will most probably cause a Java Exception to be raised. You'll need to write your own #asJavaObjectWithJvm: implementation for additional objects you need to store as values.