Hi
Me and Marius (http://blog.shortcut.no/blog/2008/5/8/nettverk) has been
playing around with an JRuby API for neo.
Is it possible to get access to a subversion laboratory account at neo ?
This is the experiment I did today
(Will look at traversal and relationship tomorrow and maybe a query API
using lucene)
# Example of usage
include Neo
start
class Person < Node
properties :name, :age
# relations :friend, :child
end
class Employee < Person
properties :salary
end
foo = Employee.new do |node| # this code body is run in a transaction
node.name = "kalle"
node.salary = 10
end
puts "Name #{foo.name}, salary: #{foo.salary}"
stop
#############
The code behind this
##############
include Java
module Neo
require 'neo-1.0-b6.jar'
require 'jta-spec1_0_1.jar'
EmbeddedNeo = org.neo4j.api.core.EmbeddedNeo
Transaction = org.neo4j.api.core.Transaction
def start
puts "start neo"
@@neo = EmbeddedNeo.new("var/neo")
end
def stop
@@neo.shutdown
end
def transaction
tx = Transaction.begin
begin
yield
tx.success
rescue Exception => e
raise e
ensure
tx.finish
end
end
def create_node
@@neo.createNode
end
class Node
def initialize
if block_given? # check if we should run in a transaction
transaction { @neo_node = Neo.create_node; yield self }
else
@neo_node = Neo.create_node
end
end
def Node.properties(*props)
props.each do |prop|
define_method(prop) do
@neo_node.get_property(prop.to_s)
end
name = (prop.to_s() +"=")
define_method(name) do |value|
@neo_node.set_property(prop.to_s, value)
end
end
end
end
end
_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user