Skip to content

LateralThoughts/hands-on-neo4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BIRGGIT - hands on Neo4J

Introduction

BIRGGIT: WTF?

BIRGGIT stands for: Barely-Implemented and Roughly Graph-based GIT. This is clearly not an industrial project and is just meant as a funny nerdy introduction to Neo4J.

Pre-requisites

  • JDK 7
  • Maven 3
  • Git 1.7+
  • a certain sense of humor

Domain

See src/main/java/com/github/lateralthoughts/hands_on_neo4j/domain.

Exercises

All exercises are versioned under src/test/java/Exercise_x_Test.java classes where x is a natural integer. Given that those are arranged by increasing difficulty, we strongly advise you to follow the suggested order.

Other classes that might be of your interest lie in com.github.lateralthoughts.birggit.domain and com.github.lateralthoughts.birggit.frontend.BIRGGIT: the actual frontend for all your almighty commands.

Unless mentioned otherwise, the exercises will mostly consist in conforming to the written tests by filling the "holes" left in com.github.lateralthoughts.birggit.frontend.BIRGGIT.

Exercise 1: create and commit!

Please execute: git checkout -f exercise_1.

Alright, you got it, BIRGGIT is just a brand new kick-ass versioning system. Let us start with basic operations. Open com.github.lateralthoughts.birggit.Exercise_1_Test and:

  1. register a project
  2. register a commit
  3. amend a commit
  4. big combo: commit to a branch of a project

Tips

As this is the first exercise, you might feel a bit lost.

Do not hesitate to check the test "infrastructure", i.e. com.github.lateralthoughts.birggit.framework.suite.GraphTestSuite. This class is responsible for starting up/shutting down an embedded Neo4J instance and exposes our software frontend class: com.github.lateralthoughts.birggit.frontend.BIRGGIT.

We also wanted to keep the code concise in our test classes and thus removed some boilerplate. To this extent, the most curious of you can check our custom AssertJ assertions for Neo4J (com.github.lateralthoughts.birggit.framework.assertions.Neo4jAssertions) as well as LabelFinder, RelationTypeFinder and PropertyFinder which are in charge on configuring/inferring respectively Neo4J Node label, Relationship type and properties.

Bonus

The current way of handling unicity constraint is kinda cumbersome. Try working with org.neo4j.graphdb.index.UniqueFactory.UniqueNodeFactory and org.neo4j.graphdb.index.UniqueFactory.UniqueRelationshipFactory as well as our crafted com.github.lateralthoughts.birggit.framework.annotations.GloballyUniqueIdentifier annotation.

Exercise 2: let's merge this sh*t!

Please execute: git checkout -f exercise_2. The goal of this phase is to discover a few tricks :

  • How to index data put into the Neo4j Graph using the embedded Lucene engine
  • How to get these data back, and create new nodes.

So the real-life goal to achieve is to merge two branches, we'll assume for the sake of simplicity that merging the branch feature into the branch master only consists in taking the last two commits of both branches and creating a third commit with the last two commits as parent. So if you're ready : Open com.github.lateralthoughts.birggit.Exercise_2_Test and let's merge !

Exercise 3: log me that!

Please execute: git checkout -f exercise_3. The goal of this exercise is to implement the real world feature of “git log”, that’s to say : “show me all the commits on a designated branch and optionally allow me to limit the number of results to be returned”. In Neo4J, this will help to understand the key concept of “Traversals”. A Traversal has its own “dsl” and allows you to follow a Graph using a start node and some conditions.

The full API Documentation is available here : http://docs.neo4j.org/chunked/stable/tutorial-traversal-java-api.html

Hint to start : org.neo4j.kernel.Traversal.description is the starting point Hint 2 : You can decide whether it will be Breadth First Search (BFS) or Depth First Search (DFS). Hint 3 : .traverse allows you to set the start node Hint 4 : relationships have a direction “INCOMING” or “OUTGOING”

Exercise 4: this is garbage!

Please execute: git checkout -f exercise_4. As many modern systems, BIRGGIT builds in a top-notch garbage collector. Well... the “top-nochness” is still up to you : you have to implement it :-) The main idea is to detect isolated commits (i.e. not in relation with any other nodes) and delete them, given they are not useful anymore.

To achieve so, let’s start playing with Cypher, the kick-ass query language developed by Neo4J. Open Exercise_4_Test and write the Cypher queries that:

  1. find a commit by its hash
  2. delete a commit by its hash
  3. delete commits by their hashes
  4. find disconnected commits

And finally: implement GC as you want! Craft a new query or re-use previous methods… feel free.

Resources:

About

Hands-on-Neo4j for the Duchess' Marmite

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages