vraptor-neo4j

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

Categories

Categories

Neo4J Data Databases
GroupId

GroupId

br.com.caelum.vraptor
ArtifactId

ArtifactId

vraptor-neo4j
Last Version

Last Version

0.9.0
Release Date

Release Date

Type

Type

jar
Description

Description

vraptor-neo4j
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

http://maven.apache.org
Source Code Management

Source Code Management

http://github.com/caelum/vraptor-neo4j

Download vraptor-neo4j

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-neo4j/ -->
<dependency>
    <groupId>br.com.caelum.vraptor</groupId>
    <artifactId>vraptor-neo4j</artifactId>
    <version>0.9.0</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-neo4j/
implementation 'br.com.caelum.vraptor:vraptor-neo4j:0.9.0'
// https://jarcasting.com/artifacts/br.com.caelum.vraptor/vraptor-neo4j/
implementation ("br.com.caelum.vraptor:vraptor-neo4j:0.9.0")
'br.com.caelum.vraptor:vraptor-neo4j:jar:0.9.0'
<dependency org="br.com.caelum.vraptor" name="vraptor-neo4j" rev="0.9.0">
  <artifact name="vraptor-neo4j" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.caelum.vraptor', module='vraptor-neo4j', version='0.9.0')
)
libraryDependencies += "br.com.caelum.vraptor" % "vraptor-neo4j" % "0.9.0"
[br.com.caelum.vraptor/vraptor-neo4j "0.9.0"]

Dependencies

compile (2)

Group / Artifact Type Version
br.com.caelum : vraptor jar 3.3.1
org.neo4j : neo4j jar 1.4.M04

provided (1)

Group / Artifact Type Version
org.mortbay.jetty : servlet-api jar 3.0.20100224

test (2)

Group / Artifact Type Version
junit : junit jar 4.8.2
org.mockito : mockito-core jar 1.8.5

Project Modules

There are no modules declared in this project.

VRaptor Neo4j Plugin

The VRaptor Neo4j plugin aims to bring to VRaptor smooth integration to Neo4j graph database, by providing out of the box transaction control, Neo4j components dependency injection and easy indexing framework access.

How to use

You can enable the Neo4j VRaptor plugin by adding a context-param to your web.xml file:

<context-param>
    <param-name>br.com.caelum.vraptor.packages</param-name>
    <param-value>
        br.com.caelum.vraptor.neo4j
    </param-value>
</context-param>

After this, you'll need to tell VRaptor where is your Neo4j database stored (if you don't do this, VRaptor will assume /tmp/database directory):

<context-param>
	<param-name>br.com.caelum.vraptor.neo4j.database</param-name>
	<param-value>/some/directory</param-value>
</context-param>

Now, VRaptor will enable 3 components:

The Neo4jEmbeddedGraphDatabaseFactory

This ApplicationScoped component is responsible for manage and provide the EmbeddedGraphDatabase instance, so you can receive it in your components by VRaptor's dependency injection, just like:

@Resource
public class PersonController {
	private AbstractGraphDatabase db;
	
	public PersonController(AbstractGraphDatabase db) {
		this.db = db;
	}
	
	@Post
	public void save(Person p) {
		Node node = db.createNode();
		// and so on
	}
}

Now, using the EmbeddedGraphDatabase instance is just as simple as declaring it as a constructor argument.

The Neo4jIndexManagerFactory

Similar to the EmbeddedGraphDatabaseFactory, the IndexManagerFactory makes possible to receive by dependency injection the Neo4j Index Manager, with whom you can create new indexes, and search using Neo4j Lucene's integration, for instance.

@Resource
public class PersonController {
	private EmbeddedGraphDatabase db;
	private IndexManager index;
	
	public PersonController(EmbeddedGraphDatabase db, IndexManager index) {
		this.db = db;
		this.index = index;
	}
	
	@Get
	public void findByName(String nameToQuery) {
		Index<Node> nameIndex = index.forNodes("nameIndex");
		IndexHits<Node> hits = nameIndex.query("name", nameToQuery)
		// and so on
	}
}

The Neo4jTransactionInterceptor

The TransactionInterceptor takes care of correctly beginning, committing and if necessary, rolling back a Neo4j transaction. So, it is guaranteed that whenever you're creating a Node, the operation will happen inside a transaction. The transaction opens on the beginning of each request and is committed at the end of it. If a validation error or an exception occurs, the transaction is rolled back.

br.com.caelum.vraptor

Caelum

Versions

Version
0.9.0