Java Object Mapping on Neo4j
Join the DZone community and get the full member experience.Join For Free
NoSQL converts are fanatical about their methods Cowan said. "I was speaking at the Ordev conference and I saw a guy walk by with a shirt that said 'Ask me about my kick-ass graph database.'" That's how Cowan was introduced to the neo4j graph database by Emil Eifrem, the CEO of Neo Technology. In structure, it is very similar to a triple store, which receives data in very simple structures called "triples". A triple consists of a subject, a predicate (verb), and an object.
Neo4j is an embedded, disk-based, fully transactional Java persistence engine that stores data structured in graphs (mathematical lingo for networks) rather than in tables. These graphs consist of nodes and directional edges. Graph databases can allow more flexible, rapid styles of development with their cyclical or acyclical data structures. The databases are fairly scalable and they support transactions. These two ingredients are essential to web-scale applications.
"These graphs are very elegant at solving problems in the space of social networking," said Cowan. For example, a piece of software that shows people what their friends bought on a website will perform transitive closures with ease, either by walking the edges of the graph or letting the inference engine take care of it. Cowan says, "The types of queries become very simple and obvious to the developer." With graphs, there are no rigid schema and developers can make use of interesting algorithms like shortest paths, maximum flow, and minimum spanning tree.
Cowan soon became interested in making his own contribution to the NoSQL, graph database movement. "I got kind of excited that there was a lot of movement and interest in non-relational storage systems, and I'm kind of a graphy guy - I like graphs - and even though this isn't semantic web, it has a strong relationship to my previous research," said Cowan. "I realized I could take the R&D effort I had put into Jenabean and repurpose pieces of it back into being an object-to-graph mapper for neo4j. I called this project 'Java objects for Neo' (jo4neo)." Jo4neo is annotations based and there's no XML binding required. It's based on plain old Java reflection, so it doesn't require byte code interweaving. Cowan said, "It just takes clean Java classes that have been annotated, and follows those annotations as directions for how your objects can be persisted into the graph store."
Right now jo4neo is a young project - it's first release was in December. Cowan says he's been blogging about how to do different data patterns and is getting a lot of interest on Twitter and some news groups. One pattern, shown below, is the user-role pattern:
Cowan says, "Regardless of how comfortable we all are with storing data as a graph, at some point we're going to have to show that information to a consumer on a website or an application." Technologies like jo4neo will make it easy to bind objects to your view in the development of create-read-update applications. Cowan says, "If we can get neo4j data into an object, then we're good to go." He said that jo4neo bridges that gap between objects and the data store.
Opinions expressed by DZone contributors are their own.