NoSQL Zone is brought to you in partnership with:

Taylor Cowan is an Architect Evangelist with Microsoft, based in Dallas, TX, where he focuses on the early adoption of Microsoft technologies for customers in Texas, Oklahoma, Arkansas, and Louisiana. He received his Master’s Degree in Computer Science from the University of North Texas, as well as a Bachelor of Music in Jazz Arranging. He is a founder and committer to the open source project jenabean, a Java to RDF binding framework. Taylor also has a special interest in other non-relational persistence and has written object bindings for both the neo4j graph database and Windows Azure storage. Taylor is a DZone MVB and is not an employee of DZone and has posted 6 posts at DZone. You can read more from them at their website. View Full User Profile

Ja.net Provides Support for Compilation of Java to .NET

03.29.2012
| 5685 views |
  • submit to reddit

I recently ran across a project called ja.net that provides support for compilation of Java to .Net.  Since neo4j has such a dependency clean kernel, I decided to try ja.net as a way of making neo4j usefull under .Net. (no slight against the RESTful interfaces, but perhaps you’d like to run neo4j on .net as an embedded graph DB under .Net). Here’s my VS2010 with the neo4j.dll referenced, and the object browser showing the EmbeddedGraphDB class as a first class .Net object:


 

Step #1 Download stuff

Download the neo4j kernel source and expand into a working directory. http://neo4j.org/download

Download the geronimo JTA spec src jar and expand under neo4j’s src/main/java directory. 

Install Ja.net from http://www.janetdev.org/

Step #2 Compile neo4j kernel using Ja.Net

C:\neo4j-kernel-1.0\src>c:\opt\java\Ja.NET\bin\javac -bam:neo4j.dll main

You can compile first then using the “bam” command to create the dll, or do it in one pass as I’ve done here.  You’ll see warnings, most look like compiler warnings, one may be of concern.  For now let’s just experiment.  No garauntees, promises, etc. 

Step #3 Create a C# console app, reference your newly created .dll, and give neo4j on .net a run.  Here’s my sample code:

class Program
{
static void Main(string[] args)
{
var graphDb = new EmbeddedGraphDatabase("graphdb");
var tx = graphDb.beginTx();
try
{
var firstNode = graphDb.createNode();
var secondNode = graphDb.createNode();
var relationship = firstNode.createRelationshipTo(
secondNode, DynamicRelationshipType.withName("KNOWS"));
firstNode.setProperty("message", "Hello, ");
secondNode.setProperty("message", "world!");
relationship.setProperty("message", "brave Neo4j ");
var i = graphDb.getAllNodes().iterator();
while (i.hasNext()) {
    var n = ((Node)i.next());
    if (n.hasProperty("message"))
    Console.WriteLine(n.getProperty("message"));
}
Console.WriteLine("bye");
tx.success();
}
finally
{
   tx.finish();
   graphDb.shutdown();
}
Console.ReadLine();
}

 

Published at DZone with permission of Taylor Cowan, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)