CDI + jo4neo = Neo4j on Java EE 6

163 views
Skip to first unread message

Pascal Salg

unread,
Dec 20, 2012, 3:36:15 PM12/20/12
to jo4...@googlegroups.com

Here I want to present a project I have been working on for the past few weeks.

As my app server of choice is JBoss AS 7 I started experimenting with CDI Extensions.
(CDI = Context & Dependency Injection)

CDI implements extensibility by Portable Extensions which can be used by dropping the jar in your WEB-INF7lib directory..
Actually there is a whole lot more ways to extend the CDI framework (like custom qualifiers, stereotypes etc but for now let's stick to the subject "portable extensions" )

By implementing a cdi portable extension you can leverage the power of the JEE environment (like transactions, lifecycle mgmt by the container..)

So by implementing different listeners for lifecycle events we can perform startup tasks like initialization, validation, instanciation or cleanup and shutdown tasks

For including Neo4j in a project please have a look at http://docs.neo4j.org/chunked/stable/tutorials-java-embedded-setup.html


Basically what I did is this:

  1. Introduced a new Environment parameter "neo.path". The value for this system property will be set at server startup if proper configuration has been done. It is either passed as a parameter or it is contained in a neo.properties file.
    1. You can pass the parameter when running your server by appending "-Dneo.path=/path/to/file/neo.properties"
    2. You can pass it contained in a neo.properties file located in the src/META-INF directory (like persistence.xml would do..)
  2. I wrote a small container class (NeoORM.java) for the jo4neo object graph (this container later could be filled with other neo4j addons as well) 
    1. NeoORM.getObjectGraph() returns the jo4neo object graph
  3. I created a cutom qualifier annotation: "@NeoEntityManager". This annotation optionally takes a String as an argument which either points to a directory (where the neo4j db will reside) or it points to a neo.properties file.
  4. By using the annotation on a class member of type NeoORM a configured instance will be injected.
  5. Implemented some fallback strategies for instanciation e.g. the neo.path system property was not set and annotations don't use the String argument (from where would the neo4j db know where to run put its files) 

I have used jo4neo in a larger project and was happy with it as I was looking for an object-graph mapper other than Spring Data (one that is lightweight but still gets the job done).

But you know how it is, you always find new spots in your own code to "refactor" ;) That's when my idea of this portable extension was born.

Please let me know who to talk to regarding committing this to the current git repo.

Greetings from Germany,

p.salg

 

Peter Neubauer

unread,
Dec 21, 2012, 3:49:34 AM12/21/12
to jo4neo, community-team
Pascal,
great to hear you are finding jo4neo useful! It has been a bit dormant
during the last months, so I would suggest to clone the repo, do your
changes, write up a blog post and promote it - we would certainly help
to get people to try your fork!

WDYT?

/peter

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html

Taylor

unread,
Dec 25, 2012, 10:52:03 AM12/25/12
to jo4...@googlegroups.com
Hi Peter, Pascal
 
Peter, had we moved jo4neo to github?  I think it's still google code, I forget.  Pascal I can give you commit privs to the project.
<w:LsdExce...
Show original

Peter Neubauer

unread,
Dec 25, 2012, 2:10:19 PM12/25/12
to jo4neo
Taylor,
yes, the project is still on Google Code. I was thinking that a move
might be good since there is a lot more infrastructure on Github?

/peter

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


Pascal Salg

unread,
Dec 25, 2012, 2:38:23 PM12/25/12
to jo4...@googlegroups.com
Hi,

I found a github repo here (which just looks like a github clone of the svn repo at google code):
https://github.com/joostbaas/jo4neo

I then cloned the trunk and created a new github repo:
https://github.com/salgmachine/neoorm

So .. I'm good, I think I don't need commit privileges for jo4neo for now ;)

Greetings from Germany,
pascal
<w:LsdExce...
Show original
Reply all
Reply to author
Forward
0 new messages