Liferay Neo4j OSGi Driver

Neo4j Java Driver with OSGi support.

License

License

Categories

Categories

Neo4J Data Databases
GroupId

GroupId

com.liferay.neo4j
ArtifactId

ArtifactId

neo4j-osgi-driver
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

bundle
Description

Description

Liferay Neo4j OSGi Driver
Neo4j Java Driver with OSGi support.
Project URL

Project URL

https://github.com/matethurzo/liferay-neo4j-driver
Source Code Management

Source Code Management

https://github.com/matethurzo/liferay-neo4j-driver

Download neo4j-osgi-driver

Dependencies

compile (4)

Group / Artifact Type Version
org.neo4j.driver : neo4j-java-driver jar 1.4.4
org.osgi : org.osgi.service.component.annotations jar 1.3.0
org.osgi : org.osgi.service.metatype jar 1.3.0
biz.aQute.bnd : biz.aQute.bndlib jar 3.1.0

Project Modules

There are no modules declared in this project.

liferay-neo4j-driver

OSGi compatible version of the Neo4j Java driver brought to you by Liferay.

This driver is wrapping the official Neo4j Java language driver by adding OSGi compatibility. The Neo4j driver is being included as-is, we haven't modified anything on it. The output of this project is an OSGi bundle that you can deploy to your OSGi container and use the driver.

Currently we are wrapping the Neo4j Java driver 1.4.4 version. For more information on the driver itself please visit the official Neo4j site.

Features

  • The bundle exports the org.neo4j.driver.v1 package and all underlying packages. On the contrary the bundle does not export the internal packages (org.neo4j.driver.internal).
  • A GraphDatabase declarative service is being registered to the OSGi service registry. GraphDatabase provides basic support to access your Neo4j instance and run simple queries against it.
  • OSGi configuration support
  • Minor utility features

Planned features

  • Continuously release new versions as the Neo4j driver version increases
  • Provide a facility to get sessions or connections to multiple Neo4j instances and register them to the service registry
  • More sophisticated session and connection management through component services
  • Gradle build support

Usage

  • Clone this repository and call mvn clean install
  • Alternatively download the pre-built JAR file from this repository's target directory
  • In you maven project add this as a dependency
<groupId>com.liferay.neo4j</groupId>
<artifactId>neo4j-osgi-driver</artifactId>
<version>1.1.2</version>
  • In case you are using Liferay and developing a custom plugin, you can add this as a gradle dependency as well
compile 'com.liferay.neo4j:neo4j-osgi-driver:1.1.2'

Once you have the JAR file you can reference it as a compile time dependency. You can drop it to the OSGi container and the driver will be available for other bundles to use.

OSGi service configuration in Liferay

Go to Control Panel > Configuration > System Settings. Select 'Other' tab and find 'Liferay Neo4j Service Configuration'.

Fill out fields according to your environment, like the following:

Service configuration screenshot

Example code

@Component(immediate = true, service = NeoTest.class)
public class NeoTest {

	@Modified
	@Activate
	public void activate() {

		// Example 1

		GraphDatabaseResult result = _graphDatabase.runStatement(
			"MATCH (n:TestNode) return n");

		result.recordStream().forEach((record) -> _log.info(record.fields()));


		// Example 2
		// Rider nodes have an attribute called name

		result = _graphDatabase.runStatement("MATCH (r:Rider) return r");

		// Prints each rider's name to the console

		result.recordStream().map(
			(record) -> record.get("r").asNode().get("name")
		).forEach(
			System.out::println
		);

		// Example 3
		// Standard Neo4j driver methods

		Session session = _graphDatabase.getSession();

		session.run("CREATE (r:Rider {number: 46}) return r");

		session.close();

		// Example 4
		// Autoclosing session

		session = _graphDatabase.getAutoclosingSession(10000);

		session.run("CREATE (r:Rider {number: 9}) return r");
	}

	@Reference
	private GraphDatabase _graphDatabase;
}

Compatibility

  • Java 1.8
  • Neo4j Java Driver 1.4.4 and Neo4j Server 3.3
  • Tested with Liferay 7.0 GA2
  • For a sample Liferay 7.0 plugin with Neo4j support check out our sample repository

Versions

Version
1.1.2
1.1.1
1.1.0
1.0.2
1.0.0